4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of libc3.
8 libc3 is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 libc3 is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with libc3. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef __C3PIXELS_H___
24 #define __C3PIXELS_H___
36 typedef struct c3pixels_t {
37 str_p name; // optional
38 uint32_t w, h; // width & height in pixels
39 size_t row; // size of one row in bytes
40 void * base; // base address
44 uint32_t own : 1, // is the base our own to delete
45 alloc : 1, // is the c3pixels_p our own to delete
46 dirty : 1, // pixels have been changed
47 psize : 4, // pixel size in byte
48 normalize : 1, // texture coordinates are 0...1
50 format : 8; // not used internally
54 c3apiobject_t texture;
55 int refCount; // TODO: Implement reference counting ?
56 } c3pixels_t, *c3pixels_p;
58 DECLARE_C_ARRAY(c3pixels_p, c3pixels_array, 4);
60 //! Allocates a new c3pixels, also allocates the pixels if row == NULL
65 int psize /* in bytes */,
69 //! Initializes p, also allocates the pixels if row == NULL
75 int psize /* in bytes */,
79 //! Dispose of the pixels, and potentially p if it was allocated with c3pixels_new
84 //! Disposes of the pixels, only
89 //! (Re)allocate pixels if pixels had been purged
94 //! Get a pixel address
100 return ((uint8_t*)p->base) + (y * p->row) + (x * p->psize);
103 //! Zeroes the pixels
108 IMPLEMENT_C_ARRAY(c3pixels_array);
110 #endif /* __C3PIXELS_H___ */