Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
55 | pj | 1 | /* $Id: image.c,v 1.1 2003-02-28 11:42:02 pj Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 4.1 |
||
6 | * |
||
7 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
||
8 | * |
||
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
10 | * copy of this software and associated documentation files (the "Software"), |
||
11 | * to deal in the Software without restriction, including without limitation |
||
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
13 | * and/or sell copies of the Software, and to permit persons to whom the |
||
14 | * Software is furnished to do so, subject to the following conditions: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | */ |
||
26 | |||
27 | #include "glheader.h" |
||
28 | #include "colormac.h" |
||
29 | #include "context.h" |
||
30 | #include "image.h" |
||
31 | #include "imports.h" |
||
32 | #include "histogram.h" |
||
33 | #include "macros.h" |
||
34 | #include "mmath.h" |
||
35 | #include "pixel.h" |
||
36 | #include "mtypes.h" |
||
37 | |||
38 | |||
39 | /* |
||
40 | * These are the image packing parameters for Mesa's internal images. |
||
41 | * That is, _mesa_unpack_image() returns image data in this format. |
||
42 | * When we execute image commands (glDrawPixels, glTexImage, etc) |
||
43 | * from within display lists we have to be sure to set the current |
||
44 | * unpacking params to these values! |
||
45 | */ |
||
46 | const struct gl_pixelstore_attrib _mesa_native_packing = { |
||
47 | 1, /* Alignment */ |
||
48 | 0, /* RowLength */ |
||
49 | 0, /* SkipPixels */ |
||
50 | 0, /* SkipRows */ |
||
51 | 0, /* ImageHeight */ |
||
52 | 0, /* SkipImages */ |
||
53 | GL_FALSE, /* SwapBytes */ |
||
54 | GL_FALSE, /* LsbFirst */ |
||
55 | GL_FALSE, /* ClientStorage */ |
||
56 | GL_FALSE /* Invert */ |
||
57 | }; |
||
58 | |||
59 | |||
60 | |||
61 | /* |
||
62 | * Flip the 8 bits in each byte of the given array. |
||
63 | * |
||
64 | * XXX try this trick to flip bytes someday: |
||
65 | * v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555); |
||
66 | * v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333); |
||
67 | * v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f); |
||
68 | */ |
||
69 | static void |
||
70 | flip_bytes( GLubyte *p, GLuint n ) |
||
71 | { |
||
72 | register GLuint i, a, b; |
||
73 | |||
74 | for (i=0;i<n;i++) { |
||
75 | b = (GLuint) p[i]; /* words are often faster than bytes */ |
||
76 | a = ((b & 0x01) << 7) | |
||
77 | ((b & 0x02) << 5) | |
||
78 | ((b & 0x04) << 3) | |
||
79 | ((b & 0x08) << 1) | |
||
80 | ((b & 0x10) >> 1) | |
||
81 | ((b & 0x20) >> 3) | |
||
82 | ((b & 0x40) >> 5) | |
||
83 | ((b & 0x80) >> 7); |
||
84 | p[i] = (GLubyte) a; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | |||
89 | /* |
||
90 | * Flip the order of the 2 bytes in each word in the given array. |
||
91 | */ |
||
92 | void |
||
93 | _mesa_swap2( GLushort *p, GLuint n ) |
||
94 | { |
||
95 | register GLuint i; |
||
96 | |||
97 | for (i=0;i<n;i++) { |
||
98 | p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | |||
103 | |||
104 | /* |
||
105 | * Flip the order of the 4 bytes in each word in the given array. |
||
106 | */ |
||
107 | void |
||
108 | _mesa_swap4( GLuint *p, GLuint n ) |
||
109 | { |
||
110 | register GLuint i, a, b; |
||
111 | |||
112 | for (i=0;i<n;i++) { |
||
113 | b = p[i]; |
||
114 | a = (b >> 24) |
||
115 | | ((b >> 8) & 0xff00) |
||
116 | | ((b << 8) & 0xff0000) |
||
117 | | ((b << 24) & 0xff000000); |
||
118 | p[i] = a; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | |||
123 | |||
124 | |||
125 | /* |
||
126 | * Return the size, in bytes, of the given GL datatype. |
||
127 | * Return 0 if GL_BITMAP. |
||
128 | * Return -1 if invalid type enum. |
||
129 | */ |
||
130 | GLint _mesa_sizeof_type( GLenum type ) |
||
131 | { |
||
132 | switch (type) { |
||
133 | case GL_BITMAP: |
||
134 | return 0; |
||
135 | case GL_UNSIGNED_BYTE: |
||
136 | return sizeof(GLubyte); |
||
137 | case GL_BYTE: |
||
138 | return sizeof(GLbyte); |
||
139 | case GL_UNSIGNED_SHORT: |
||
140 | return sizeof(GLushort); |
||
141 | case GL_SHORT: |
||
142 | return sizeof(GLshort); |
||
143 | case GL_UNSIGNED_INT: |
||
144 | return sizeof(GLuint); |
||
145 | case GL_INT: |
||
146 | return sizeof(GLint); |
||
147 | case GL_FLOAT: |
||
148 | return sizeof(GLfloat); |
||
149 | default: |
||
150 | return -1; |
||
151 | } |
||
152 | } |
||
153 | |||
154 | |||
155 | /* |
||
156 | * Same as _mesa_sizeof_packed_type() but we also accept the |
||
157 | * packed pixel format datatypes. |
||
158 | */ |
||
159 | GLint _mesa_sizeof_packed_type( GLenum type ) |
||
160 | { |
||
161 | switch (type) { |
||
162 | case GL_BITMAP: |
||
163 | return 0; |
||
164 | case GL_UNSIGNED_BYTE: |
||
165 | return sizeof(GLubyte); |
||
166 | case GL_BYTE: |
||
167 | return sizeof(GLbyte); |
||
168 | case GL_UNSIGNED_SHORT: |
||
169 | return sizeof(GLushort); |
||
170 | case GL_SHORT: |
||
171 | return sizeof(GLshort); |
||
172 | case GL_UNSIGNED_INT: |
||
173 | return sizeof(GLuint); |
||
174 | case GL_INT: |
||
175 | return sizeof(GLint); |
||
176 | case GL_FLOAT: |
||
177 | return sizeof(GLfloat); |
||
178 | case GL_UNSIGNED_BYTE_3_3_2: |
||
179 | return sizeof(GLubyte); |
||
180 | case GL_UNSIGNED_BYTE_2_3_3_REV: |
||
181 | return sizeof(GLubyte); |
||
182 | case GL_UNSIGNED_SHORT_5_6_5: |
||
183 | return sizeof(GLushort); |
||
184 | case GL_UNSIGNED_SHORT_5_6_5_REV: |
||
185 | return sizeof(GLushort); |
||
186 | case GL_UNSIGNED_SHORT_4_4_4_4: |
||
187 | return sizeof(GLushort); |
||
188 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
||
189 | return sizeof(GLushort); |
||
190 | case GL_UNSIGNED_SHORT_5_5_5_1: |
||
191 | return sizeof(GLushort); |
||
192 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
||
193 | return sizeof(GLushort); |
||
194 | case GL_UNSIGNED_INT_8_8_8_8: |
||
195 | return sizeof(GLuint); |
||
196 | case GL_UNSIGNED_INT_8_8_8_8_REV: |
||
197 | return sizeof(GLuint); |
||
198 | case GL_UNSIGNED_INT_10_10_10_2: |
||
199 | return sizeof(GLuint); |
||
200 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
||
201 | return sizeof(GLuint); |
||
202 | case GL_UNSIGNED_SHORT_8_8_MESA: |
||
203 | case GL_UNSIGNED_SHORT_8_8_REV_MESA: |
||
204 | return sizeof(GLushort); |
||
205 | default: |
||
206 | return -1; |
||
207 | } |
||
208 | } |
||
209 | |||
210 | |||
211 | |||
212 | /* |
||
213 | * Return the number of components in a GL enum pixel type. |
||
214 | * Return -1 if bad format. |
||
215 | */ |
||
216 | GLint _mesa_components_in_format( GLenum format ) |
||
217 | { |
||
218 | switch (format) { |
||
219 | case GL_COLOR_INDEX: |
||
220 | case GL_COLOR_INDEX1_EXT: |
||
221 | case GL_COLOR_INDEX2_EXT: |
||
222 | case GL_COLOR_INDEX4_EXT: |
||
223 | case GL_COLOR_INDEX8_EXT: |
||
224 | case GL_COLOR_INDEX12_EXT: |
||
225 | case GL_COLOR_INDEX16_EXT: |
||
226 | case GL_STENCIL_INDEX: |
||
227 | case GL_DEPTH_COMPONENT: |
||
228 | case GL_RED: |
||
229 | case GL_GREEN: |
||
230 | case GL_BLUE: |
||
231 | case GL_ALPHA: |
||
232 | case GL_LUMINANCE: |
||
233 | case GL_INTENSITY: |
||
234 | return 1; |
||
235 | case GL_LUMINANCE_ALPHA: |
||
236 | return 2; |
||
237 | case GL_RGB: |
||
238 | return 3; |
||
239 | case GL_RGBA: |
||
240 | return 4; |
||
241 | case GL_BGR: |
||
242 | return 3; |
||
243 | case GL_BGRA: |
||
244 | return 4; |
||
245 | case GL_ABGR_EXT: |
||
246 | return 4; |
||
247 | case GL_YCBCR_MESA: |
||
248 | return 2; |
||
249 | default: |
||
250 | return -1; |
||
251 | } |
||
252 | } |
||
253 | |||
254 | |||
255 | /* |
||
256 | * Return bytes per pixel for given format and type |
||
257 | * Return -1 if bad format or type. |
||
258 | */ |
||
259 | GLint _mesa_bytes_per_pixel( GLenum format, GLenum type ) |
||
260 | { |
||
261 | GLint comps = _mesa_components_in_format( format ); |
||
262 | if (comps < 0) |
||
263 | return -1; |
||
264 | |||
265 | switch (type) { |
||
266 | case GL_BITMAP: |
||
267 | return 0; /* special case */ |
||
268 | case GL_BYTE: |
||
269 | case GL_UNSIGNED_BYTE: |
||
270 | return comps * sizeof(GLubyte); |
||
271 | case GL_SHORT: |
||
272 | case GL_UNSIGNED_SHORT: |
||
273 | return comps * sizeof(GLshort); |
||
274 | case GL_INT: |
||
275 | case GL_UNSIGNED_INT: |
||
276 | return comps * sizeof(GLint); |
||
277 | case GL_FLOAT: |
||
278 | return comps * sizeof(GLfloat); |
||
279 | case GL_UNSIGNED_BYTE_3_3_2: |
||
280 | case GL_UNSIGNED_BYTE_2_3_3_REV: |
||
281 | if (format == GL_RGB || format == GL_BGR) |
||
282 | return sizeof(GLubyte); |
||
283 | else |
||
284 | return -1; /* error */ |
||
285 | case GL_UNSIGNED_SHORT_5_6_5: |
||
286 | case GL_UNSIGNED_SHORT_5_6_5_REV: |
||
287 | if (format == GL_RGB || format == GL_BGR) |
||
288 | return sizeof(GLushort); |
||
289 | else |
||
290 | return -1; /* error */ |
||
291 | case GL_UNSIGNED_SHORT_4_4_4_4: |
||
292 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
||
293 | case GL_UNSIGNED_SHORT_5_5_5_1: |
||
294 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
||
295 | if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT) |
||
296 | return sizeof(GLushort); |
||
297 | else |
||
298 | return -1; |
||
299 | case GL_UNSIGNED_INT_8_8_8_8: |
||
300 | case GL_UNSIGNED_INT_8_8_8_8_REV: |
||
301 | case GL_UNSIGNED_INT_10_10_10_2: |
||
302 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
||
303 | if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT) |
||
304 | return sizeof(GLuint); |
||
305 | else |
||
306 | return -1; |
||
307 | case GL_UNSIGNED_SHORT_8_8_MESA: |
||
308 | case GL_UNSIGNED_SHORT_8_8_REV_MESA: |
||
309 | if (format == GL_YCBCR_MESA) |
||
310 | return sizeof(GLushort); |
||
311 | else |
||
312 | return -1; |
||
313 | default: |
||
314 | return -1; |
||
315 | } |
||
316 | } |
||
317 | |||
318 | |||
319 | /* |
||
320 | * Test if the given pixel format and type are legal. |
||
321 | * Return GL_TRUE for legal, GL_FALSE for illegal. |
||
322 | */ |
||
323 | GLboolean |
||
324 | _mesa_is_legal_format_and_type( GLenum format, GLenum type ) |
||
325 | { |
||
326 | switch (format) { |
||
327 | case GL_COLOR_INDEX: |
||
328 | case GL_STENCIL_INDEX: |
||
329 | switch (type) { |
||
330 | case GL_BITMAP: |
||
331 | case GL_BYTE: |
||
332 | case GL_UNSIGNED_BYTE: |
||
333 | case GL_SHORT: |
||
334 | case GL_UNSIGNED_SHORT: |
||
335 | case GL_INT: |
||
336 | case GL_UNSIGNED_INT: |
||
337 | case GL_FLOAT: |
||
338 | return GL_TRUE; |
||
339 | default: |
||
340 | return GL_FALSE; |
||
341 | } |
||
342 | case GL_RED: |
||
343 | case GL_GREEN: |
||
344 | case GL_BLUE: |
||
345 | case GL_ALPHA: |
||
346 | case GL_INTENSITY: |
||
347 | case GL_LUMINANCE: |
||
348 | case GL_LUMINANCE_ALPHA: |
||
349 | case GL_DEPTH_COMPONENT: |
||
350 | switch (type) { |
||
351 | case GL_BYTE: |
||
352 | case GL_UNSIGNED_BYTE: |
||
353 | case GL_SHORT: |
||
354 | case GL_UNSIGNED_SHORT: |
||
355 | case GL_INT: |
||
356 | case GL_UNSIGNED_INT: |
||
357 | case GL_FLOAT: |
||
358 | return GL_TRUE; |
||
359 | default: |
||
360 | return GL_FALSE; |
||
361 | } |
||
362 | case GL_RGB: |
||
363 | case GL_BGR: |
||
364 | switch (type) { |
||
365 | case GL_BYTE: |
||
366 | case GL_UNSIGNED_BYTE: |
||
367 | case GL_SHORT: |
||
368 | case GL_UNSIGNED_SHORT: |
||
369 | case GL_INT: |
||
370 | case GL_UNSIGNED_INT: |
||
371 | case GL_FLOAT: |
||
372 | case GL_UNSIGNED_BYTE_3_3_2: |
||
373 | case GL_UNSIGNED_BYTE_2_3_3_REV: |
||
374 | case GL_UNSIGNED_SHORT_5_6_5: |
||
375 | case GL_UNSIGNED_SHORT_5_6_5_REV: |
||
376 | return GL_TRUE; |
||
377 | default: |
||
378 | return GL_FALSE; |
||
379 | } |
||
380 | case GL_RGBA: |
||
381 | case GL_BGRA: |
||
382 | case GL_ABGR_EXT: |
||
383 | switch (type) { |
||
384 | case GL_BYTE: |
||
385 | case GL_UNSIGNED_BYTE: |
||
386 | case GL_SHORT: |
||
387 | case GL_UNSIGNED_SHORT: |
||
388 | case GL_INT: |
||
389 | case GL_UNSIGNED_INT: |
||
390 | case GL_FLOAT: |
||
391 | case GL_UNSIGNED_SHORT_4_4_4_4: |
||
392 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
||
393 | case GL_UNSIGNED_SHORT_5_5_5_1: |
||
394 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
||
395 | case GL_UNSIGNED_INT_8_8_8_8: |
||
396 | case GL_UNSIGNED_INT_8_8_8_8_REV: |
||
397 | case GL_UNSIGNED_INT_10_10_10_2: |
||
398 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
||
399 | return GL_TRUE; |
||
400 | default: |
||
401 | return GL_FALSE; |
||
402 | } |
||
403 | case GL_YCBCR_MESA: |
||
404 | if (type == GL_UNSIGNED_SHORT_8_8_MESA || |
||
405 | type == GL_UNSIGNED_SHORT_8_8_REV_MESA) |
||
406 | return GL_TRUE; |
||
407 | else |
||
408 | return GL_FALSE; |
||
409 | default: |
||
410 | ; /* fall-through */ |
||
411 | } |
||
412 | return GL_FALSE; |
||
413 | } |
||
414 | |||
415 | |||
416 | |||
417 | /* |
||
418 | * Return the address of a pixel in an image (actually a volume). |
||
419 | * Pixel unpacking/packing parameters are observed according to 'packing'. |
||
420 | * Input: image - start of image data |
||
421 | * width, height - size of image |
||
422 | * format - image format |
||
423 | * type - pixel component type |
||
424 | * packing - the pixelstore attributes |
||
425 | * img - which image in the volume (0 for 1D or 2D images) |
||
426 | * row, column - location of pixel in the image |
||
427 | * Return: address of pixel at (image,row,column) in image or NULL if error. |
||
428 | */ |
||
429 | GLvoid * |
||
430 | _mesa_image_address( const struct gl_pixelstore_attrib *packing, |
||
431 | const GLvoid *image, GLsizei width, |
||
432 | GLsizei height, GLenum format, GLenum type, |
||
433 | GLint img, GLint row, GLint column ) |
||
434 | { |
||
435 | GLint alignment; /* 1, 2 or 4 */ |
||
436 | GLint pixels_per_row; |
||
437 | GLint rows_per_image; |
||
438 | GLint skiprows; |
||
439 | GLint skippixels; |
||
440 | GLint skipimages; /* for 3-D volume images */ |
||
441 | GLubyte *pixel_addr; |
||
442 | |||
443 | alignment = packing->Alignment; |
||
444 | if (packing->RowLength > 0) { |
||
445 | pixels_per_row = packing->RowLength; |
||
446 | } |
||
447 | else { |
||
448 | pixels_per_row = width; |
||
449 | } |
||
450 | if (packing->ImageHeight > 0) { |
||
451 | rows_per_image = packing->ImageHeight; |
||
452 | } |
||
453 | else { |
||
454 | rows_per_image = height; |
||
455 | } |
||
456 | skiprows = packing->SkipRows; |
||
457 | skippixels = packing->SkipPixels; |
||
458 | skipimages = packing->SkipImages; |
||
459 | |||
460 | if (type==GL_BITMAP) { |
||
461 | /* BITMAP data */ |
||
462 | GLint comp_per_pixel; /* components per pixel */ |
||
463 | GLint bytes_per_comp; /* bytes per component */ |
||
464 | GLint bytes_per_row; |
||
465 | GLint bytes_per_image; |
||
466 | |||
467 | /* Compute bytes per component */ |
||
468 | bytes_per_comp = _mesa_sizeof_packed_type( type ); |
||
469 | if (bytes_per_comp<0) { |
||
470 | return NULL; |
||
471 | } |
||
472 | |||
473 | /* Compute number of components per pixel */ |
||
474 | comp_per_pixel = _mesa_components_in_format( format ); |
||
475 | if (comp_per_pixel<0 && type != GL_BITMAP) { |
||
476 | return NULL; |
||
477 | } |
||
478 | |||
479 | bytes_per_row = alignment |
||
480 | * CEILING( comp_per_pixel*pixels_per_row, 8*alignment ); |
||
481 | |||
482 | bytes_per_image = bytes_per_row * rows_per_image; |
||
483 | |||
484 | pixel_addr = (GLubyte *) image |
||
485 | + (skipimages + img) * bytes_per_image |
||
486 | + (skiprows + row) * bytes_per_row |
||
487 | + (skippixels + column) / 8; |
||
488 | } |
||
489 | else { |
||
490 | /* Non-BITMAP data */ |
||
491 | GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image; |
||
492 | GLint topOfImage; |
||
493 | |||
494 | bytes_per_pixel = _mesa_bytes_per_pixel( format, type ); |
||
495 | |||
496 | /* The pixel type and format should have been error checked earlier */ |
||
497 | assert(bytes_per_pixel > 0); |
||
498 | |||
499 | bytes_per_row = pixels_per_row * bytes_per_pixel; |
||
500 | remainder = bytes_per_row % alignment; |
||
501 | if (remainder > 0) |
||
502 | bytes_per_row += (alignment - remainder); |
||
503 | |||
504 | ASSERT(bytes_per_row % alignment == 0); |
||
505 | |||
506 | bytes_per_image = bytes_per_row * rows_per_image; |
||
507 | |||
508 | if (packing->Invert) { |
||
509 | /* set pixel_addr to the last row */ |
||
510 | topOfImage = bytes_per_row * (height - 1); |
||
511 | bytes_per_row = -bytes_per_row; |
||
512 | } |
||
513 | else { |
||
514 | topOfImage = 0; |
||
515 | } |
||
516 | |||
517 | /* compute final pixel address */ |
||
518 | pixel_addr = (GLubyte *) image |
||
519 | + (skipimages + img) * bytes_per_image |
||
520 | + topOfImage |
||
521 | + (skiprows + row) * bytes_per_row |
||
522 | + (skippixels + column) * bytes_per_pixel; |
||
523 | } |
||
524 | |||
525 | return (GLvoid *) pixel_addr; |
||
526 | } |
||
527 | |||
528 | |||
529 | |||
530 | /* |
||
531 | * Compute the stride between image rows (in bytes) for the given |
||
532 | * pixel packing parameters and image width, format and type. |
||
533 | */ |
||
534 | GLint |
||
535 | _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing, |
||
536 | GLint width, GLenum format, GLenum type ) |
||
537 | { |
||
538 | ASSERT(packing); |
||
539 | if (type == GL_BITMAP) { |
||
540 | /* BITMAP data */ |
||
541 | GLint bytes; |
||
542 | if (packing->RowLength == 0) { |
||
543 | bytes = (width + 7) / 8; |
||
544 | } |
||
545 | else { |
||
546 | bytes = (packing->RowLength + 7) / 8; |
||
547 | } |
||
548 | if (packing->Invert) { |
||
549 | /* negate the bytes per row (negative row stride) */ |
||
550 | bytes = -bytes; |
||
551 | } |
||
552 | return bytes; |
||
553 | } |
||
554 | else { |
||
555 | /* Non-BITMAP data */ |
||
556 | const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type); |
||
557 | GLint bytesPerRow, remainder; |
||
558 | if (bytesPerPixel <= 0) |
||
559 | return -1; /* error */ |
||
560 | if (packing->RowLength == 0) { |
||
561 | bytesPerRow = bytesPerPixel * width; |
||
562 | } |
||
563 | else { |
||
564 | bytesPerRow = bytesPerPixel * packing->RowLength; |
||
565 | } |
||
566 | remainder = bytesPerRow % packing->Alignment; |
||
567 | if (remainder > 0) |
||
568 | bytesPerRow += (packing->Alignment - remainder); |
||
569 | if (packing->Invert) |
||
570 | bytesPerRow = -bytesPerRow; |
||
571 | return bytesPerRow; |
||
572 | } |
||
573 | } |
||
574 | |||
575 | |||
576 | |||
577 | /* |
||
578 | * Compute the stride between images in a 3D texture (in bytes) for the given |
||
579 | * pixel packing parameters and image width, format and type. |
||
580 | */ |
||
581 | GLint |
||
582 | _mesa_image_image_stride( const struct gl_pixelstore_attrib *packing, |
||
583 | GLint width, GLint height, |
||
584 | GLenum format, GLenum type ) |
||
585 | { |
||
586 | ASSERT(packing); |
||
587 | ASSERT(type != GL_BITMAP); |
||
588 | |||
589 | { |
||
590 | const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type); |
||
591 | GLint bytesPerRow, bytesPerImage, remainder; |
||
592 | |||
593 | if (bytesPerPixel <= 0) |
||
594 | return -1; /* error */ |
||
595 | if (packing->RowLength == 0) { |
||
596 | bytesPerRow = bytesPerPixel * width; |
||
597 | } |
||
598 | else { |
||
599 | bytesPerRow = bytesPerPixel * packing->RowLength; |
||
600 | } |
||
601 | remainder = bytesPerRow % packing->Alignment; |
||
602 | if (remainder > 0) |
||
603 | bytesPerRow += (packing->Alignment - remainder); |
||
604 | |||
605 | if (packing->ImageHeight == 0) |
||
606 | bytesPerImage = bytesPerRow * height; |
||
607 | else |
||
608 | bytesPerImage = bytesPerRow * packing->ImageHeight; |
||
609 | |||
610 | return bytesPerImage; |
||
611 | } |
||
612 | } |
||
613 | |||
614 | |||
615 | |||
616 | |||
617 | /* |
||
618 | * Unpack a 32x32 pixel polygon stipple from user memory using the |
||
619 | * current pixel unpack settings. |
||
620 | */ |
||
621 | void |
||
622 | _mesa_unpack_polygon_stipple( const GLubyte *pattern, GLuint dest[32], |
||
623 | const struct gl_pixelstore_attrib *unpacking ) |
||
624 | { |
||
625 | GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap( 32, 32, pattern, unpacking ); |
||
626 | if (ptrn) { |
||
627 | /* Convert pattern from GLubytes to GLuints and handle big/little |
||
628 | * endian differences |
||
629 | */ |
||
630 | GLubyte *p = ptrn; |
||
631 | GLint i; |
||
632 | for (i = 0; i < 32; i++) { |
||
633 | dest[i] = (p[0] << 24) |
||
634 | | (p[1] << 16) |
||
635 | | (p[2] << 8) |
||
636 | | (p[3] ); |
||
637 | p += 4; |
||
638 | } |
||
639 | FREE(ptrn); |
||
640 | } |
||
641 | } |
||
642 | |||
643 | |||
644 | |||
645 | /* |
||
646 | * Pack polygon stipple into user memory given current pixel packing |
||
647 | * settings. |
||
648 | */ |
||
649 | void |
||
650 | _mesa_pack_polygon_stipple( const GLuint pattern[32], GLubyte *dest, |
||
651 | const struct gl_pixelstore_attrib *packing ) |
||
652 | { |
||
653 | /* Convert pattern from GLuints to GLubytes to handle big/little |
||
654 | * endian differences. |
||
655 | */ |
||
656 | GLubyte ptrn[32*4]; |
||
657 | GLint i; |
||
658 | for (i = 0; i < 32; i++) { |
||
659 | ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff); |
||
660 | ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff); |
||
661 | ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff); |
||
662 | ptrn[i * 4 + 3] = (GLubyte) ((pattern[i] ) & 0xff); |
||
663 | } |
||
664 | |||
665 | _mesa_pack_bitmap(32, 32, ptrn, dest, packing); |
||
666 | } |
||
667 | |||
668 | |||
669 | /* |
||
670 | * Unpack bitmap data. Resulting data will be in most-significant-bit-first |
||
671 | * order with row alignment = 1 byte. |
||
672 | */ |
||
673 | GLvoid * |
||
674 | _mesa_unpack_bitmap( GLint width, GLint height, const GLubyte *pixels, |
||
675 | const struct gl_pixelstore_attrib *packing ) |
||
676 | { |
||
677 | GLint bytes, row, width_in_bytes; |
||
678 | GLubyte *buffer, *dst; |
||
679 | |||
680 | if (!pixels) |
||
681 | return NULL; |
||
682 | |||
683 | /* Alloc dest storage */ |
||
684 | bytes = ((width + 7) / 8 * height); |
||
685 | buffer = (GLubyte *) MALLOC( bytes ); |
||
686 | if (!buffer) |
||
687 | return NULL; |
||
688 | |||
689 | |||
690 | width_in_bytes = CEILING( width, 8 ); |
||
691 | dst = buffer; |
||
692 | for (row = 0; row < height; row++) { |
||
693 | const GLubyte *src = (const GLubyte *) |
||
694 | _mesa_image_address(packing, pixels, width, height, |
||
695 | GL_COLOR_INDEX, GL_BITMAP, 0, row, 0); |
||
696 | if (!src) { |
||
697 | FREE(buffer); |
||
698 | return NULL; |
||
699 | } |
||
700 | |||
701 | if (packing->SkipPixels == 0) { |
||
702 | MEMCPY( dst, src, width_in_bytes ); |
||
703 | if (packing->LsbFirst) { |
||
704 | flip_bytes( dst, width_in_bytes ); |
||
705 | } |
||
706 | } |
||
707 | else { |
||
708 | /* handling SkipPixels is a bit tricky (no pun intended!) */ |
||
709 | GLint i; |
||
710 | if (packing->LsbFirst) { |
||
711 | GLubyte srcMask = 1 << (packing->SkipPixels & 0x7); |
||
712 | GLubyte dstMask = 128; |
||
713 | const GLubyte *s = src; |
||
714 | GLubyte *d = dst; |
||
715 | *d = 0; |
||
716 | for (i = 0; i < width; i++) { |
||
717 | if (*s & srcMask) { |
||
718 | *d |= dstMask; |
||
719 | } |
||
720 | if (srcMask == 128) { |
||
721 | srcMask = 1; |
||
722 | s++; |
||
723 | } |
||
724 | else { |
||
725 | srcMask = srcMask << 1; |
||
726 | } |
||
727 | if (dstMask == 1) { |
||
728 | dstMask = 128; |
||
729 | d++; |
||
730 | *d = 0; |
||
731 | } |
||
732 | else { |
||
733 | dstMask = dstMask >> 1; |
||
734 | } |
||
735 | } |
||
736 | } |
||
737 | else { |
||
738 | GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7); |
||
739 | GLubyte dstMask = 128; |
||
740 | const GLubyte *s = src; |
||
741 | GLubyte *d = dst; |
||
742 | *d = 0; |
||
743 | for (i = 0; i < width; i++) { |
||
744 | if (*s & srcMask) { |
||
745 | *d |= dstMask; |
||
746 | } |
||
747 | if (srcMask == 1) { |
||
748 | srcMask = 128; |
||
749 | s++; |
||
750 | } |
||
751 | else { |
||
752 | srcMask = srcMask >> 1; |
||
753 | } |
||
754 | if (dstMask == 1) { |
||
755 | dstMask = 128; |
||
756 | d++; |
||
757 | *d = 0; |
||
758 | } |
||
759 | else { |
||
760 | dstMask = dstMask >> 1; |
||
761 | } |
||
762 | } |
||
763 | } |
||
764 | } |
||
765 | dst += width_in_bytes; |
||
766 | } |
||
767 | |||
768 | return buffer; |
||
769 | } |
||
770 | |||
771 | |||
772 | /* |
||
773 | * Pack bitmap data. |
||
774 | */ |
||
775 | void |
||
776 | _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source, |
||
777 | GLubyte *dest, const struct gl_pixelstore_attrib *packing ) |
||
778 | { |
||
779 | GLint row, width_in_bytes; |
||
780 | const GLubyte *src; |
||
781 | |||
782 | if (!source) |
||
783 | return; |
||
784 | |||
785 | width_in_bytes = CEILING( width, 8 ); |
||
786 | src = source; |
||
787 | for (row = 0; row < height; row++) { |
||
788 | GLubyte *dst = (GLubyte *) _mesa_image_address( packing, dest, |
||
789 | width, height, GL_COLOR_INDEX, GL_BITMAP, 0, row, 0 ); |
||
790 | if (!dst) |
||
791 | return; |
||
792 | |||
793 | if (packing->SkipPixels == 0) { |
||
794 | MEMCPY( dst, src, width_in_bytes ); |
||
795 | if (packing->LsbFirst) { |
||
796 | flip_bytes( dst, width_in_bytes ); |
||
797 | } |
||
798 | } |
||
799 | else { |
||
800 | /* handling SkipPixels is a bit tricky (no pun intended!) */ |
||
801 | GLint i; |
||
802 | if (packing->LsbFirst) { |
||
803 | GLubyte srcMask = 1 << (packing->SkipPixels & 0x7); |
||
804 | GLubyte dstMask = 128; |
||
805 | const GLubyte *s = src; |
||
806 | GLubyte *d = dst; |
||
807 | *d = 0; |
||
808 | for (i = 0; i < width; i++) { |
||
809 | if (*s & srcMask) { |
||
810 | *d |= dstMask; |
||
811 | } |
||
812 | if (srcMask == 128) { |
||
813 | srcMask = 1; |
||
814 | s++; |
||
815 | } |
||
816 | else { |
||
817 | srcMask = srcMask << 1; |
||
818 | } |
||
819 | if (dstMask == 1) { |
||
820 | dstMask = 128; |
||
821 | d++; |
||
822 | *d = 0; |
||
823 | } |
||
824 | else { |
||
825 | dstMask = dstMask >> 1; |
||
826 | } |
||
827 | } |
||
828 | } |
||
829 | else { |
||
830 | GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7); |
||
831 | GLubyte dstMask = 128; |
||
832 | const GLubyte *s = src; |
||
833 | GLubyte *d = dst; |
||
834 | *d = 0; |
||
835 | for (i = 0; i < width; i++) { |
||
836 | if (*s & srcMask) { |
||
837 | *d |= dstMask; |
||
838 | } |
||
839 | if (srcMask == 1) { |
||
840 | srcMask = 128; |
||
841 | s++; |
||
842 | } |
||
843 | else { |
||
844 | srcMask = srcMask >> 1; |
||
845 | } |
||
846 | if (dstMask == 1) { |
||
847 | dstMask = 128; |
||
848 | d++; |
||
849 | *d = 0; |
||
850 | } |
||
851 | else { |
||
852 | dstMask = dstMask >> 1; |
||
853 | } |
||
854 | } |
||
855 | } |
||
856 | } |
||
857 | src += width_in_bytes; |
||
858 | } |
||
859 | } |
||
860 | |||
861 | |||
862 | |||
863 | /* |
||
864 | * Used to pack an array [][4] of RGBA GLchan colors as specified |
||
865 | * by the dstFormat, dstType and dstPacking. Used by glReadPixels, |
||
866 | * glGetConvolutionFilter(), etc. |
||
867 | */ |
||
868 | void |
||
869 | _mesa_pack_float_rgba_span( GLcontext *ctx, |
||
870 | GLuint n, CONST GLfloat rgbaIn[][4], |
||
871 | GLenum dstFormat, GLenum dstType, |
||
872 | GLvoid *dstAddr, |
||
873 | const struct gl_pixelstore_attrib *dstPacking, |
||
874 | GLuint transferOps ) |
||
875 | { |
||
876 | const GLint comps = _mesa_components_in_format(dstFormat); |
||
877 | GLfloat luminance[MAX_WIDTH]; |
||
878 | GLfloat (*rgba)[4]; |
||
879 | GLuint i; |
||
880 | |||
881 | if (transferOps) { |
||
882 | /* make copy of incoming data */ |
||
883 | DEFMARRAY(GLfloat, rgbaCopy, MAX_WIDTH, 4); /* mac 32k limitation */ |
||
884 | CHECKARRAY(rgbaCopy, return); /* mac 32k limitation */ |
||
885 | |||
886 | for (i = 0; i < n; i++) { |
||
887 | rgbaCopy[i][0] = rgbaIn[i][0]; |
||
888 | rgbaCopy[i][1] = rgbaIn[i][1]; |
||
889 | rgbaCopy[i][2] = rgbaIn[i][2]; |
||
890 | rgbaCopy[i][3] = rgbaIn[i][3]; |
||
891 | } |
||
892 | |||
893 | rgba = (GLfloat (*)[4]) rgbaCopy; |
||
894 | |||
895 | /* scale & bias */ |
||
896 | if (transferOps & IMAGE_SCALE_BIAS_BIT) { |
||
897 | _mesa_scale_and_bias_rgba(ctx, n, rgba, |
||
898 | ctx->Pixel.RedScale, ctx->Pixel.GreenScale, |
||
899 | ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale, |
||
900 | ctx->Pixel.RedBias, ctx->Pixel.GreenBias, |
||
901 | ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias); |
||
902 | } |
||
903 | /* color map lookup */ |
||
904 | if (transferOps & IMAGE_MAP_COLOR_BIT) { |
||
905 | _mesa_map_rgba( ctx, n, rgba ); |
||
906 | } |
||
907 | /* GL_COLOR_TABLE lookup */ |
||
908 | if (transferOps & IMAGE_COLOR_TABLE_BIT) { |
||
909 | _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); |
||
910 | } |
||
911 | /* convolution */ |
||
912 | if (transferOps & IMAGE_CONVOLUTION_BIT) { |
||
913 | /* this has to be done in the calling code */ |
||
914 | } |
||
915 | /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */ |
||
916 | if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) { |
||
917 | _mesa_scale_and_bias_rgba(ctx, n, rgba, |
||
918 | ctx->Pixel.PostConvolutionScale[RCOMP], |
||
919 | ctx->Pixel.PostConvolutionScale[GCOMP], |
||
920 | ctx->Pixel.PostConvolutionScale[BCOMP], |
||
921 | ctx->Pixel.PostConvolutionScale[ACOMP], |
||
922 | ctx->Pixel.PostConvolutionBias[RCOMP], |
||
923 | ctx->Pixel.PostConvolutionBias[GCOMP], |
||
924 | ctx->Pixel.PostConvolutionBias[BCOMP], |
||
925 | ctx->Pixel.PostConvolutionBias[ACOMP]); |
||
926 | } |
||
927 | /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ |
||
928 | if (transferOps & IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT) { |
||
929 | _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, n, rgba); |
||
930 | } |
||
931 | /* color matrix transform */ |
||
932 | if (transferOps & IMAGE_COLOR_MATRIX_BIT) { |
||
933 | _mesa_transform_rgba(ctx, n, rgba); |
||
934 | } |
||
935 | /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ |
||
936 | if (transferOps & IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT) { |
||
937 | _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba); |
||
938 | } |
||
939 | /* update histogram count */ |
||
940 | if (transferOps & IMAGE_HISTOGRAM_BIT) { |
||
941 | _mesa_update_histogram(ctx, n, (CONST GLfloat (*)[4]) rgba); |
||
942 | } |
||
943 | /* min/max here */ |
||
944 | if (transferOps & IMAGE_MIN_MAX_BIT) { |
||
945 | _mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba); |
||
946 | if (ctx->MinMax.Sink) { |
||
947 | UNDEFARRAY(rgbaCopy); /* mac 32k limitation */ |
||
948 | return; |
||
949 | } |
||
950 | } |
||
951 | UNDEFARRAY(rgbaCopy); /* mac 32k limitation */ |
||
952 | } |
||
953 | else { |
||
954 | /* use incoming data, not a copy */ |
||
955 | rgba = (GLfloat (*)[4]) rgbaIn; |
||
956 | } |
||
957 | |||
958 | /* XXX clamp rgba to [0,1]? */ |
||
959 | |||
960 | |||
961 | if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) { |
||
962 | for (i = 0; i < n; i++) { |
||
963 | GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP]; |
||
964 | #if CHAN_TYPE == GL_FLOAT |
||
965 | luminance[i] = sum; |
||
966 | #else |
||
967 | luminance[i] = CLAMP(sum, 0.0F, 1.0F); |
||
968 | #endif |
||
969 | } |
||
970 | } |
||
971 | |||
972 | /* |
||
973 | * Pack/store the pixels. Ugh! Lots of cases!!! |
||
974 | */ |
||
975 | switch (dstType) { |
||
976 | case GL_UNSIGNED_BYTE: |
||
977 | { |
||
978 | GLubyte *dst = (GLubyte *) dstAddr; |
||
979 | switch (dstFormat) { |
||
980 | case GL_RED: |
||
981 | for (i=0;i<n;i++) |
||
982 | dst[i] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
||
983 | break; |
||
984 | case GL_GREEN: |
||
985 | for (i=0;i<n;i++) |
||
986 | dst[i] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
||
987 | break; |
||
988 | case GL_BLUE: |
||
989 | for (i=0;i<n;i++) |
||
990 | dst[i] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
||
991 | break; |
||
992 | case GL_ALPHA: |
||
993 | for (i=0;i<n;i++) |
||
994 | dst[i] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
||
995 | break; |
||
996 | case GL_LUMINANCE: |
||
997 | for (i=0;i<n;i++) |
||
998 | dst[i] = FLOAT_TO_UBYTE(luminance[i]); |
||
999 | break; |
||
1000 | case GL_LUMINANCE_ALPHA: |
||
1001 | for (i=0;i<n;i++) { |
||
1002 | dst[i*2+0] = FLOAT_TO_UBYTE(luminance[i]); |
||
1003 | dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
||
1004 | } |
||
1005 | break; |
||
1006 | case GL_RGB: |
||
1007 | for (i=0;i<n;i++) { |
||
1008 | dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
||
1009 | dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
||
1010 | dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
||
1011 | } |
||
1012 | break; |
||
1013 | case GL_RGBA: |
||
1014 | for (i=0;i<n;i++) { |
||
1015 | dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
||
1016 | dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
||
1017 | dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
||
1018 | dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
||
1019 | } |
||
1020 | break; |
||
1021 | case GL_BGR: |
||
1022 | for (i=0;i<n;i++) { |
||
1023 | dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
||
1024 | dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
||
1025 | dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
||
1026 | } |
||
1027 | break; |
||
1028 | case GL_BGRA: |
||
1029 | for (i=0;i<n;i++) { |
||
1030 | dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
||
1031 | dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
||
1032 | dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
||
1033 | dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
||
1034 | } |
||
1035 | break; |
||
1036 | case GL_ABGR_EXT: |
||
1037 | for (i=0;i<n;i++) { |
||
1038 | dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][ACOMP]); |
||
1039 | dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][BCOMP]); |
||
1040 | dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][GCOMP]); |
||
1041 | dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][RCOMP]); |
||
1042 | } |
||
1043 | break; |
||
1044 | default: |
||
1045 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1046 | } |
||
1047 | } |
||
1048 | break; |
||
1049 | case GL_BYTE: |
||
1050 | { |
||
1051 | GLbyte *dst = (GLbyte *) dstAddr; |
||
1052 | switch (dstFormat) { |
||
1053 | case GL_RED: |
||
1054 | for (i=0;i<n;i++) |
||
1055 | dst[i] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
||
1056 | break; |
||
1057 | case GL_GREEN: |
||
1058 | for (i=0;i<n;i++) |
||
1059 | dst[i] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
||
1060 | break; |
||
1061 | case GL_BLUE: |
||
1062 | for (i=0;i<n;i++) |
||
1063 | dst[i] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
||
1064 | break; |
||
1065 | case GL_ALPHA: |
||
1066 | for (i=0;i<n;i++) |
||
1067 | dst[i] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
||
1068 | break; |
||
1069 | case GL_LUMINANCE: |
||
1070 | for (i=0;i<n;i++) |
||
1071 | dst[i] = FLOAT_TO_BYTE(luminance[i]); |
||
1072 | break; |
||
1073 | case GL_LUMINANCE_ALPHA: |
||
1074 | for (i=0;i<n;i++) { |
||
1075 | dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]); |
||
1076 | dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
||
1077 | } |
||
1078 | break; |
||
1079 | case GL_RGB: |
||
1080 | for (i=0;i<n;i++) { |
||
1081 | dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
||
1082 | dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
||
1083 | dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
||
1084 | } |
||
1085 | break; |
||
1086 | case GL_RGBA: |
||
1087 | for (i=0;i<n;i++) { |
||
1088 | dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
||
1089 | dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
||
1090 | dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
||
1091 | dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
||
1092 | } |
||
1093 | break; |
||
1094 | case GL_BGR: |
||
1095 | for (i=0;i<n;i++) { |
||
1096 | dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
||
1097 | dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
||
1098 | dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
||
1099 | } |
||
1100 | break; |
||
1101 | case GL_BGRA: |
||
1102 | for (i=0;i<n;i++) { |
||
1103 | dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
||
1104 | dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
||
1105 | dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
||
1106 | dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
||
1107 | } |
||
1108 | case GL_ABGR_EXT: |
||
1109 | for (i=0;i<n;i++) { |
||
1110 | dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][ACOMP]); |
||
1111 | dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][BCOMP]); |
||
1112 | dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][GCOMP]); |
||
1113 | dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][RCOMP]); |
||
1114 | } |
||
1115 | break; |
||
1116 | default: |
||
1117 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1118 | } |
||
1119 | } |
||
1120 | break; |
||
1121 | case GL_UNSIGNED_SHORT: |
||
1122 | { |
||
1123 | GLushort *dst = (GLushort *) dstAddr; |
||
1124 | switch (dstFormat) { |
||
1125 | case GL_RED: |
||
1126 | for (i=0;i<n;i++) |
||
1127 | dst[i] = FLOAT_TO_USHORT(rgba[i][RCOMP]); |
||
1128 | break; |
||
1129 | case GL_GREEN: |
||
1130 | for (i=0;i<n;i++) |
||
1131 | dst[i] = FLOAT_TO_USHORT(rgba[i][GCOMP]); |
||
1132 | break; |
||
1133 | case GL_BLUE: |
||
1134 | for (i=0;i<n;i++) |
||
1135 | dst[i] = FLOAT_TO_USHORT(rgba[i][BCOMP]); |
||
1136 | break; |
||
1137 | case GL_ALPHA: |
||
1138 | for (i=0;i<n;i++) |
||
1139 | dst[i] = FLOAT_TO_USHORT(rgba[i][ACOMP]); |
||
1140 | break; |
||
1141 | case GL_LUMINANCE: |
||
1142 | for (i=0;i<n;i++) |
||
1143 | dst[i] = FLOAT_TO_USHORT(luminance[i]); |
||
1144 | break; |
||
1145 | case GL_LUMINANCE_ALPHA: |
||
1146 | for (i=0;i<n;i++) { |
||
1147 | dst[i*2+0] = FLOAT_TO_USHORT(luminance[i]); |
||
1148 | dst[i*2+1] = FLOAT_TO_USHORT(rgba[i][ACOMP]); |
||
1149 | } |
||
1150 | break; |
||
1151 | case GL_RGB: |
||
1152 | for (i=0;i<n;i++) { |
||
1153 | dst[i*3+0] = FLOAT_TO_USHORT(rgba[i][RCOMP]); |
||
1154 | dst[i*3+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]); |
||
1155 | dst[i*3+2] = FLOAT_TO_USHORT(rgba[i][BCOMP]); |
||
1156 | } |
||
1157 | break; |
||
1158 | case GL_RGBA: |
||
1159 | for (i=0;i<n;i++) { |
||
1160 | dst[i*4+0] = FLOAT_TO_USHORT(rgba[i][RCOMP]); |
||
1161 | dst[i*4+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]); |
||
1162 | dst[i*4+2] = FLOAT_TO_USHORT(rgba[i][BCOMP]); |
||
1163 | dst[i*4+3] = FLOAT_TO_USHORT(rgba[i][ACOMP]); |
||
1164 | } |
||
1165 | break; |
||
1166 | case GL_BGR: |
||
1167 | for (i=0;i<n;i++) { |
||
1168 | dst[i*3+0] = FLOAT_TO_USHORT(rgba[i][BCOMP]); |
||
1169 | dst[i*3+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]); |
||
1170 | dst[i*3+2] = FLOAT_TO_USHORT(rgba[i][RCOMP]); |
||
1171 | } |
||
1172 | break; |
||
1173 | case GL_BGRA: |
||
1174 | for (i=0;i<n;i++) { |
||
1175 | dst[i*4+0] = FLOAT_TO_USHORT(rgba[i][BCOMP]); |
||
1176 | dst[i*4+1] = FLOAT_TO_USHORT(rgba[i][GCOMP]); |
||
1177 | dst[i*4+2] = FLOAT_TO_USHORT(rgba[i][RCOMP]); |
||
1178 | dst[i*4+3] = FLOAT_TO_USHORT(rgba[i][ACOMP]); |
||
1179 | } |
||
1180 | break; |
||
1181 | case GL_ABGR_EXT: |
||
1182 | for (i=0;i<n;i++) { |
||
1183 | dst[i*4+0] = FLOAT_TO_USHORT(rgba[i][ACOMP]); |
||
1184 | dst[i*4+1] = FLOAT_TO_USHORT(rgba[i][BCOMP]); |
||
1185 | dst[i*4+2] = FLOAT_TO_USHORT(rgba[i][GCOMP]); |
||
1186 | dst[i*4+3] = FLOAT_TO_USHORT(rgba[i][RCOMP]); |
||
1187 | } |
||
1188 | break; |
||
1189 | default: |
||
1190 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1191 | } |
||
1192 | if (dstPacking->SwapBytes) { |
||
1193 | _mesa_swap2( (GLushort *) dst, n * comps); |
||
1194 | } |
||
1195 | } |
||
1196 | break; |
||
1197 | case GL_SHORT: |
||
1198 | { |
||
1199 | GLshort *dst = (GLshort *) dstAddr; |
||
1200 | switch (dstFormat) { |
||
1201 | case GL_RED: |
||
1202 | for (i=0;i<n;i++) |
||
1203 | dst[i] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
||
1204 | break; |
||
1205 | case GL_GREEN: |
||
1206 | for (i=0;i<n;i++) |
||
1207 | dst[i] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
||
1208 | break; |
||
1209 | case GL_BLUE: |
||
1210 | for (i=0;i<n;i++) |
||
1211 | dst[i] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
||
1212 | break; |
||
1213 | case GL_ALPHA: |
||
1214 | for (i=0;i<n;i++) |
||
1215 | dst[i] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
||
1216 | break; |
||
1217 | case GL_LUMINANCE: |
||
1218 | for (i=0;i<n;i++) |
||
1219 | dst[i] = FLOAT_TO_SHORT(luminance[i]); |
||
1220 | break; |
||
1221 | case GL_LUMINANCE_ALPHA: |
||
1222 | for (i=0;i<n;i++) { |
||
1223 | dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]); |
||
1224 | dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
||
1225 | } |
||
1226 | break; |
||
1227 | case GL_RGB: |
||
1228 | for (i=0;i<n;i++) { |
||
1229 | dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
||
1230 | dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
||
1231 | dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
||
1232 | } |
||
1233 | break; |
||
1234 | case GL_RGBA: |
||
1235 | for (i=0;i<n;i++) { |
||
1236 | dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
||
1237 | dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
||
1238 | dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
||
1239 | dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
||
1240 | } |
||
1241 | break; |
||
1242 | case GL_BGR: |
||
1243 | for (i=0;i<n;i++) { |
||
1244 | dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
||
1245 | dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
||
1246 | dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
||
1247 | } |
||
1248 | break; |
||
1249 | case GL_BGRA: |
||
1250 | for (i=0;i<n;i++) { |
||
1251 | dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
||
1252 | dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
||
1253 | dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
||
1254 | dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
||
1255 | } |
||
1256 | case GL_ABGR_EXT: |
||
1257 | for (i=0;i<n;i++) { |
||
1258 | dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][ACOMP]); |
||
1259 | dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][BCOMP]); |
||
1260 | dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][GCOMP]); |
||
1261 | dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][RCOMP]); |
||
1262 | } |
||
1263 | break; |
||
1264 | default: |
||
1265 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1266 | } |
||
1267 | if (dstPacking->SwapBytes) { |
||
1268 | _mesa_swap2( (GLushort *) dst, n * comps ); |
||
1269 | } |
||
1270 | } |
||
1271 | break; |
||
1272 | case GL_UNSIGNED_INT: |
||
1273 | { |
||
1274 | GLuint *dst = (GLuint *) dstAddr; |
||
1275 | switch (dstFormat) { |
||
1276 | case GL_RED: |
||
1277 | for (i=0;i<n;i++) |
||
1278 | dst[i] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
||
1279 | break; |
||
1280 | case GL_GREEN: |
||
1281 | for (i=0;i<n;i++) |
||
1282 | dst[i] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
||
1283 | break; |
||
1284 | case GL_BLUE: |
||
1285 | for (i=0;i<n;i++) |
||
1286 | dst[i] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
||
1287 | break; |
||
1288 | case GL_ALPHA: |
||
1289 | for (i=0;i<n;i++) |
||
1290 | dst[i] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
||
1291 | break; |
||
1292 | case GL_LUMINANCE: |
||
1293 | for (i=0;i<n;i++) |
||
1294 | dst[i] = FLOAT_TO_UINT(luminance[i]); |
||
1295 | break; |
||
1296 | case GL_LUMINANCE_ALPHA: |
||
1297 | for (i=0;i<n;i++) { |
||
1298 | dst[i*2+0] = FLOAT_TO_UINT(luminance[i]); |
||
1299 | dst[i*2+1] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
||
1300 | } |
||
1301 | break; |
||
1302 | case GL_RGB: |
||
1303 | for (i=0;i<n;i++) { |
||
1304 | dst[i*3+0] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
||
1305 | dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
||
1306 | dst[i*3+2] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
||
1307 | } |
||
1308 | break; |
||
1309 | case GL_RGBA: |
||
1310 | for (i=0;i<n;i++) { |
||
1311 | dst[i*4+0] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
||
1312 | dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
||
1313 | dst[i*4+2] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
||
1314 | dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
||
1315 | } |
||
1316 | break; |
||
1317 | case GL_BGR: |
||
1318 | for (i=0;i<n;i++) { |
||
1319 | dst[i*3+0] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
||
1320 | dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
||
1321 | dst[i*3+2] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
||
1322 | } |
||
1323 | break; |
||
1324 | case GL_BGRA: |
||
1325 | for (i=0;i<n;i++) { |
||
1326 | dst[i*4+0] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
||
1327 | dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
||
1328 | dst[i*4+2] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
||
1329 | dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
||
1330 | } |
||
1331 | break; |
||
1332 | case GL_ABGR_EXT: |
||
1333 | for (i=0;i<n;i++) { |
||
1334 | dst[i*4+0] = FLOAT_TO_UINT(rgba[i][ACOMP]); |
||
1335 | dst[i*4+1] = FLOAT_TO_UINT(rgba[i][BCOMP]); |
||
1336 | dst[i*4+2] = FLOAT_TO_UINT(rgba[i][GCOMP]); |
||
1337 | dst[i*4+3] = FLOAT_TO_UINT(rgba[i][RCOMP]); |
||
1338 | } |
||
1339 | break; |
||
1340 | default: |
||
1341 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1342 | } |
||
1343 | if (dstPacking->SwapBytes) { |
||
1344 | _mesa_swap4( (GLuint *) dst, n * comps ); |
||
1345 | } |
||
1346 | } |
||
1347 | break; |
||
1348 | case GL_INT: |
||
1349 | { |
||
1350 | GLint *dst = (GLint *) dstAddr; |
||
1351 | switch (dstFormat) { |
||
1352 | case GL_RED: |
||
1353 | for (i=0;i<n;i++) |
||
1354 | dst[i] = FLOAT_TO_INT(rgba[i][RCOMP]); |
||
1355 | break; |
||
1356 | case GL_GREEN: |
||
1357 | for (i=0;i<n;i++) |
||
1358 | dst[i] = FLOAT_TO_INT(rgba[i][GCOMP]); |
||
1359 | break; |
||
1360 | case GL_BLUE: |
||
1361 | for (i=0;i<n;i++) |
||
1362 | dst[i] = FLOAT_TO_INT(rgba[i][BCOMP]); |
||
1363 | break; |
||
1364 | case GL_ALPHA: |
||
1365 | for (i=0;i<n;i++) |
||
1366 | dst[i] = FLOAT_TO_INT(rgba[i][ACOMP]); |
||
1367 | break; |
||
1368 | case GL_LUMINANCE: |
||
1369 | for (i=0;i<n;i++) |
||
1370 | dst[i] = FLOAT_TO_INT(luminance[i]); |
||
1371 | break; |
||
1372 | case GL_LUMINANCE_ALPHA: |
||
1373 | for (i=0;i<n;i++) { |
||
1374 | dst[i*2+0] = FLOAT_TO_INT(luminance[i]); |
||
1375 | dst[i*2+1] = FLOAT_TO_INT(rgba[i][ACOMP]); |
||
1376 | } |
||
1377 | break; |
||
1378 | case GL_RGB: |
||
1379 | for (i=0;i<n;i++) { |
||
1380 | dst[i*3+0] = FLOAT_TO_INT(rgba[i][RCOMP]); |
||
1381 | dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
||
1382 | dst[i*3+2] = FLOAT_TO_INT(rgba[i][BCOMP]); |
||
1383 | } |
||
1384 | break; |
||
1385 | case GL_RGBA: |
||
1386 | for (i=0;i<n;i++) { |
||
1387 | dst[i*4+0] = FLOAT_TO_INT(rgba[i][RCOMP]); |
||
1388 | dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
||
1389 | dst[i*4+2] = FLOAT_TO_INT(rgba[i][BCOMP]); |
||
1390 | dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]); |
||
1391 | } |
||
1392 | break; |
||
1393 | case GL_BGR: |
||
1394 | for (i=0;i<n;i++) { |
||
1395 | dst[i*3+0] = FLOAT_TO_INT(rgba[i][BCOMP]); |
||
1396 | dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
||
1397 | dst[i*3+2] = FLOAT_TO_INT(rgba[i][RCOMP]); |
||
1398 | } |
||
1399 | break; |
||
1400 | case GL_BGRA: |
||
1401 | for (i=0;i<n;i++) { |
||
1402 | dst[i*4+0] = FLOAT_TO_INT(rgba[i][BCOMP]); |
||
1403 | dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]); |
||
1404 | dst[i*4+2] = FLOAT_TO_INT(rgba[i][RCOMP]); |
||
1405 | dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]); |
||
1406 | } |
||
1407 | break; |
||
1408 | case GL_ABGR_EXT: |
||
1409 | for (i=0;i<n;i++) { |
||
1410 | dst[i*4+0] = FLOAT_TO_INT(rgba[i][ACOMP]); |
||
1411 | dst[i*4+1] = FLOAT_TO_INT(rgba[i][BCOMP]); |
||
1412 | dst[i*4+2] = FLOAT_TO_INT(rgba[i][GCOMP]); |
||
1413 | dst[i*4+3] = FLOAT_TO_INT(rgba[i][RCOMP]); |
||
1414 | } |
||
1415 | break; |
||
1416 | default: |
||
1417 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1418 | } |
||
1419 | if (dstPacking->SwapBytes) { |
||
1420 | _mesa_swap4( (GLuint *) dst, n * comps ); |
||
1421 | } |
||
1422 | } |
||
1423 | break; |
||
1424 | case GL_FLOAT: |
||
1425 | { |
||
1426 | GLfloat *dst = (GLfloat *) dstAddr; |
||
1427 | switch (dstFormat) { |
||
1428 | case GL_RED: |
||
1429 | for (i=0;i<n;i++) |
||
1430 | dst[i] = rgba[i][RCOMP]; |
||
1431 | break; |
||
1432 | case GL_GREEN: |
||
1433 | for (i=0;i<n;i++) |
||
1434 | dst[i] = rgba[i][GCOMP]; |
||
1435 | break; |
||
1436 | case GL_BLUE: |
||
1437 | for (i=0;i<n;i++) |
||
1438 | dst[i] = rgba[i][BCOMP]; |
||
1439 | break; |
||
1440 | case GL_ALPHA: |
||
1441 | for (i=0;i<n;i++) |
||
1442 | dst[i] = rgba[i][ACOMP]; |
||
1443 | break; |
||
1444 | case GL_LUMINANCE: |
||
1445 | for (i=0;i<n;i++) |
||
1446 | dst[i] = luminance[i]; |
||
1447 | break; |
||
1448 | case GL_LUMINANCE_ALPHA: |
||
1449 | for (i=0;i<n;i++) { |
||
1450 | dst[i*2+0] = luminance[i]; |
||
1451 | dst[i*2+1] = rgba[i][ACOMP]; |
||
1452 | } |
||
1453 | break; |
||
1454 | case GL_RGB: |
||
1455 | for (i=0;i<n;i++) { |
||
1456 | dst[i*3+0] = rgba[i][RCOMP]; |
||
1457 | dst[i*3+1] = rgba[i][GCOMP]; |
||
1458 | dst[i*3+2] = rgba[i][BCOMP]; |
||
1459 | } |
||
1460 | break; |
||
1461 | case GL_RGBA: |
||
1462 | for (i=0;i<n;i++) { |
||
1463 | dst[i*4+0] = rgba[i][RCOMP]; |
||
1464 | dst[i*4+1] = rgba[i][GCOMP]; |
||
1465 | dst[i*4+2] = rgba[i][BCOMP]; |
||
1466 | dst[i*4+3] = rgba[i][ACOMP]; |
||
1467 | } |
||
1468 | break; |
||
1469 | case GL_BGR: |
||
1470 | for (i=0;i<n;i++) { |
||
1471 | dst[i*3+0] = rgba[i][BCOMP]; |
||
1472 | dst[i*3+1] = rgba[i][GCOMP]; |
||
1473 | dst[i*3+2] = rgba[i][RCOMP]; |
||
1474 | } |
||
1475 | break; |
||
1476 | case GL_BGRA: |
||
1477 | for (i=0;i<n;i++) { |
||
1478 | dst[i*4+0] = rgba[i][BCOMP]; |
||
1479 | dst[i*4+1] = rgba[i][GCOMP]; |
||
1480 | dst[i*4+2] = rgba[i][RCOMP]; |
||
1481 | dst[i*4+3] = rgba[i][ACOMP]; |
||
1482 | } |
||
1483 | break; |
||
1484 | case GL_ABGR_EXT: |
||
1485 | for (i=0;i<n;i++) { |
||
1486 | dst[i*4+0] = rgba[i][ACOMP]; |
||
1487 | dst[i*4+1] = rgba[i][BCOMP]; |
||
1488 | dst[i*4+2] = rgba[i][GCOMP]; |
||
1489 | dst[i*4+3] = rgba[i][RCOMP]; |
||
1490 | } |
||
1491 | break; |
||
1492 | default: |
||
1493 | _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n"); |
||
1494 | } |
||
1495 | if (dstPacking->SwapBytes) { |
||
1496 | _mesa_swap4( (GLuint *) dst, n * comps ); |
||
1497 | } |
||
1498 | } |
||
1499 | break; |
||
1500 | case GL_UNSIGNED_BYTE_3_3_2: |
||
1501 | if (dstFormat == GL_RGB) { |
||
1502 | GLubyte *dst = (GLubyte *) dstAddr; |
||
1503 | for (i=0;i<n;i++) { |
||
1504 | dst[i] = (((GLint) (rgba[i][RCOMP] * 7.0F)) << 5) |
||
1505 | | (((GLint) (rgba[i][GCOMP] * 7.0F)) << 2) |
||
1506 | | (((GLint) (rgba[i][BCOMP] * 3.0F)) ); |
||
1507 | } |
||
1508 | } |
||
1509 | break; |
||
1510 | case GL_UNSIGNED_BYTE_2_3_3_REV: |
||
1511 | if (dstFormat == GL_RGB) { |
||
1512 | GLubyte *dst = (GLubyte *) dstAddr; |
||
1513 | for (i=0;i<n;i++) { |
||
1514 | dst[i] = (((GLint) (rgba[i][RCOMP] * 7.0F)) ) |
||
1515 | | (((GLint) (rgba[i][GCOMP] * 7.0F)) << 3) |
||
1516 | | (((GLint) (rgba[i][BCOMP] * 3.0F)) << 5); |
||
1517 | } |
||
1518 | } |
||
1519 | break; |
||
1520 | case GL_UNSIGNED_SHORT_5_6_5: |
||
1521 | if (dstFormat == GL_RGB) { |
||
1522 | GLushort *dst = (GLushort *) dstAddr; |
||
1523 | for (i=0;i<n;i++) { |
||
1524 | dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) << 11) |
||
1525 | | (((GLint) (rgba[i][GCOMP] * 63.0F)) << 5) |
||
1526 | | (((GLint) (rgba[i][BCOMP] * 31.0F)) ); |
||
1527 | } |
||
1528 | } |
||
1529 | break; |
||
1530 | case GL_UNSIGNED_SHORT_5_6_5_REV: |
||
1531 | if (dstFormat == GL_RGB) { |
||
1532 | GLushort *dst = (GLushort *) dstAddr; |
||
1533 | for (i=0;i<n;i++) { |
||
1534 | dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) ) |
||
1535 | | (((GLint) (rgba[i][GCOMP] * 63.0F)) << 5) |
||
1536 | | (((GLint) (rgba[i][BCOMP] * 31.0F)) << 11); |
||
1537 | } |
||
1538 | } |
||
1539 | break; |
||
1540 | case GL_UNSIGNED_SHORT_4_4_4_4: |
||
1541 | if (dstFormat == GL_RGBA) { |
||
1542 | GLushort *dst = (GLushort *) dstAddr; |
||
1543 | for (i=0;i<n;i++) { |
||
1544 | dst[i] = (((GLint) (rgba[i][RCOMP] * 15.0F)) << 12) |
||
1545 | | (((GLint) (rgba[i][GCOMP] * 15.0F)) << 8) |
||
1546 | | (((GLint) (rgba[i][BCOMP] * 15.0F)) << 4) |
||
1547 | | (((GLint) (rgba[i][ACOMP] * 15.0F)) ); |
||
1548 | } |
||
1549 | } |
||
1550 | else if (dstFormat == GL_BGRA) { |
||
1551 | GLushort *dst = (GLushort *) dstAddr; |
||
1552 | for (i=0;i<n;i++) { |
||
1553 | dst[i] = (((GLint) (rgba[i][BCOMP] * 15.0F)) << 12) |
||
1554 | | (((GLint) (rgba[i][GCOMP] * 15.0F)) << 8) |
||
1555 | | (((GLint) (rgba[i][RCOMP] * 15.0F)) << 4) |
||
1556 | | (((GLint) (rgba[i][ACOMP] * 15.0F)) ); |
||
1557 | } |
||
1558 | } |
||
1559 | else if (dstFormat == GL_ABGR_EXT) { |
||
1560 | GLushort *dst = (GLushort *) dstAddr; |
||
1561 | for (i=0;i<n;i++) { |
||
1562 | dst[i] = (((GLint) (rgba[i][ACOMP] * 15.0F)) << 4) |
||
1563 | | (((GLint) (rgba[i][BCOMP] * 15.0F)) << 8) |
||
1564 | | (((GLint) (rgba[i][GCOMP] * 15.0F)) << 12) |
||
1565 | | (((GLint) (rgba[i][RCOMP] * 15.0F)) ); |
||
1566 | } |
||
1567 | } |
||
1568 | break; |
||
1569 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
||
1570 | if (dstFormat == GL_RGBA) { |
||
1571 | GLushort *dst = (GLushort *) dstAddr; |
||
1572 | for (i=0;i<n;i++) { |
||
1573 | dst[i] = (((GLint) (rgba[i][RCOMP] * 15.0F)) ) |
||
1574 | | (((GLint) (rgba[i][GCOMP] * 15.0F)) << 4) |
||
1575 | | (((GLint) (rgba[i][BCOMP] * 15.0F)) << 8) |
||
1576 | | (((GLint) (rgba[i][ACOMP] * 15.0F)) << 12); |
||
1577 | } |
||
1578 | } |
||
1579 | else if (dstFormat == GL_BGRA) { |
||
1580 | GLushort *dst = (GLushort *) dstAddr; |
||
1581 | for (i=0;i<n;i++) { |
||
1582 | dst[i] = (((GLint) (rgba[i][BCOMP] * 15.0F)) ) |
||
1583 | | (((GLint) (rgba[i][GCOMP] * 15.0F)) << 4) |
||
1584 | | (((GLint) (rgba[i][RCOMP] * 15.0F)) << 8) |
||
1585 | | (((GLint) (rgba[i][ACOMP] * 15.0F)) << 12); |
||
1586 | } |
||
1587 | } |
||
1588 | else if (dstFormat == GL_ABGR_EXT) { |
||
1589 | GLushort *dst = (GLushort *) dstAddr; |
||
1590 | for (i=0;i<n;i++) { |
||
1591 | dst[i] = (((GLint) (rgba[i][ACOMP] * 15.0F)) ) |
||
1592 | | (((GLint) (rgba[i][BCOMP] * 15.0F)) << 4) |
||
1593 | | (((GLint) (rgba[i][GCOMP] * 15.0F)) << 8) |
||
1594 | | (((GLint) (rgba[i][RCOMP] * 15.0F)) << 12); |
||
1595 | } |
||
1596 | } |
||
1597 | break; |
||
1598 | case GL_UNSIGNED_SHORT_5_5_5_1: |
||
1599 | if (dstFormat == GL_RGBA) { |
||
1600 | GLushort *dst = (GLushort *) dstAddr; |
||
1601 | for (i=0;i<n;i++) { |
||
1602 | dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) << 11) |
||
1603 | | (((GLint) (rgba[i][GCOMP] * 31.0F)) << 6) |
||
1604 | | (((GLint) (rgba[i][BCOMP] * 31.0F)) << 1) |
||
1605 | | (((GLint) (rgba[i][ACOMP] * 1.0F)) ); |
||
1606 | } |
||
1607 | } |
||
1608 | else if (dstFormat == GL_BGRA) { |
||
1609 | GLushort *dst = (GLushort *) dstAddr; |
||
1610 | for (i=0;i<n;i++) { |
||
1611 | dst[i] = (((GLint) (rgba[i][BCOMP] * 31.0F)) << 11) |
||
1612 | | (((GLint) (rgba[i][GCOMP] * 31.0F)) << 6) |
||
1613 | | (((GLint) (rgba[i][RCOMP] * 31.0F)) << 1) |
||
1614 | | (((GLint) (rgba[i][ACOMP] * 1.0F)) ); |
||
1615 | } |
||
1616 | } |
||
1617 | else if (dstFormat == GL_ABGR_EXT) { |
||
1618 | GLushort *dst = (GLushort *) dstAddr; |
||
1619 | for (i=0;i<n;i++) { |
||
1620 | dst[i] = (((GLint) (rgba[i][ACOMP] * 31.0F)) << 11) |
||
1621 | | (((GLint) (rgba[i][BCOMP] * 31.0F)) << 6) |
||
1622 | | (((GLint) (rgba[i][GCOMP] * 31.0F)) << 1) |
||
1623 | | (((GLint) (rgba[i][RCOMP] * 1.0F)) ); |
||
1624 | } |
||
1625 | } |
||
1626 | break; |
||
1627 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
||
1628 | if (dstFormat == GL_RGBA) { |
||
1629 | GLushort *dst = (GLushort *) dstAddr; |
||
1630 | for (i=0;i<n;i++) { |
||
1631 | dst[i] = (((GLint) (rgba[i][RCOMP] * 31.0F)) ) |
||
1632 | | (((GLint) (rgba[i][GCOMP] * 31.0F)) << 5) |
||
1633 | | (((GLint) (rgba[i][BCOMP] * 31.0F)) << 10) |
||
1634 | | (((GLint) (rgba[i][ACOMP] * 1.0F)) << 15); |
||
1635 | } |
||
1636 | } |
||
1637 | else if (dstFormat == GL_BGRA) { |
||
1638 | GLushort *dst = (GLushort *) dstAddr; |
||
1639 | for (i=0;i<n;i++) { |
||
1640 | dst[i] = (((GLint) (rgba[i][BCOMP] * 31.0F)) ) |
||
1641 | | (((GLint) (rgba[i][GCOMP] * 31.0F)) << 5) |
||
1642 | | (((GLint) (rgba[i][RCOMP] * 31.0F)) << 10) |
||
1643 | | (((GLint) (rgba[i][ACOMP] * 1.0F)) << 15); |
||
1644 | } |
||
1645 | } |
||
1646 | else if (dstFormat == GL_ABGR_EXT) { |
||
1647 | GLushort *dst = (GLushort *) dstAddr; |
||
1648 | for (i=0;i<n;i++) { |
||
1649 | dst[i] = (((GLint) (rgba[i][ACOMP] * 31.0F)) ) |
||
1650 | | (((GLint) (rgba[i][BCOMP] * 31.0F)) << 5) |
||
1651 | | (((GLint) (rgba[i][GCOMP] * 31.0F)) << 10) |
||
1652 | | (((GLint) (rgba[i][RCOMP] * 1.0F)) << 15); |
||
1653 | } |
||
1654 | } |
||
1655 | break; |
||
1656 | case GL_UNSIGNED_INT_8_8_8_8: |
||
1657 | if (dstFormat == GL_RGBA) { |
||
1658 | GLuint *dst = (GLuint *) dstAddr; |
||
1659 | for (i=0;i<n;i++) { |
||
1660 | dst[i] = (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 24) |
||
1661 | | (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 16) |
||
1662 | | (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 8) |
||
1663 | | (((GLuint) (rgba[i][ACOMP] * 255.0F)) ); |
||
1664 | } |
||
1665 | } |
||
1666 | else if (dstFormat == GL_BGRA) { |
||
1667 | GLuint *dst = (GLuint *) dstAddr; |
||
1668 | for (i=0;i<n;i++) { |
||
1669 | dst[i] = (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 24) |
||
1670 | | (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 16) |
||
1671 | | (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 8) |
||
1672 | | (((GLuint) (rgba[i][ACOMP] * 255.0F)) ); |
||
1673 | } |
||
1674 | } |
||
1675 | else if (dstFormat == GL_ABGR_EXT) { |
||
1676 | GLuint *dst = (GLuint *) dstAddr; |
||
1677 | for (i=0;i<n;i++) { |
||
1678 | dst[i] = (((GLuint) (rgba[i][ACOMP] * 255.0F)) << 24) |
||
1679 | | (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 16) |
||
1680 | | (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 8) |
||
1681 | | (((GLuint) (rgba[i][RCOMP] * 255.0F)) ); |
||
1682 | } |
||
1683 | } |
||
1684 | break; |
||
1685 | case GL_UNSIGNED_INT_8_8_8_8_REV: |
||
1686 | if (dstFormat == GL_RGBA) { |
||
1687 | GLuint *dst = (GLuint *) dstAddr; |
||
1688 | for (i=0;i<n;i++) { |
||
1689 | dst[i] = (((GLuint) (rgba[i][RCOMP] * 255.0F)) ) |
||
1690 | | (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 8) |
||
1691 | | (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 16) |
||
1692 | | (((GLuint) (rgba[i][ACOMP] * 255.0F)) << 24); |
||
1693 | } |
||
1694 | } |
||
1695 | else if (dstFormat == GL_BGRA) { |
||
1696 | GLuint *dst = (GLuint *) dstAddr; |
||
1697 | for (i=0;i<n;i++) { |
||
1698 | dst[i] = (((GLuint) (rgba[i][BCOMP] * 255.0F)) ) |
||
1699 | | (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 8) |
||
1700 | | (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 16) |
||
1701 | | (((GLuint) (rgba[i][ACOMP] * 255.0F)) << 24); |
||
1702 | } |
||
1703 | } |
||
1704 | else if (dstFormat == GL_ABGR_EXT) { |
||
1705 | GLuint *dst = (GLuint *) dstAddr; |
||
1706 | for (i=0;i<n;i++) { |
||
1707 | dst[i] = (((GLuint) (rgba[i][ACOMP] * 255.0F)) ) |
||
1708 | | (((GLuint) (rgba[i][BCOMP] * 255.0F)) << 8) |
||
1709 | | (((GLuint) (rgba[i][GCOMP] * 255.0F)) << 16) |
||
1710 | | (((GLuint) (rgba[i][RCOMP] * 255.0F)) << 24); |
||
1711 | } |
||
1712 | } |
||
1713 | break; |
||
1714 | case GL_UNSIGNED_INT_10_10_10_2: |
||
1715 | if (dstFormat == GL_RGBA) { |
||
1716 | GLuint *dst = (GLuint *) dstAddr; |
||
1717 | for (i=0;i<n;i++) { |
||
1718 | dst[i] = (((GLuint) (rgba[i][RCOMP] * 1023.0F)) << 22) |
||
1719 | | (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 12) |
||
1720 | | (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 2) |
||
1721 | | (((GLuint) (rgba[i][ACOMP] * 3.0F)) ); |
||
1722 | } |
||
1723 | } |
||
1724 | else if (dstFormat == GL_BGRA) { |
||
1725 | GLuint *dst = (GLuint *) dstAddr; |
||
1726 | for (i=0;i<n;i++) { |
||
1727 | dst[i] = (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 22) |
||
1728 | | (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 12) |
||
1729 | | (((GLuint) (rgba[i][RCOMP] * 1023.0F)) << 2) |
||
1730 | | (((GLuint) (rgba[i][ACOMP] * 3.0F)) ); |
||
1731 | } |
||
1732 | } |
||
1733 | else if (dstFormat == GL_ABGR_EXT) { |
||
1734 | GLuint *dst = (GLuint *) dstAddr; |
||
1735 | for (i=0;i<n;i++) { |
||
1736 | dst[i] = (((GLuint) (rgba[i][ACOMP] * 1023.0F)) << 22) |
||
1737 | | (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 12) |
||
1738 | | (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 2) |
||
1739 | | (((GLuint) (rgba[i][RCOMP] * 3.0F)) ); |
||
1740 | } |
||
1741 | } |
||
1742 | break; |
||
1743 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
||
1744 | if (dstFormat == GL_RGBA) { |
||
1745 | GLuint *dst = (GLuint *) dstAddr; |
||
1746 | for (i=0;i<n;i++) { |
||
1747 | dst[i] = (((GLuint) (rgba[i][RCOMP] * 1023.0F)) ) |
||
1748 | | (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 10) |
||
1749 | | (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 20) |
||
1750 | | (((GLuint) (rgba[i][ACOMP] * 3.0F)) << 30); |
||
1751 | } |
||
1752 | } |
||
1753 | else if (dstFormat == GL_BGRA) { |
||
1754 | GLuint *dst = (GLuint *) dstAddr; |
||
1755 | for (i=0;i<n;i++) { |
||
1756 | dst[i] = (((GLuint) (rgba[i][BCOMP] * 1023.0F)) ) |
||
1757 | | (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 10) |
||
1758 | | (((GLuint) (rgba[i][RCOMP] * 1023.0F)) << 20) |
||
1759 | | (((GLuint) (rgba[i][ACOMP] * 3.0F)) << 30); |
||
1760 | } |
||
1761 | } |
||
1762 | else if (dstFormat == GL_ABGR_EXT) { |
||
1763 | GLuint *dst = (GLuint *) dstAddr; |
||
1764 | for (i=0;i<n;i++) { |
||
1765 | dst[i] = (((GLuint) (rgba[i][ACOMP] * 1023.0F)) ) |
||
1766 | | (((GLuint) (rgba[i][BCOMP] * 1023.0F)) << 10) |
||
1767 | | (((GLuint) (rgba[i][GCOMP] * 1023.0F)) << 20) |
||
1768 | | (((GLuint) (rgba[i][RCOMP] * 3.0F)) << 30); |
||
1769 | } |
||
1770 | } |
||
1771 | break; |
||
1772 | default: |
||
1773 | _mesa_problem(ctx, "bad type in _mesa_pack_float_rgba_span"); |
||
1774 | } |
||
1775 | } |
||
1776 | |||
1777 | |||
1778 | |||
1779 | /* |
||
1780 | * Pack the given RGBA span into client memory at 'dest' address |
||
1781 | * in the given pixel format and type. |
||
1782 | * Optionally apply the enabled pixel transfer ops. |
||
1783 | * Pack into memory using the given packing params struct. |
||
1784 | * This is used by glReadPixels and glGetTexImage?D() |
||
1785 | * Input: ctx - the context |
||
1786 | * n - number of pixels in the span |
||
1787 | * rgba - the pixels |
||
1788 | * format - dest packing format |
||
1789 | * type - dest packing datatype |
||
1790 | * destination - destination packing address |
||
1791 | * packing - pixel packing parameters |
||
1792 | * transferOps - bitmask of IMAGE_*_BIT operations to apply |
||
1793 | */ |
||
1794 | void |
||
1795 | _mesa_pack_rgba_span( GLcontext *ctx, |
||
1796 | GLuint n, CONST GLchan srcRgba[][4], |
||
1797 | GLenum dstFormat, GLenum dstType, |
||
1798 | GLvoid *dstAddr, |
||
1799 | const struct gl_pixelstore_attrib *dstPacking, |
||
1800 | GLuint transferOps) |
||
1801 | { |
||
1802 | ASSERT((ctx->NewState & _NEW_PIXEL) == 0 || transferOps == 0); |
||
1803 | |||
1804 | /* Test for optimized case first */ |
||
1805 | if (transferOps == 0 && dstFormat == GL_RGBA && dstType == CHAN_TYPE) { |
||
1806 | /* common simple case */ |
||
1807 | MEMCPY(dstAddr, srcRgba, n * 4 * sizeof(GLchan)); |
||
1808 | } |
||
1809 | else if (transferOps == 0 && dstFormat == GL_RGB && dstType == CHAN_TYPE) { |
||
1810 | /* common simple case */ |
||
1811 | GLuint i; |
||
1812 | GLchan *dest = (GLchan *) dstAddr; |
||
1813 | for (i = 0; i < n; i++) { |
||
1814 | dest[0] = srcRgba[i][RCOMP]; |
||
1815 | dest[1] = srcRgba[i][GCOMP]; |
||
1816 | dest[2] = srcRgba[i][BCOMP]; |
||
1817 | dest += 3; |
||
1818 | } |
||
1819 | } |
||
1820 | else if (transferOps == 0 && dstFormat == GL_RGBA && dstType == GL_UNSIGNED_BYTE) { |
||
1821 | /* common simple case */ |
||
1822 | GLuint i; |
||
1823 | GLubyte *dest = (GLubyte *) dstAddr; |
||
1824 | for (i = 0; i < n; i++) { |
||
1825 | dest[0] = CHAN_TO_UBYTE(srcRgba[i][RCOMP]); |
||
1826 | dest[1] = CHAN_TO_UBYTE(srcRgba[i][GCOMP]); |
||
1827 | dest[2] = CHAN_TO_UBYTE(srcRgba[i][BCOMP]); |
||
1828 | dest[3] = CHAN_TO_UBYTE(srcRgba[i][ACOMP]); |
||
1829 | dest += 4; |
||
1830 | } |
||
1831 | } |
||
1832 | else { |
||
1833 | /* general solution */ |
||
1834 | GLuint i; |
||
1835 | DEFMARRAY(GLfloat, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ |
||
1836 | CHECKARRAY(rgba, return); /* mac 32k limitation */ |
||
1837 | |||
1838 | assert(n <= MAX_WIDTH); |
||
1839 | /* convert color components to floating point */ |
||
1840 | for (i=0;i<n;i++) { |
||
1841 | rgba[i][RCOMP] = CHAN_TO_FLOAT(srcRgba[i][RCOMP]); |
||
1842 | rgba[i][GCOMP] = CHAN_TO_FLOAT(srcRgba[i][GCOMP]); |
||
1843 | rgba[i][BCOMP] = CHAN_TO_FLOAT(srcRgba[i][BCOMP]); |
||
1844 | rgba[i][ACOMP] = CHAN_TO_FLOAT(srcRgba[i][ACOMP]); |
||
1845 | } |
||
1846 | _mesa_pack_float_rgba_span(ctx, n, (const GLfloat (*)[4]) rgba, |
||
1847 | dstFormat, dstType, dstAddr, |
||
1848 | dstPacking, transferOps); |
||
1849 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
1850 | } |
||
1851 | } |
||
1852 | |||
1853 | |||
1854 | #define SWAP2BYTE(VALUE) \ |
||
1855 | { \ |
||
1856 | GLubyte *bytes = (GLubyte *) &(VALUE); \ |
||
1857 | GLubyte tmp = bytes[0]; \ |
||
1858 | bytes[0] = bytes[1]; \ |
||
1859 | bytes[1] = tmp; \ |
||
1860 | } |
||
1861 | |||
1862 | #define SWAP4BYTE(VALUE) \ |
||
1863 | { \ |
||
1864 | GLubyte *bytes = (GLubyte *) &(VALUE); \ |
||
1865 | GLubyte tmp = bytes[0]; \ |
||
1866 | bytes[0] = bytes[3]; \ |
||
1867 | bytes[3] = tmp; \ |
||
1868 | tmp = bytes[1]; \ |
||
1869 | bytes[1] = bytes[2]; \ |
||
1870 | bytes[2] = tmp; \ |
||
1871 | } |
||
1872 | |||
1873 | |||
1874 | static void |
||
1875 | extract_uint_indexes(GLuint n, GLuint indexes[], |
||
1876 | GLenum srcFormat, GLenum srcType, const GLvoid *src, |
||
1877 | const struct gl_pixelstore_attrib *unpack ) |
||
1878 | { |
||
1879 | assert(srcFormat == GL_COLOR_INDEX); |
||
1880 | |||
1881 | ASSERT(srcType == GL_BITMAP || |
||
1882 | srcType == GL_UNSIGNED_BYTE || |
||
1883 | srcType == GL_BYTE || |
||
1884 | srcType == GL_UNSIGNED_SHORT || |
||
1885 | srcType == GL_SHORT || |
||
1886 | srcType == GL_UNSIGNED_INT || |
||
1887 | srcType == GL_INT || |
||
1888 | srcType == GL_FLOAT); |
||
1889 | |||
1890 | switch (srcType) { |
||
1891 | case GL_BITMAP: |
||
1892 | { |
||
1893 | GLubyte *ubsrc = (GLubyte *) src; |
||
1894 | if (unpack->LsbFirst) { |
||
1895 | GLubyte mask = 1 << (unpack->SkipPixels & 0x7); |
||
1896 | GLuint i; |
||
1897 | for (i = 0; i < n; i++) { |
||
1898 | indexes[i] = (*ubsrc & mask) ? 1 : 0; |
||
1899 | if (mask == 128) { |
||
1900 | mask = 1; |
||
1901 | ubsrc++; |
||
1902 | } |
||
1903 | else { |
||
1904 | mask = mask << 1; |
||
1905 | } |
||
1906 | } |
||
1907 | } |
||
1908 | else { |
||
1909 | GLubyte mask = 128 >> (unpack->SkipPixels & 0x7); |
||
1910 | GLuint i; |
||
1911 | for (i = 0; i < n; i++) { |
||
1912 | indexes[i] = (*ubsrc & mask) ? 1 : 0; |
||
1913 | if (mask == 1) { |
||
1914 | mask = 128; |
||
1915 | ubsrc++; |
||
1916 | } |
||
1917 | else { |
||
1918 | mask = mask >> 1; |
||
1919 | } |
||
1920 | } |
||
1921 | } |
||
1922 | } |
||
1923 | break; |
||
1924 | case GL_UNSIGNED_BYTE: |
||
1925 | { |
||
1926 | GLuint i; |
||
1927 | const GLubyte *s = (const GLubyte *) src; |
||
1928 | for (i = 0; i < n; i++) |
||
1929 | indexes[i] = s[i]; |
||
1930 | } |
||
1931 | break; |
||
1932 | case GL_BYTE: |
||
1933 | { |
||
1934 | GLuint i; |
||
1935 | const GLbyte *s = (const GLbyte *) src; |
||
1936 | for (i = 0; i < n; i++) |
||
1937 | indexes[i] = s[i]; |
||
1938 | } |
||
1939 | break; |
||
1940 | case GL_UNSIGNED_SHORT: |
||
1941 | { |
||
1942 | GLuint i; |
||
1943 | const GLushort *s = (const GLushort *) src; |
||
1944 | if (unpack->SwapBytes) { |
||
1945 | for (i = 0; i < n; i++) { |
||
1946 | GLushort value = s[i]; |
||
1947 | SWAP2BYTE(value); |
||
1948 | indexes[i] = value; |
||
1949 | } |
||
1950 | } |
||
1951 | else { |
||
1952 | for (i = 0; i < n; i++) |
||
1953 | indexes[i] = s[i]; |
||
1954 | } |
||
1955 | } |
||
1956 | break; |
||
1957 | case GL_SHORT: |
||
1958 | { |
||
1959 | GLuint i; |
||
1960 | const GLshort *s = (const GLshort *) src; |
||
1961 | if (unpack->SwapBytes) { |
||
1962 | for (i = 0; i < n; i++) { |
||
1963 | GLshort value = s[i]; |
||
1964 | SWAP2BYTE(value); |
||
1965 | indexes[i] = value; |
||
1966 | } |
||
1967 | } |
||
1968 | else { |
||
1969 | for (i = 0; i < n; i++) |
||
1970 | indexes[i] = s[i]; |
||
1971 | } |
||
1972 | } |
||
1973 | break; |
||
1974 | case GL_UNSIGNED_INT: |
||
1975 | { |
||
1976 | GLuint i; |
||
1977 | const GLuint *s = (const GLuint *) src; |
||
1978 | if (unpack->SwapBytes) { |
||
1979 | for (i = 0; i < n; i++) { |
||
1980 | GLuint value = s[i]; |
||
1981 | SWAP4BYTE(value); |
||
1982 | indexes[i] = value; |
||
1983 | } |
||
1984 | } |
||
1985 | else { |
||
1986 | for (i = 0; i < n; i++) |
||
1987 | indexes[i] = s[i]; |
||
1988 | } |
||
1989 | } |
||
1990 | break; |
||
1991 | case GL_INT: |
||
1992 | { |
||
1993 | GLuint i; |
||
1994 | const GLint *s = (const GLint *) src; |
||
1995 | if (unpack->SwapBytes) { |
||
1996 | for (i = 0; i < n; i++) { |
||
1997 | GLint value = s[i]; |
||
1998 | SWAP4BYTE(value); |
||
1999 | indexes[i] = value; |
||
2000 | } |
||
2001 | } |
||
2002 | else { |
||
2003 | for (i = 0; i < n; i++) |
||
2004 | indexes[i] = s[i]; |
||
2005 | } |
||
2006 | } |
||
2007 | break; |
||
2008 | case GL_FLOAT: |
||
2009 | { |
||
2010 | GLuint i; |
||
2011 | const GLfloat *s = (const GLfloat *) src; |
||
2012 | if (unpack->SwapBytes) { |
||
2013 | for (i = 0; i < n; i++) { |
||
2014 | GLfloat value = s[i]; |
||
2015 | SWAP4BYTE(value); |
||
2016 | indexes[i] = (GLuint) value; |
||
2017 | } |
||
2018 | } |
||
2019 | else { |
||
2020 | for (i = 0; i < n; i++) |
||
2021 | indexes[i] = (GLuint) s[i]; |
||
2022 | } |
||
2023 | } |
||
2024 | break; |
||
2025 | default: |
||
2026 | _mesa_problem(NULL, "bad srcType in extract_uint_indexes"); |
||
2027 | return; |
||
2028 | } |
||
2029 | } |
||
2030 | |||
2031 | |||
2032 | |||
2033 | /* |
||
2034 | * This function extracts floating point RGBA values from arbitrary |
||
2035 | * image data. srcFormat and srcType are the format and type parameters |
||
2036 | * passed to glDrawPixels, glTexImage[123]D, glTexSubImage[123]D, etc. |
||
2037 | * |
||
2038 | * Refering to section 3.6.4 of the OpenGL 1.2 spec, this function |
||
2039 | * implements the "Conversion to floating point", "Conversion to RGB", |
||
2040 | * and "Final Expansion to RGBA" operations. |
||
2041 | * |
||
2042 | * Args: n - number of pixels |
||
2043 | * rgba - output colors |
||
2044 | * srcFormat - format of incoming data |
||
2045 | * srcType - datatype of incoming data |
||
2046 | * src - source data pointer |
||
2047 | * swapBytes - perform byteswapping of incoming data? |
||
2048 | */ |
||
2049 | static void |
||
2050 | extract_float_rgba(GLuint n, GLfloat rgba[][4], |
||
2051 | GLenum srcFormat, GLenum srcType, const GLvoid *src, |
||
2052 | GLboolean swapBytes) |
||
2053 | { |
||
2054 | GLint redIndex, greenIndex, blueIndex, alphaIndex; |
||
2055 | GLint stride; |
||
2056 | GLint rComp, bComp, gComp, aComp; |
||
2057 | |||
2058 | ASSERT(srcFormat == GL_RED || |
||
2059 | srcFormat == GL_GREEN || |
||
2060 | srcFormat == GL_BLUE || |
||
2061 | srcFormat == GL_ALPHA || |
||
2062 | srcFormat == GL_LUMINANCE || |
||
2063 | srcFormat == GL_LUMINANCE_ALPHA || |
||
2064 | srcFormat == GL_INTENSITY || |
||
2065 | srcFormat == GL_RGB || |
||
2066 | srcFormat == GL_BGR || |
||
2067 | srcFormat == GL_RGBA || |
||
2068 | srcFormat == GL_BGRA || |
||
2069 | srcFormat == GL_ABGR_EXT); |
||
2070 | |||
2071 | ASSERT(srcType == GL_UNSIGNED_BYTE || |
||
2072 | srcType == GL_BYTE || |
||
2073 | srcType == GL_UNSIGNED_SHORT || |
||
2074 | srcType == GL_SHORT || |
||
2075 | srcType == GL_UNSIGNED_INT || |
||
2076 | srcType == GL_INT || |
||
2077 | srcType == GL_FLOAT || |
||
2078 | srcType == GL_UNSIGNED_BYTE_3_3_2 || |
||
2079 | srcType == GL_UNSIGNED_BYTE_2_3_3_REV || |
||
2080 | srcType == GL_UNSIGNED_SHORT_5_6_5 || |
||
2081 | srcType == GL_UNSIGNED_SHORT_5_6_5_REV || |
||
2082 | srcType == GL_UNSIGNED_SHORT_4_4_4_4 || |
||
2083 | srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || |
||
2084 | srcType == GL_UNSIGNED_SHORT_5_5_5_1 || |
||
2085 | srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || |
||
2086 | srcType == GL_UNSIGNED_INT_8_8_8_8 || |
||
2087 | srcType == GL_UNSIGNED_INT_8_8_8_8_REV || |
||
2088 | srcType == GL_UNSIGNED_INT_10_10_10_2 || |
||
2089 | srcType == GL_UNSIGNED_INT_2_10_10_10_REV); |
||
2090 | |||
2091 | rComp = gComp = bComp = aComp = -1; |
||
2092 | |||
2093 | switch (srcFormat) { |
||
2094 | case GL_RED: |
||
2095 | redIndex = 0; |
||
2096 | greenIndex = blueIndex = alphaIndex = -1; |
||
2097 | stride = 1; |
||
2098 | break; |
||
2099 | case GL_GREEN: |
||
2100 | greenIndex = 0; |
||
2101 | redIndex = blueIndex = alphaIndex = -1; |
||
2102 | stride = 1; |
||
2103 | break; |
||
2104 | case GL_BLUE: |
||
2105 | blueIndex = 0; |
||
2106 | redIndex = greenIndex = alphaIndex = -1; |
||
2107 | stride = 1; |
||
2108 | break; |
||
2109 | case GL_ALPHA: |
||
2110 | redIndex = greenIndex = blueIndex = -1; |
||
2111 | alphaIndex = 0; |
||
2112 | stride = 1; |
||
2113 | break; |
||
2114 | case GL_LUMINANCE: |
||
2115 | redIndex = greenIndex = blueIndex = 0; |
||
2116 | alphaIndex = -1; |
||
2117 | stride = 1; |
||
2118 | break; |
||
2119 | case GL_LUMINANCE_ALPHA: |
||
2120 | redIndex = greenIndex = blueIndex = 0; |
||
2121 | alphaIndex = 1; |
||
2122 | stride = 2; |
||
2123 | break; |
||
2124 | case GL_INTENSITY: |
||
2125 | redIndex = greenIndex = blueIndex = alphaIndex = 0; |
||
2126 | stride = 1; |
||
2127 | break; |
||
2128 | case GL_RGB: |
||
2129 | redIndex = 0; |
||
2130 | greenIndex = 1; |
||
2131 | blueIndex = 2; |
||
2132 | alphaIndex = -1; |
||
2133 | stride = 3; |
||
2134 | break; |
||
2135 | case GL_BGR: |
||
2136 | redIndex = 2; |
||
2137 | greenIndex = 1; |
||
2138 | blueIndex = 0; |
||
2139 | alphaIndex = -1; |
||
2140 | stride = 3; |
||
2141 | break; |
||
2142 | case GL_RGBA: |
||
2143 | redIndex = 0; |
||
2144 | greenIndex = 1; |
||
2145 | blueIndex = 2; |
||
2146 | alphaIndex = 3; |
||
2147 | rComp = 0; |
||
2148 | gComp = 1; |
||
2149 | bComp = 2; |
||
2150 | aComp = 3; |
||
2151 | stride = 4; |
||
2152 | break; |
||
2153 | case GL_BGRA: |
||
2154 | redIndex = 2; |
||
2155 | greenIndex = 1; |
||
2156 | blueIndex = 0; |
||
2157 | alphaIndex = 3; |
||
2158 | rComp = 2; |
||
2159 | gComp = 1; |
||
2160 | bComp = 0; |
||
2161 | aComp = 3; |
||
2162 | stride = 4; |
||
2163 | break; |
||
2164 | case GL_ABGR_EXT: |
||
2165 | redIndex = 3; |
||
2166 | greenIndex = 2; |
||
2167 | blueIndex = 1; |
||
2168 | alphaIndex = 0; |
||
2169 | rComp = 3; |
||
2170 | gComp = 2; |
||
2171 | bComp = 1; |
||
2172 | aComp = 0; |
||
2173 | stride = 4; |
||
2174 | break; |
||
2175 | default: |
||
2176 | _mesa_problem(NULL, "bad srcFormat in extract float data"); |
||
2177 | return; |
||
2178 | } |
||
2179 | |||
2180 | |||
2181 | #define PROCESS(INDEX, CHANNEL, DEFAULT, TYPE, CONVERSION) \ |
||
2182 | if ((INDEX) < 0) { \ |
||
2183 | GLuint i; \ |
||
2184 | for (i = 0; i < n; i++) { \ |
||
2185 | rgba[i][CHANNEL] = DEFAULT; \ |
||
2186 | } \ |
||
2187 | } \ |
||
2188 | else if (swapBytes) { \ |
||
2189 | const TYPE *s = (const TYPE *) src; \ |
||
2190 | GLuint i; \ |
||
2191 | for (i = 0; i < n; i++) { \ |
||
2192 | TYPE value = s[INDEX]; \ |
||
2193 | if (sizeof(TYPE) == 2) { \ |
||
2194 | SWAP2BYTE(value); \ |
||
2195 | } \ |
||
2196 | else if (sizeof(TYPE) == 4) { \ |
||
2197 | SWAP4BYTE(value); \ |
||
2198 | } \ |
||
2199 | rgba[i][CHANNEL] = (GLfloat) CONVERSION(value); \ |
||
2200 | s += stride; \ |
||
2201 | } \ |
||
2202 | } \ |
||
2203 | else { \ |
||
2204 | const TYPE *s = (const TYPE *) src; \ |
||
2205 | GLuint i; \ |
||
2206 | for (i = 0; i < n; i++) { \ |
||
2207 | rgba[i][CHANNEL] = (GLfloat) CONVERSION(s[INDEX]); \ |
||
2208 | s += stride; \ |
||
2209 | } \ |
||
2210 | } |
||
2211 | |||
2212 | switch (srcType) { |
||
2213 | case GL_UNSIGNED_BYTE: |
||
2214 | PROCESS(redIndex, RCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); |
||
2215 | PROCESS(greenIndex, GCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); |
||
2216 | PROCESS(blueIndex, BCOMP, 0.0F, GLubyte, UBYTE_TO_FLOAT); |
||
2217 | PROCESS(alphaIndex, ACOMP, 1.0F, GLubyte, UBYTE_TO_FLOAT); |
||
2218 | break; |
||
2219 | case GL_BYTE: |
||
2220 | PROCESS(redIndex, RCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); |
||
2221 | PROCESS(greenIndex, GCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); |
||
2222 | PROCESS(blueIndex, BCOMP, 0.0F, GLbyte, BYTE_TO_FLOAT); |
||
2223 | PROCESS(alphaIndex, ACOMP, 1.0F, GLbyte, BYTE_TO_FLOAT); |
||
2224 | break; |
||
2225 | case GL_UNSIGNED_SHORT: |
||
2226 | PROCESS(redIndex, RCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); |
||
2227 | PROCESS(greenIndex, GCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); |
||
2228 | PROCESS(blueIndex, BCOMP, 0.0F, GLushort, USHORT_TO_FLOAT); |
||
2229 | PROCESS(alphaIndex, ACOMP, 1.0F, GLushort, USHORT_TO_FLOAT); |
||
2230 | break; |
||
2231 | case GL_SHORT: |
||
2232 | PROCESS(redIndex, RCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); |
||
2233 | PROCESS(greenIndex, GCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); |
||
2234 | PROCESS(blueIndex, BCOMP, 0.0F, GLshort, SHORT_TO_FLOAT); |
||
2235 | PROCESS(alphaIndex, ACOMP, 1.0F, GLshort, SHORT_TO_FLOAT); |
||
2236 | break; |
||
2237 | case GL_UNSIGNED_INT: |
||
2238 | PROCESS(redIndex, RCOMP, 0.0F, GLuint, UINT_TO_FLOAT); |
||
2239 | PROCESS(greenIndex, GCOMP, 0.0F, GLuint, UINT_TO_FLOAT); |
||
2240 | PROCESS(blueIndex, BCOMP, 0.0F, GLuint, UINT_TO_FLOAT); |
||
2241 | PROCESS(alphaIndex, ACOMP, 1.0F, GLuint, UINT_TO_FLOAT); |
||
2242 | break; |
||
2243 | case GL_INT: |
||
2244 | PROCESS(redIndex, RCOMP, 0.0F, GLint, INT_TO_FLOAT); |
||
2245 | PROCESS(greenIndex, GCOMP, 0.0F, GLint, INT_TO_FLOAT); |
||
2246 | PROCESS(blueIndex, BCOMP, 0.0F, GLint, INT_TO_FLOAT); |
||
2247 | PROCESS(alphaIndex, ACOMP, 1.0F, GLint, INT_TO_FLOAT); |
||
2248 | break; |
||
2249 | case GL_FLOAT: |
||
2250 | PROCESS(redIndex, RCOMP, 0.0F, GLfloat, (GLfloat)); |
||
2251 | PROCESS(greenIndex, GCOMP, 0.0F, GLfloat, (GLfloat)); |
||
2252 | PROCESS(blueIndex, BCOMP, 0.0F, GLfloat, (GLfloat)); |
||
2253 | PROCESS(alphaIndex, ACOMP, 1.0F, GLfloat, (GLfloat)); |
||
2254 | break; |
||
2255 | case GL_UNSIGNED_BYTE_3_3_2: |
||
2256 | { |
||
2257 | const GLubyte *ubsrc = (const GLubyte *) src; |
||
2258 | GLuint i; |
||
2259 | for (i = 0; i < n; i ++) { |
||
2260 | GLubyte p = ubsrc[i]; |
||
2261 | rgba[i][RCOMP] = ((p >> 5) ) * (1.0F / 7.0F); |
||
2262 | rgba[i][GCOMP] = ((p >> 2) & 0x7) * (1.0F / 7.0F); |
||
2263 | rgba[i][BCOMP] = ((p ) & 0x3) * (1.0F / 3.0F); |
||
2264 | rgba[i][ACOMP] = 1.0F; |
||
2265 | } |
||
2266 | } |
||
2267 | break; |
||
2268 | case GL_UNSIGNED_BYTE_2_3_3_REV: |
||
2269 | { |
||
2270 | const GLubyte *ubsrc = (const GLubyte *) src; |
||
2271 | GLuint i; |
||
2272 | for (i = 0; i < n; i ++) { |
||
2273 | GLubyte p = ubsrc[i]; |
||
2274 | rgba[i][RCOMP] = ((p ) & 0x7) * (1.0F / 7.0F); |
||
2275 | rgba[i][GCOMP] = ((p >> 3) & 0x7) * (1.0F / 7.0F); |
||
2276 | rgba[i][BCOMP] = ((p >> 6) ) * (1.0F / 3.0F); |
||
2277 | rgba[i][ACOMP] = 1.0F; |
||
2278 | } |
||
2279 | } |
||
2280 | break; |
||
2281 | case GL_UNSIGNED_SHORT_5_6_5: |
||
2282 | if (swapBytes) { |
||
2283 | const GLushort *ussrc = (const GLushort *) src; |
||
2284 | GLuint i; |
||
2285 | for (i = 0; i < n; i ++) { |
||
2286 | GLushort p = ussrc[i]; |
||
2287 | SWAP2BYTE(p); |
||
2288 | rgba[i][RCOMP] = ((p >> 11) ) * (1.0F / 31.0F); |
||
2289 | rgba[i][GCOMP] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
||
2290 | rgba[i][BCOMP] = ((p ) & 0x1f) * (1.0F / 31.0F); |
||
2291 | rgba[i][ACOMP] = 1.0F; |
||
2292 | } |
||
2293 | } |
||
2294 | else { |
||
2295 | const GLushort *ussrc = (const GLushort *) src; |
||
2296 | GLuint i; |
||
2297 | for (i = 0; i < n; i ++) { |
||
2298 | GLushort p = ussrc[i]; |
||
2299 | rgba[i][RCOMP] = ((p >> 11) ) * (1.0F / 31.0F); |
||
2300 | rgba[i][GCOMP] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
||
2301 | rgba[i][BCOMP] = ((p ) & 0x1f) * (1.0F / 31.0F); |
||
2302 | rgba[i][ACOMP] = 1.0F; |
||
2303 | } |
||
2304 | } |
||
2305 | break; |
||
2306 | case GL_UNSIGNED_SHORT_5_6_5_REV: |
||
2307 | if (swapBytes) { |
||
2308 | const GLushort *ussrc = (const GLushort *) src; |
||
2309 | GLuint i; |
||
2310 | for (i = 0; i < n; i ++) { |
||
2311 | GLushort p = ussrc[i]; |
||
2312 | SWAP2BYTE(p); |
||
2313 | rgba[i][RCOMP] = ((p ) & 0x1f) * (1.0F / 31.0F); |
||
2314 | rgba[i][GCOMP] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
||
2315 | rgba[i][BCOMP] = ((p >> 11) ) * (1.0F / 31.0F); |
||
2316 | rgba[i][ACOMP] = 1.0F; |
||
2317 | } |
||
2318 | } |
||
2319 | else { |
||
2320 | const GLushort *ussrc = (const GLushort *) src; |
||
2321 | GLuint i; |
||
2322 | for (i = 0; i < n; i ++) { |
||
2323 | GLushort p = ussrc[i]; |
||
2324 | rgba[i][RCOMP] = ((p ) & 0x1f) * (1.0F / 31.0F); |
||
2325 | rgba[i][GCOMP] = ((p >> 5) & 0x3f) * (1.0F / 63.0F); |
||
2326 | rgba[i][BCOMP] = ((p >> 11) ) * (1.0F / 31.0F); |
||
2327 | rgba[i][ACOMP] = 1.0F; |
||
2328 | } |
||
2329 | } |
||
2330 | break; |
||
2331 | case GL_UNSIGNED_SHORT_4_4_4_4: |
||
2332 | if (swapBytes) { |
||
2333 | const GLushort *ussrc = (const GLushort *) src; |
||
2334 | GLuint i; |
||
2335 | for (i = 0; i < n; i ++) { |
||
2336 | GLushort p = ussrc[i]; |
||
2337 | SWAP2BYTE(p); |
||
2338 | rgba[i][rComp] = ((p >> 12) ) * (1.0F / 15.0F); |
||
2339 | rgba[i][gComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
||
2340 | rgba[i][bComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
||
2341 | rgba[i][aComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
||
2342 | } |
||
2343 | } |
||
2344 | else { |
||
2345 | const GLushort *ussrc = (const GLushort *) src; |
||
2346 | GLuint i; |
||
2347 | for (i = 0; i < n; i ++) { |
||
2348 | GLushort p = ussrc[i]; |
||
2349 | rgba[i][rComp] = ((p >> 12) ) * (1.0F / 15.0F); |
||
2350 | rgba[i][gComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
||
2351 | rgba[i][bComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
||
2352 | rgba[i][aComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
||
2353 | } |
||
2354 | } |
||
2355 | break; |
||
2356 | case GL_UNSIGNED_SHORT_4_4_4_4_REV: |
||
2357 | if (swapBytes) { |
||
2358 | const GLushort *ussrc = (const GLushort *) src; |
||
2359 | GLuint i; |
||
2360 | for (i = 0; i < n; i ++) { |
||
2361 | GLushort p = ussrc[i]; |
||
2362 | SWAP2BYTE(p); |
||
2363 | rgba[i][rComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
||
2364 | rgba[i][gComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
||
2365 | rgba[i][bComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
||
2366 | rgba[i][aComp] = ((p >> 12) ) * (1.0F / 15.0F); |
||
2367 | } |
||
2368 | } |
||
2369 | else { |
||
2370 | const GLushort *ussrc = (const GLushort *) src; |
||
2371 | GLuint i; |
||
2372 | for (i = 0; i < n; i ++) { |
||
2373 | GLushort p = ussrc[i]; |
||
2374 | rgba[i][rComp] = ((p ) & 0xf) * (1.0F / 15.0F); |
||
2375 | rgba[i][gComp] = ((p >> 4) & 0xf) * (1.0F / 15.0F); |
||
2376 | rgba[i][bComp] = ((p >> 8) & 0xf) * (1.0F / 15.0F); |
||
2377 | rgba[i][aComp] = ((p >> 12) ) * (1.0F / 15.0F); |
||
2378 | } |
||
2379 | } |
||
2380 | break; |
||
2381 | case GL_UNSIGNED_SHORT_5_5_5_1: |
||
2382 | if (swapBytes) { |
||
2383 | const GLushort *ussrc = (const GLushort *) src; |
||
2384 | GLuint i; |
||
2385 | for (i = 0; i < n; i ++) { |
||
2386 | GLushort p = ussrc[i]; |
||
2387 | SWAP2BYTE(p); |
||
2388 | rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); |
||
2389 | rgba[i][gComp] = ((p >> 6) & 0x1f) * (1.0F / 31.0F); |
||
2390 | rgba[i][bComp] = ((p >> 1) & 0x1f) * (1.0F / 31.0F); |
||
2391 | rgba[i][aComp] = ((p ) & 0x1) * (1.0F / 1.0F); |
||
2392 | } |
||
2393 | } |
||
2394 | else { |
||
2395 | const GLushort *ussrc = (const GLushort *) src; |
||
2396 | GLuint i; |
||
2397 | for (i = 0; i < n; i ++) { |
||
2398 | GLushort p = ussrc[i]; |
||
2399 | rgba[i][rComp] = ((p >> 11) ) * (1.0F / 31.0F); |
||
2400 | rgba[i][gComp] = ((p >> 6) & 0x1f) * (1.0F / 31.0F); |
||
2401 | rgba[i][bComp] = ((p >> 1) & 0x1f) * (1.0F / 31.0F); |
||
2402 | rgba[i][aComp] = ((p ) & 0x1) * (1.0F / 1.0F); |
||
2403 | } |
||
2404 | } |
||
2405 | break; |
||
2406 | case GL_UNSIGNED_SHORT_1_5_5_5_REV: |
||
2407 | if (swapBytes) { |
||
2408 | const GLushort *ussrc = (const GLushort *) src; |
||
2409 | GLuint i; |
||
2410 | for (i = 0; i < n; i ++) { |
||
2411 | GLushort p = ussrc[i]; |
||
2412 | SWAP2BYTE(p); |
||
2413 | rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
||
2414 | rgba[i][gComp] = ((p >> 5) & 0x1f) * (1.0F / 31.0F); |
||
2415 | rgba[i][bComp] = ((p >> 10) & 0x1f) * (1.0F / 31.0F); |
||
2416 | rgba[i][aComp] = ((p >> 15) ) * (1.0F / 1.0F); |
||
2417 | } |
||
2418 | } |
||
2419 | else { |
||
2420 | const GLushort *ussrc = (const GLushort *) src; |
||
2421 | GLuint i; |
||
2422 | for (i = 0; i < n; i ++) { |
||
2423 | GLushort p = ussrc[i]; |
||
2424 | rgba[i][rComp] = ((p ) & 0x1f) * (1.0F / 31.0F); |
||
2425 | rgba[i][gComp] = ((p >> 5) & 0x1f) * (1.0F / 31.0F); |
||
2426 | rgba[i][bComp] = ((p >> 10) & 0x1f) * (1.0F / 31.0F); |
||
2427 | rgba[i][aComp] = ((p >> 15) ) * (1.0F / 1.0F); |
||
2428 | } |
||
2429 | } |
||
2430 | break; |
||
2431 | case GL_UNSIGNED_INT_8_8_8_8: |
||
2432 | if (swapBytes) { |
||
2433 | const GLuint *uisrc = (const GLuint *) src; |
||
2434 | GLuint i; |
||
2435 | for (i = 0; i < n; i ++) { |
||
2436 | GLuint p = uisrc[i]; |
||
2437 | rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
||
2438 | rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
||
2439 | rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
||
2440 | rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); |
||
2441 | } |
||
2442 | } |
||
2443 | else { |
||
2444 | const GLuint *uisrc = (const GLuint *) src; |
||
2445 | GLuint i; |
||
2446 | for (i = 0; i < n; i ++) { |
||
2447 | GLuint p = uisrc[i]; |
||
2448 | rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); |
||
2449 | rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
||
2450 | rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
||
2451 | rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
||
2452 | } |
||
2453 | } |
||
2454 | break; |
||
2455 | case GL_UNSIGNED_INT_8_8_8_8_REV: |
||
2456 | if (swapBytes) { |
||
2457 | const GLuint *uisrc = (const GLuint *) src; |
||
2458 | GLuint i; |
||
2459 | for (i = 0; i < n; i ++) { |
||
2460 | GLuint p = uisrc[i]; |
||
2461 | rgba[i][rComp] = UBYTE_TO_FLOAT((p >> 24) ); |
||
2462 | rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
||
2463 | rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
||
2464 | rgba[i][aComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
||
2465 | } |
||
2466 | } |
||
2467 | else { |
||
2468 | const GLuint *uisrc = (const GLuint *) src; |
||
2469 | GLuint i; |
||
2470 | for (i = 0; i < n; i ++) { |
||
2471 | GLuint p = uisrc[i]; |
||
2472 | rgba[i][rComp] = UBYTE_TO_FLOAT((p ) & 0xff); |
||
2473 | rgba[i][gComp] = UBYTE_TO_FLOAT((p >> 8) & 0xff); |
||
2474 | rgba[i][bComp] = UBYTE_TO_FLOAT((p >> 16) & 0xff); |
||
2475 | rgba[i][aComp] = UBYTE_TO_FLOAT((p >> 24) ); |
||
2476 | } |
||
2477 | } |
||
2478 | break; |
||
2479 | case GL_UNSIGNED_INT_10_10_10_2: |
||
2480 | if (swapBytes) { |
||
2481 | const GLuint *uisrc = (const GLuint *) src; |
||
2482 | GLuint i; |
||
2483 | for (i = 0; i < n; i ++) { |
||
2484 | GLuint p = uisrc[i]; |
||
2485 | SWAP4BYTE(p); |
||
2486 | rgba[i][rComp] = ((p >> 22) ) * (1.0F / 1023.0F); |
||
2487 | rgba[i][gComp] = ((p >> 12) & 0x3ff) * (1.0F / 1023.0F); |
||
2488 | rgba[i][bComp] = ((p >> 2) & 0x3ff) * (1.0F / 1023.0F); |
||
2489 | rgba[i][aComp] = ((p ) & 0x3 ) * (1.0F / 3.0F); |
||
2490 | } |
||
2491 | } |
||
2492 | else { |
||
2493 | const GLuint *uisrc = (const GLuint *) src; |
||
2494 | GLuint i; |
||
2495 | for (i = 0; i < n; i ++) { |
||
2496 | GLuint p = uisrc[i]; |
||
2497 | rgba[i][rComp] = ((p >> 22) ) * (1.0F / 1023.0F); |
||
2498 | rgba[i][gComp] = ((p >> 12) & 0x3ff) * (1.0F / 1023.0F); |
||
2499 | rgba[i][bComp] = ((p >> 2) & 0x3ff) * (1.0F / 1023.0F); |
||
2500 | rgba[i][aComp] = ((p ) & 0x3 ) * (1.0F / 3.0F); |
||
2501 | } |
||
2502 | } |
||
2503 | break; |
||
2504 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
||
2505 | if (swapBytes) { |
||
2506 | const GLuint *uisrc = (const GLuint *) src; |
||
2507 | GLuint i; |
||
2508 | for (i = 0; i < n; i ++) { |
||
2509 | GLuint p = uisrc[i]; |
||
2510 | SWAP4BYTE(p); |
||
2511 | rgba[i][rComp] = ((p ) & 0x3ff) * (1.0F / 1023.0F); |
||
2512 | rgba[i][gComp] = ((p >> 10) & 0x3ff) * (1.0F / 1023.0F); |
||
2513 | rgba[i][bComp] = ((p >> 20) & 0x3ff) * (1.0F / 1023.0F); |
||
2514 | rgba[i][aComp] = ((p >> 30) ) * (1.0F / 3.0F); |
||
2515 | } |
||
2516 | } |
||
2517 | else { |
||
2518 | const GLuint *uisrc = (const GLuint *) src; |
||
2519 | GLuint i; |
||
2520 | for (i = 0; i < n; i ++) { |
||
2521 | GLuint p = uisrc[i]; |
||
2522 | rgba[i][rComp] = ((p ) & 0x3ff) * (1.0F / 1023.0F); |
||
2523 | rgba[i][gComp] = ((p >> 10) & 0x3ff) * (1.0F / 1023.0F); |
||
2524 | rgba[i][bComp] = ((p >> 20) & 0x3ff) * (1.0F / 1023.0F); |
||
2525 | rgba[i][aComp] = ((p >> 30) ) * (1.0F / 3.0F); |
||
2526 | } |
||
2527 | } |
||
2528 | break; |
||
2529 | default: |
||
2530 | _mesa_problem(NULL, "bad srcType in extract float data"); |
||
2531 | break; |
||
2532 | } |
||
2533 | } |
||
2534 | |||
2535 | |||
2536 | |||
2537 | /* |
||
2538 | * Unpack a row of color image data from a client buffer according to |
||
2539 | * the pixel unpacking parameters. |
||
2540 | * Return GLubyte values in the specified dest image format. |
||
2541 | * This is (or will be) used by glDrawPixels and glTexImage?D(). |
||
2542 | * Input: ctx - the context |
||
2543 | * n - number of pixels in the span |
||
2544 | * dstFormat - format of destination color array |
||
2545 | * dest - the destination color array |
||
2546 | * srcFormat - source image format |
||
2547 | * srcType - source image datatype |
||
2548 | * source - source image pointer |
||
2549 | * srcPacking - pixel unpacking parameters |
||
2550 | * transferOps - bitmask of IMAGE_*_BIT values of operations to apply |
||
2551 | * |
||
2552 | * XXX perhaps expand this to process whole images someday. |
||
2553 | */ |
||
2554 | void |
||
2555 | _mesa_unpack_chan_color_span( GLcontext *ctx, |
||
2556 | GLuint n, GLenum dstFormat, GLchan dest[], |
||
2557 | GLenum srcFormat, GLenum srcType, |
||
2558 | const GLvoid *source, |
||
2559 | const struct gl_pixelstore_attrib *srcPacking, |
||
2560 | GLuint transferOps ) |
||
2561 | { |
||
2562 | ASSERT(dstFormat == GL_ALPHA || |
||
2563 | dstFormat == GL_LUMINANCE || |
||
2564 | dstFormat == GL_LUMINANCE_ALPHA || |
||
2565 | dstFormat == GL_INTENSITY || |
||
2566 | dstFormat == GL_RGB || |
||
2567 | dstFormat == GL_RGBA || |
||
2568 | dstFormat == GL_COLOR_INDEX); |
||
2569 | |||
2570 | ASSERT(srcFormat == GL_RED || |
||
2571 | srcFormat == GL_GREEN || |
||
2572 | srcFormat == GL_BLUE || |
||
2573 | srcFormat == GL_ALPHA || |
||
2574 | srcFormat == GL_LUMINANCE || |
||
2575 | srcFormat == GL_LUMINANCE_ALPHA || |
||
2576 | srcFormat == GL_INTENSITY || |
||
2577 | srcFormat == GL_RGB || |
||
2578 | srcFormat == GL_BGR || |
||
2579 | srcFormat == GL_RGBA || |
||
2580 | srcFormat == GL_BGRA || |
||
2581 | srcFormat == GL_ABGR_EXT || |
||
2582 | srcFormat == GL_COLOR_INDEX); |
||
2583 | |||
2584 | ASSERT(srcType == GL_BITMAP || |
||
2585 | srcType == GL_UNSIGNED_BYTE || |
||
2586 | srcType == GL_BYTE || |
||
2587 | srcType == GL_UNSIGNED_SHORT || |
||
2588 | srcType == GL_SHORT || |
||
2589 | srcType == GL_UNSIGNED_INT || |
||
2590 | srcType == GL_INT || |
||
2591 | srcType == GL_FLOAT || |
||
2592 | srcType == GL_UNSIGNED_BYTE_3_3_2 || |
||
2593 | srcType == GL_UNSIGNED_BYTE_2_3_3_REV || |
||
2594 | srcType == GL_UNSIGNED_SHORT_5_6_5 || |
||
2595 | srcType == GL_UNSIGNED_SHORT_5_6_5_REV || |
||
2596 | srcType == GL_UNSIGNED_SHORT_4_4_4_4 || |
||
2597 | srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || |
||
2598 | srcType == GL_UNSIGNED_SHORT_5_5_5_1 || |
||
2599 | srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || |
||
2600 | srcType == GL_UNSIGNED_INT_8_8_8_8 || |
||
2601 | srcType == GL_UNSIGNED_INT_8_8_8_8_REV || |
||
2602 | srcType == GL_UNSIGNED_INT_10_10_10_2 || |
||
2603 | srcType == GL_UNSIGNED_INT_2_10_10_10_REV); |
||
2604 | |||
2605 | /* Try simple cases first */ |
||
2606 | if (transferOps == 0 ){ |
||
2607 | if (srcType == CHAN_TYPE) { |
||
2608 | if (dstFormat == GL_RGBA) { |
||
2609 | if (srcFormat == GL_RGBA) { |
||
2610 | MEMCPY( dest, source, n * 4 * sizeof(GLchan) ); |
||
2611 | return; |
||
2612 | } |
||
2613 | else if (srcFormat == GL_RGB) { |
||
2614 | GLuint i; |
||
2615 | const GLchan *src = (const GLchan *) source; |
||
2616 | GLchan *dst = dest; |
||
2617 | for (i = 0; i < n; i++) { |
||
2618 | dst[0] = src[0]; |
||
2619 | dst[1] = src[1]; |
||
2620 | dst[2] = src[2]; |
||
2621 | dst[3] = CHAN_MAX; |
||
2622 | src += 3; |
||
2623 | dst += 4; |
||
2624 | } |
||
2625 | return; |
||
2626 | } |
||
2627 | } |
||
2628 | else if (dstFormat == GL_RGB) { |
||
2629 | if (srcFormat == GL_RGB) { |
||
2630 | MEMCPY( dest, source, n * 3 * sizeof(GLchan) ); |
||
2631 | return; |
||
2632 | } |
||
2633 | else if (srcFormat == GL_RGBA) { |
||
2634 | GLuint i; |
||
2635 | const GLchan *src = (const GLchan *) source; |
||
2636 | GLchan *dst = dest; |
||
2637 | for (i = 0; i < n; i++) { |
||
2638 | dst[0] = src[0]; |
||
2639 | dst[1] = src[1]; |
||
2640 | dst[2] = src[2]; |
||
2641 | src += 4; |
||
2642 | dst += 3; |
||
2643 | } |
||
2644 | return; |
||
2645 | } |
||
2646 | } |
||
2647 | else if (dstFormat == srcFormat) { |
||
2648 | GLint comps = _mesa_components_in_format(srcFormat); |
||
2649 | assert(comps > 0); |
||
2650 | MEMCPY( dest, source, n * comps * sizeof(GLchan) ); |
||
2651 | return; |
||
2652 | } |
||
2653 | } |
||
2654 | /* |
||
2655 | * Common situation, loading 8bit RGBA/RGB source images |
||
2656 | * into 16/32 bit destination. (OSMesa16/32) |
||
2657 | */ |
||
2658 | else if (srcType == GL_UNSIGNED_BYTE) { |
||
2659 | if (dstFormat == GL_RGBA) { |
||
2660 | if (srcFormat == GL_RGB) { |
||
2661 | GLuint i; |
||
2662 | const GLubyte *src = (const GLubyte *) source; |
||
2663 | GLchan *dst = dest; |
||
2664 | for (i = 0; i < n; i++) { |
||
2665 | dst[0] = UBYTE_TO_CHAN(src[0]); |
||
2666 | dst[1] = UBYTE_TO_CHAN(src[1]); |
||
2667 | dst[2] = UBYTE_TO_CHAN(src[2]); |
||
2668 | dst[3] = CHAN_MAX; |
||
2669 | src += 3; |
||
2670 | dst += 4; |
||
2671 | } |
||
2672 | return; |
||
2673 | } |
||
2674 | else if (srcFormat == GL_RGBA) { |
||
2675 | GLuint i; |
||
2676 | const GLubyte *src = (const GLubyte *) source; |
||
2677 | GLchan *dst = dest; |
||
2678 | for (i = 0; i < n; i++) { |
||
2679 | dst[0] = UBYTE_TO_CHAN(src[0]); |
||
2680 | dst[1] = UBYTE_TO_CHAN(src[1]); |
||
2681 | dst[2] = UBYTE_TO_CHAN(src[2]); |
||
2682 | dst[3] = UBYTE_TO_CHAN(src[3]); |
||
2683 | src += 4; |
||
2684 | dst += 4; |
||
2685 | } |
||
2686 | return; |
||
2687 | } |
||
2688 | } |
||
2689 | else if (dstFormat == GL_RGB) { |
||
2690 | if (srcFormat == GL_RGB) { |
||
2691 | GLuint i; |
||
2692 | const GLubyte *src = (const GLubyte *) source; |
||
2693 | GLchan *dst = dest; |
||
2694 | for (i = 0; i < n; i++) { |
||
2695 | dst[0] = UBYTE_TO_CHAN(src[0]); |
||
2696 | dst[1] = UBYTE_TO_CHAN(src[1]); |
||
2697 | dst[2] = UBYTE_TO_CHAN(src[2]); |
||
2698 | src += 3; |
||
2699 | dst += 3; |
||
2700 | } |
||
2701 | return; |
||
2702 | } |
||
2703 | else if (srcFormat == GL_RGBA) { |
||
2704 | GLuint i; |
||
2705 | const GLubyte *src = (const GLubyte *) source; |
||
2706 | GLchan *dst = dest; |
||
2707 | for (i = 0; i < n; i++) { |
||
2708 | dst[0] = UBYTE_TO_CHAN(src[0]); |
||
2709 | dst[1] = UBYTE_TO_CHAN(src[1]); |
||
2710 | dst[2] = UBYTE_TO_CHAN(src[2]); |
||
2711 | src += 4; |
||
2712 | dst += 3; |
||
2713 | } |
||
2714 | return; |
||
2715 | } |
||
2716 | } |
||
2717 | } |
||
2718 | } |
||
2719 | |||
2720 | |||
2721 | /* general solution begins here */ |
||
2722 | { |
||
2723 | GLint dstComponents; |
||
2724 | GLint dstRedIndex, dstGreenIndex, dstBlueIndex, dstAlphaIndex; |
||
2725 | GLint dstLuminanceIndex, dstIntensityIndex; |
||
2726 | DEFMARRAY(GLfloat, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ |
||
2727 | CHECKARRAY(rgba, return); /* mac 32k limitation */ |
||
2728 | |||
2729 | dstComponents = _mesa_components_in_format( dstFormat ); |
||
2730 | /* source & dest image formats should have been error checked by now */ |
||
2731 | assert(dstComponents > 0); |
||
2732 | |||
2733 | /* |
||
2734 | * Extract image data and convert to RGBA floats |
||
2735 | */ |
||
2736 | assert(n <= MAX_WIDTH); |
||
2737 | if (srcFormat == GL_COLOR_INDEX) { |
||
2738 | GLuint indexes[MAX_WIDTH]; |
||
2739 | extract_uint_indexes(n, indexes, srcFormat, srcType, source, |
||
2740 | srcPacking); |
||
2741 | |||
2742 | if (dstFormat == GL_COLOR_INDEX |
||
2743 | && (transferOps & IMAGE_MAP_COLOR_BIT)) { |
||
2744 | _mesa_map_ci(ctx, n, indexes); |
||
2745 | } |
||
2746 | if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
||
2747 | _mesa_shift_and_offset_ci(ctx, n, indexes); |
||
2748 | } |
||
2749 | |||
2750 | if (dstFormat == GL_COLOR_INDEX) { |
||
2751 | /* convert to GLchan and return */ |
||
2752 | GLuint i; |
||
2753 | for (i = 0; i < n; i++) { |
||
2754 | dest[i] = (GLchan) (indexes[i] & 0xff); |
||
2755 | } |
||
2756 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
2757 | return; |
||
2758 | } |
||
2759 | else { |
||
2760 | /* Convert indexes to RGBA */ |
||
2761 | _mesa_map_ci_to_rgba(ctx, n, indexes, rgba); |
||
2762 | } |
||
2763 | } |
||
2764 | else { |
||
2765 | extract_float_rgba(n, rgba, srcFormat, srcType, source, |
||
2766 | srcPacking->SwapBytes); |
||
2767 | |||
2768 | /* scale and bias colors */ |
||
2769 | if (transferOps & IMAGE_SCALE_BIAS_BIT) { |
||
2770 | _mesa_scale_and_bias_rgba(ctx, n, rgba, |
||
2771 | ctx->Pixel.RedScale, ctx->Pixel.GreenScale, |
||
2772 | ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale, |
||
2773 | ctx->Pixel.RedBias, ctx->Pixel.GreenBias, |
||
2774 | ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias); |
||
2775 | } |
||
2776 | /* color map lookup */ |
||
2777 | if (transferOps & IMAGE_MAP_COLOR_BIT) { |
||
2778 | _mesa_map_rgba(ctx, n, rgba); |
||
2779 | } |
||
2780 | } |
||
2781 | |||
2782 | if (transferOps) { |
||
2783 | /* GL_COLOR_TABLE lookup */ |
||
2784 | if (transferOps & IMAGE_COLOR_TABLE_BIT) { |
||
2785 | _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); |
||
2786 | } |
||
2787 | /* convolution */ |
||
2788 | if (transferOps & IMAGE_CONVOLUTION_BIT) { |
||
2789 | /* this has to be done in the calling code */ |
||
2790 | } |
||
2791 | /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */ |
||
2792 | if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) { |
||
2793 | _mesa_scale_and_bias_rgba(ctx, n, rgba, |
||
2794 | ctx->Pixel.PostConvolutionScale[RCOMP], |
||
2795 | ctx->Pixel.PostConvolutionScale[GCOMP], |
||
2796 | ctx->Pixel.PostConvolutionScale[BCOMP], |
||
2797 | ctx->Pixel.PostConvolutionScale[ACOMP], |
||
2798 | ctx->Pixel.PostConvolutionBias[RCOMP], |
||
2799 | ctx->Pixel.PostConvolutionBias[GCOMP], |
||
2800 | ctx->Pixel.PostConvolutionBias[BCOMP], |
||
2801 | ctx->Pixel.PostConvolutionBias[ACOMP]); |
||
2802 | } |
||
2803 | /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ |
||
2804 | if (transferOps & IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT) { |
||
2805 | _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, n, rgba); |
||
2806 | } |
||
2807 | /* color matrix transform */ |
||
2808 | if (transferOps & IMAGE_COLOR_MATRIX_BIT) { |
||
2809 | _mesa_transform_rgba(ctx, n, rgba); |
||
2810 | } |
||
2811 | /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ |
||
2812 | if (transferOps & IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT) { |
||
2813 | _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba); |
||
2814 | } |
||
2815 | /* update histogram count */ |
||
2816 | if (transferOps & IMAGE_HISTOGRAM_BIT) { |
||
2817 | _mesa_update_histogram(ctx, n, (CONST GLfloat (*)[4]) rgba); |
||
2818 | } |
||
2819 | /* min/max here */ |
||
2820 | if (transferOps & IMAGE_MIN_MAX_BIT) { |
||
2821 | _mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba); |
||
2822 | } |
||
2823 | } |
||
2824 | |||
2825 | /* clamp to [0,1] */ |
||
2826 | #if CHAN_TYPE != GL_FLOAT |
||
2827 | { |
||
2828 | GLuint i; |
||
2829 | for (i = 0; i < n; i++) { |
||
2830 | rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F); |
||
2831 | rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F); |
||
2832 | rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F); |
||
2833 | rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F); |
||
2834 | } |
||
2835 | } |
||
2836 | #endif |
||
2837 | |||
2838 | /* Now determine which color channels we need to produce. |
||
2839 | * And determine the dest index (offset) within each color tuple. |
||
2840 | */ |
||
2841 | switch (dstFormat) { |
||
2842 | case GL_ALPHA: |
||
2843 | dstAlphaIndex = 0; |
||
2844 | dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
||
2845 | dstLuminanceIndex = dstIntensityIndex = -1; |
||
2846 | break; |
||
2847 | case GL_LUMINANCE: |
||
2848 | dstLuminanceIndex = 0; |
||
2849 | dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
||
2850 | dstIntensityIndex = -1; |
||
2851 | break; |
||
2852 | case GL_LUMINANCE_ALPHA: |
||
2853 | dstLuminanceIndex = 0; |
||
2854 | dstAlphaIndex = 1; |
||
2855 | dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
||
2856 | dstIntensityIndex = -1; |
||
2857 | break; |
||
2858 | case GL_INTENSITY: |
||
2859 | dstIntensityIndex = 0; |
||
2860 | dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
||
2861 | dstLuminanceIndex = -1; |
||
2862 | break; |
||
2863 | case GL_RGB: |
||
2864 | dstRedIndex = 0; |
||
2865 | dstGreenIndex = 1; |
||
2866 | dstBlueIndex = 2; |
||
2867 | dstAlphaIndex = dstLuminanceIndex = dstIntensityIndex = -1; |
||
2868 | break; |
||
2869 | case GL_RGBA: |
||
2870 | dstRedIndex = 0; |
||
2871 | dstGreenIndex = 1; |
||
2872 | dstBlueIndex = 2; |
||
2873 | dstAlphaIndex = 3; |
||
2874 | dstLuminanceIndex = dstIntensityIndex = -1; |
||
2875 | break; |
||
2876 | default: |
||
2877 | _mesa_problem(ctx, "bad dstFormat in _mesa_unpack_chan_span()"); |
||
2878 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
2879 | return; |
||
2880 | } |
||
2881 | |||
2882 | |||
2883 | /* Now return the GLchan data in the requested dstFormat */ |
||
2884 | |||
2885 | if (dstRedIndex >= 0) { |
||
2886 | GLchan *dst = dest; |
||
2887 | GLuint i; |
||
2888 | for (i = 0; i < n; i++) { |
||
2889 | CLAMPED_FLOAT_TO_CHAN(dst[dstRedIndex], rgba[i][RCOMP]); |
||
2890 | dst += dstComponents; |
||
2891 | } |
||
2892 | } |
||
2893 | |||
2894 | if (dstGreenIndex >= 0) { |
||
2895 | GLchan *dst = dest; |
||
2896 | GLuint i; |
||
2897 | for (i = 0; i < n; i++) { |
||
2898 | CLAMPED_FLOAT_TO_CHAN(dst[dstGreenIndex], rgba[i][GCOMP]); |
||
2899 | dst += dstComponents; |
||
2900 | } |
||
2901 | } |
||
2902 | |||
2903 | if (dstBlueIndex >= 0) { |
||
2904 | GLchan *dst = dest; |
||
2905 | GLuint i; |
||
2906 | for (i = 0; i < n; i++) { |
||
2907 | CLAMPED_FLOAT_TO_CHAN(dst[dstBlueIndex], rgba[i][BCOMP]); |
||
2908 | dst += dstComponents; |
||
2909 | } |
||
2910 | } |
||
2911 | |||
2912 | if (dstAlphaIndex >= 0) { |
||
2913 | GLchan *dst = dest; |
||
2914 | GLuint i; |
||
2915 | for (i = 0; i < n; i++) { |
||
2916 | CLAMPED_FLOAT_TO_CHAN(dst[dstAlphaIndex], rgba[i][ACOMP]); |
||
2917 | dst += dstComponents; |
||
2918 | } |
||
2919 | } |
||
2920 | |||
2921 | if (dstIntensityIndex >= 0) { |
||
2922 | GLchan *dst = dest; |
||
2923 | GLuint i; |
||
2924 | assert(dstIntensityIndex == 0); |
||
2925 | assert(dstComponents == 1); |
||
2926 | for (i = 0; i < n; i++) { |
||
2927 | /* Intensity comes from red channel */ |
||
2928 | CLAMPED_FLOAT_TO_CHAN(dst[i], rgba[i][RCOMP]); |
||
2929 | } |
||
2930 | } |
||
2931 | |||
2932 | if (dstLuminanceIndex >= 0) { |
||
2933 | GLchan *dst = dest; |
||
2934 | GLuint i; |
||
2935 | assert(dstLuminanceIndex == 0); |
||
2936 | for (i = 0; i < n; i++) { |
||
2937 | /* Luminance comes from red channel */ |
||
2938 | CLAMPED_FLOAT_TO_CHAN(dst[0], rgba[i][RCOMP]); |
||
2939 | dst += dstComponents; |
||
2940 | } |
||
2941 | } |
||
2942 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
2943 | } |
||
2944 | } |
||
2945 | |||
2946 | |||
2947 | void |
||
2948 | _mesa_unpack_float_color_span( GLcontext *ctx, |
||
2949 | GLuint n, GLenum dstFormat, GLfloat dest[], |
||
2950 | GLenum srcFormat, GLenum srcType, |
||
2951 | const GLvoid *source, |
||
2952 | const struct gl_pixelstore_attrib *srcPacking, |
||
2953 | GLuint transferOps, GLboolean clamp ) |
||
2954 | { |
||
2955 | ASSERT(dstFormat == GL_ALPHA || |
||
2956 | dstFormat == GL_LUMINANCE || |
||
2957 | dstFormat == GL_LUMINANCE_ALPHA || |
||
2958 | dstFormat == GL_INTENSITY || |
||
2959 | dstFormat == GL_RGB || |
||
2960 | dstFormat == GL_RGBA || |
||
2961 | dstFormat == GL_COLOR_INDEX); |
||
2962 | |||
2963 | ASSERT(srcFormat == GL_RED || |
||
2964 | srcFormat == GL_GREEN || |
||
2965 | srcFormat == GL_BLUE || |
||
2966 | srcFormat == GL_ALPHA || |
||
2967 | srcFormat == GL_LUMINANCE || |
||
2968 | srcFormat == GL_LUMINANCE_ALPHA || |
||
2969 | srcFormat == GL_INTENSITY || |
||
2970 | srcFormat == GL_RGB || |
||
2971 | srcFormat == GL_BGR || |
||
2972 | srcFormat == GL_RGBA || |
||
2973 | srcFormat == GL_BGRA || |
||
2974 | srcFormat == GL_ABGR_EXT || |
||
2975 | srcFormat == GL_COLOR_INDEX); |
||
2976 | |||
2977 | ASSERT(srcType == GL_BITMAP || |
||
2978 | srcType == GL_UNSIGNED_BYTE || |
||
2979 | srcType == GL_BYTE || |
||
2980 | srcType == GL_UNSIGNED_SHORT || |
||
2981 | srcType == GL_SHORT || |
||
2982 | srcType == GL_UNSIGNED_INT || |
||
2983 | srcType == GL_INT || |
||
2984 | srcType == GL_FLOAT || |
||
2985 | srcType == GL_UNSIGNED_BYTE_3_3_2 || |
||
2986 | srcType == GL_UNSIGNED_BYTE_2_3_3_REV || |
||
2987 | srcType == GL_UNSIGNED_SHORT_5_6_5 || |
||
2988 | srcType == GL_UNSIGNED_SHORT_5_6_5_REV || |
||
2989 | srcType == GL_UNSIGNED_SHORT_4_4_4_4 || |
||
2990 | srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV || |
||
2991 | srcType == GL_UNSIGNED_SHORT_5_5_5_1 || |
||
2992 | srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV || |
||
2993 | srcType == GL_UNSIGNED_INT_8_8_8_8 || |
||
2994 | srcType == GL_UNSIGNED_INT_8_8_8_8_REV || |
||
2995 | srcType == GL_UNSIGNED_INT_10_10_10_2 || |
||
2996 | srcType == GL_UNSIGNED_INT_2_10_10_10_REV); |
||
2997 | |||
2998 | /* general solution, no special cases, yet */ |
||
2999 | { |
||
3000 | GLint dstComponents; |
||
3001 | GLint dstRedIndex, dstGreenIndex, dstBlueIndex, dstAlphaIndex; |
||
3002 | GLint dstLuminanceIndex, dstIntensityIndex; |
||
3003 | DEFMARRAY(GLfloat, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ |
||
3004 | CHECKARRAY(rgba, return); /* mac 32k limitation */ |
||
3005 | |||
3006 | dstComponents = _mesa_components_in_format( dstFormat ); |
||
3007 | /* source & dest image formats should have been error checked by now */ |
||
3008 | assert(dstComponents > 0); |
||
3009 | |||
3010 | /* |
||
3011 | * Extract image data and convert to RGBA floats |
||
3012 | */ |
||
3013 | assert(n <= MAX_WIDTH); |
||
3014 | if (srcFormat == GL_COLOR_INDEX) { |
||
3015 | GLuint indexes[MAX_WIDTH]; |
||
3016 | extract_uint_indexes(n, indexes, srcFormat, srcType, source, |
||
3017 | srcPacking); |
||
3018 | |||
3019 | if (dstFormat == GL_COLOR_INDEX |
||
3020 | && (transferOps & IMAGE_MAP_COLOR_BIT)) { |
||
3021 | _mesa_map_ci(ctx, n, indexes); |
||
3022 | } |
||
3023 | if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
||
3024 | _mesa_shift_and_offset_ci(ctx, n, indexes); |
||
3025 | } |
||
3026 | |||
3027 | if (dstFormat == GL_COLOR_INDEX) { |
||
3028 | /* convert to GLchan and return */ |
||
3029 | GLuint i; |
||
3030 | for (i = 0; i < n; i++) { |
||
3031 | dest[i] = (GLchan) (indexes[i] & 0xff); |
||
3032 | } |
||
3033 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
3034 | return; |
||
3035 | } |
||
3036 | else { |
||
3037 | /* Convert indexes to RGBA */ |
||
3038 | _mesa_map_ci_to_rgba(ctx, n, indexes, rgba); |
||
3039 | } |
||
3040 | } |
||
3041 | else { |
||
3042 | extract_float_rgba(n, rgba, srcFormat, srcType, source, |
||
3043 | srcPacking->SwapBytes); |
||
3044 | |||
3045 | /* scale and bias colors */ |
||
3046 | if (transferOps & IMAGE_SCALE_BIAS_BIT) { |
||
3047 | _mesa_scale_and_bias_rgba(ctx, n, rgba, |
||
3048 | ctx->Pixel.RedScale, ctx->Pixel.GreenScale, |
||
3049 | ctx->Pixel.BlueScale, ctx->Pixel.AlphaScale, |
||
3050 | ctx->Pixel.RedBias, ctx->Pixel.GreenBias, |
||
3051 | ctx->Pixel.BlueBias, ctx->Pixel.AlphaBias); |
||
3052 | } |
||
3053 | /* color map lookup */ |
||
3054 | if (transferOps & IMAGE_MAP_COLOR_BIT) { |
||
3055 | _mesa_map_rgba(ctx, n, rgba); |
||
3056 | } |
||
3057 | } |
||
3058 | |||
3059 | if (transferOps) { |
||
3060 | /* GL_COLOR_TABLE lookup */ |
||
3061 | if (transferOps & IMAGE_COLOR_TABLE_BIT) { |
||
3062 | _mesa_lookup_rgba(&ctx->ColorTable, n, rgba); |
||
3063 | } |
||
3064 | /* convolution */ |
||
3065 | if (transferOps & IMAGE_CONVOLUTION_BIT) { |
||
3066 | /* XXX to do */ |
||
3067 | } |
||
3068 | /* GL_POST_CONVOLUTION_RED/GREEN/BLUE/ALPHA_SCALE/BIAS */ |
||
3069 | if (transferOps & IMAGE_POST_CONVOLUTION_SCALE_BIAS) { |
||
3070 | _mesa_scale_and_bias_rgba(ctx, n, rgba, |
||
3071 | ctx->Pixel.PostConvolutionScale[RCOMP], |
||
3072 | ctx->Pixel.PostConvolutionScale[GCOMP], |
||
3073 | ctx->Pixel.PostConvolutionScale[BCOMP], |
||
3074 | ctx->Pixel.PostConvolutionScale[ACOMP], |
||
3075 | ctx->Pixel.PostConvolutionBias[RCOMP], |
||
3076 | ctx->Pixel.PostConvolutionBias[GCOMP], |
||
3077 | ctx->Pixel.PostConvolutionBias[BCOMP], |
||
3078 | ctx->Pixel.PostConvolutionBias[ACOMP]); |
||
3079 | } |
||
3080 | /* GL_POST_CONVOLUTION_COLOR_TABLE lookup */ |
||
3081 | if (transferOps & IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT) { |
||
3082 | _mesa_lookup_rgba(&ctx->PostConvolutionColorTable, n, rgba); |
||
3083 | } |
||
3084 | /* color matrix transform */ |
||
3085 | if (transferOps & IMAGE_COLOR_MATRIX_BIT) { |
||
3086 | _mesa_transform_rgba(ctx, n, rgba); |
||
3087 | } |
||
3088 | /* GL_POST_COLOR_MATRIX_COLOR_TABLE lookup */ |
||
3089 | if (transferOps & IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT) { |
||
3090 | _mesa_lookup_rgba(&ctx->PostColorMatrixColorTable, n, rgba); |
||
3091 | } |
||
3092 | /* update histogram count */ |
||
3093 | if (transferOps & IMAGE_HISTOGRAM_BIT) { |
||
3094 | _mesa_update_histogram(ctx, n, (CONST GLfloat (*)[4]) rgba); |
||
3095 | } |
||
3096 | /* min/max here */ |
||
3097 | if (transferOps & IMAGE_MIN_MAX_BIT) { |
||
3098 | _mesa_update_minmax(ctx, n, (CONST GLfloat (*)[4]) rgba); |
||
3099 | } |
||
3100 | } |
||
3101 | |||
3102 | /* clamp to [0,1] */ |
||
3103 | #if CHAN_TYPE != GL_FLOAT |
||
3104 | if (clamp) { |
||
3105 | GLuint i; |
||
3106 | for (i = 0; i < n; i++) { |
||
3107 | rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], 0.0F, 1.0F); |
||
3108 | rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], 0.0F, 1.0F); |
||
3109 | rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], 0.0F, 1.0F); |
||
3110 | rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0F, 1.0F); |
||
3111 | } |
||
3112 | } |
||
3113 | #endif |
||
3114 | |||
3115 | /* Now determine which color channels we need to produce. |
||
3116 | * And determine the dest index (offset) within each color tuple. |
||
3117 | */ |
||
3118 | switch (dstFormat) { |
||
3119 | case GL_ALPHA: |
||
3120 | dstAlphaIndex = 0; |
||
3121 | dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
||
3122 | dstLuminanceIndex = dstIntensityIndex = -1; |
||
3123 | break; |
||
3124 | case GL_LUMINANCE: |
||
3125 | dstLuminanceIndex = 0; |
||
3126 | dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
||
3127 | dstIntensityIndex = -1; |
||
3128 | break; |
||
3129 | case GL_LUMINANCE_ALPHA: |
||
3130 | dstLuminanceIndex = 0; |
||
3131 | dstAlphaIndex = 1; |
||
3132 | dstRedIndex = dstGreenIndex = dstBlueIndex = -1; |
||
3133 | dstIntensityIndex = -1; |
||
3134 | break; |
||
3135 | case GL_INTENSITY: |
||
3136 | dstIntensityIndex = 0; |
||
3137 | dstRedIndex = dstGreenIndex = dstBlueIndex = dstAlphaIndex = -1; |
||
3138 | dstLuminanceIndex = -1; |
||
3139 | break; |
||
3140 | case GL_RGB: |
||
3141 | dstRedIndex = 0; |
||
3142 | dstGreenIndex = 1; |
||
3143 | dstBlueIndex = 2; |
||
3144 | dstAlphaIndex = dstLuminanceIndex = dstIntensityIndex = -1; |
||
3145 | break; |
||
3146 | case GL_RGBA: |
||
3147 | dstRedIndex = 0; |
||
3148 | dstGreenIndex = 1; |
||
3149 | dstBlueIndex = 2; |
||
3150 | dstAlphaIndex = 3; |
||
3151 | dstLuminanceIndex = dstIntensityIndex = -1; |
||
3152 | break; |
||
3153 | default: |
||
3154 | _mesa_problem(ctx, "bad dstFormat in _mesa_unpack_float_color_span()"); |
||
3155 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
3156 | return; |
||
3157 | } |
||
3158 | |||
3159 | /* Now pack results in the requested dstFormat */ |
||
3160 | if (dstRedIndex >= 0) { |
||
3161 | GLfloat *dst = dest; |
||
3162 | GLuint i; |
||
3163 | for (i = 0; i < n; i++) { |
||
3164 | dst[dstRedIndex] = rgba[i][RCOMP]; |
||
3165 | dst += dstComponents; |
||
3166 | } |
||
3167 | } |
||
3168 | |||
3169 | if (dstGreenIndex >= 0) { |
||
3170 | GLfloat *dst = dest; |
||
3171 | GLuint i; |
||
3172 | for (i = 0; i < n; i++) { |
||
3173 | dst[dstGreenIndex] = rgba[i][GCOMP]; |
||
3174 | dst += dstComponents; |
||
3175 | } |
||
3176 | } |
||
3177 | |||
3178 | if (dstBlueIndex >= 0) { |
||
3179 | GLfloat *dst = dest; |
||
3180 | GLuint i; |
||
3181 | for (i = 0; i < n; i++) { |
||
3182 | dst[dstBlueIndex] = rgba[i][BCOMP]; |
||
3183 | dst += dstComponents; |
||
3184 | } |
||
3185 | } |
||
3186 | |||
3187 | if (dstAlphaIndex >= 0) { |
||
3188 | GLfloat *dst = dest; |
||
3189 | GLuint i; |
||
3190 | for (i = 0; i < n; i++) { |
||
3191 | dst[dstAlphaIndex] = rgba[i][ACOMP]; |
||
3192 | dst += dstComponents; |
||
3193 | } |
||
3194 | } |
||
3195 | |||
3196 | if (dstIntensityIndex >= 0) { |
||
3197 | GLfloat *dst = dest; |
||
3198 | GLuint i; |
||
3199 | assert(dstIntensityIndex == 0); |
||
3200 | assert(dstComponents == 1); |
||
3201 | for (i = 0; i < n; i++) { |
||
3202 | /* Intensity comes from red channel */ |
||
3203 | dst[i] = rgba[i][RCOMP]; |
||
3204 | } |
||
3205 | } |
||
3206 | |||
3207 | if (dstLuminanceIndex >= 0) { |
||
3208 | GLfloat *dst = dest; |
||
3209 | GLuint i; |
||
3210 | assert(dstLuminanceIndex == 0); |
||
3211 | for (i = 0; i < n; i++) { |
||
3212 | /* Luminance comes from red channel */ |
||
3213 | dst[0] = rgba[i][RCOMP]; |
||
3214 | dst += dstComponents; |
||
3215 | } |
||
3216 | } |
||
3217 | UNDEFARRAY(rgba); /* mac 32k limitation */ |
||
3218 | } |
||
3219 | } |
||
3220 | |||
3221 | |||
3222 | |||
3223 | |||
3224 | /* |
||
3225 | * Unpack a row of color index data from a client buffer according to |
||
3226 | * the pixel unpacking parameters. |
||
3227 | * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc. |
||
3228 | * |
||
3229 | * Args: ctx - the context |
||
3230 | * n - number of pixels |
||
3231 | * dstType - destination datatype |
||
3232 | * dest - destination array |
||
3233 | * srcType - source pixel type |
||
3234 | * source - source data pointer |
||
3235 | * srcPacking - pixel unpacking parameters |
||
3236 | * transferOps - the pixel transfer operations to apply |
||
3237 | */ |
||
3238 | void |
||
3239 | _mesa_unpack_index_span( const GLcontext *ctx, GLuint n, |
||
3240 | GLenum dstType, GLvoid *dest, |
||
3241 | GLenum srcType, const GLvoid *source, |
||
3242 | const struct gl_pixelstore_attrib *srcPacking, |
||
3243 | GLuint transferOps ) |
||
3244 | { |
||
3245 | ASSERT(srcType == GL_BITMAP || |
||
3246 | srcType == GL_UNSIGNED_BYTE || |
||
3247 | srcType == GL_BYTE || |
||
3248 | srcType == GL_UNSIGNED_SHORT || |
||
3249 | srcType == GL_SHORT || |
||
3250 | srcType == GL_UNSIGNED_INT || |
||
3251 | srcType == GL_INT || |
||
3252 | srcType == GL_FLOAT); |
||
3253 | |||
3254 | ASSERT(dstType == GL_UNSIGNED_BYTE || |
||
3255 | dstType == GL_UNSIGNED_SHORT || |
||
3256 | dstType == GL_UNSIGNED_INT); |
||
3257 | |||
3258 | |||
3259 | transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT); |
||
3260 | |||
3261 | /* |
||
3262 | * Try simple cases first |
||
3263 | */ |
||
3264 | if (transferOps == 0 && srcType == GL_UNSIGNED_BYTE |
||
3265 | && dstType == GL_UNSIGNED_BYTE) { |
||
3266 | MEMCPY(dest, source, n * sizeof(GLubyte)); |
||
3267 | } |
||
3268 | else if (transferOps == 0 && srcType == GL_UNSIGNED_INT |
||
3269 | && dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) { |
||
3270 | MEMCPY(dest, source, n * sizeof(GLuint)); |
||
3271 | } |
||
3272 | else { |
||
3273 | /* |
||
3274 | * general solution |
||
3275 | */ |
||
3276 | GLuint indexes[MAX_WIDTH]; |
||
3277 | assert(n <= MAX_WIDTH); |
||
3278 | |||
3279 | extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source, |
||
3280 | srcPacking); |
||
3281 | |||
3282 | if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
||
3283 | /* shift and offset indexes */ |
||
3284 | _mesa_shift_and_offset_ci(ctx, n, indexes); |
||
3285 | } |
||
3286 | if (transferOps & IMAGE_MAP_COLOR_BIT) { |
||
3287 | /* Apply lookup table */ |
||
3288 | _mesa_map_ci(ctx, n, indexes); |
||
3289 | } |
||
3290 | |||
3291 | /* convert to dest type */ |
||
3292 | switch (dstType) { |
||
3293 | case GL_UNSIGNED_BYTE: |
||
3294 | { |
||
3295 | GLubyte *dst = (GLubyte *) dest; |
||
3296 | GLuint i; |
||
3297 | for (i = 0; i < n; i++) { |
||
3298 | dst[i] = (GLubyte) (indexes[i] & 0xff); |
||
3299 | } |
||
3300 | } |
||
3301 | break; |
||
3302 | case GL_UNSIGNED_SHORT: |
||
3303 | { |
||
3304 | GLuint *dst = (GLuint *) dest; |
||
3305 | GLuint i; |
||
3306 | for (i = 0; i < n; i++) { |
||
3307 | dst[i] = (GLushort) (indexes[i] & 0xffff); |
||
3308 | } |
||
3309 | } |
||
3310 | break; |
||
3311 | case GL_UNSIGNED_INT: |
||
3312 | MEMCPY(dest, indexes, n * sizeof(GLuint)); |
||
3313 | break; |
||
3314 | default: |
||
3315 | _mesa_problem(ctx, "bad dstType in _mesa_unpack_index_span"); |
||
3316 | } |
||
3317 | } |
||
3318 | } |
||
3319 | |||
3320 | |||
3321 | void |
||
3322 | _mesa_pack_index_span( const GLcontext *ctx, GLuint n, |
||
3323 | GLenum dstType, GLvoid *dest, const GLuint *source, |
||
3324 | const struct gl_pixelstore_attrib *dstPacking, |
||
3325 | GLuint transferOps ) |
||
3326 | { |
||
3327 | GLuint indexes[MAX_WIDTH]; |
||
3328 | |||
3329 | ASSERT(n <= MAX_WIDTH); |
||
3330 | |||
3331 | transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT); |
||
3332 | |||
3333 | if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) { |
||
3334 | /* make a copy of input */ |
||
3335 | MEMCPY(indexes, source, n * sizeof(GLuint)); |
||
3336 | if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
||
3337 | _mesa_shift_and_offset_ci( ctx, n, indexes); |
||
3338 | } |
||
3339 | if (transferOps & IMAGE_MAP_COLOR_BIT) { |
||
3340 | _mesa_map_ci(ctx, n, indexes); |
||
3341 | } |
||
3342 | source = indexes; |
||
3343 | } |
||
3344 | |||
3345 | switch (dstType) { |
||
3346 | case GL_UNSIGNED_BYTE: |
||
3347 | { |
||
3348 | GLubyte *dst = (GLubyte *) dest; |
||
3349 | GLuint i; |
||
3350 | for (i = 0; i < n; i++) { |
||
3351 | *dst++ = (GLubyte) source[i]; |
||
3352 | } |
||
3353 | } |
||
3354 | break; |
||
3355 | case GL_BYTE: |
||
3356 | { |
||
3357 | GLbyte *dst = (GLbyte *) dest; |
||
3358 | GLuint i; |
||
3359 | for (i = 0; i < n; i++) { |
||
3360 | dst[i] = (GLbyte) source[i]; |
||
3361 | } |
||
3362 | } |
||
3363 | break; |
||
3364 | case GL_UNSIGNED_SHORT: |
||
3365 | { |
||
3366 | GLushort *dst = (GLushort *) dest; |
||
3367 | GLuint i; |
||
3368 | for (i = 0; i < n; i++) { |
||
3369 | dst[i] = (GLushort) source[i]; |
||
3370 | } |
||
3371 | if (dstPacking->SwapBytes) { |
||
3372 | _mesa_swap2( (GLushort *) dst, n ); |
||
3373 | } |
||
3374 | } |
||
3375 | break; |
||
3376 | case GL_SHORT: |
||
3377 | { |
||
3378 | GLshort *dst = (GLshort *) dest; |
||
3379 | GLuint i; |
||
3380 | for (i = 0; i < n; i++) { |
||
3381 | dst[i] = (GLshort) source[i]; |
||
3382 | } |
||
3383 | if (dstPacking->SwapBytes) { |
||
3384 | _mesa_swap2( (GLushort *) dst, n ); |
||
3385 | } |
||
3386 | } |
||
3387 | break; |
||
3388 | case GL_UNSIGNED_INT: |
||
3389 | { |
||
3390 | GLuint *dst = (GLuint *) dest; |
||
3391 | GLuint i; |
||
3392 | for (i = 0; i < n; i++) { |
||
3393 | dst[i] = (GLuint) source[i]; |
||
3394 | } |
||
3395 | if (dstPacking->SwapBytes) { |
||
3396 | _mesa_swap4( (GLuint *) dst, n ); |
||
3397 | } |
||
3398 | } |
||
3399 | break; |
||
3400 | case GL_INT: |
||
3401 | { |
||
3402 | GLint *dst = (GLint *) dest; |
||
3403 | GLuint i; |
||
3404 | for (i = 0; i < n; i++) { |
||
3405 | dst[i] = (GLint) source[i]; |
||
3406 | } |
||
3407 | if (dstPacking->SwapBytes) { |
||
3408 | _mesa_swap4( (GLuint *) dst, n ); |
||
3409 | } |
||
3410 | } |
||
3411 | break; |
||
3412 | case GL_FLOAT: |
||
3413 | { |
||
3414 | GLfloat *dst = (GLfloat *) dest; |
||
3415 | GLuint i; |
||
3416 | for (i = 0; i < n; i++) { |
||
3417 | dst[i] = (GLfloat) source[i]; |
||
3418 | } |
||
3419 | if (dstPacking->SwapBytes) { |
||
3420 | _mesa_swap4( (GLuint *) dst, n ); |
||
3421 | } |
||
3422 | } |
||
3423 | break; |
||
3424 | default: |
||
3425 | _mesa_problem(ctx, "bad type in _mesa_pack_index_span"); |
||
3426 | } |
||
3427 | } |
||
3428 | |||
3429 | |||
3430 | |||
3431 | /* |
||
3432 | * Unpack a row of stencil data from a client buffer according to |
||
3433 | * the pixel unpacking parameters. |
||
3434 | * This is (or will be) used by glDrawPixels |
||
3435 | * |
||
3436 | * Args: ctx - the context |
||
3437 | * n - number of pixels |
||
3438 | * dstType - destination datatype |
||
3439 | * dest - destination array |
||
3440 | * srcType - source pixel type |
||
3441 | * source - source data pointer |
||
3442 | * srcPacking - pixel unpacking parameters |
||
3443 | * transferOps - apply offset/bias/lookup ops? |
||
3444 | */ |
||
3445 | void |
||
3446 | _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n, |
||
3447 | GLenum dstType, GLvoid *dest, |
||
3448 | GLenum srcType, const GLvoid *source, |
||
3449 | const struct gl_pixelstore_attrib *srcPacking, |
||
3450 | GLuint transferOps ) |
||
3451 | { |
||
3452 | ASSERT(srcType == GL_BITMAP || |
||
3453 | srcType == GL_UNSIGNED_BYTE || |
||
3454 | srcType == GL_BYTE || |
||
3455 | srcType == GL_UNSIGNED_SHORT || |
||
3456 | srcType == GL_SHORT || |
||
3457 | srcType == GL_UNSIGNED_INT || |
||
3458 | srcType == GL_INT || |
||
3459 | srcType == GL_FLOAT); |
||
3460 | |||
3461 | ASSERT(dstType == GL_UNSIGNED_BYTE || |
||
3462 | dstType == GL_UNSIGNED_SHORT || |
||
3463 | dstType == GL_UNSIGNED_INT); |
||
3464 | |||
3465 | /* only shift and offset apply to stencil */ |
||
3466 | transferOps &= IMAGE_SHIFT_OFFSET_BIT; |
||
3467 | |||
3468 | /* |
||
3469 | * Try simple cases first |
||
3470 | */ |
||
3471 | if (transferOps == 0 && |
||
3472 | srcType == GL_UNSIGNED_BYTE && |
||
3473 | dstType == GL_UNSIGNED_BYTE) { |
||
3474 | MEMCPY(dest, source, n * sizeof(GLubyte)); |
||
3475 | } |
||
3476 | else if (transferOps == 0 && |
||
3477 | srcType == GL_UNSIGNED_INT && |
||
3478 | dstType == GL_UNSIGNED_INT && |
||
3479 | !srcPacking->SwapBytes) { |
||
3480 | MEMCPY(dest, source, n * sizeof(GLuint)); |
||
3481 | } |
||
3482 | else { |
||
3483 | /* |
||
3484 | * general solution |
||
3485 | */ |
||
3486 | GLuint indexes[MAX_WIDTH]; |
||
3487 | assert(n <= MAX_WIDTH); |
||
3488 | |||
3489 | extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source, |
||
3490 | srcPacking); |
||
3491 | |||
3492 | if (transferOps) { |
||
3493 | if (transferOps & IMAGE_SHIFT_OFFSET_BIT) { |
||
3494 | /* shift and offset indexes */ |
||
3495 | _mesa_shift_and_offset_ci(ctx, n, indexes); |
||
3496 | } |
||
3497 | |||
3498 | if (ctx->Pixel.MapStencilFlag) { |
||
3499 | /* Apply stencil lookup table */ |
||
3500 | GLuint mask = ctx->Pixel.MapStoSsize - 1; |
||
3501 | GLuint i; |
||
3502 | for (i=0;i<n;i++) { |
||
3503 | indexes[i] = ctx->Pixel.MapStoS[ indexes[i] & mask ]; |
||
3504 | } |
||
3505 | } |
||
3506 | } |
||
3507 | |||
3508 | /* convert to dest type */ |
||
3509 | switch (dstType) { |
||
3510 | case GL_UNSIGNED_BYTE: |
||
3511 | { |
||
3512 | GLubyte *dst = (GLubyte *) dest; |
||
3513 | GLuint i; |
||
3514 | for (i = 0; i < n; i++) { |
||
3515 | dst[i] = (GLubyte) (indexes[i] & 0xff); |
||
3516 | } |
||
3517 | } |
||
3518 | break; |
||
3519 | case GL_UNSIGNED_SHORT: |
||
3520 | { |
||
3521 | GLuint *dst = (GLuint *) dest; |
||
3522 | GLuint i; |
||
3523 | for (i = 0; i < n; i++) { |
||
3524 | dst[i] = (GLushort) (indexes[i] & 0xffff); |
||
3525 | } |
||
3526 | } |
||
3527 | break; |
||
3528 | case GL_UNSIGNED_INT: |
||
3529 | MEMCPY(dest, indexes, n * sizeof(GLuint)); |
||
3530 | break; |
||
3531 | default: |
||
3532 | _mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span"); |
||
3533 | } |
||
3534 | } |
||
3535 | } |
||
3536 | |||
3537 | |||
3538 | void |
||
3539 | _mesa_pack_stencil_span( const GLcontext *ctx, GLuint n, |
||
3540 | GLenum dstType, GLvoid *dest, const GLstencil *source, |
||
3541 | const struct gl_pixelstore_attrib *dstPacking ) |
||
3542 | { |
||
3543 | GLstencil stencil[MAX_WIDTH]; |
||
3544 | |||
3545 | ASSERT(n <= MAX_WIDTH); |
||
3546 | |||
3547 | if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset || |
||
3548 | ctx->Pixel.MapStencilFlag) { |
||
3549 | /* make a copy of input */ |
||
3550 | MEMCPY(stencil, source, n * sizeof(GLstencil)); |
||
3551 | if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset) { |
||
3552 | _mesa_shift_and_offset_stencil( ctx, n, stencil ); |
||
3553 | } |
||
3554 | if (ctx->Pixel.MapStencilFlag) { |
||
3555 | _mesa_map_stencil( ctx, n, stencil ); |
||
3556 | } |
||
3557 | source = stencil; |
||
3558 | } |
||
3559 | |||
3560 | switch (dstType) { |
||
3561 | case GL_UNSIGNED_BYTE: |
||
3562 | if (sizeof(GLstencil) == 8) { |
||
3563 | MEMCPY( dest, source, n ); |
||
3564 | } |
||
3565 | else { |
||
3566 | GLubyte *dst = (GLubyte *) dest; |
||
3567 | GLuint i; |
||
3568 | for (i=0;i<n;i++) { |
||
3569 | dst[i] = (GLubyte) source[i]; |
||
3570 | } |
||
3571 | } |
||
3572 | break; |
||
3573 | case GL_BYTE: |
||
3574 | if (sizeof(GLstencil) == 8) { |
||
3575 | MEMCPY( dest, source, n ); |
||
3576 | } |
||
3577 | else { |
||
3578 | GLbyte *dst = (GLbyte *) dest; |
||
3579 | GLuint i; |
||
3580 | for (i=0;i<n;i++) { |
||
3581 | dst[i] = (GLbyte) source[i]; |
||
3582 | } |
||
3583 | } |
||
3584 | break; |
||
3585 | case GL_UNSIGNED_SHORT: |
||
3586 | { |
||
3587 | GLushort *dst = (GLushort *) dest; |
||
3588 | GLuint i; |
||
3589 | for (i=0;i<n;i++) { |
||
3590 | dst[i] = (GLushort) source[i]; |
||
3591 | } |
||
3592 | if (dstPacking->SwapBytes) { |
||
3593 | _mesa_swap2( (GLushort *) dst, n ); |
||
3594 | } |
||
3595 | } |
||
3596 | break; |
||
3597 | case GL_SHORT: |
||
3598 | { |
||
3599 | GLshort *dst = (GLshort *) dest; |
||
3600 | GLuint i; |
||
3601 | for (i=0;i<n;i++) { |
||
3602 | dst[i] = (GLshort) source[i]; |
||
3603 | } |
||
3604 | if (dstPacking->SwapBytes) { |
||
3605 | _mesa_swap2( (GLushort *) dst, n ); |
||
3606 | } |
||
3607 | } |
||
3608 | break; |
||
3609 | case GL_UNSIGNED_INT: |
||
3610 | { |
||
3611 | GLuint *dst = (GLuint *) dest; |
||
3612 | GLuint i; |
||
3613 | for (i=0;i<n;i++) { |
||
3614 | dst[i] = (GLuint) source[i]; |
||
3615 | } |
||
3616 | if (dstPacking->SwapBytes) { |
||
3617 | _mesa_swap4( (GLuint *) dst, n ); |
||
3618 | } |
||
3619 | } |
||
3620 | break; |
||
3621 | case GL_INT: |
||
3622 | { |
||
3623 | GLint *dst = (GLint *) dest; |
||
3624 | GLuint i; |
||
3625 | for (i=0;i<n;i++) { |
||
3626 | *dst++ = (GLint) source[i]; |
||
3627 | } |
||
3628 | if (dstPacking->SwapBytes) { |
||
3629 | _mesa_swap4( (GLuint *) dst, n ); |
||
3630 | } |
||
3631 | } |
||
3632 | break; |
||
3633 | case GL_FLOAT: |
||
3634 | { |
||
3635 | GLfloat *dst = (GLfloat *) dest; |
||
3636 | GLuint i; |
||
3637 | for (i=0;i<n;i++) { |
||
3638 | dst[i] = (GLfloat) source[i]; |
||
3639 | } |
||
3640 | if (dstPacking->SwapBytes) { |
||
3641 | _mesa_swap4( (GLuint *) dst, n ); |
||
3642 | } |
||
3643 | } |
||
3644 | break; |
||
3645 | case GL_BITMAP: |
||
3646 | if (dstPacking->LsbFirst) { |
||
3647 | GLubyte *dst = (GLubyte *) dest; |
||
3648 | GLint shift = 0; |
||
3649 | GLuint i; |
||
3650 | for (i = 0; i < n; i++) { |
||
3651 | if (shift == 0) |
||
3652 | *dst = 0; |
||
3653 | *dst |= ((source[i] != 0) << shift); |
||
3654 | shift++; |
||
3655 | if (shift == 8) { |
||
3656 | shift = 0; |
||
3657 | dst++; |
||
3658 | } |
||
3659 | } |
||
3660 | } |
||
3661 | else { |
||
3662 | GLubyte *dst = (GLubyte *) dest; |
||
3663 | GLint shift = 7; |
||
3664 | GLuint i; |
||
3665 | for (i = 0; i < n; i++) { |
||
3666 | if (shift == 7) |
||
3667 | *dst = 0; |
||
3668 | *dst |= ((source[i] != 0) << shift); |
||
3669 | shift--; |
||
3670 | if (shift < 0) { |
||
3671 | shift = 7; |
||
3672 | dst++; |
||
3673 | } |
||
3674 | } |
||
3675 | } |
||
3676 | break; |
||
3677 | default: |
||
3678 | _mesa_problem(ctx, "bad type in _mesa_pack_index_span"); |
||
3679 | } |
||
3680 | } |
||
3681 | |||
3682 | |||
3683 | |||
3684 | void |
||
3685 | _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, GLfloat *dest, |
||
3686 | GLenum srcType, const GLvoid *source, |
||
3687 | const struct gl_pixelstore_attrib *srcPacking ) |
||
3688 | { |
||
3689 | switch (srcType) { |
||
3690 | case GL_BYTE: |
||
3691 | { |
||
3692 | GLuint i; |
||
3693 | const GLubyte *src = (const GLubyte *) source; |
||
3694 | for (i = 0; i < n; i++) { |
||
3695 | dest[i] = BYTE_TO_FLOAT(src[i]); |
||
3696 | } |
||
3697 | } |
||
3698 | break; |
||
3699 | case GL_UNSIGNED_BYTE: |
||
3700 | { |
||
3701 | GLuint i; |
||
3702 | const GLubyte *src = (const GLubyte *) source; |
||
3703 | for (i = 0; i < n; i++) { |
||
3704 | dest[i] = UBYTE_TO_FLOAT(src[i]); |
||
3705 | } |
||
3706 | } |
||
3707 | break; |
||
3708 | case GL_SHORT: |
||
3709 | { |
||
3710 | GLuint i; |
||
3711 | const GLshort *src = (const GLshort *) source; |
||
3712 | for (i = 0; i < n; i++) { |
||
3713 | dest[i] = SHORT_TO_FLOAT(src[i]); |
||
3714 | } |
||
3715 | } |
||
3716 | break; |
||
3717 | case GL_UNSIGNED_SHORT: |
||
3718 | { |
||
3719 | GLuint i; |
||
3720 | const GLushort *src = (const GLushort *) source; |
||
3721 | for (i = 0; i < n; i++) { |
||
3722 | dest[i] = USHORT_TO_FLOAT(src[i]); |
||
3723 | } |
||
3724 | } |
||
3725 | break; |
||
3726 | case GL_INT: |
||
3727 | { |
||
3728 | GLuint i; |
||
3729 | const GLint *src = (const GLint *) source; |
||
3730 | for (i = 0; i < n; i++) { |
||
3731 | dest[i] = INT_TO_FLOAT(src[i]); |
||
3732 | } |
||
3733 | } |
||
3734 | break; |
||
3735 | case GL_UNSIGNED_INT: |
||
3736 | { |
||
3737 | GLuint i; |
||
3738 | const GLuint *src = (const GLuint *) source; |
||
3739 | for (i = 0; i < n; i++) { |
||
3740 | dest[i] = UINT_TO_FLOAT(src[i]); |
||
3741 | } |
||
3742 | } |
||
3743 | break; |
||
3744 | case GL_FLOAT: |
||
3745 | MEMCPY(dest, source, n * sizeof(GLfloat)); |
||
3746 | break; |
||
3747 | default: |
||
3748 | _mesa_problem(NULL, "bad type in _mesa_unpack_depth_span()"); |
||
3749 | return; |
||
3750 | } |
||
3751 | |||
3752 | |||
3753 | /* apply depth scale and bias and clamp to [0,1] */ |
||
3754 | if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) { |
||
3755 | GLuint i; |
||
3756 | for (i = 0; i < n; i++) { |
||
3757 | GLfloat d = dest[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias; |
||
3758 | dest[i] = CLAMP(d, 0.0F, 1.0F); |
||
3759 | } |
||
3760 | } |
||
3761 | } |
||
3762 | |||
3763 | |||
3764 | |||
3765 | /* |
||
3766 | * Pack an array of depth values. The values are floats in [0,1]. |
||
3767 | */ |
||
3768 | void |
||
3769 | _mesa_pack_depth_span( const GLcontext *ctx, GLuint n, GLvoid *dest, |
||
3770 | GLenum dstType, const GLfloat *depthSpan, |
||
3771 | const struct gl_pixelstore_attrib *dstPacking ) |
||
3772 | { |
||
3773 | GLfloat depthCopy[MAX_WIDTH]; |
||
3774 | const GLboolean bias_or_scale = ctx->Pixel.DepthBias != 0.0 || |
||
3775 | ctx->Pixel.DepthScale != 1.0; |
||
3776 | |||
3777 | ASSERT(n <= MAX_WIDTH); |
||
3778 | |||
3779 | if (bias_or_scale) { |
||
3780 | GLuint i; |
||
3781 | for (i = 0; i < n; i++) { |
||
3782 | GLfloat d; |
||
3783 | d = depthSpan[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias; |
||
3784 | depthCopy[i] = CLAMP(d, 0.0F, 1.0F); |
||
3785 | } |
||
3786 | depthSpan = depthCopy; |
||
3787 | } |
||
3788 | |||
3789 | switch (dstType) { |
||
3790 | case GL_UNSIGNED_BYTE: |
||
3791 | { |
||
3792 | GLubyte *dst = (GLubyte *) dest; |
||
3793 | GLuint i; |
||
3794 | for (i = 0; i < n; i++) { |
||
3795 | dst[i] = FLOAT_TO_UBYTE( depthSpan[i] ); |
||
3796 | } |
||
3797 | } |
||
3798 | break; |
||
3799 | case GL_BYTE: |
||
3800 | { |
||
3801 | GLbyte *dst = (GLbyte *) dest; |
||
3802 | GLuint i; |
||
3803 | for (i = 0; i < n; i++) { |
||
3804 | dst[i] = FLOAT_TO_BYTE( depthSpan[i] ); |
||
3805 | } |
||
3806 | } |
||
3807 | break; |
||
3808 | case GL_UNSIGNED_SHORT: |
||
3809 | { |
||
3810 | GLushort *dst = (GLushort *) dest; |
||
3811 | GLuint i; |
||
3812 | for (i = 0; i < n; i++) { |
||
3813 | dst[i] = FLOAT_TO_USHORT( depthSpan[i] ); |
||
3814 | } |
||
3815 | if (dstPacking->SwapBytes) { |
||
3816 | _mesa_swap2( (GLushort *) dst, n ); |
||
3817 | } |
||
3818 | } |
||
3819 | break; |
||
3820 | case GL_SHORT: |
||
3821 | { |
||
3822 | GLshort *dst = (GLshort *) dest; |
||
3823 | GLuint i; |
||
3824 | for (i = 0; i < n; i++) { |
||
3825 | dst[i] = FLOAT_TO_SHORT( depthSpan[i] ); |
||
3826 | } |
||
3827 | if (dstPacking->SwapBytes) { |
||
3828 | _mesa_swap2( (GLushort *) dst, n ); |
||
3829 | } |
||
3830 | } |
||
3831 | break; |
||
3832 | case GL_UNSIGNED_INT: |
||
3833 | { |
||
3834 | GLuint *dst = (GLuint *) dest; |
||
3835 | GLuint i; |
||
3836 | for (i = 0; i < n; i++) { |
||
3837 | dst[i] = FLOAT_TO_UINT( depthSpan[i] ); |
||
3838 | } |
||
3839 | if (dstPacking->SwapBytes) { |
||
3840 | _mesa_swap4( (GLuint *) dst, n ); |
||
3841 | } |
||
3842 | } |
||
3843 | break; |
||
3844 | case GL_INT: |
||
3845 | { |
||
3846 | GLint *dst = (GLint *) dest; |
||
3847 | GLuint i; |
||
3848 | for (i = 0; i < n; i++) { |
||
3849 | dst[i] = FLOAT_TO_INT( depthSpan[i] ); |
||
3850 | } |
||
3851 | if (dstPacking->SwapBytes) { |
||
3852 | _mesa_swap4( (GLuint *) dst, n ); |
||
3853 | } |
||
3854 | } |
||
3855 | break; |
||
3856 | case GL_FLOAT: |
||
3857 | { |
||
3858 | GLfloat *dst = (GLfloat *) dest; |
||
3859 | GLuint i; |
||
3860 | for (i = 0; i < n; i++) { |
||
3861 | dst[i] = depthSpan[i]; |
||
3862 | } |
||
3863 | if (dstPacking->SwapBytes) { |
||
3864 | _mesa_swap4( (GLuint *) dst, n ); |
||
3865 | } |
||
3866 | } |
||
3867 | break; |
||
3868 | default: |
||
3869 | _mesa_problem(ctx, "bad type in _mesa_pack_depth_span"); |
||
3870 | } |
||
3871 | } |
||
3872 | |||
3873 | |||
3874 | |||
3875 | |||
3876 | /* |
||
3877 | * Unpack image data. Apply byteswapping, byte flipping (bitmap). |
||
3878 | * Return all image data in a contiguous block. |
||
3879 | */ |
||
3880 | void * |
||
3881 | _mesa_unpack_image( GLsizei width, GLsizei height, GLsizei depth, |
||
3882 | GLenum format, GLenum type, const GLvoid *pixels, |
||
3883 | const struct gl_pixelstore_attrib *unpack ) |
||
3884 | { |
||
3885 | GLint bytesPerRow, compsPerRow; |
||
3886 | GLboolean flipBytes, swap2, swap4; |
||
3887 | |||
3888 | if (!pixels) |
||
3889 | return NULL; /* not necessarily an error */ |
||
3890 | |||
3891 | if (width <= 0 || height <= 0 || depth <= 0) |
||
3892 | return NULL; /* generate error later */ |
||
3893 | |||
3894 | if (format == GL_BITMAP) { |
||
3895 | bytesPerRow = (width + 7) >> 3; |
||
3896 | flipBytes = !unpack->LsbFirst; |
||
3897 | swap2 = swap4 = GL_FALSE; |
||
3898 | compsPerRow = 0; |
||
3899 | } |
||
3900 | else { |
||
3901 | const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type); |
||
3902 | const GLint components = _mesa_components_in_format(format); |
||
3903 | GLint bytesPerComp; |
||
3904 | if (bytesPerPixel <= 0 || components <= 0) |
||
3905 | return NULL; /* bad format or type. generate error later */ |
||
3906 | bytesPerRow = bytesPerPixel * width; |
||
3907 | bytesPerComp = bytesPerPixel / components; |
||
3908 | flipBytes = GL_FALSE; |
||
3909 | swap2 = (bytesPerComp == 2) && unpack->SwapBytes; |
||
3910 | swap4 = (bytesPerComp == 4) && unpack->SwapBytes; |
||
3911 | compsPerRow = components * width; |
||
3912 | assert(compsPerRow >= width); |
||
3913 | } |
||
3914 | |||
3915 | { |
||
3916 | GLubyte *destBuffer = (GLubyte *) MALLOC(bytesPerRow * height * depth); |
||
3917 | GLubyte *dst; |
||
3918 | GLint img, row; |
||
3919 | if (!destBuffer) |
||
3920 | return NULL; /* generate GL_OUT_OF_MEMORY later */ |
||
3921 | |||
3922 | dst = destBuffer; |
||
3923 | for (img = 0; img < depth; img++) { |
||
3924 | for (row = 0; row < height; row++) { |
||
3925 | const GLvoid *src = _mesa_image_address(unpack, pixels, |
||
3926 | width, height, format, type, img, row, 0); |
||
3927 | MEMCPY(dst, src, bytesPerRow); |
||
3928 | /* byte flipping/swapping */ |
||
3929 | if (flipBytes) { |
||
3930 | flip_bytes((GLubyte *) dst, bytesPerRow); |
||
3931 | } |
||
3932 | else if (swap2) { |
||
3933 | _mesa_swap2((GLushort*) dst, compsPerRow); |
||
3934 | } |
||
3935 | else if (swap4) { |
||
3936 | _mesa_swap4((GLuint*) dst, compsPerRow); |
||
3937 | } |
||
3938 | dst += bytesPerRow; |
||
3939 | } |
||
3940 | } |
||
3941 | return destBuffer; |
||
3942 | } |
||
3943 | } |