1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "cr_pixeldata.h"
|
---|
8 | #include "cr_error.h"
|
---|
9 | #include "cr_mem.h"
|
---|
10 | #include "cr_version.h"
|
---|
11 |
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Maybe export this someday.
|
---|
15 | */
|
---|
16 | static int crSizeOfType( GLenum type )
|
---|
17 | {
|
---|
18 | switch (type) {
|
---|
19 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
20 | case GL_UNSIGNED_BYTE_3_3_2:
|
---|
21 | case GL_UNSIGNED_BYTE_2_3_3_REV:
|
---|
22 | #endif
|
---|
23 | case GL_UNSIGNED_BYTE:
|
---|
24 | case GL_BYTE:
|
---|
25 | return 1;
|
---|
26 | case GL_BITMAP:
|
---|
27 | return 0; /* special case */
|
---|
28 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
29 | case GL_UNSIGNED_SHORT_5_6_5:
|
---|
30 | case GL_UNSIGNED_SHORT_5_6_5_REV:
|
---|
31 | case GL_UNSIGNED_SHORT_5_5_5_1:
|
---|
32 | case GL_UNSIGNED_SHORT_1_5_5_5_REV:
|
---|
33 | case GL_UNSIGNED_SHORT_4_4_4_4:
|
---|
34 | case GL_UNSIGNED_SHORT_4_4_4_4_REV:
|
---|
35 | #endif
|
---|
36 | case GL_UNSIGNED_SHORT:
|
---|
37 | case GL_SHORT:
|
---|
38 | return 2;
|
---|
39 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
40 | case GL_UNSIGNED_INT_8_8_8_8:
|
---|
41 | case GL_UNSIGNED_INT_8_8_8_8_REV:
|
---|
42 | case GL_UNSIGNED_INT_10_10_10_2:
|
---|
43 | case GL_UNSIGNED_INT_2_10_10_10_REV:
|
---|
44 | #endif
|
---|
45 | case GL_UNSIGNED_INT:
|
---|
46 | case GL_INT:
|
---|
47 | case GL_FLOAT:
|
---|
48 | return 4;
|
---|
49 | case GL_DOUBLE:
|
---|
50 | return 8;
|
---|
51 | default:
|
---|
52 | crError( "Unknown pixel type in crSizeOfType: 0x%x", (unsigned int) type );
|
---|
53 | return 0;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Compute bytes per pixel for the given format/type combination.
|
---|
60 | * \return bytes per pixel or -1 for invalid format or type, 0 for bitmap data.
|
---|
61 | */
|
---|
62 | int crPixelSize( GLenum format, GLenum type )
|
---|
63 | {
|
---|
64 | int bytes = 1; /* picky Windows compiler, we override later */
|
---|
65 |
|
---|
66 | switch (type) {
|
---|
67 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
68 | case GL_UNSIGNED_BYTE_3_3_2:
|
---|
69 | case GL_UNSIGNED_BYTE_2_3_3_REV:
|
---|
70 | return 1;
|
---|
71 | #endif
|
---|
72 | case GL_UNSIGNED_BYTE:
|
---|
73 | case GL_BYTE:
|
---|
74 | bytes = 1;
|
---|
75 | break;
|
---|
76 | case GL_BITMAP:
|
---|
77 | return 0; /* special case */
|
---|
78 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
79 | case GL_UNSIGNED_SHORT_5_6_5:
|
---|
80 | case GL_UNSIGNED_SHORT_5_6_5_REV:
|
---|
81 | case GL_UNSIGNED_SHORT_5_5_5_1:
|
---|
82 | case GL_UNSIGNED_SHORT_1_5_5_5_REV:
|
---|
83 | case GL_UNSIGNED_SHORT_4_4_4_4:
|
---|
84 | case GL_UNSIGNED_SHORT_4_4_4_4_REV:
|
---|
85 | return 2;
|
---|
86 | #endif
|
---|
87 | case GL_UNSIGNED_SHORT:
|
---|
88 | case GL_SHORT:
|
---|
89 | bytes = 2;
|
---|
90 | break;
|
---|
91 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
92 | case GL_UNSIGNED_INT_8_8_8_8:
|
---|
93 | case GL_UNSIGNED_INT_8_8_8_8_REV:
|
---|
94 | case GL_UNSIGNED_INT_10_10_10_2:
|
---|
95 | case GL_UNSIGNED_INT_2_10_10_10_REV:
|
---|
96 | return 4;
|
---|
97 | #endif
|
---|
98 | case GL_UNSIGNED_INT:
|
---|
99 | case GL_INT:
|
---|
100 | case GL_FLOAT:
|
---|
101 | bytes = 4;
|
---|
102 | break;
|
---|
103 | default:
|
---|
104 | crWarning( "Unknown pixel type in crPixelSize: type:0x%x(fmt:0x%x)", (unsigned int) type, (unsigned int) format);
|
---|
105 | return 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | switch (format) {
|
---|
109 | case GL_COLOR_INDEX:
|
---|
110 | case GL_STENCIL_INDEX:
|
---|
111 | case GL_DEPTH_COMPONENT:
|
---|
112 | case GL_RED:
|
---|
113 | case GL_GREEN:
|
---|
114 | case GL_BLUE:
|
---|
115 | case GL_ALPHA:
|
---|
116 | case GL_LUMINANCE:
|
---|
117 | case GL_INTENSITY:
|
---|
118 | break;
|
---|
119 | case GL_LUMINANCE_ALPHA:
|
---|
120 | bytes *= 2;
|
---|
121 | break;
|
---|
122 | case GL_RGB:
|
---|
123 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
124 | case GL_BGR:
|
---|
125 | #endif
|
---|
126 | bytes *= 3;
|
---|
127 | break;
|
---|
128 | case GL_RGBA:
|
---|
129 | #ifdef GL_ABGR_EXT
|
---|
130 | case GL_ABGR_EXT:
|
---|
131 | #endif
|
---|
132 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
133 | case GL_BGRA:
|
---|
134 | #endif
|
---|
135 | bytes *= 4;
|
---|
136 | break;
|
---|
137 | default:
|
---|
138 | crWarning( "Unknown pixel format in crPixelSize: type:0x%x(fmt:0x%x)", (unsigned int) type, (unsigned int) format);
|
---|
139 | return 0;
|
---|
140 | }
|
---|
141 |
|
---|
142 | return bytes;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | #define BYTE_TO_FLOAT(b) ((b) * (1.0/127.0))
|
---|
147 | #define FLOAT_TO_BYTE(f) ((GLbyte) ((f) * 127.0))
|
---|
148 |
|
---|
149 | #define UBYTE_TO_FLOAT(b) ((b) * (1.0/255.0))
|
---|
150 | #define FLOAT_TO_UBYTE(f) ((GLbyte) ((f) * 255.0))
|
---|
151 |
|
---|
152 | #define SHORT_TO_FLOAT(s) ((s) * (1.0/32768.0))
|
---|
153 | #define FLOAT_TO_SHORT(f) ((GLshort) ((f) * 32768.0))
|
---|
154 |
|
---|
155 | #define USHORT_TO_FLOAT(s) ((s) * (1.0/65535.0))
|
---|
156 | #define FLOAT_TO_USHORT(f) ((GLushort) ((f) * 65535.0))
|
---|
157 |
|
---|
158 | #define INT_TO_FLOAT(i) ((i) * (1.0F/2147483647.0))
|
---|
159 | #define FLOAT_TO_INT(f) ((GLint) ((f) * 2147483647.0))
|
---|
160 |
|
---|
161 | #define UINT_TO_FLOAT(i) ((i) * (1.0F / 4294967295.0F))
|
---|
162 | #define FLOAT_TO_UINT(f) ((GLuint) ((f) * 4294967295.0))
|
---|
163 |
|
---|
164 |
|
---|
165 | #ifdef _MSC_VER
|
---|
166 | /** @todo bird: MSC takes 5..20 mins to compile get_row and/or put_row with global
|
---|
167 | * optimizations enabled. It varies a bit between 8.0/64 and 7.1/32 - the latter seems
|
---|
168 | * to be fine with just disabling opts for get_row, while the former needs both to be
|
---|
169 | * disabled to compile it a decent time. It seems this isn't important code after all,
|
---|
170 | * so we're not overly worried about the performance degration. Even so, we might want
|
---|
171 | * to look into it before long, perhaps checking with Visual C++ 9.0 (aka 2008). */
|
---|
172 | # pragma optimize("g", off)
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | /*
|
---|
176 | * Pack src pixel data into tmpRow array as either GLfloat[][1] or
|
---|
177 | * GLfloat[][4] depending on whether the format is for colors.
|
---|
178 | */
|
---|
179 | static void
|
---|
180 | get_row(const char *src, GLenum srcFormat, GLenum srcType,
|
---|
181 | GLsizei width, GLfloat *tmpRow)
|
---|
182 | {
|
---|
183 | const GLbyte *bSrc = (GLbyte *) src;
|
---|
184 | const GLubyte *ubSrc = (GLubyte *) src;
|
---|
185 | const GLshort *sSrc = (GLshort *) src;
|
---|
186 | const GLushort *usSrc = (GLushort *) src;
|
---|
187 | const GLint *iSrc = (GLint *) src;
|
---|
188 | const GLuint *uiSrc = (GLuint *) src;
|
---|
189 | const GLfloat *fSrc = (GLfloat *) src;
|
---|
190 | const GLdouble *dSrc = (GLdouble *) src;
|
---|
191 | int i;
|
---|
192 |
|
---|
193 | if (srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX) {
|
---|
194 | switch (srcType) {
|
---|
195 | case GL_BYTE:
|
---|
196 | for (i = 0; i < width; i++)
|
---|
197 | tmpRow[i] = (GLfloat) bSrc[i];
|
---|
198 | break;
|
---|
199 | case GL_UNSIGNED_BYTE:
|
---|
200 | for (i = 0; i < width; i++)
|
---|
201 | tmpRow[i] = (GLfloat) ubSrc[i];
|
---|
202 | break;
|
---|
203 | case GL_SHORT:
|
---|
204 | for (i = 0; i < width; i++)
|
---|
205 | tmpRow[i] = (GLfloat) sSrc[i];
|
---|
206 | break;
|
---|
207 | case GL_UNSIGNED_SHORT:
|
---|
208 | for (i = 0; i < width; i++)
|
---|
209 | tmpRow[i] = (GLfloat) usSrc[i];
|
---|
210 | break;
|
---|
211 | case GL_INT:
|
---|
212 | for (i = 0; i < width; i++)
|
---|
213 | tmpRow[i] = (GLfloat) iSrc[i];
|
---|
214 | break;
|
---|
215 | case GL_UNSIGNED_INT:
|
---|
216 | for (i = 0; i < width; i++)
|
---|
217 | tmpRow[i] = (GLfloat) uiSrc[i];
|
---|
218 | break;
|
---|
219 | case GL_FLOAT:
|
---|
220 | for (i = 0; i < width; i++)
|
---|
221 | tmpRow[i] = fSrc[i];
|
---|
222 | break;
|
---|
223 | case GL_DOUBLE:
|
---|
224 | for (i = 0; i < width; i++)
|
---|
225 | tmpRow[i] = (GLfloat) dSrc[i];
|
---|
226 | break;
|
---|
227 | default:
|
---|
228 | crError("unexpected type in get_row in pixel.c");
|
---|
229 | }
|
---|
230 | }
|
---|
231 | else if (srcFormat == GL_DEPTH_COMPONENT) {
|
---|
232 | switch (srcType) {
|
---|
233 | case GL_BYTE:
|
---|
234 | for (i = 0; i < width; i++)
|
---|
235 | tmpRow[i] = (GLfloat) BYTE_TO_FLOAT(bSrc[i]);
|
---|
236 | break;
|
---|
237 | case GL_UNSIGNED_BYTE:
|
---|
238 | for (i = 0; i < width; i++)
|
---|
239 | tmpRow[i] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i]);
|
---|
240 | break;
|
---|
241 | case GL_SHORT:
|
---|
242 | for (i = 0; i < width; i++)
|
---|
243 | tmpRow[i] = (GLfloat) SHORT_TO_FLOAT(sSrc[i]);
|
---|
244 | break;
|
---|
245 | case GL_UNSIGNED_SHORT:
|
---|
246 | for (i = 0; i < width; i++)
|
---|
247 | tmpRow[i] = (GLfloat) USHORT_TO_FLOAT(usSrc[i]);
|
---|
248 | break;
|
---|
249 | case GL_INT:
|
---|
250 | for (i = 0; i < width; i++)
|
---|
251 | tmpRow[i] = (GLfloat) INT_TO_FLOAT(bSrc[i]);
|
---|
252 | break;
|
---|
253 | case GL_UNSIGNED_INT:
|
---|
254 | for (i = 0; i < width; i++)
|
---|
255 | tmpRow[i] = (GLfloat) UINT_TO_FLOAT(bSrc[i]);
|
---|
256 | break;
|
---|
257 | case GL_FLOAT:
|
---|
258 | for (i = 0; i < width; i++)
|
---|
259 | tmpRow[i] = fSrc[i];
|
---|
260 | break;
|
---|
261 | case GL_DOUBLE:
|
---|
262 | for (i = 0; i < width; i++)
|
---|
263 | tmpRow[i] = (GLfloat) dSrc[i];
|
---|
264 | break;
|
---|
265 | default:
|
---|
266 | crError("unexpected type in get_row in pixel.c");
|
---|
267 | }
|
---|
268 | }
|
---|
269 | else if (srcFormat == GL_RED || srcFormat == GL_GREEN ||
|
---|
270 | srcFormat == GL_BLUE || srcFormat == GL_ALPHA) {
|
---|
271 | int dst;
|
---|
272 | if (srcFormat == GL_RED)
|
---|
273 | dst = 0;
|
---|
274 | else if (srcFormat == GL_GREEN)
|
---|
275 | dst = 1;
|
---|
276 | else if (srcFormat == GL_BLUE)
|
---|
277 | dst = 2;
|
---|
278 | else
|
---|
279 | dst = 3;
|
---|
280 | for (i = 0; i < width; i++) {
|
---|
281 | tmpRow[i*4+0] = 0.0;
|
---|
282 | tmpRow[i*4+1] = 0.0;
|
---|
283 | tmpRow[i*4+2] = 0.0;
|
---|
284 | tmpRow[i*4+3] = 1.0;
|
---|
285 | }
|
---|
286 | switch (srcType) {
|
---|
287 | case GL_BYTE:
|
---|
288 | for (i = 0; i < width; i++, dst += 4)
|
---|
289 | tmpRow[dst] = (GLfloat) BYTE_TO_FLOAT(bSrc[i]);
|
---|
290 | break;
|
---|
291 | case GL_UNSIGNED_BYTE:
|
---|
292 | for (i = 0; i < width; i++, dst += 4)
|
---|
293 | tmpRow[dst] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i]);
|
---|
294 | break;
|
---|
295 | case GL_SHORT:
|
---|
296 | for (i = 0; i < width; i++, dst += 4)
|
---|
297 | tmpRow[dst] = (GLfloat) SHORT_TO_FLOAT(sSrc[i]);
|
---|
298 | break;
|
---|
299 | case GL_UNSIGNED_SHORT:
|
---|
300 | for (i = 0; i < width; i++, dst += 4)
|
---|
301 | tmpRow[dst] = (GLfloat) USHORT_TO_FLOAT(usSrc[i]);
|
---|
302 | break;
|
---|
303 | case GL_INT:
|
---|
304 | for (i = 0; i < width; i++, dst += 4)
|
---|
305 | tmpRow[dst] = (GLfloat) INT_TO_FLOAT(iSrc[i]);
|
---|
306 | break;
|
---|
307 | case GL_UNSIGNED_INT:
|
---|
308 | for (i = 0; i < width; i++, dst += 4)
|
---|
309 | tmpRow[dst] = (GLfloat) UINT_TO_FLOAT(uiSrc[i]);
|
---|
310 | break;
|
---|
311 | case GL_FLOAT:
|
---|
312 | for (i = 0; i < width; i++, dst += 4)
|
---|
313 | tmpRow[dst] = fSrc[i];
|
---|
314 | break;
|
---|
315 | case GL_DOUBLE:
|
---|
316 | for (i = 0; i < width; i++, dst += 4)
|
---|
317 | tmpRow[dst] = (GLfloat) fSrc[i];
|
---|
318 | break;
|
---|
319 | default:
|
---|
320 | crError("unexpected type in get_row in pixel.c");
|
---|
321 | }
|
---|
322 | }
|
---|
323 | else if (srcFormat == GL_LUMINANCE) {
|
---|
324 | switch (srcType) {
|
---|
325 | case GL_BYTE:
|
---|
326 | for (i = 0; i < width; i++) {
|
---|
327 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
328 | = (GLfloat) BYTE_TO_FLOAT(bSrc[i]);
|
---|
329 | tmpRow[i*4+3] = 1.0;
|
---|
330 | }
|
---|
331 | break;
|
---|
332 | case GL_UNSIGNED_BYTE:
|
---|
333 | for (i = 0; i < width; i++) {
|
---|
334 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
335 | = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i]);
|
---|
336 | tmpRow[i*4+3] = 1.0;
|
---|
337 | }
|
---|
338 | break;
|
---|
339 | case GL_SHORT:
|
---|
340 | for (i = 0; i < width; i++) {
|
---|
341 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
342 | = (GLfloat) SHORT_TO_FLOAT(sSrc[i]);
|
---|
343 | tmpRow[i*4+3] = 1.0;
|
---|
344 | }
|
---|
345 | break;
|
---|
346 | case GL_UNSIGNED_SHORT:
|
---|
347 | for (i = 0; i < width; i++) {
|
---|
348 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
349 | = (GLfloat) USHORT_TO_FLOAT(usSrc[i]);
|
---|
350 | tmpRow[i*4+3] = 1.0;
|
---|
351 | }
|
---|
352 | break;
|
---|
353 | case GL_INT:
|
---|
354 | for (i = 0; i < width; i++) {
|
---|
355 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
356 | = (GLfloat) INT_TO_FLOAT(iSrc[i]);
|
---|
357 | tmpRow[i*4+3] = 1.0;
|
---|
358 | }
|
---|
359 | break;
|
---|
360 | case GL_UNSIGNED_INT:
|
---|
361 | for (i = 0; i < width; i++) {
|
---|
362 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
363 | = (GLfloat) UINT_TO_FLOAT(uiSrc[i]);
|
---|
364 | tmpRow[i*4+3] = 1.0;
|
---|
365 | }
|
---|
366 | break;
|
---|
367 | case GL_FLOAT:
|
---|
368 | for (i = 0; i < width; i++) {
|
---|
369 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = fSrc[i];
|
---|
370 | tmpRow[i*4+3] = 1.0;
|
---|
371 | }
|
---|
372 | break;
|
---|
373 | case GL_DOUBLE:
|
---|
374 | for (i = 0; i < width; i++) {
|
---|
375 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = (GLfloat) dSrc[i];
|
---|
376 | tmpRow[i*4+3] = 1.0;
|
---|
377 | }
|
---|
378 | break;
|
---|
379 | default:
|
---|
380 | crError("unexpected type in get_row in pixel.c");
|
---|
381 | }
|
---|
382 | }
|
---|
383 | else if (srcFormat == GL_INTENSITY) {
|
---|
384 | switch (srcType) {
|
---|
385 | case GL_BYTE:
|
---|
386 | for (i = 0; i < width; i++)
|
---|
387 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
388 | = (GLfloat) BYTE_TO_FLOAT(bSrc[i]);
|
---|
389 | break;
|
---|
390 | case GL_UNSIGNED_BYTE:
|
---|
391 | for (i = 0; i < width; i++)
|
---|
392 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
393 | = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i]);
|
---|
394 | break;
|
---|
395 | case GL_SHORT:
|
---|
396 | for (i = 0; i < width; i++)
|
---|
397 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
398 | = (GLfloat) SHORT_TO_FLOAT(sSrc[i]);
|
---|
399 | break;
|
---|
400 | case GL_UNSIGNED_SHORT:
|
---|
401 | for (i = 0; i < width; i++)
|
---|
402 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
403 | = (GLfloat) USHORT_TO_FLOAT(usSrc[i]);
|
---|
404 | break;
|
---|
405 | case GL_INT:
|
---|
406 | for (i = 0; i < width; i++)
|
---|
407 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
408 | = (GLfloat) INT_TO_FLOAT(iSrc[i]);
|
---|
409 | break;
|
---|
410 | case GL_UNSIGNED_INT:
|
---|
411 | for (i = 0; i < width; i++)
|
---|
412 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
413 | = UINT_TO_FLOAT(uiSrc[i]);
|
---|
414 | break;
|
---|
415 | case GL_FLOAT:
|
---|
416 | for (i = 0; i < width; i++)
|
---|
417 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
418 | = fSrc[i];
|
---|
419 | break;
|
---|
420 | case GL_DOUBLE:
|
---|
421 | for (i = 0; i < width; i++)
|
---|
422 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = tmpRow[i*4+3]
|
---|
423 | = (GLfloat) dSrc[i];
|
---|
424 | break;
|
---|
425 | default:
|
---|
426 | crError("unexpected type in get_row in pixel.c");
|
---|
427 | }
|
---|
428 | }
|
---|
429 | else if (srcFormat == GL_LUMINANCE_ALPHA) {
|
---|
430 | switch (srcType) {
|
---|
431 | case GL_BYTE:
|
---|
432 | for (i = 0; i < width; i++) {
|
---|
433 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
434 | = (GLfloat) BYTE_TO_FLOAT(bSrc[i*2+0]);
|
---|
435 | tmpRow[i*4+3] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*2+1]);
|
---|
436 | }
|
---|
437 | break;
|
---|
438 | case GL_UNSIGNED_BYTE:
|
---|
439 | for (i = 0; i < width; i++) {
|
---|
440 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
441 | = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*2+0]);
|
---|
442 | tmpRow[i*4+3] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*2+1]);
|
---|
443 | }
|
---|
444 | break;
|
---|
445 | case GL_SHORT:
|
---|
446 | for (i = 0; i < width; i++) {
|
---|
447 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
448 | = (GLfloat) SHORT_TO_FLOAT(sSrc[i*2+0]);
|
---|
449 | tmpRow[i*4+3] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*2+1]);
|
---|
450 | }
|
---|
451 | break;
|
---|
452 | case GL_UNSIGNED_SHORT:
|
---|
453 | for (i = 0; i < width; i++) {
|
---|
454 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
455 | = (GLfloat) USHORT_TO_FLOAT(usSrc[i*2+0]);
|
---|
456 | tmpRow[i*4+3] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*2+1]);
|
---|
457 | }
|
---|
458 | break;
|
---|
459 | case GL_INT:
|
---|
460 | for (i = 0; i < width; i++) {
|
---|
461 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
462 | = (GLfloat) INT_TO_FLOAT(iSrc[i*2+0]);
|
---|
463 | tmpRow[i*4+3] = (GLfloat) INT_TO_FLOAT(iSrc[i*2+1]);
|
---|
464 | }
|
---|
465 | break;
|
---|
466 | case GL_UNSIGNED_INT:
|
---|
467 | for (i = 0; i < width; i++) {
|
---|
468 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
469 | = (GLfloat) UINT_TO_FLOAT(uiSrc[i*2+0]);
|
---|
470 | tmpRow[i*4+3] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*2+1]);
|
---|
471 | }
|
---|
472 | break;
|
---|
473 | case GL_FLOAT:
|
---|
474 | for (i = 0; i < width; i++) {
|
---|
475 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2] = fSrc[i*2+0];
|
---|
476 | tmpRow[i*4+3] = fSrc[i*2+1];
|
---|
477 | }
|
---|
478 | break;
|
---|
479 | case GL_DOUBLE:
|
---|
480 | for (i = 0; i < width; i++) {
|
---|
481 | tmpRow[i*4+0] = tmpRow[i*4+1] = tmpRow[i*4+2]
|
---|
482 | = (GLfloat) dSrc[i*2+0];
|
---|
483 | tmpRow[i*4+3] = (GLfloat) dSrc[i*2+1];
|
---|
484 | }
|
---|
485 | break;
|
---|
486 | default:
|
---|
487 | crError("unexpected type in get_row in pixel.c");
|
---|
488 | }
|
---|
489 | }
|
---|
490 | else if (srcFormat == GL_RGB
|
---|
491 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
492 | || srcFormat == GL_BGR
|
---|
493 | #endif
|
---|
494 | ) {
|
---|
495 | int r, b;
|
---|
496 | if (srcFormat == GL_RGB) {
|
---|
497 | r = 0; b = 2;
|
---|
498 | }
|
---|
499 | else {
|
---|
500 | r = 2; b = 0;
|
---|
501 | }
|
---|
502 | switch (srcType) {
|
---|
503 | case GL_BYTE:
|
---|
504 | for (i = 0; i < width; i++) {
|
---|
505 | tmpRow[i*4+0] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*3+r]);
|
---|
506 | tmpRow[i*4+1] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*3+1]);
|
---|
507 | tmpRow[i*4+2] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*3+b]);
|
---|
508 | tmpRow[i*4+3] = 1.0;
|
---|
509 | }
|
---|
510 | break;
|
---|
511 | case GL_UNSIGNED_BYTE:
|
---|
512 | for (i = 0; i < width; i++) {
|
---|
513 | tmpRow[i*4+0] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*3+r]);
|
---|
514 | tmpRow[i*4+1] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*3+1]);
|
---|
515 | tmpRow[i*4+2] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*3+b]);
|
---|
516 | tmpRow[i*4+3] = 1.0;
|
---|
517 | }
|
---|
518 | break;
|
---|
519 | case GL_SHORT:
|
---|
520 | for (i = 0; i < width; i++) {
|
---|
521 | tmpRow[i*4+0] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*3+r]);
|
---|
522 | tmpRow[i*4+1] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*3+1]);
|
---|
523 | tmpRow[i*4+2] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*3+b]);
|
---|
524 | tmpRow[i*4+3] = 1.0;
|
---|
525 | }
|
---|
526 | break;
|
---|
527 | case GL_UNSIGNED_SHORT:
|
---|
528 | for (i = 0; i < width; i++) {
|
---|
529 | tmpRow[i*4+0] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*3+r]);
|
---|
530 | tmpRow[i*4+1] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*3+1]);
|
---|
531 | tmpRow[i*4+2] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*3+b]);
|
---|
532 | tmpRow[i*4+3] = 1.0;
|
---|
533 | }
|
---|
534 | break;
|
---|
535 | case GL_INT:
|
---|
536 | for (i = 0; i < width; i++) {
|
---|
537 | tmpRow[i*4+0] = (GLfloat) INT_TO_FLOAT(iSrc[i*3+r]);
|
---|
538 | tmpRow[i*4+1] = (GLfloat) INT_TO_FLOAT(iSrc[i*3+1]);
|
---|
539 | tmpRow[i*4+2] = (GLfloat) INT_TO_FLOAT(iSrc[i*3+b]);
|
---|
540 | tmpRow[i*4+3] = 1.0;
|
---|
541 | }
|
---|
542 | break;
|
---|
543 | case GL_UNSIGNED_INT:
|
---|
544 | for (i = 0; i < width; i++) {
|
---|
545 | tmpRow[i*4+0] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*3+r]);
|
---|
546 | tmpRow[i*4+1] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*3+1]);
|
---|
547 | tmpRow[i*4+2] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*3+b]);
|
---|
548 | tmpRow[i*4+3] = 1.0;
|
---|
549 | }
|
---|
550 | break;
|
---|
551 | case GL_FLOAT:
|
---|
552 | for (i = 0; i < width; i++) {
|
---|
553 | tmpRow[i*4+0] = fSrc[i*3+r];
|
---|
554 | tmpRow[i*4+1] = fSrc[i*3+1];
|
---|
555 | tmpRow[i*4+2] = fSrc[i*3+b];
|
---|
556 | tmpRow[i*4+3] = 1.0;
|
---|
557 | }
|
---|
558 | break;
|
---|
559 | case GL_DOUBLE:
|
---|
560 | for (i = 0; i < width; i++) {
|
---|
561 | tmpRow[i*4+0] = (GLfloat) dSrc[i*3+r];
|
---|
562 | tmpRow[i*4+1] = (GLfloat) dSrc[i*3+1];
|
---|
563 | tmpRow[i*4+2] = (GLfloat) dSrc[i*3+b];
|
---|
564 | tmpRow[i*4+3] = 1.0;
|
---|
565 | }
|
---|
566 | break;
|
---|
567 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
568 | case GL_UNSIGNED_BYTE_3_3_2:
|
---|
569 | for (i = 0; i < width; i++) {
|
---|
570 | tmpRow[i*4+r] = (GLfloat) ((ubSrc[i] >> 5) ) / 7.0f;
|
---|
571 | tmpRow[i*4+1] = (GLfloat) ((ubSrc[i] >> 2) & 0x7) / 7.0f;
|
---|
572 | tmpRow[i*4+b] = (GLfloat) ((ubSrc[i] ) & 0x3) / 3.0f;
|
---|
573 | tmpRow[i*4+3] = 1.0;
|
---|
574 | }
|
---|
575 | break;
|
---|
576 | case GL_UNSIGNED_BYTE_2_3_3_REV:
|
---|
577 | for (i = 0; i < width; i++) {
|
---|
578 | tmpRow[i*4+r] = (GLfloat) ((ubSrc[i] ) & 0x7) / 7.0f;
|
---|
579 | tmpRow[i*4+1] = (GLfloat) ((ubSrc[i] >> 3) & 0x7) / 7.0f;
|
---|
580 | tmpRow[i*4+b] = (GLfloat) ((ubSrc[i] >> 6) ) / 3.0f;
|
---|
581 | tmpRow[i*4+3] = 1.0;
|
---|
582 | }
|
---|
583 | break;
|
---|
584 | case GL_UNSIGNED_SHORT_5_6_5:
|
---|
585 | for (i = 0; i < width; i++) {
|
---|
586 | tmpRow[i*4+r] = (GLfloat) ((usSrc[i] >> 11) & 0x1f) / 31.0f;
|
---|
587 | tmpRow[i*4+1] = (GLfloat) ((usSrc[i] >> 5) & 0x3f) / 63.0f;
|
---|
588 | tmpRow[i*4+b] = (GLfloat) ((usSrc[i] ) & 0x1f) / 31.0f;
|
---|
589 | tmpRow[i*4+3] = 1.0;
|
---|
590 | }
|
---|
591 | break;
|
---|
592 | case GL_UNSIGNED_SHORT_5_6_5_REV:
|
---|
593 | for (i = 0; i < width; i++) {
|
---|
594 | tmpRow[i*4+r] = (GLfloat) ((usSrc[i] ) & 0x1f) / 31.0f;
|
---|
595 | tmpRow[i*4+1] = (GLfloat) ((usSrc[i] >> 5) & 0x3f) / 63.0f;
|
---|
596 | tmpRow[i*4+b] = (GLfloat) ((usSrc[i] >> 11) & 0x1f) / 31.0f;
|
---|
597 | tmpRow[i*4+3] = 1.0;
|
---|
598 | }
|
---|
599 | break;
|
---|
600 | #endif
|
---|
601 | default:
|
---|
602 | crError("unexpected type in get_row in pixel.c");
|
---|
603 | }
|
---|
604 | }
|
---|
605 | else if (srcFormat == GL_RGBA
|
---|
606 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
607 | || srcFormat == GL_BGRA
|
---|
608 | #endif
|
---|
609 | ) {
|
---|
610 | int r, b;
|
---|
611 | if (srcFormat == GL_RGB) {
|
---|
612 | r = 0; b = 2;
|
---|
613 | }
|
---|
614 | else {
|
---|
615 | r = 2; b = 0;
|
---|
616 | }
|
---|
617 | switch (srcType) {
|
---|
618 | case GL_BYTE:
|
---|
619 | for (i = 0; i < width; i++) {
|
---|
620 | tmpRow[i*4+0] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*4+r]);
|
---|
621 | tmpRow[i*4+1] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*4+1]);
|
---|
622 | tmpRow[i*4+2] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*4+b]);
|
---|
623 | tmpRow[i*4+3] = (GLfloat) BYTE_TO_FLOAT(bSrc[i*4+3]);
|
---|
624 | }
|
---|
625 | break;
|
---|
626 | case GL_UNSIGNED_BYTE:
|
---|
627 | for (i = 0; i < width; i++) {
|
---|
628 | tmpRow[i*4+0] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*4+r]);
|
---|
629 | tmpRow[i*4+1] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*4+1]);
|
---|
630 | tmpRow[i*4+2] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*4+b]);
|
---|
631 | tmpRow[i*4+3] = (GLfloat) UBYTE_TO_FLOAT(ubSrc[i*4+3]);
|
---|
632 | }
|
---|
633 | break;
|
---|
634 | case GL_SHORT:
|
---|
635 | for (i = 0; i < width; i++) {
|
---|
636 | tmpRow[i*4+0] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*4+r]);
|
---|
637 | tmpRow[i*4+1] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*4+1]);
|
---|
638 | tmpRow[i*4+2] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*4+b]);
|
---|
639 | tmpRow[i*4+3] = (GLfloat) SHORT_TO_FLOAT(sSrc[i*4+3]);
|
---|
640 | }
|
---|
641 | break;
|
---|
642 | case GL_UNSIGNED_SHORT:
|
---|
643 | for (i = 0; i < width; i++) {
|
---|
644 | tmpRow[i*4+0] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*4+r]);
|
---|
645 | tmpRow[i*4+1] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*4+1]);
|
---|
646 | tmpRow[i*4+2] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*4+b]);
|
---|
647 | tmpRow[i*4+3] = (GLfloat) USHORT_TO_FLOAT(usSrc[i*4+3]);
|
---|
648 | }
|
---|
649 | break;
|
---|
650 | case GL_INT:
|
---|
651 | for (i = 0; i < width; i++) {
|
---|
652 | tmpRow[i*4+0] = (GLfloat) INT_TO_FLOAT(iSrc[i*4+r]);
|
---|
653 | tmpRow[i*4+1] = (GLfloat) INT_TO_FLOAT(iSrc[i*4+1]);
|
---|
654 | tmpRow[i*4+2] = (GLfloat) INT_TO_FLOAT(iSrc[i*4+b]);
|
---|
655 | tmpRow[i*4+3] = (GLfloat) INT_TO_FLOAT(iSrc[i*4+3]);
|
---|
656 | }
|
---|
657 | break;
|
---|
658 | case GL_UNSIGNED_INT:
|
---|
659 | for (i = 0; i < width; i++) {
|
---|
660 | tmpRow[i*4+0] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*4+r]);
|
---|
661 | tmpRow[i*4+1] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*4+1]);
|
---|
662 | tmpRow[i*4+2] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*4+b]);
|
---|
663 | tmpRow[i*4+3] = (GLfloat) UINT_TO_FLOAT(uiSrc[i*4+3]);
|
---|
664 | }
|
---|
665 | break;
|
---|
666 | case GL_FLOAT:
|
---|
667 | for (i = 0; i < width; i++) {
|
---|
668 | tmpRow[i*4+0] = fSrc[i*4+r];
|
---|
669 | tmpRow[i*4+1] = fSrc[i*4+1];
|
---|
670 | tmpRow[i*4+2] = fSrc[i*4+b];
|
---|
671 | tmpRow[i*4+3] = fSrc[i*4+3];
|
---|
672 | }
|
---|
673 | break;
|
---|
674 | case GL_DOUBLE:
|
---|
675 | for (i = 0; i < width; i++) {
|
---|
676 | tmpRow[i*4+0] = (GLfloat) dSrc[i*4+r];
|
---|
677 | tmpRow[i*4+1] = (GLfloat) dSrc[i*4+1];
|
---|
678 | tmpRow[i*4+2] = (GLfloat) dSrc[i*4+b];
|
---|
679 | tmpRow[i*4+3] = (GLfloat) dSrc[i*4+3];
|
---|
680 | }
|
---|
681 | break;
|
---|
682 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
683 | case GL_UNSIGNED_SHORT_5_5_5_1:
|
---|
684 | for (i = 0; i < width; i++) {
|
---|
685 | tmpRow[i*4+r] = (GLfloat) ((usSrc[i] >> 11) ) / 31.0f;
|
---|
686 | tmpRow[i*4+1] = (GLfloat) ((usSrc[i] >> 6) & 0x1f) / 31.0f;
|
---|
687 | tmpRow[i*4+b] = (GLfloat) ((usSrc[i] >> 1) & 0x1f) / 31.0f;
|
---|
688 | tmpRow[i*4+3] = (GLfloat) ((usSrc[i] ) & 0x01);
|
---|
689 | }
|
---|
690 | break;
|
---|
691 | case GL_UNSIGNED_SHORT_1_5_5_5_REV:
|
---|
692 | for (i = 0; i < width; i++) {
|
---|
693 | tmpRow[i*4+r] = (GLfloat) ((usSrc[i] ) & 0x1f) / 31.0f;
|
---|
694 | tmpRow[i*4+1] = (GLfloat) ((usSrc[i] >> 5) & 0x1f) / 31.0f;
|
---|
695 | tmpRow[i*4+b] = (GLfloat) ((usSrc[i] >> 10) & 0x1f) / 31.0f;
|
---|
696 | tmpRow[i*4+3] = (GLfloat) ((usSrc[i] >> 15) );
|
---|
697 | }
|
---|
698 | break;
|
---|
699 | case GL_UNSIGNED_SHORT_4_4_4_4:
|
---|
700 | for (i = 0; i < width; i++) {
|
---|
701 | tmpRow[i*4+r] = (GLfloat) ((usSrc[i] >> 12) & 0xf) / 15.0f;
|
---|
702 | tmpRow[i*4+1] = (GLfloat) ((usSrc[i] >> 8) & 0xf) / 15.0f;
|
---|
703 | tmpRow[i*4+b] = (GLfloat) ((usSrc[i] >> 4) & 0xf) / 15.0f;
|
---|
704 | tmpRow[i*4+3] = (GLfloat) ((usSrc[i] ) & 0xf) / 15.0f;
|
---|
705 | }
|
---|
706 | break;
|
---|
707 | case GL_UNSIGNED_SHORT_4_4_4_4_REV:
|
---|
708 | for (i = 0; i < width; i++) {
|
---|
709 | tmpRow[i*4+r] = (GLfloat) ((usSrc[i] ) & 0xf) / 15.0f;
|
---|
710 | tmpRow[i*4+1] = (GLfloat) ((usSrc[i] >> 4) & 0xf) / 15.0f;
|
---|
711 | tmpRow[i*4+b] = (GLfloat) ((usSrc[i] >> 8) & 0xf) / 15.0f;
|
---|
712 | tmpRow[i*4+3] = (GLfloat) ((usSrc[i] >> 12) & 0xf) / 15.0f;
|
---|
713 | }
|
---|
714 | break;
|
---|
715 | case GL_UNSIGNED_INT_8_8_8_8:
|
---|
716 | for (i = 0; i < width; i++) {
|
---|
717 | tmpRow[i*4+r] = (GLfloat) ((uiSrc[i] >> 24) & 0xff) / 255.0f;
|
---|
718 | tmpRow[i*4+1] = (GLfloat) ((uiSrc[i] >> 16) & 0xff) / 255.0f;
|
---|
719 | tmpRow[i*4+b] = (GLfloat) ((uiSrc[i] >> 8) & 0xff) / 255.0f;
|
---|
720 | tmpRow[i*4+3] = (GLfloat) ((uiSrc[i] ) & 0xff) / 255.0f;
|
---|
721 | }
|
---|
722 | break;
|
---|
723 | case GL_UNSIGNED_INT_8_8_8_8_REV:
|
---|
724 | for (i = 0; i < width; i++) {
|
---|
725 | tmpRow[i*4+r] = (GLfloat) ((uiSrc[i] ) & 0xff) / 255.0f;
|
---|
726 | tmpRow[i*4+1] = (GLfloat) ((uiSrc[i] >> 8) & 0xff) / 255.0f;
|
---|
727 | tmpRow[i*4+b] = (GLfloat) ((uiSrc[i] >> 16) & 0xff) / 255.0f;
|
---|
728 | tmpRow[i*4+3] = (GLfloat) ((uiSrc[i] >> 24) & 0xff) / 255.0f;
|
---|
729 | }
|
---|
730 | break;
|
---|
731 | case GL_UNSIGNED_INT_10_10_10_2:
|
---|
732 | for (i = 0; i < width; i++) {
|
---|
733 | tmpRow[i*4+r] = (GLfloat) ((uiSrc[i] >> 22) & 0x3ff) / 1023.0f;
|
---|
734 | tmpRow[i*4+1] = (GLfloat) ((uiSrc[i] >> 12) & 0x3ff) / 1023.0f;
|
---|
735 | tmpRow[i*4+b] = (GLfloat) ((uiSrc[i] >> 2) & 0x3ff) / 1023.0f;
|
---|
736 | tmpRow[i*4+3] = (GLfloat) ((uiSrc[i] ) & 0x003) / 3.0f;
|
---|
737 | }
|
---|
738 | break;
|
---|
739 | case GL_UNSIGNED_INT_2_10_10_10_REV:
|
---|
740 | for (i = 0; i < width; i++) {
|
---|
741 | tmpRow[i*4+r] = (GLfloat) ((uiSrc[i] ) & 0x3ff) / 1023.0f;
|
---|
742 | tmpRow[i*4+1] = (GLfloat) ((uiSrc[i] >> 10) & 0x3ff) / 1023.0f;
|
---|
743 | tmpRow[i*4+b] = (GLfloat) ((uiSrc[i] >> 20) & 0x3ff) / 1023.0f;
|
---|
744 | tmpRow[i*4+3] = (GLfloat) ((uiSrc[i] >> 30) & 0x003) / 3.0f;
|
---|
745 | }
|
---|
746 | break;
|
---|
747 | #endif
|
---|
748 | default:
|
---|
749 | crError("unexpected type in get_row in pixel.c");
|
---|
750 | }
|
---|
751 | }
|
---|
752 | else{
|
---|
753 | crError("unexpected source format in get_row in pixel.c");
|
---|
754 | }
|
---|
755 | }
|
---|
756 |
|
---|
757 |
|
---|
758 | static void put_row(char *dst, GLenum dstFormat, GLenum dstType,
|
---|
759 | GLsizei width, const GLfloat *tmpRow)
|
---|
760 | {
|
---|
761 | GLbyte *bDst = (GLbyte *) dst;
|
---|
762 | GLubyte *ubDst = (GLubyte *) dst;
|
---|
763 | GLshort *sDst = (GLshort *) dst;
|
---|
764 | GLushort *usDst = (GLushort *) dst;
|
---|
765 | GLint *iDst = (GLint *) dst;
|
---|
766 | GLuint *uiDst = (GLuint *) dst;
|
---|
767 | GLfloat *fDst = (GLfloat *) dst;
|
---|
768 | GLdouble *dDst = (GLdouble *) dst;
|
---|
769 | int i;
|
---|
770 |
|
---|
771 | if (dstFormat == GL_COLOR_INDEX || dstFormat == GL_STENCIL_INDEX) {
|
---|
772 | switch (dstType) {
|
---|
773 | case GL_BYTE:
|
---|
774 | for (i = 0; i < width; i++)
|
---|
775 | bDst[i] = (GLbyte) tmpRow[i];
|
---|
776 | break;
|
---|
777 | case GL_UNSIGNED_BYTE:
|
---|
778 | for (i = 0; i < width; i++)
|
---|
779 | ubDst[i] = (GLubyte) tmpRow[i];
|
---|
780 | break;
|
---|
781 | case GL_SHORT:
|
---|
782 | for (i = 0; i < width; i++)
|
---|
783 | sDst[i] = (GLshort) tmpRow[i];
|
---|
784 | break;
|
---|
785 | case GL_UNSIGNED_SHORT:
|
---|
786 | for (i = 0; i < width; i++)
|
---|
787 | usDst[i] = (GLushort) tmpRow[i];
|
---|
788 | break;
|
---|
789 | case GL_INT:
|
---|
790 | for (i = 0; i < width; i++)
|
---|
791 | iDst[i] = (GLint) tmpRow[i];
|
---|
792 | break;
|
---|
793 | case GL_UNSIGNED_INT:
|
---|
794 | for (i = 0; i < width; i++)
|
---|
795 | uiDst[i] = (GLuint) tmpRow[i];
|
---|
796 | break;
|
---|
797 | case GL_FLOAT:
|
---|
798 | for (i = 0; i < width; i++)
|
---|
799 | fDst[i] = tmpRow[i];
|
---|
800 | break;
|
---|
801 | case GL_DOUBLE:
|
---|
802 | for (i = 0; i < width; i++)
|
---|
803 | dDst[i] = tmpRow[i];
|
---|
804 | break;
|
---|
805 | default:
|
---|
806 | crError("unexpected type in put_row in pixel.c");
|
---|
807 | }
|
---|
808 | }
|
---|
809 | else if (dstFormat == GL_DEPTH_COMPONENT) {
|
---|
810 | switch (dstType) {
|
---|
811 | case GL_BYTE:
|
---|
812 | for (i = 0; i < width; i++)
|
---|
813 | bDst[i] = FLOAT_TO_BYTE(tmpRow[i]);
|
---|
814 | break;
|
---|
815 | case GL_UNSIGNED_BYTE:
|
---|
816 | for (i = 0; i < width; i++)
|
---|
817 | ubDst[i] = FLOAT_TO_UBYTE(tmpRow[i]);
|
---|
818 | break;
|
---|
819 | case GL_SHORT:
|
---|
820 | for (i = 0; i < width; i++)
|
---|
821 | sDst[i] = FLOAT_TO_SHORT(tmpRow[i]);
|
---|
822 | break;
|
---|
823 | case GL_UNSIGNED_SHORT:
|
---|
824 | for (i = 0; i < width; i++)
|
---|
825 | sDst[i] = FLOAT_TO_SHORT(tmpRow[i]);
|
---|
826 | break;
|
---|
827 | case GL_INT:
|
---|
828 | for (i = 0; i < width; i++)
|
---|
829 | bDst[i] = (GLbyte) FLOAT_TO_INT(tmpRow[i]);
|
---|
830 | break;
|
---|
831 | case GL_UNSIGNED_INT:
|
---|
832 | for (i = 0; i < width; i++)
|
---|
833 | bDst[i] = (GLbyte) FLOAT_TO_UINT(tmpRow[i]);
|
---|
834 | break;
|
---|
835 | case GL_FLOAT:
|
---|
836 | for (i = 0; i < width; i++)
|
---|
837 | fDst[i] = tmpRow[i];
|
---|
838 | break;
|
---|
839 | case GL_DOUBLE:
|
---|
840 | for (i = 0; i < width; i++)
|
---|
841 | dDst[i] = tmpRow[i];
|
---|
842 | break;
|
---|
843 | default:
|
---|
844 | crError("unexpected type in put_row in pixel.c");
|
---|
845 | }
|
---|
846 | }
|
---|
847 | else if (dstFormat == GL_RED || dstFormat == GL_GREEN ||
|
---|
848 | dstFormat == GL_BLUE || dstFormat == GL_ALPHA ||
|
---|
849 | dstFormat == GL_LUMINANCE || dstFormat == GL_INTENSITY) {
|
---|
850 | int index;
|
---|
851 | if (dstFormat == GL_RED)
|
---|
852 | index = 0;
|
---|
853 | else if (dstFormat == GL_LUMINANCE)
|
---|
854 | index = 0;
|
---|
855 | else if (dstFormat == GL_INTENSITY)
|
---|
856 | index = 0;
|
---|
857 | else if (dstFormat == GL_GREEN)
|
---|
858 | index = 1;
|
---|
859 | else if (dstFormat == GL_BLUE)
|
---|
860 | index = 2;
|
---|
861 | else
|
---|
862 | index = 3;
|
---|
863 | switch (dstType) {
|
---|
864 | case GL_BYTE:
|
---|
865 | for (i = 0; i < width; i++)
|
---|
866 | bDst[i] = FLOAT_TO_BYTE(tmpRow[i*4+index]);
|
---|
867 | break;
|
---|
868 | case GL_UNSIGNED_BYTE:
|
---|
869 | for (i = 0; i < width; i++)
|
---|
870 | ubDst[i] = FLOAT_TO_UBYTE(tmpRow[i*4+index]);
|
---|
871 | break;
|
---|
872 | case GL_SHORT:
|
---|
873 | for (i = 0; i < width; i++)
|
---|
874 | sDst[i] = FLOAT_TO_SHORT(tmpRow[i*4+index]);
|
---|
875 | break;
|
---|
876 | case GL_UNSIGNED_SHORT:
|
---|
877 | for (i = 0; i < width; i++)
|
---|
878 | usDst[i] = FLOAT_TO_USHORT(tmpRow[i*4+index]);
|
---|
879 | break;
|
---|
880 | case GL_INT:
|
---|
881 | for (i = 0; i < width; i++)
|
---|
882 | iDst[i] = FLOAT_TO_INT(tmpRow[i*4+index]);
|
---|
883 | break;
|
---|
884 | case GL_UNSIGNED_INT:
|
---|
885 | for (i = 0; i < width; i++)
|
---|
886 | uiDst[i] = FLOAT_TO_UINT(tmpRow[i*4+index]);
|
---|
887 | break;
|
---|
888 | case GL_FLOAT:
|
---|
889 | for (i = 0; i < width; i++)
|
---|
890 | fDst[i] = tmpRow[i*4+index];
|
---|
891 | break;
|
---|
892 | case GL_DOUBLE:
|
---|
893 | for (i = 0; i < width; i++)
|
---|
894 | dDst[i] = tmpRow[i*4+index];
|
---|
895 | break;
|
---|
896 | default:
|
---|
897 | crError("unexpected type in put_row in pixel.c");
|
---|
898 | }
|
---|
899 | }
|
---|
900 | else if (dstFormat == GL_LUMINANCE_ALPHA) {
|
---|
901 | switch (dstType) {
|
---|
902 | case GL_BYTE:
|
---|
903 | for (i = 0; i < width; i++) {
|
---|
904 | bDst[i*2+0] = FLOAT_TO_BYTE(tmpRow[i*4+0]);
|
---|
905 | bDst[i*2+1] = FLOAT_TO_BYTE(tmpRow[i*4+3]);
|
---|
906 | }
|
---|
907 | break;
|
---|
908 | case GL_UNSIGNED_BYTE:
|
---|
909 | for (i = 0; i < width; i++) {
|
---|
910 | ubDst[i*2+0] = FLOAT_TO_UBYTE(tmpRow[i*4+0]);
|
---|
911 | ubDst[i*2+1] = FLOAT_TO_UBYTE(tmpRow[i*4+3]);
|
---|
912 | }
|
---|
913 | break;
|
---|
914 | case GL_SHORT:
|
---|
915 | for (i = 0; i < width; i++) {
|
---|
916 | sDst[i*2+0] = FLOAT_TO_SHORT(tmpRow[i*4+0]);
|
---|
917 | sDst[i*2+1] = FLOAT_TO_SHORT(tmpRow[i*4+3]);
|
---|
918 | }
|
---|
919 | break;
|
---|
920 | case GL_UNSIGNED_SHORT:
|
---|
921 | for (i = 0; i < width; i++) {
|
---|
922 | usDst[i*2+0] = FLOAT_TO_USHORT(tmpRow[i*4+0]);
|
---|
923 | usDst[i*2+1] = FLOAT_TO_USHORT(tmpRow[i*4+3]);
|
---|
924 | }
|
---|
925 | break;
|
---|
926 | case GL_INT:
|
---|
927 | for (i = 0; i < width; i++) {
|
---|
928 | iDst[i*2+0] = FLOAT_TO_INT(tmpRow[i*4+0]);
|
---|
929 | iDst[i*2+1] = FLOAT_TO_INT(tmpRow[i*4+3]);
|
---|
930 | }
|
---|
931 | break;
|
---|
932 | case GL_UNSIGNED_INT:
|
---|
933 | for (i = 0; i < width; i++) {
|
---|
934 | uiDst[i*2+0] = FLOAT_TO_UINT(tmpRow[i*4+0]);
|
---|
935 | uiDst[i*2+1] = FLOAT_TO_UINT(tmpRow[i*4+3]);
|
---|
936 | }
|
---|
937 | break;
|
---|
938 | case GL_FLOAT:
|
---|
939 | for (i = 0; i < width; i++) {
|
---|
940 | fDst[i*2+0] = tmpRow[i*4+0];
|
---|
941 | fDst[i*2+1] = tmpRow[i*4+3];
|
---|
942 | }
|
---|
943 | break;
|
---|
944 | case GL_DOUBLE:
|
---|
945 | for (i = 0; i < width; i++) {
|
---|
946 | dDst[i*2+0] = tmpRow[i*4+0];
|
---|
947 | dDst[i*2+1] = tmpRow[i*4+3];
|
---|
948 | }
|
---|
949 | break;
|
---|
950 | default:
|
---|
951 | crError("unexpected type in put_row in pixel.c");
|
---|
952 | }
|
---|
953 | }
|
---|
954 | else if (dstFormat == GL_RGB
|
---|
955 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
956 | || dstFormat == GL_BGR
|
---|
957 | #endif
|
---|
958 | ) {
|
---|
959 | int r, b;
|
---|
960 | if (dstFormat == GL_RGB) {
|
---|
961 | r = 0; b = 2;
|
---|
962 | }
|
---|
963 | else {
|
---|
964 | r = 2; b = 0;
|
---|
965 | }
|
---|
966 | switch (dstType) {
|
---|
967 | case GL_BYTE:
|
---|
968 | for (i = 0; i < width; i++) {
|
---|
969 | bDst[i*3+r] = FLOAT_TO_BYTE(tmpRow[i*4+0]);
|
---|
970 | bDst[i*3+1] = FLOAT_TO_BYTE(tmpRow[i*4+1]);
|
---|
971 | bDst[i*3+b] = FLOAT_TO_BYTE(tmpRow[i*4+2]);
|
---|
972 | }
|
---|
973 | break;
|
---|
974 | case GL_UNSIGNED_BYTE:
|
---|
975 | for (i = 0; i < width; i++) {
|
---|
976 | ubDst[i*3+r] = FLOAT_TO_UBYTE(tmpRow[i*4+0]);
|
---|
977 | ubDst[i*3+1] = FLOAT_TO_UBYTE(tmpRow[i*4+1]);
|
---|
978 | ubDst[i*3+b] = FLOAT_TO_UBYTE(tmpRow[i*4+2]);
|
---|
979 | }
|
---|
980 | break;
|
---|
981 | case GL_SHORT:
|
---|
982 | for (i = 0; i < width; i++) {
|
---|
983 | sDst[i*3+r] = FLOAT_TO_SHORT(tmpRow[i*4+0]);
|
---|
984 | sDst[i*3+1] = FLOAT_TO_SHORT(tmpRow[i*4+1]);
|
---|
985 | sDst[i*3+b] = FLOAT_TO_SHORT(tmpRow[i*4+2]);
|
---|
986 | }
|
---|
987 | break;
|
---|
988 | case GL_UNSIGNED_SHORT:
|
---|
989 | for (i = 0; i < width; i++) {
|
---|
990 | usDst[i*3+r] = FLOAT_TO_USHORT(tmpRow[i*4+0]);
|
---|
991 | usDst[i*3+1] = FLOAT_TO_USHORT(tmpRow[i*4+1]);
|
---|
992 | usDst[i*3+b] = FLOAT_TO_USHORT(tmpRow[i*4+2]);
|
---|
993 | }
|
---|
994 | break;
|
---|
995 | case GL_INT:
|
---|
996 | for (i = 0; i < width; i++) {
|
---|
997 | iDst[i*3+r] = FLOAT_TO_INT(tmpRow[i*4+0]);
|
---|
998 | iDst[i*3+1] = FLOAT_TO_INT(tmpRow[i*4+1]);
|
---|
999 | iDst[i*3+b] = FLOAT_TO_INT(tmpRow[i*4+2]);
|
---|
1000 | }
|
---|
1001 | break;
|
---|
1002 | case GL_UNSIGNED_INT:
|
---|
1003 | for (i = 0; i < width; i++) {
|
---|
1004 | uiDst[i*3+r] = FLOAT_TO_UINT(tmpRow[i*4+0]);
|
---|
1005 | uiDst[i*3+1] = FLOAT_TO_UINT(tmpRow[i*4+1]);
|
---|
1006 | uiDst[i*3+b] = FLOAT_TO_UINT(tmpRow[i*4+2]);
|
---|
1007 | }
|
---|
1008 | break;
|
---|
1009 | case GL_FLOAT:
|
---|
1010 | for (i = 0; i < width; i++) {
|
---|
1011 | fDst[i*3+r] = tmpRow[i*4+0];
|
---|
1012 | fDst[i*3+1] = tmpRow[i*4+1];
|
---|
1013 | fDst[i*3+b] = tmpRow[i*4+2];
|
---|
1014 | }
|
---|
1015 | break;
|
---|
1016 | case GL_DOUBLE:
|
---|
1017 | for (i = 0; i < width; i++) {
|
---|
1018 | dDst[i*3+r] = tmpRow[i*4+0];
|
---|
1019 | dDst[i*3+1] = tmpRow[i*4+1];
|
---|
1020 | dDst[i*3+b] = tmpRow[i*4+2];
|
---|
1021 | }
|
---|
1022 | break;
|
---|
1023 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1024 | case GL_UNSIGNED_BYTE_3_3_2:
|
---|
1025 | for (i = 0; i < width; i++) {
|
---|
1026 | int red = (int) (tmpRow[i*4+r] * 7.0);
|
---|
1027 | int green = (int) (tmpRow[i*4+1] * 7.0);
|
---|
1028 | int blue = (int) (tmpRow[i*4+b] * 3.0);
|
---|
1029 | ubDst[i] = (red << 5) | (green << 2) | blue;
|
---|
1030 | }
|
---|
1031 | break;
|
---|
1032 | case GL_UNSIGNED_BYTE_2_3_3_REV:
|
---|
1033 | for (i = 0; i < width; i++) {
|
---|
1034 | int red = (int) (tmpRow[i*4+r] * 7.0);
|
---|
1035 | int green = (int) (tmpRow[i*4+1] * 7.0);
|
---|
1036 | int blue = (int) (tmpRow[i*4+b] * 3.0);
|
---|
1037 | ubDst[i] = red | (green << 3) | (blue << 6);
|
---|
1038 | }
|
---|
1039 | break;
|
---|
1040 | case GL_UNSIGNED_SHORT_5_6_5:
|
---|
1041 | for (i = 0; i < width; i++) {
|
---|
1042 | int red = (int) (tmpRow[i*4+r] * 31.0);
|
---|
1043 | int green = (int) (tmpRow[i*4+1] * 63.0);
|
---|
1044 | int blue = (int) (tmpRow[i*4+b] * 31.0);
|
---|
1045 | usDst[i] = (red << 11) | (green << 5) | blue;
|
---|
1046 | }
|
---|
1047 | break;
|
---|
1048 | case GL_UNSIGNED_SHORT_5_6_5_REV:
|
---|
1049 | for (i = 0; i < width; i++) {
|
---|
1050 | int red = (int) (tmpRow[i*4+r] * 31.0);
|
---|
1051 | int green = (int) (tmpRow[i*4+1] * 63.0);
|
---|
1052 | int blue = (int) (tmpRow[i*4+b] * 31.0);
|
---|
1053 | usDst[i] = (blue << 11) | (green << 5) | red;
|
---|
1054 | }
|
---|
1055 | break;
|
---|
1056 | #endif
|
---|
1057 | default:
|
---|
1058 | crError("unexpected type in put_row in pixel.c");
|
---|
1059 | }
|
---|
1060 | }
|
---|
1061 | else if (dstFormat == GL_RGBA
|
---|
1062 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1063 | || dstFormat == GL_BGRA
|
---|
1064 | #endif
|
---|
1065 | ) {
|
---|
1066 | int r, b;
|
---|
1067 | if (dstFormat == GL_RGB) {
|
---|
1068 | r = 0; b = 2;
|
---|
1069 | }
|
---|
1070 | else {
|
---|
1071 | r = 2; b = 0;
|
---|
1072 | }
|
---|
1073 | switch (dstType) {
|
---|
1074 | case GL_BYTE:
|
---|
1075 | for (i = 0; i < width; i++) {
|
---|
1076 | bDst[i*4+r] = FLOAT_TO_BYTE(tmpRow[i*4+0]);
|
---|
1077 | bDst[i*4+1] = FLOAT_TO_BYTE(tmpRow[i*4+1]);
|
---|
1078 | bDst[i*4+b] = FLOAT_TO_BYTE(tmpRow[i*4+2]);
|
---|
1079 | bDst[i*4+3] = FLOAT_TO_BYTE(tmpRow[i*4+3]);
|
---|
1080 | }
|
---|
1081 | break;
|
---|
1082 | case GL_UNSIGNED_BYTE:
|
---|
1083 | for (i = 0; i < width; i++) {
|
---|
1084 | ubDst[i*4+r] = FLOAT_TO_UBYTE(tmpRow[i*4+0]);
|
---|
1085 | ubDst[i*4+1] = FLOAT_TO_UBYTE(tmpRow[i*4+1]);
|
---|
1086 | ubDst[i*4+b] = FLOAT_TO_UBYTE(tmpRow[i*4+2]);
|
---|
1087 | ubDst[i*4+3] = FLOAT_TO_UBYTE(tmpRow[i*4+3]);
|
---|
1088 | }
|
---|
1089 | break;
|
---|
1090 | case GL_SHORT:
|
---|
1091 | for (i = 0; i < width; i++) {
|
---|
1092 | sDst[i*4+r] = FLOAT_TO_SHORT(tmpRow[i*4+0]);
|
---|
1093 | sDst[i*4+1] = FLOAT_TO_SHORT(tmpRow[i*4+1]);
|
---|
1094 | sDst[i*4+b] = FLOAT_TO_SHORT(tmpRow[i*4+2]);
|
---|
1095 | sDst[i*4+3] = FLOAT_TO_SHORT(tmpRow[i*4+3]);
|
---|
1096 | }
|
---|
1097 | break;
|
---|
1098 | case GL_UNSIGNED_SHORT:
|
---|
1099 | for (i = 0; i < width; i++) {
|
---|
1100 | usDst[i*4+r] = FLOAT_TO_USHORT(tmpRow[i*4+0]);
|
---|
1101 | usDst[i*4+1] = FLOAT_TO_USHORT(tmpRow[i*4+1]);
|
---|
1102 | usDst[i*4+b] = FLOAT_TO_USHORT(tmpRow[i*4+2]);
|
---|
1103 | usDst[i*4+3] = FLOAT_TO_USHORT(tmpRow[i*4+3]);
|
---|
1104 | }
|
---|
1105 | break;
|
---|
1106 | case GL_INT:
|
---|
1107 | for (i = 0; i < width; i++) {
|
---|
1108 | iDst[i*4+r] = FLOAT_TO_INT(tmpRow[i*4+0]);
|
---|
1109 | iDst[i*4+1] = FLOAT_TO_INT(tmpRow[i*4+1]);
|
---|
1110 | iDst[i*4+b] = FLOAT_TO_INT(tmpRow[i*4+2]);
|
---|
1111 | iDst[i*4+3] = FLOAT_TO_INT(tmpRow[i*4+3]);
|
---|
1112 | }
|
---|
1113 | break;
|
---|
1114 | case GL_UNSIGNED_INT:
|
---|
1115 | for (i = 0; i < width; i++) {
|
---|
1116 | uiDst[i*4+r] = FLOAT_TO_UINT(tmpRow[i*4+0]);
|
---|
1117 | uiDst[i*4+1] = FLOAT_TO_UINT(tmpRow[i*4+1]);
|
---|
1118 | uiDst[i*4+b] = FLOAT_TO_UINT(tmpRow[i*4+2]);
|
---|
1119 | uiDst[i*4+3] = FLOAT_TO_UINT(tmpRow[i*4+3]);
|
---|
1120 | }
|
---|
1121 | break;
|
---|
1122 | case GL_FLOAT:
|
---|
1123 | for (i = 0; i < width; i++) {
|
---|
1124 | fDst[i*4+r] = tmpRow[i*4+0];
|
---|
1125 | fDst[i*4+1] = tmpRow[i*4+1];
|
---|
1126 | fDst[i*4+b] = tmpRow[i*4+2];
|
---|
1127 | fDst[i*4+3] = tmpRow[i*4+3];
|
---|
1128 | }
|
---|
1129 | break;
|
---|
1130 | case GL_DOUBLE:
|
---|
1131 | for (i = 0; i < width; i++) {
|
---|
1132 | dDst[i*4+r] = tmpRow[i*4+0];
|
---|
1133 | dDst[i*4+1] = tmpRow[i*4+1];
|
---|
1134 | dDst[i*4+b] = tmpRow[i*4+2];
|
---|
1135 | dDst[i*4+3] = tmpRow[i*4+3];
|
---|
1136 | }
|
---|
1137 | break;
|
---|
1138 | #ifdef CR_OPENGL_VERSION_1_2
|
---|
1139 | case GL_UNSIGNED_SHORT_5_5_5_1:
|
---|
1140 | for (i = 0; i < width; i++) {
|
---|
1141 | int red = (int) (tmpRow[i*4+r] * 31.0);
|
---|
1142 | int green = (int) (tmpRow[i*4+1] * 31.0);
|
---|
1143 | int blue = (int) (tmpRow[i*4+b] * 31.0);
|
---|
1144 | int alpha = (int) (tmpRow[i*4+3]);
|
---|
1145 | usDst[i] = (red << 11) | (green << 6) | (blue << 1) | alpha;
|
---|
1146 | }
|
---|
1147 | break;
|
---|
1148 | case GL_UNSIGNED_SHORT_1_5_5_5_REV:
|
---|
1149 | for (i = 0; i < width; i++) {
|
---|
1150 | int red = (int) (tmpRow[i*4+r] * 31.0);
|
---|
1151 | int green = (int) (tmpRow[i*4+1] * 31.0);
|
---|
1152 | int blue = (int) (tmpRow[i*4+b] * 31.0);
|
---|
1153 | int alpha = (int) (tmpRow[i*4+3]);
|
---|
1154 | usDst[i] = (alpha << 15) | (blue << 10) | (green << 5) | red;
|
---|
1155 | }
|
---|
1156 | break;
|
---|
1157 | case GL_UNSIGNED_SHORT_4_4_4_4:
|
---|
1158 | for (i = 0; i < width; i++) {
|
---|
1159 | int red = (int) (tmpRow[i*4+r] * 15.0f);
|
---|
1160 | int green = (int) (tmpRow[i*4+1] * 15.0f);
|
---|
1161 | int blue = (int) (tmpRow[i*4+b] * 15.0f);
|
---|
1162 | int alpha = (int) (tmpRow[i*4+3] * 15.0f);
|
---|
1163 | usDst[i] = (red << 12) | (green << 8) | (blue << 4) | alpha;
|
---|
1164 | }
|
---|
1165 | break;
|
---|
1166 | case GL_UNSIGNED_SHORT_4_4_4_4_REV:
|
---|
1167 | for (i = 0; i < width; i++) {
|
---|
1168 | int red = (int) (tmpRow[i*4+r] * 15.0f);
|
---|
1169 | int green = (int) (tmpRow[i*4+1] * 15.0f);
|
---|
1170 | int blue = (int) (tmpRow[i*4+b] * 15.0f);
|
---|
1171 | int alpha = (int) (tmpRow[i*4+3] * 15.0f);
|
---|
1172 | usDst[i] = (alpha << 12) | (blue << 8) | (green << 4) | red;
|
---|
1173 | }
|
---|
1174 | break;
|
---|
1175 | case GL_UNSIGNED_INT_8_8_8_8:
|
---|
1176 | for (i = 0; i < width; i++) {
|
---|
1177 | int red = (int) (tmpRow[i*4+r] * 255.0f);
|
---|
1178 | int green = (int) (tmpRow[i*4+1] * 255.0f);
|
---|
1179 | int blue = (int) (tmpRow[i*4+b] * 255.0f);
|
---|
1180 | int alpha = (int) (tmpRow[i*4+3] * 255.0f);
|
---|
1181 | uiDst[i] = (red << 24) | (green << 16) | (blue << 8) | alpha;
|
---|
1182 | }
|
---|
1183 | break;
|
---|
1184 | case GL_UNSIGNED_INT_8_8_8_8_REV:
|
---|
1185 | for (i = 0; i < width; i++) {
|
---|
1186 | int red = (int) (tmpRow[i*4+r] * 255.0f);
|
---|
1187 | int green = (int) (tmpRow[i*4+1] * 255.0f);
|
---|
1188 | int blue = (int) (tmpRow[i*4+b] * 255.0f);
|
---|
1189 | int alpha = (int) (tmpRow[i*4+3] * 255.0f);
|
---|
1190 | uiDst[i] = (alpha << 24) | (blue << 16) | (green << 8) | red;
|
---|
1191 | }
|
---|
1192 | break;
|
---|
1193 | case GL_UNSIGNED_INT_10_10_10_2:
|
---|
1194 | for (i = 0; i < width; i++) {
|
---|
1195 | int red = (int) (tmpRow[i*4+r] * 1023.0f);
|
---|
1196 | int green = (int) (tmpRow[i*4+1] * 1023.0f);
|
---|
1197 | int blue = (int) (tmpRow[i*4+b] * 1023.0f);
|
---|
1198 | int alpha = (int) (tmpRow[i*4+3] * 3.0f);
|
---|
1199 | uiDst[i] = (red << 22) | (green << 12) | (blue << 2) | alpha;
|
---|
1200 | }
|
---|
1201 | break;
|
---|
1202 | case GL_UNSIGNED_INT_2_10_10_10_REV:
|
---|
1203 | for (i = 0; i < width; i++) {
|
---|
1204 | int red = (int) (tmpRow[i*4+r] * 1023.0f);
|
---|
1205 | int green = (int) (tmpRow[i*4+1] * 1023.0f);
|
---|
1206 | int blue = (int) (tmpRow[i*4+b] * 1023.0f);
|
---|
1207 | int alpha = (int) (tmpRow[i*4+3] * 3.0f);
|
---|
1208 | uiDst[i] = (alpha << 30) | (blue << 20) | (green << 10) | red;
|
---|
1209 | }
|
---|
1210 | break;
|
---|
1211 | #endif
|
---|
1212 | default:
|
---|
1213 | crError("unexpected type in put_row in pixel.c");
|
---|
1214 | }
|
---|
1215 | }
|
---|
1216 | else{
|
---|
1217 | crError("unexpected dest type in put_row in pixel.c");
|
---|
1218 | }
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | #ifdef _MSC_VER
|
---|
1222 | # pragma optimize("", on) /* bird: see #pragma optimize("g", off) above. */
|
---|
1223 | #endif
|
---|
1224 |
|
---|
1225 | /**
|
---|
1226 | * Byte-swap an array of GLushorts
|
---|
1227 | */
|
---|
1228 | static void
|
---|
1229 | swap2(GLushort *us, GLuint n)
|
---|
1230 | {
|
---|
1231 | GLuint i;
|
---|
1232 | for (i = 0; i < n; i++) {
|
---|
1233 | us[i] = (us[i] >> 8) | (us[i] << 8);
|
---|
1234 | }
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 |
|
---|
1238 | /**
|
---|
1239 | * Byte-swap an array of GLuints
|
---|
1240 | */
|
---|
1241 | static void
|
---|
1242 | swap4(GLuint *ui, GLuint n)
|
---|
1243 | {
|
---|
1244 | GLuint i;
|
---|
1245 |
|
---|
1246 | for (i = 0; i < n; i++) {
|
---|
1247 | GLuint b = ui[i];
|
---|
1248 | ui[i] = (b >> 24)
|
---|
1249 | | ((b >> 8) & 0xff00)
|
---|
1250 | | ((b << 8) & 0xff0000)
|
---|
1251 | | ((b << 24) & 0xff000000);
|
---|
1252 | }
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 |
|
---|
1256 | /**
|
---|
1257 | * Return number of bytes of storage needed to accomodate an
|
---|
1258 | * image with the given format, type, and size.
|
---|
1259 | * \return size in bytes or -1 if bad format or type
|
---|
1260 | */
|
---|
1261 | unsigned int crImageSize( GLenum format, GLenum type, GLsizei width, GLsizei height )
|
---|
1262 | {
|
---|
1263 | unsigned int bytes = width * height;
|
---|
1264 |
|
---|
1265 | if (type == GL_BITMAP)
|
---|
1266 | {
|
---|
1267 | /* This was wrong in the old code! */
|
---|
1268 | bytes = ((width + 7) / 8) * height;
|
---|
1269 | }
|
---|
1270 | else if (GL_DEPTH_COMPONENT==format && type!=GL_FLOAT)
|
---|
1271 | {
|
---|
1272 | /*GL_DEPTH_COMPONENT with GL_UNSIGNED_BYTE seems to be more than 1 byte per pixel*/
|
---|
1273 | bytes = 4 * width * height * crPixelSize( format, type );
|
---|
1274 | }
|
---|
1275 | else
|
---|
1276 | {
|
---|
1277 | bytes = width * height * crPixelSize( format, type );
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | return bytes;
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | /**
|
---|
1284 | * Return number of bytes of storage needed to accomodate a
|
---|
1285 | * 3D texture with the give format, type, and size.
|
---|
1286 | * \return size in bytes or -1 if bad format or type
|
---|
1287 | */
|
---|
1288 | unsigned int crTextureSize( GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth )
|
---|
1289 | {
|
---|
1290 | unsigned int bytes = width * height;
|
---|
1291 |
|
---|
1292 | if (type == GL_BITMAP)
|
---|
1293 | {
|
---|
1294 | /*
|
---|
1295 | * Not sure about this one, so just multiply
|
---|
1296 | * by the depth?
|
---|
1297 | */
|
---|
1298 | bytes = ((width + 7) / 8) * height * depth;
|
---|
1299 | }
|
---|
1300 | else
|
---|
1301 | {
|
---|
1302 | bytes = width * height * depth * crPixelSize( format, type );
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | return bytes;
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | static const CRPixelPackState defaultPacking = {
|
---|
1309 | 0, /* rowLength */
|
---|
1310 | 0, /* skipRows */
|
---|
1311 | 0, /* skipPixels */
|
---|
1312 | 1, /* alignment */
|
---|
1313 | 0, /* imageHeight */
|
---|
1314 | 0, /* skipImages */
|
---|
1315 | GL_FALSE, /* swapBytes */
|
---|
1316 | GL_FALSE /* psLSBFirst */
|
---|
1317 | };
|
---|
1318 |
|
---|
1319 |
|
---|
1320 | void crPixelCopy1D( GLvoid *dstPtr, GLenum dstFormat, GLenum dstType,
|
---|
1321 | const GLvoid *srcPtr, GLenum srcFormat, GLenum srcType,
|
---|
1322 | GLsizei width, const CRPixelPackState *srcPacking )
|
---|
1323 | {
|
---|
1324 | crPixelCopy2D( width, 1,
|
---|
1325 | dstPtr, dstFormat, dstType, NULL, /* dst */
|
---|
1326 | srcPtr, srcFormat, srcType, srcPacking ); /* src */
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | void crPixelCopy2D( GLsizei width, GLsizei height,
|
---|
1330 | GLvoid *dstPtr, GLenum dstFormat, GLenum dstType,
|
---|
1331 | const CRPixelPackState *dstPacking,
|
---|
1332 | const GLvoid *srcPtr, GLenum srcFormat, GLenum srcType,
|
---|
1333 | const CRPixelPackState *srcPacking )
|
---|
1334 |
|
---|
1335 | {
|
---|
1336 | const char *src = (const char *) srcPtr;
|
---|
1337 | char *dst = (char *) dstPtr;
|
---|
1338 | int srcBytesPerPixel;
|
---|
1339 | int dstBytesPerPixel;
|
---|
1340 | int srcBytesPerRow;
|
---|
1341 | int dstBytesPerRow;
|
---|
1342 | int srcRowStrideBytes;
|
---|
1343 | int dstRowStrideBytes;
|
---|
1344 | int bytesPerRow;
|
---|
1345 | int i;
|
---|
1346 |
|
---|
1347 | if (!dstPacking)
|
---|
1348 | dstPacking = &defaultPacking;
|
---|
1349 |
|
---|
1350 | if (!srcPacking)
|
---|
1351 | srcPacking = &defaultPacking;
|
---|
1352 |
|
---|
1353 | if (srcType == GL_BITMAP)
|
---|
1354 | {
|
---|
1355 | CRASSERT(dstType == GL_BITMAP);
|
---|
1356 | bytesPerRow = (width + 7) / 8;
|
---|
1357 | if (srcPacking->rowLength > 0)
|
---|
1358 | srcRowStrideBytes = (srcPacking->rowLength + 7) / 8;
|
---|
1359 | else
|
---|
1360 | srcRowStrideBytes = bytesPerRow;
|
---|
1361 | dstRowStrideBytes = bytesPerRow;
|
---|
1362 |
|
---|
1363 | for (i=0; i<height; i++) {
|
---|
1364 | crMemcpy( (void *) dst, (const void *) src, bytesPerRow );
|
---|
1365 | dst += dstRowStrideBytes;
|
---|
1366 | src += srcRowStrideBytes;
|
---|
1367 | }
|
---|
1368 | }
|
---|
1369 | else
|
---|
1370 | {
|
---|
1371 | CRASSERT(dstType != GL_BITMAP);
|
---|
1372 | srcBytesPerPixel = crPixelSize( srcFormat, srcType );
|
---|
1373 | dstBytesPerPixel = crPixelSize( dstFormat, dstType );
|
---|
1374 | if (srcBytesPerPixel < 0 || dstBytesPerPixel < 0)
|
---|
1375 | return;
|
---|
1376 |
|
---|
1377 | /* Stride between rows (in bytes) */
|
---|
1378 | if (srcPacking->rowLength > 0)
|
---|
1379 | srcRowStrideBytes = srcPacking->rowLength * srcBytesPerPixel;
|
---|
1380 | else
|
---|
1381 | srcRowStrideBytes = width * srcBytesPerPixel;
|
---|
1382 |
|
---|
1383 | if (dstPacking->rowLength > 0)
|
---|
1384 | dstRowStrideBytes = dstPacking->rowLength * dstBytesPerPixel;
|
---|
1385 | else
|
---|
1386 | dstRowStrideBytes = width * dstBytesPerPixel;
|
---|
1387 |
|
---|
1388 | /* bytes per row */
|
---|
1389 | srcBytesPerRow = width * srcBytesPerPixel;
|
---|
1390 | dstBytesPerRow = width * dstBytesPerPixel;
|
---|
1391 |
|
---|
1392 | /* handle the alignment */
|
---|
1393 | if (srcPacking->alignment != 1) {
|
---|
1394 | i = ((long) src) % srcPacking->alignment;
|
---|
1395 | if (i)
|
---|
1396 | src += srcPacking->alignment - i;
|
---|
1397 | i = (long) srcRowStrideBytes % srcPacking->alignment;
|
---|
1398 | if (i)
|
---|
1399 | srcRowStrideBytes += srcPacking->alignment - i;
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | if (dstPacking->alignment != 1) {
|
---|
1403 | i = ((long) dst) % dstPacking->alignment;
|
---|
1404 | if (i)
|
---|
1405 | dst += dstPacking->alignment - i;
|
---|
1406 | i = (long) dstRowStrideBytes % dstPacking->alignment;
|
---|
1407 | if (i)
|
---|
1408 | dstRowStrideBytes += dstPacking->alignment - i;
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | /* handle skip rows */
|
---|
1412 | src += srcPacking->skipRows * srcRowStrideBytes;
|
---|
1413 | dst += dstPacking->skipRows * dstRowStrideBytes;
|
---|
1414 |
|
---|
1415 | /* handle skip pixels */
|
---|
1416 | src += srcPacking->skipPixels * srcBytesPerPixel;
|
---|
1417 | dst += dstPacking->skipPixels * dstBytesPerPixel;
|
---|
1418 |
|
---|
1419 | /* we don't do LSBFirst yet */
|
---|
1420 | if (srcPacking->psLSBFirst)
|
---|
1421 | crError( "Sorry, no lsbfirst for you" );
|
---|
1422 | if (dstPacking->psLSBFirst)
|
---|
1423 | crError( "Sorry, no lsbfirst for you" );
|
---|
1424 |
|
---|
1425 | if (srcFormat == dstFormat && srcType == dstType)
|
---|
1426 | {
|
---|
1427 | CRASSERT(srcBytesPerRow == dstBytesPerRow);
|
---|
1428 |
|
---|
1429 | if (srcBytesPerRow==srcRowStrideBytes
|
---|
1430 | && srcRowStrideBytes==dstRowStrideBytes)
|
---|
1431 | {
|
---|
1432 | crMemcpy( (void *) dst, (const void *) src, height * srcBytesPerRow );
|
---|
1433 | }
|
---|
1434 | else
|
---|
1435 | //crDebug("Sending texture, BytesPerRow!=RowStrideBytes");
|
---|
1436 | for (i = 0; i < height; i++)
|
---|
1437 | {
|
---|
1438 | crMemcpy( (void *) dst, (const void *) src, srcBytesPerRow );
|
---|
1439 | #if 0
|
---|
1440 | /* check if src XOR dst swapping */
|
---|
1441 | if (srcPacking->swapBytes ^ dstPacking->swapBytes) {
|
---|
1442 | const GLint size = crSizeOfType(srcType);
|
---|
1443 | CRASSERT(srcType == dstType);
|
---|
1444 | if (size == 2) {
|
---|
1445 | swap2((GLushort *) dst, srcBytesPerRow / size);
|
---|
1446 | }
|
---|
1447 | else if (size == 4) {
|
---|
1448 | swap4((GLuint *) dst, srcBytesPerRow / size);
|
---|
1449 | }
|
---|
1450 | }
|
---|
1451 | #endif
|
---|
1452 | dst += dstRowStrideBytes;
|
---|
1453 | src += srcRowStrideBytes;
|
---|
1454 | }
|
---|
1455 | }
|
---|
1456 | else
|
---|
1457 | {
|
---|
1458 | /* need to do format and/or type conversion */
|
---|
1459 | char *swapRow = NULL;
|
---|
1460 | GLfloat *tmpRow = crAlloc( 4 * width * sizeof(GLfloat) );
|
---|
1461 |
|
---|
1462 | crDebug("Converting texture format");
|
---|
1463 |
|
---|
1464 | if (!tmpRow)
|
---|
1465 | crError("Out of memory in crPixelCopy2D");
|
---|
1466 |
|
---|
1467 | if (srcPacking->swapBytes) {
|
---|
1468 | swapRow = (char *) crAlloc(width * srcBytesPerPixel);
|
---|
1469 | if (!swapRow) {
|
---|
1470 | crError("Out of memory in crPixelCopy2D");
|
---|
1471 | }
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | for (i = 0; i < height; i++)
|
---|
1475 | {
|
---|
1476 | /* get src row as floats */
|
---|
1477 | if (srcPacking->swapBytes) {
|
---|
1478 | const GLint size = crSizeOfType(srcType);
|
---|
1479 | const GLint bytes = width * srcBytesPerPixel;
|
---|
1480 | crMemcpy(swapRow, src, bytes);
|
---|
1481 | if (size == 2)
|
---|
1482 | swap2((GLushort *) swapRow, bytes / 2);
|
---|
1483 | else if (size == 4)
|
---|
1484 | swap4((GLuint *) swapRow, bytes / 4);
|
---|
1485 | get_row(swapRow, srcFormat, srcType, width, tmpRow);
|
---|
1486 | }
|
---|
1487 | else {
|
---|
1488 | get_row(src, srcFormat, srcType, width, tmpRow);
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | /* store floats in dest row */
|
---|
1492 | if (dstPacking->swapBytes) {
|
---|
1493 | const GLint size = crSizeOfType(dstType);
|
---|
1494 | const GLint bytes = dstBytesPerPixel * width;
|
---|
1495 | put_row(dst, dstFormat, dstType, width, tmpRow);
|
---|
1496 | if (size == 2)
|
---|
1497 | swap2((GLushort *) dst, bytes / 2);
|
---|
1498 | else if (size == 4)
|
---|
1499 | swap4((GLuint *) dst, bytes / 4);
|
---|
1500 | }
|
---|
1501 | else {
|
---|
1502 | put_row(dst, dstFormat, dstType, width, tmpRow);
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | /* increment pointers for next row */
|
---|
1506 | dst += dstRowStrideBytes;
|
---|
1507 | src += srcRowStrideBytes;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | crFree(tmpRow);
|
---|
1511 | if (swapRow)
|
---|
1512 | crFree(swapRow);
|
---|
1513 | }
|
---|
1514 | }
|
---|
1515 | }
|
---|
1516 |
|
---|
1517 | void crPixelCopy3D( GLsizei width, GLsizei height, GLsizei depth,
|
---|
1518 | GLvoid *dstPtr, GLenum dstFormat, GLenum dstType,
|
---|
1519 | const CRPixelPackState *dstPacking,
|
---|
1520 | const GLvoid *srcPtr, GLenum srcFormat, GLenum srcType,
|
---|
1521 | const CRPixelPackState *srcPacking )
|
---|
1522 |
|
---|
1523 | {
|
---|
1524 | int tex_size = 0;
|
---|
1525 |
|
---|
1526 | (void)srcPacking;
|
---|
1527 | (void)srcType;
|
---|
1528 | (void)srcFormat;
|
---|
1529 | (void)dstPacking;
|
---|
1530 |
|
---|
1531 | /*@todo this should be implemented properly*/
|
---|
1532 |
|
---|
1533 | crWarning( "crPixelCopy3D: simply crMemcpy'ing from srcPtr to dstPtr" );
|
---|
1534 | if (dstFormat != srcFormat)
|
---|
1535 | crWarning( "crPixelCopy3D: formats don't match!" );
|
---|
1536 | if (dstType != srcType)
|
---|
1537 | crWarning( "crPixelCopy3D: formats don't match!" );
|
---|
1538 |
|
---|
1539 | tex_size = RT_MIN (crTextureSize( dstFormat, dstType, width, height, depth ),
|
---|
1540 | crTextureSize( srcFormat, srcType, width, height, depth ));
|
---|
1541 | crMemcpy( (void *) dstPtr, (void *) srcPtr, tex_size );
|
---|
1542 | }
|
---|
1543 |
|
---|
1544 | /* Round N up to the next multiple of 8 */
|
---|
1545 | #define CEIL8(N) (((N) + 7) & ~0x7)
|
---|
1546 |
|
---|
1547 | void crBitmapCopy( GLsizei width, GLsizei height, GLubyte *dstPtr,
|
---|
1548 | const GLubyte *srcPtr, const CRPixelPackState *srcPacking )
|
---|
1549 | {
|
---|
1550 | if (srcPacking->psLSBFirst == GL_FALSE &&
|
---|
1551 | (srcPacking->rowLength == 0 || srcPacking->rowLength == width) &&
|
---|
1552 | srcPacking->skipRows == 0 &&
|
---|
1553 | srcPacking->skipPixels == 0 &&
|
---|
1554 | srcPacking->alignment == 1) {
|
---|
1555 | /* simple case */
|
---|
1556 | crMemcpy(dstPtr, srcPtr, CEIL8(width) * height / 8);
|
---|
1557 | }
|
---|
1558 | else {
|
---|
1559 | /* general case */
|
---|
1560 | const GLubyte *srcRow;
|
---|
1561 | const GLint dst_row_length = CEIL8(width) / 8;
|
---|
1562 | GLubyte *dstRow;
|
---|
1563 | GLint src_row_length;
|
---|
1564 | GLint i, j;
|
---|
1565 |
|
---|
1566 | if (srcPacking->rowLength > 0)
|
---|
1567 | src_row_length = srcPacking->rowLength;
|
---|
1568 | else
|
---|
1569 | src_row_length = width;
|
---|
1570 |
|
---|
1571 | switch (srcPacking->alignment) {
|
---|
1572 | case 1:
|
---|
1573 | src_row_length = ( ( src_row_length + 7 ) & ~7 ) >> 3;
|
---|
1574 | break;
|
---|
1575 | case 2:
|
---|
1576 | src_row_length = ( ( src_row_length + 15 ) & ~15 ) >> 3;
|
---|
1577 | break;
|
---|
1578 | case 4:
|
---|
1579 | src_row_length = ( ( src_row_length + 31 ) & ~31 ) >> 3;
|
---|
1580 | break;
|
---|
1581 | case 8:
|
---|
1582 | src_row_length = ( ( src_row_length + 63 ) & ~63 ) >> 3;
|
---|
1583 | break;
|
---|
1584 | default:
|
---|
1585 | crError( "Invalid unpack alignment in crBitmapCopy");
|
---|
1586 | return;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | /* src_row_length and dst_row_length are in bytes */
|
---|
1590 |
|
---|
1591 | srcRow = srcPtr + src_row_length * srcPacking->skipRows;
|
---|
1592 | dstRow = dstPtr;
|
---|
1593 |
|
---|
1594 | if (srcPacking->psLSBFirst) {
|
---|
1595 | for (j = 0; j < height; j++) {
|
---|
1596 | crMemZero(dstRow, dst_row_length);
|
---|
1597 | for (i = 0; i < width; i++) {
|
---|
1598 | const GLint iByte = (i + srcPacking->skipPixels) / 8;
|
---|
1599 | const GLint iBit = (i + srcPacking->skipPixels) % 8;
|
---|
1600 | const GLubyte b = srcRow[iByte];
|
---|
1601 | if (b & (1 << iBit))
|
---|
1602 | dstRow[i / 8] |= (128 >> (i % 8));
|
---|
1603 | }
|
---|
1604 | srcRow += src_row_length;
|
---|
1605 | dstRow += dst_row_length;
|
---|
1606 | }
|
---|
1607 | }
|
---|
1608 | else {
|
---|
1609 | /* unpack MSB first */
|
---|
1610 | for (j = 0; j < height; j++) {
|
---|
1611 | crMemZero(dstRow, dst_row_length);
|
---|
1612 | for (i = 0; i < width; i++) {
|
---|
1613 | const GLint iByte = (i + srcPacking->skipPixels) / 8;
|
---|
1614 | const GLint iBit = (i + srcPacking->skipPixels) % 8;
|
---|
1615 | const GLubyte b = srcRow[iByte];
|
---|
1616 | if (b & (128 >> iBit))
|
---|
1617 | dstRow[i / 8] |= (128 >> (i % 8));
|
---|
1618 | }
|
---|
1619 | srcRow += src_row_length;
|
---|
1620 | dstRow += dst_row_length;
|
---|
1621 | }
|
---|
1622 | }
|
---|
1623 | }
|
---|
1624 | }
|
---|