1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
/*-----------------------------------------------------------------
LOG
GEM - Graphics Environment for Multimedia
GemPixUtil.h
- contains image functions for pix objects
- part of GEM
Copyright (c) 1997-1999 Mark Danks. mark@danks.org
Copyright (c) Günther Geiger. geiger@epy.co.at
Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM. zmoelnig@iem.kug.ac.at
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-----------------------------------------------------------------*/
#ifndef INCLUDE_GEMPIXUTIL_H_
#define INCLUDE_GEMPIXUTIL_H_
#include "Base/GemGL.h"
#ifdef __APPLE__
# include <QuickTime/QuickTime.h>
#endif // __APPLE__
#include <string.h>
#include <stdlib.h>
///////////////////////////////////////////////////////////////////////////////
// Color component defines
//
// These should be used to reference the various color channels
///////////////////////////////////////////////////////////////////////////////
/* RGBA */
#if GL_RGBA_GEM == GL_RGBA
const int chRed = 0;
const int chGreen = 1;
const int chBlue = 2;
const int chAlpha = 3;
#else
const int chAlpha = 0;
const int chRed = 1;
const int chGreen = 2;
const int chBlue = 3;
#endif
/* Gray */
const int chGray = 0;
/* YUV422 */
const int chU = 0;
const int chY0 = 1;
const int chV = 2;
const int chY1 = 3;
// basic helper functions, like CLAMP and powerOfTwo
#include "Base/GemFuncUtil.h"
// utility functions from PeteHelpers.h
#include "Base/GemPixPete.h"
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
imageStruct
The basic image structure
-----------------------------------------------------------------*/
// we now have a class "imageStruct";
// since i need to compile some of the sources with an older version of Gem
// there is a new define here:
#define IMAGE_CLASS
struct GEM_EXTERN imageStruct
{
imageStruct();
~imageStruct();
void info();
//////////
// columns
unsigned char* allocate(size_t size);
unsigned char* allocate();
// if we have allocated some space already, only re-allocate when needed.
unsigned char* reallocate(size_t size);
unsigned char* reallocate();
// delete the buffer (if it is ours)
void clear();
//////////
// dimensions of the image
GLint xsize;
GLint ysize;
//////////
// (average) width of 1 pixel (LUMINANCE = 1, RGBA = 4, YUV = 2)
GLint csize;
//////////
// data type - always GL_UNSIGNED_BYTE (except for OS X)
GLenum type;
//////////
// the format - either GL_RGBA, GL_LUMINANCE
// or GL_YCBCR_422_GEM (which is on mac-computers GL_YCBCR_422_APPLE)
GLenum format;
//////////
// is this owned by us (? what about underscores ?)
int notowned;
//////////
// gets a pixel
/* X,Y are the coordinates
* C is the offset in the interleaved data (like chRed==0 for red)
* you should use chRed instead of 0 (because it might not be 0)
*/
// heck, why are X&Y swapped ?? (JMZ)
inline unsigned char GetPixel(int Y, int X, int C)
{ return(data[Y * xsize * csize + X * csize + C]); }
//////////
// sets a pixel
/* while X and Y should be clear (coordinates),
* C is the offset (like chRed==0 for red).
* VAL is the value to set.
*/
inline void SetPixel(int Y, int X, int C, unsigned char VAL)
{ data[Y * xsize * csize + X * csize + C] = VAL; }
/////////
// gets the color of a pixel
void getRGB(int X, int Y, unsigned char*r, unsigned char*g, unsigned char*b);
void getGrey(int X, int Y, unsigned char*g);
void getYUV(int X, int Y, unsigned char*y, unsigned char*u, unsigned char*v);
/* following will set the whole image-data to either black or white
* the size of the image-data is NOT xsize*ysize*csize but datasize
* this is mostly slower
* i have put the datasize into private (like pdata) (bad idea?)
*/
void setBlack();
void setWhite();
/* certain formats are bound to certain csizes,
* it's quite annoying to have to think again and again (ok, not much thinking)
* so we just give the format (like GL_LUMINANCE)
* and it will set the image format to this format
* and set and return the correct csize (like 1)
* if no format is given the current format is used
*/
int setCsizeByFormat(int format);
int setCsizeByFormat();
/* various copy functions
* sometimes we want to copy the whole image (including pixel-data),
* but often it is enough to just copy the meta-data (without pixel-data)
* into a new imageStruct
*/
void copy2Image(imageStruct *to);
void copy2ImageStruct(imageStruct *to); // copy the imageStruct (but not the actual data)
/* this is a sort of better copy2Image,
* which only copies the imageStruct-data if it is needed
*/
void refreshImage(imageStruct *to);
/* inplace swapping Red and Blue channel */
void swapRedBlue ();
///////////////////////////////////////////////////////////////////////////////
// acquiring data including colour-transformations
// should be accelerated if possible
/* i wonder whether this is the right place to put these routines
* they should be stored somewhere centrally
* (because maybe a lot of objects would like them) (like [pix_rgba]...)
* but it might be better to put them (the actual conversion routines) into
* separate files (a separate library?)
* orgdata points to the actual data in the given format
* the datasize will be read from image.xsize, image.ysize
* the dest-format will be given by image.format
* this is maybe not really clean (the meta-data is stored in the destination,
* while the source has no meta-data of its own)
*/
void convertTo (imageStruct*to, GLenum dest_format=0);
void convertFrom(imageStruct*from, GLenum dest_format=0);
void fromRGB (unsigned char* orgdata);
void fromRGBA (unsigned char* orgdata);
void fromBGR (unsigned char* orgdata);
void fromBGRA (unsigned char* orgdata);
void fromRGB16 (unsigned char* orgdata);
void fromGray (unsigned char* orgdata);
void fromGray (short* orgdata);
void fromUYVY (unsigned char* orgdata);
void fromYUY2 (unsigned char* orgdata); // YUYV
void fromYVYU (unsigned char* orgdata);
/* planar YUV420: this is rather generic and not really YV12 only */
void fromYV12 (unsigned char* Y, unsigned char*U, unsigned char*V);
/* assume that the planes are near each other: YVU */
void fromYV12 (unsigned char* orgdata);
/* assume that the planes are near each other: YVU */
void fromYU12 (unsigned char* orgdata);
/* overloading the above two in order to accept pdp YV12 packets */
void fromYV12 (short* Y, short*U, short*V);
void fromYV12 (short* orgdata);
/* aliases */
void fromYUV422 (unsigned char* orgdata){fromUYVY(orgdata);}
void fromYUV420P(unsigned char* orgdata){fromYV12(orgdata);}
void fromYUV420P(unsigned char*Y,unsigned char*U,unsigned char*V){fromYV12(Y,U,V);}
// "data" points to the image.
// the memory could(!) be reserved by this class or someone else
// "notowned" should be set to "1", if "data" points to foreign memory
// "data" is not freed directly, when the destructor is called
unsigned char *data; // the pointer to the data
private:
// "pdata" is the private data, and is the memory reserved by this class
// this data is freed when the destructor is called
unsigned char *pdata;
// "datasize" is the size of data reserved at "pdata"
size_t datasize;
public:
//////////
// true if the image is flipped horizontally (origin is upper-left)
// false if the image is openGL-conformant (origin is lower-left)
GLboolean upsidedown;
};
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
pixBlock
The pix block structure
-----------------------------------------------------------------*/
struct GEM_EXTERN pixBlock
{
pixBlock();
//////////
// the block's image
imageStruct image;
//////////
// is this a newimage since last time?
// ie, has it been refreshed
int newimage;
//////////
// keeps track of when new films are loaded
// useful for rectangle_textures on OSX
int newfilm;
};
///////////////////////////////////////////////////////////////////////////////
// imageStruct utility functions
//
///////////////////////////////////////////////////////////////////////////////
//////////
// copies all of the data over and mallocs memory
GEM_EXTERN extern void copy2Image(imageStruct *to, imageStruct *from);
//////////
// assumes that it only has to refresh the data
GEM_EXTERN extern void refreshImage(imageStruct *to, imageStruct *from);
GEM_EXTERN extern int getPixFormat(char*);
#endif // GEMPIXUTIL_H_
|