image: fix legal types for packed integer formats.
[mesa.git] / src / mesa / main / image.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file image.c
29 * Image handling.
30 */
31
32
33 #include "glheader.h"
34 #include "colormac.h"
35 #include "image.h"
36 #include "imports.h"
37 #include "macros.h"
38 #include "mfeatures.h"
39 #include "mtypes.h"
40
41
42
43 /**
44 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
45 */
46 GLboolean
47 _mesa_type_is_packed(GLenum type)
48 {
49 switch (type) {
50 case GL_UNSIGNED_BYTE_3_3_2:
51 case GL_UNSIGNED_BYTE_2_3_3_REV:
52 case MESA_UNSIGNED_BYTE_4_4:
53 case GL_UNSIGNED_SHORT_5_6_5:
54 case GL_UNSIGNED_SHORT_5_6_5_REV:
55 case GL_UNSIGNED_SHORT_4_4_4_4:
56 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
57 case GL_UNSIGNED_SHORT_5_5_5_1:
58 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
59 case GL_UNSIGNED_INT_8_8_8_8:
60 case GL_UNSIGNED_INT_8_8_8_8_REV:
61 case GL_UNSIGNED_INT_10_10_10_2:
62 case GL_UNSIGNED_INT_2_10_10_10_REV:
63 case GL_UNSIGNED_SHORT_8_8_MESA:
64 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
65 case GL_UNSIGNED_INT_24_8_EXT:
66 case GL_UNSIGNED_INT_5_9_9_9_REV:
67 case GL_UNSIGNED_INT_10F_11F_11F_REV:
68 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
69 return GL_TRUE;
70 }
71
72 return GL_FALSE;
73 }
74
75
76
77 /**
78 * Flip the order of the 2 bytes in each word in the given array.
79 *
80 * \param p array.
81 * \param n number of words.
82 */
83 void
84 _mesa_swap2( GLushort *p, GLuint n )
85 {
86 GLuint i;
87 for (i = 0; i < n; i++) {
88 p[i] = (p[i] >> 8) | ((p[i] << 8) & 0xff00);
89 }
90 }
91
92
93
94 /*
95 * Flip the order of the 4 bytes in each word in the given array.
96 */
97 void
98 _mesa_swap4( GLuint *p, GLuint n )
99 {
100 GLuint i, a, b;
101 for (i = 0; i < n; i++) {
102 b = p[i];
103 a = (b >> 24)
104 | ((b >> 8) & 0xff00)
105 | ((b << 8) & 0xff0000)
106 | ((b << 24) & 0xff000000);
107 p[i] = a;
108 }
109 }
110
111
112 /**
113 * Get the size of a GL data type.
114 *
115 * \param type GL data type.
116 *
117 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
118 * if an invalid type enum.
119 */
120 GLint
121 _mesa_sizeof_type( GLenum type )
122 {
123 switch (type) {
124 case GL_BITMAP:
125 return 0;
126 case GL_UNSIGNED_BYTE:
127 return sizeof(GLubyte);
128 case GL_BYTE:
129 return sizeof(GLbyte);
130 case GL_UNSIGNED_SHORT:
131 return sizeof(GLushort);
132 case GL_SHORT:
133 return sizeof(GLshort);
134 case GL_UNSIGNED_INT:
135 return sizeof(GLuint);
136 case GL_INT:
137 return sizeof(GLint);
138 case GL_FLOAT:
139 return sizeof(GLfloat);
140 case GL_DOUBLE:
141 return sizeof(GLdouble);
142 case GL_HALF_FLOAT_ARB:
143 return sizeof(GLhalfARB);
144 case GL_FIXED:
145 return sizeof(GLfixed);
146 default:
147 return -1;
148 }
149 }
150
151
152 /**
153 * Same as _mesa_sizeof_type() but also accepting the packed pixel
154 * format data types.
155 */
156 GLint
157 _mesa_sizeof_packed_type( GLenum type )
158 {
159 switch (type) {
160 case GL_BITMAP:
161 return 0;
162 case GL_UNSIGNED_BYTE:
163 return sizeof(GLubyte);
164 case GL_BYTE:
165 return sizeof(GLbyte);
166 case GL_UNSIGNED_SHORT:
167 return sizeof(GLushort);
168 case GL_SHORT:
169 return sizeof(GLshort);
170 case GL_UNSIGNED_INT:
171 return sizeof(GLuint);
172 case GL_INT:
173 return sizeof(GLint);
174 case GL_HALF_FLOAT_ARB:
175 return sizeof(GLhalfARB);
176 case GL_FLOAT:
177 return sizeof(GLfloat);
178 case GL_UNSIGNED_BYTE_3_3_2:
179 case GL_UNSIGNED_BYTE_2_3_3_REV:
180 case MESA_UNSIGNED_BYTE_4_4:
181 return sizeof(GLubyte);
182 case GL_UNSIGNED_SHORT_5_6_5:
183 case GL_UNSIGNED_SHORT_5_6_5_REV:
184 case GL_UNSIGNED_SHORT_4_4_4_4:
185 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
186 case GL_UNSIGNED_SHORT_5_5_5_1:
187 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
188 case GL_UNSIGNED_SHORT_8_8_MESA:
189 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
190 return sizeof(GLushort);
191 case GL_UNSIGNED_INT_8_8_8_8:
192 case GL_UNSIGNED_INT_8_8_8_8_REV:
193 case GL_UNSIGNED_INT_10_10_10_2:
194 case GL_UNSIGNED_INT_2_10_10_10_REV:
195 case GL_UNSIGNED_INT_24_8_EXT:
196 case GL_UNSIGNED_INT_5_9_9_9_REV:
197 case GL_UNSIGNED_INT_10F_11F_11F_REV:
198 return sizeof(GLuint);
199 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
200 return 8;
201 default:
202 return -1;
203 }
204 }
205
206
207 /**
208 * Get the number of components in a pixel format.
209 *
210 * \param format pixel format.
211 *
212 * \return the number of components in the given format, or -1 if a bad format.
213 */
214 GLint
215 _mesa_components_in_format( GLenum format )
216 {
217 switch (format) {
218 case GL_COLOR_INDEX:
219 case GL_STENCIL_INDEX:
220 case GL_DEPTH_COMPONENT:
221 case GL_RED:
222 case GL_RED_INTEGER_EXT:
223 case GL_GREEN:
224 case GL_GREEN_INTEGER_EXT:
225 case GL_BLUE:
226 case GL_BLUE_INTEGER_EXT:
227 case GL_ALPHA:
228 case GL_ALPHA_INTEGER_EXT:
229 case GL_LUMINANCE:
230 case GL_LUMINANCE_INTEGER_EXT:
231 case GL_INTENSITY:
232 return 1;
233
234 case GL_LUMINANCE_ALPHA:
235 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
236 case GL_RG:
237 case GL_YCBCR_MESA:
238 case GL_DEPTH_STENCIL_EXT:
239 case GL_DUDV_ATI:
240 case GL_DU8DV8_ATI:
241 return 2;
242
243 case GL_RGB:
244 case GL_BGR:
245 case GL_RGB_INTEGER_EXT:
246 return 3;
247
248 case GL_RGBA:
249 case GL_BGRA:
250 case GL_ABGR_EXT:
251 case GL_RGBA_INTEGER_EXT:
252 return 4;
253
254 default:
255 return -1;
256 }
257 }
258
259
260 /**
261 * Get the bytes per pixel of pixel format type pair.
262 *
263 * \param format pixel format.
264 * \param type pixel type.
265 *
266 * \return bytes per pixel, or -1 if a bad format or type was given.
267 */
268 GLint
269 _mesa_bytes_per_pixel( GLenum format, GLenum type )
270 {
271 GLint comps = _mesa_components_in_format( format );
272 if (comps < 0)
273 return -1;
274
275 switch (type) {
276 case GL_BITMAP:
277 return 0; /* special case */
278 case GL_BYTE:
279 case GL_UNSIGNED_BYTE:
280 return comps * sizeof(GLubyte);
281 case GL_SHORT:
282 case GL_UNSIGNED_SHORT:
283 return comps * sizeof(GLshort);
284 case GL_INT:
285 case GL_UNSIGNED_INT:
286 return comps * sizeof(GLint);
287 case GL_FLOAT:
288 return comps * sizeof(GLfloat);
289 case GL_HALF_FLOAT_ARB:
290 return comps * sizeof(GLhalfARB);
291 case GL_UNSIGNED_BYTE_3_3_2:
292 case GL_UNSIGNED_BYTE_2_3_3_REV:
293 if (format == GL_RGB || format == GL_BGR ||
294 format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
295 return sizeof(GLubyte);
296 else
297 return -1; /* error */
298 case GL_UNSIGNED_SHORT_5_6_5:
299 case GL_UNSIGNED_SHORT_5_6_5_REV:
300 if (format == GL_RGB || format == GL_BGR ||
301 format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
302 return sizeof(GLushort);
303 else
304 return -1; /* error */
305 case GL_UNSIGNED_SHORT_4_4_4_4:
306 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
307 case GL_UNSIGNED_SHORT_5_5_5_1:
308 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
309 if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
310 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
311 return sizeof(GLushort);
312 else
313 return -1;
314 case GL_UNSIGNED_INT_8_8_8_8:
315 case GL_UNSIGNED_INT_8_8_8_8_REV:
316 case GL_UNSIGNED_INT_10_10_10_2:
317 case GL_UNSIGNED_INT_2_10_10_10_REV:
318 if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
319 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
320 return sizeof(GLuint);
321 else
322 return -1;
323 case GL_UNSIGNED_SHORT_8_8_MESA:
324 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
325 if (format == GL_YCBCR_MESA)
326 return sizeof(GLushort);
327 else
328 return -1;
329 case GL_UNSIGNED_INT_24_8_EXT:
330 if (format == GL_DEPTH_STENCIL_EXT)
331 return sizeof(GLuint);
332 else
333 return -1;
334 case GL_UNSIGNED_INT_5_9_9_9_REV:
335 if (format == GL_RGB)
336 return sizeof(GLuint);
337 else
338 return -1;
339 case GL_UNSIGNED_INT_10F_11F_11F_REV:
340 if (format == GL_RGB)
341 return sizeof(GLuint);
342 else
343 return -1;
344 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
345 if (format == GL_DEPTH_STENCIL)
346 return 8;
347 else
348 return -1;
349 default:
350 return -1;
351 }
352 }
353
354
355 /**
356 * Test for a legal pixel format and type.
357 *
358 * \param format pixel format.
359 * \param type pixel type.
360 *
361 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
362 * otherwise.
363 */
364 GLboolean
365 _mesa_is_legal_format_and_type(const struct gl_context *ctx,
366 GLenum format, GLenum type)
367 {
368 switch (format) {
369 case GL_COLOR_INDEX:
370 case GL_STENCIL_INDEX:
371 switch (type) {
372 case GL_BITMAP:
373 case GL_BYTE:
374 case GL_UNSIGNED_BYTE:
375 case GL_SHORT:
376 case GL_UNSIGNED_SHORT:
377 case GL_INT:
378 case GL_UNSIGNED_INT:
379 case GL_FLOAT:
380 return GL_TRUE;
381 case GL_HALF_FLOAT_ARB:
382 return ctx->Extensions.ARB_half_float_pixel;
383 default:
384 return GL_FALSE;
385 }
386 case GL_RED:
387 case GL_GREEN:
388 case GL_BLUE:
389 case GL_ALPHA:
390 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
391 case GL_INTENSITY:
392 #endif
393 case GL_LUMINANCE:
394 case GL_LUMINANCE_ALPHA:
395 case GL_DEPTH_COMPONENT:
396 switch (type) {
397 case GL_BYTE:
398 case GL_UNSIGNED_BYTE:
399 case GL_SHORT:
400 case GL_UNSIGNED_SHORT:
401 case GL_INT:
402 case GL_UNSIGNED_INT:
403 case GL_FLOAT:
404 return GL_TRUE;
405 case GL_HALF_FLOAT_ARB:
406 return ctx->Extensions.ARB_half_float_pixel;
407 default:
408 return GL_FALSE;
409 }
410 case GL_RG:
411 if (!ctx->Extensions.ARB_texture_rg)
412 return GL_FALSE;
413
414 switch (type) {
415 case GL_BYTE:
416 case GL_UNSIGNED_BYTE:
417 case GL_SHORT:
418 case GL_UNSIGNED_SHORT:
419 case GL_INT:
420 case GL_UNSIGNED_INT:
421 case GL_FLOAT:
422 return GL_TRUE;
423 case GL_HALF_FLOAT_ARB:
424 return ctx->Extensions.ARB_half_float_pixel;
425 default:
426 return GL_FALSE;
427 }
428 case GL_RGB:
429 switch (type) {
430 case GL_BYTE:
431 case GL_UNSIGNED_BYTE:
432 case GL_SHORT:
433 case GL_UNSIGNED_SHORT:
434 case GL_INT:
435 case GL_UNSIGNED_INT:
436 case GL_FLOAT:
437 case GL_UNSIGNED_BYTE_3_3_2:
438 case GL_UNSIGNED_BYTE_2_3_3_REV:
439 case GL_UNSIGNED_SHORT_5_6_5:
440 case GL_UNSIGNED_SHORT_5_6_5_REV:
441 return GL_TRUE;
442 case GL_HALF_FLOAT_ARB:
443 return ctx->Extensions.ARB_half_float_pixel;
444 case GL_UNSIGNED_INT_5_9_9_9_REV:
445 return ctx->Extensions.EXT_texture_shared_exponent;
446 case GL_UNSIGNED_INT_10F_11F_11F_REV:
447 return ctx->Extensions.EXT_packed_float;
448 default:
449 return GL_FALSE;
450 }
451 case GL_BGR:
452 switch (type) {
453 /* NOTE: no packed types are supported with BGR. That's
454 * intentional, according to the GL spec.
455 */
456 case GL_BYTE:
457 case GL_UNSIGNED_BYTE:
458 case GL_SHORT:
459 case GL_UNSIGNED_SHORT:
460 case GL_INT:
461 case GL_UNSIGNED_INT:
462 case GL_FLOAT:
463 return GL_TRUE;
464 case GL_HALF_FLOAT_ARB:
465 return ctx->Extensions.ARB_half_float_pixel;
466 default:
467 return GL_FALSE;
468 }
469 case GL_RGBA:
470 case GL_BGRA:
471 case GL_ABGR_EXT:
472 switch (type) {
473 case GL_BYTE:
474 case GL_UNSIGNED_BYTE:
475 case GL_SHORT:
476 case GL_UNSIGNED_SHORT:
477 case GL_INT:
478 case GL_UNSIGNED_INT:
479 case GL_FLOAT:
480 case GL_UNSIGNED_SHORT_4_4_4_4:
481 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
482 case GL_UNSIGNED_SHORT_5_5_5_1:
483 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
484 case GL_UNSIGNED_INT_8_8_8_8:
485 case GL_UNSIGNED_INT_8_8_8_8_REV:
486 case GL_UNSIGNED_INT_10_10_10_2:
487 case GL_UNSIGNED_INT_2_10_10_10_REV:
488 return GL_TRUE;
489 case GL_HALF_FLOAT_ARB:
490 return ctx->Extensions.ARB_half_float_pixel;
491 default:
492 return GL_FALSE;
493 }
494 case GL_YCBCR_MESA:
495 if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
496 type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
497 return GL_TRUE;
498 else
499 return GL_FALSE;
500 case GL_DEPTH_STENCIL_EXT:
501 if ((ctx->Extensions.EXT_packed_depth_stencil &&
502 type == GL_UNSIGNED_INT_24_8_EXT) ||
503 (ctx->Extensions.ARB_depth_buffer_float &&
504 type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV))
505 return GL_TRUE;
506 else
507 return GL_FALSE;
508 case GL_DUDV_ATI:
509 case GL_DU8DV8_ATI:
510 switch (type) {
511 case GL_BYTE:
512 case GL_UNSIGNED_BYTE:
513 case GL_SHORT:
514 case GL_UNSIGNED_SHORT:
515 case GL_INT:
516 case GL_UNSIGNED_INT:
517 case GL_FLOAT:
518 return GL_TRUE;
519 default:
520 return GL_FALSE;
521 }
522
523 /* integer-valued formats */
524 case GL_RED_INTEGER_EXT:
525 case GL_GREEN_INTEGER_EXT:
526 case GL_BLUE_INTEGER_EXT:
527 case GL_ALPHA_INTEGER_EXT:
528 switch (type) {
529 case GL_BYTE:
530 case GL_UNSIGNED_BYTE:
531 case GL_SHORT:
532 case GL_UNSIGNED_SHORT:
533 case GL_INT:
534 case GL_UNSIGNED_INT:
535 return ctx->Extensions.EXT_texture_integer;
536 default:
537 return GL_FALSE;
538 }
539
540 case GL_RGB_INTEGER_EXT:
541 switch (type) {
542 case GL_BYTE:
543 case GL_UNSIGNED_BYTE:
544 case GL_SHORT:
545 case GL_UNSIGNED_SHORT:
546 case GL_INT:
547 case GL_UNSIGNED_INT:
548 return ctx->Extensions.EXT_texture_integer;
549 case GL_UNSIGNED_BYTE_3_3_2:
550 case GL_UNSIGNED_BYTE_2_3_3_REV:
551 case GL_UNSIGNED_SHORT_5_6_5:
552 case GL_UNSIGNED_SHORT_5_6_5_REV:
553 return ctx->Extensions.ARB_texture_rgb10_a2ui;
554 default:
555 return GL_FALSE;
556 }
557
558 case GL_BGR_INTEGER_EXT:
559 switch (type) {
560 case GL_BYTE:
561 case GL_UNSIGNED_BYTE:
562 case GL_SHORT:
563 case GL_UNSIGNED_SHORT:
564 case GL_INT:
565 case GL_UNSIGNED_INT:
566 /* NOTE: no packed formats w/ BGR format */
567 return ctx->Extensions.EXT_texture_integer;
568 default:
569 return GL_FALSE;
570 }
571
572 case GL_RGBA_INTEGER_EXT:
573 case GL_BGRA_INTEGER_EXT:
574 switch (type) {
575 case GL_BYTE:
576 case GL_UNSIGNED_BYTE:
577 case GL_SHORT:
578 case GL_UNSIGNED_SHORT:
579 case GL_INT:
580 case GL_UNSIGNED_INT:
581 return ctx->Extensions.EXT_texture_integer;
582 case GL_UNSIGNED_SHORT_4_4_4_4:
583 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
584 case GL_UNSIGNED_SHORT_5_5_5_1:
585 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
586 case GL_UNSIGNED_INT_8_8_8_8:
587 case GL_UNSIGNED_INT_8_8_8_8_REV:
588 case GL_UNSIGNED_INT_10_10_10_2:
589 case GL_UNSIGNED_INT_2_10_10_10_REV:
590 return ctx->Extensions.ARB_texture_rgb10_a2ui;
591 default:
592 return GL_FALSE;
593 }
594
595 case GL_LUMINANCE_INTEGER_EXT:
596 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
597 switch (type) {
598 case GL_BYTE:
599 case GL_UNSIGNED_BYTE:
600 case GL_SHORT:
601 case GL_UNSIGNED_SHORT:
602 case GL_INT:
603 case GL_UNSIGNED_INT:
604 return ctx->Extensions.EXT_texture_integer;
605 default:
606 return GL_FALSE;
607 }
608
609 default:
610 ; /* fall-through */
611 }
612 return GL_FALSE;
613 }
614
615
616 /**
617 * Test if the given image format is a color/RGBA format (i.e., not color
618 * index, depth, stencil, etc).
619 * \param format the image format value (may by an internal texture format)
620 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
621 */
622 GLboolean
623 _mesa_is_color_format(GLenum format)
624 {
625 switch (format) {
626 case GL_RED:
627 case GL_GREEN:
628 case GL_BLUE:
629 case GL_ALPHA:
630 case GL_ALPHA4:
631 case GL_ALPHA8:
632 case GL_ALPHA12:
633 case GL_ALPHA16:
634 case 1:
635 case GL_LUMINANCE:
636 case GL_LUMINANCE4:
637 case GL_LUMINANCE8:
638 case GL_LUMINANCE12:
639 case GL_LUMINANCE16:
640 case 2:
641 case GL_LUMINANCE_ALPHA:
642 case GL_LUMINANCE4_ALPHA4:
643 case GL_LUMINANCE6_ALPHA2:
644 case GL_LUMINANCE8_ALPHA8:
645 case GL_LUMINANCE12_ALPHA4:
646 case GL_LUMINANCE12_ALPHA12:
647 case GL_LUMINANCE16_ALPHA16:
648 case GL_INTENSITY:
649 case GL_INTENSITY4:
650 case GL_INTENSITY8:
651 case GL_INTENSITY12:
652 case GL_INTENSITY16:
653 case GL_R8:
654 case GL_R16:
655 case GL_RG:
656 case GL_RG8:
657 case GL_RG16:
658 case 3:
659 case GL_RGB:
660 case GL_BGR:
661 case GL_R3_G3_B2:
662 case GL_RGB4:
663 case GL_RGB5:
664 case GL_RGB8:
665 case GL_RGB10:
666 case GL_RGB12:
667 case GL_RGB16:
668 case 4:
669 case GL_ABGR_EXT:
670 case GL_RGBA:
671 case GL_BGRA:
672 case GL_RGBA2:
673 case GL_RGBA4:
674 case GL_RGB5_A1:
675 case GL_RGBA8:
676 case GL_RGB10_A2:
677 case GL_RGBA12:
678 case GL_RGBA16:
679 /* float texture formats */
680 case GL_ALPHA16F_ARB:
681 case GL_ALPHA32F_ARB:
682 case GL_LUMINANCE16F_ARB:
683 case GL_LUMINANCE32F_ARB:
684 case GL_LUMINANCE_ALPHA16F_ARB:
685 case GL_LUMINANCE_ALPHA32F_ARB:
686 case GL_INTENSITY16F_ARB:
687 case GL_INTENSITY32F_ARB:
688 case GL_R16F:
689 case GL_R32F:
690 case GL_RG16F:
691 case GL_RG32F:
692 case GL_RGB16F_ARB:
693 case GL_RGB32F_ARB:
694 case GL_RGBA16F_ARB:
695 case GL_RGBA32F_ARB:
696 /* compressed formats */
697 case GL_COMPRESSED_ALPHA:
698 case GL_COMPRESSED_LUMINANCE:
699 case GL_COMPRESSED_LUMINANCE_ALPHA:
700 case GL_COMPRESSED_INTENSITY:
701 case GL_COMPRESSED_RED:
702 case GL_COMPRESSED_RG:
703 case GL_COMPRESSED_RGB:
704 case GL_COMPRESSED_RGBA:
705 case GL_RGB_S3TC:
706 case GL_RGB4_S3TC:
707 case GL_RGBA_S3TC:
708 case GL_RGBA4_S3TC:
709 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
710 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
711 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
712 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
713 case GL_COMPRESSED_RGB_FXT1_3DFX:
714 case GL_COMPRESSED_RGBA_FXT1_3DFX:
715 #if FEATURE_EXT_texture_sRGB
716 case GL_SRGB_EXT:
717 case GL_SRGB8_EXT:
718 case GL_SRGB_ALPHA_EXT:
719 case GL_SRGB8_ALPHA8_EXT:
720 case GL_SLUMINANCE_ALPHA_EXT:
721 case GL_SLUMINANCE8_ALPHA8_EXT:
722 case GL_SLUMINANCE_EXT:
723 case GL_SLUMINANCE8_EXT:
724 case GL_COMPRESSED_SRGB_EXT:
725 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
726 case GL_COMPRESSED_SRGB_ALPHA_EXT:
727 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
728 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
729 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
730 case GL_COMPRESSED_SLUMINANCE_EXT:
731 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
732 #endif /* FEATURE_EXT_texture_sRGB */
733 case GL_COMPRESSED_RED_RGTC1:
734 case GL_COMPRESSED_SIGNED_RED_RGTC1:
735 case GL_COMPRESSED_RG_RGTC2:
736 case GL_COMPRESSED_SIGNED_RG_RGTC2:
737 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
738 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
739 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
740 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
741 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
742 /* generic integer formats */
743 case GL_RED_INTEGER_EXT:
744 case GL_GREEN_INTEGER_EXT:
745 case GL_BLUE_INTEGER_EXT:
746 case GL_ALPHA_INTEGER_EXT:
747 case GL_RGB_INTEGER_EXT:
748 case GL_RGBA_INTEGER_EXT:
749 case GL_BGR_INTEGER_EXT:
750 case GL_BGRA_INTEGER_EXT:
751 case GL_LUMINANCE_INTEGER_EXT:
752 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
753 /* sized integer formats */
754 case GL_RGBA32UI_EXT:
755 case GL_RGB32UI_EXT:
756 case GL_ALPHA32UI_EXT:
757 case GL_INTENSITY32UI_EXT:
758 case GL_LUMINANCE32UI_EXT:
759 case GL_LUMINANCE_ALPHA32UI_EXT:
760 case GL_RGBA16UI_EXT:
761 case GL_RGB16UI_EXT:
762 case GL_ALPHA16UI_EXT:
763 case GL_INTENSITY16UI_EXT:
764 case GL_LUMINANCE16UI_EXT:
765 case GL_LUMINANCE_ALPHA16UI_EXT:
766 case GL_RGBA8UI_EXT:
767 case GL_RGB8UI_EXT:
768 case GL_ALPHA8UI_EXT:
769 case GL_INTENSITY8UI_EXT:
770 case GL_LUMINANCE8UI_EXT:
771 case GL_LUMINANCE_ALPHA8UI_EXT:
772 case GL_RGBA32I_EXT:
773 case GL_RGB32I_EXT:
774 case GL_ALPHA32I_EXT:
775 case GL_INTENSITY32I_EXT:
776 case GL_LUMINANCE32I_EXT:
777 case GL_LUMINANCE_ALPHA32I_EXT:
778 case GL_RGBA16I_EXT:
779 case GL_RGB16I_EXT:
780 case GL_ALPHA16I_EXT:
781 case GL_INTENSITY16I_EXT:
782 case GL_LUMINANCE16I_EXT:
783 case GL_LUMINANCE_ALPHA16I_EXT:
784 case GL_RGBA8I_EXT:
785 case GL_RGB8I_EXT:
786 case GL_ALPHA8I_EXT:
787 case GL_INTENSITY8I_EXT:
788 case GL_LUMINANCE8I_EXT:
789 case GL_LUMINANCE_ALPHA8I_EXT:
790 /* signed, normalized texture formats */
791 case GL_RED_SNORM:
792 case GL_R8_SNORM:
793 case GL_R16_SNORM:
794 case GL_RG_SNORM:
795 case GL_RG8_SNORM:
796 case GL_RG16_SNORM:
797 case GL_RGB_SNORM:
798 case GL_RGB8_SNORM:
799 case GL_RGB16_SNORM:
800 case GL_RGBA_SNORM:
801 case GL_RGBA8_SNORM:
802 case GL_RGBA16_SNORM:
803 case GL_ALPHA_SNORM:
804 case GL_ALPHA8_SNORM:
805 case GL_ALPHA16_SNORM:
806 case GL_LUMINANCE_SNORM:
807 case GL_LUMINANCE8_SNORM:
808 case GL_LUMINANCE16_SNORM:
809 case GL_LUMINANCE_ALPHA_SNORM:
810 case GL_LUMINANCE8_ALPHA8_SNORM:
811 case GL_LUMINANCE16_ALPHA16_SNORM:
812 case GL_INTENSITY_SNORM:
813 case GL_INTENSITY8_SNORM:
814 case GL_INTENSITY16_SNORM:
815 case GL_RGB9_E5:
816 case GL_R11F_G11F_B10F:
817 return GL_TRUE;
818 case GL_YCBCR_MESA: /* not considered to be RGB */
819 /* fall-through */
820 default:
821 return GL_FALSE;
822 }
823 }
824
825
826 /**
827 * Test if the given image format is a depth component format.
828 */
829 GLboolean
830 _mesa_is_depth_format(GLenum format)
831 {
832 switch (format) {
833 case GL_DEPTH_COMPONENT:
834 case GL_DEPTH_COMPONENT16:
835 case GL_DEPTH_COMPONENT24:
836 case GL_DEPTH_COMPONENT32:
837 case GL_DEPTH_COMPONENT32F:
838 return GL_TRUE;
839 default:
840 return GL_FALSE;
841 }
842 }
843
844
845 /**
846 * Test if the given image format is a stencil format.
847 */
848 GLboolean
849 _mesa_is_stencil_format(GLenum format)
850 {
851 switch (format) {
852 case GL_STENCIL_INDEX:
853 case GL_DEPTH_STENCIL:
854 return GL_TRUE;
855 default:
856 return GL_FALSE;
857 }
858 }
859
860
861 /**
862 * Test if the given image format is a YCbCr format.
863 */
864 GLboolean
865 _mesa_is_ycbcr_format(GLenum format)
866 {
867 switch (format) {
868 case GL_YCBCR_MESA:
869 return GL_TRUE;
870 default:
871 return GL_FALSE;
872 }
873 }
874
875
876 /**
877 * Test if the given image format is a depth+stencil format.
878 */
879 GLboolean
880 _mesa_is_depthstencil_format(GLenum format)
881 {
882 switch (format) {
883 case GL_DEPTH24_STENCIL8_EXT:
884 case GL_DEPTH_STENCIL_EXT:
885 case GL_DEPTH32F_STENCIL8:
886 return GL_TRUE;
887 default:
888 return GL_FALSE;
889 }
890 }
891
892
893 /**
894 * Test if the given image format is a depth or stencil format.
895 */
896 GLboolean
897 _mesa_is_depth_or_stencil_format(GLenum format)
898 {
899 switch (format) {
900 case GL_DEPTH_COMPONENT:
901 case GL_DEPTH_COMPONENT16:
902 case GL_DEPTH_COMPONENT24:
903 case GL_DEPTH_COMPONENT32:
904 case GL_STENCIL_INDEX:
905 case GL_STENCIL_INDEX1_EXT:
906 case GL_STENCIL_INDEX4_EXT:
907 case GL_STENCIL_INDEX8_EXT:
908 case GL_STENCIL_INDEX16_EXT:
909 case GL_DEPTH_STENCIL_EXT:
910 case GL_DEPTH24_STENCIL8_EXT:
911 case GL_DEPTH_COMPONENT32F:
912 case GL_DEPTH32F_STENCIL8:
913 return GL_TRUE;
914 default:
915 return GL_FALSE;
916 }
917 }
918
919
920 /**
921 * Test if the given image format is a dudv format.
922 */
923 GLboolean
924 _mesa_is_dudv_format(GLenum format)
925 {
926 switch (format) {
927 case GL_DUDV_ATI:
928 case GL_DU8DV8_ATI:
929 return GL_TRUE;
930 default:
931 return GL_FALSE;
932 }
933 }
934
935
936 /**
937 * Test if the given format is an integer (non-normalized) format.
938 */
939 GLboolean
940 _mesa_is_integer_format(GLenum format)
941 {
942 switch (format) {
943 /* generic integer formats */
944 case GL_RED_INTEGER_EXT:
945 case GL_GREEN_INTEGER_EXT:
946 case GL_BLUE_INTEGER_EXT:
947 case GL_ALPHA_INTEGER_EXT:
948 case GL_RGB_INTEGER_EXT:
949 case GL_RGBA_INTEGER_EXT:
950 case GL_BGR_INTEGER_EXT:
951 case GL_BGRA_INTEGER_EXT:
952 case GL_LUMINANCE_INTEGER_EXT:
953 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
954 /* specific integer formats */
955 case GL_RGBA32UI_EXT:
956 case GL_RGB32UI_EXT:
957 case GL_RG32UI:
958 case GL_R32UI:
959 case GL_ALPHA32UI_EXT:
960 case GL_INTENSITY32UI_EXT:
961 case GL_LUMINANCE32UI_EXT:
962 case GL_LUMINANCE_ALPHA32UI_EXT:
963 case GL_RGBA16UI_EXT:
964 case GL_RGB16UI_EXT:
965 case GL_RG16UI:
966 case GL_R16UI:
967 case GL_ALPHA16UI_EXT:
968 case GL_INTENSITY16UI_EXT:
969 case GL_LUMINANCE16UI_EXT:
970 case GL_LUMINANCE_ALPHA16UI_EXT:
971 case GL_RGBA8UI_EXT:
972 case GL_RGB8UI_EXT:
973 case GL_RG8UI:
974 case GL_R8UI:
975 case GL_ALPHA8UI_EXT:
976 case GL_INTENSITY8UI_EXT:
977 case GL_LUMINANCE8UI_EXT:
978 case GL_LUMINANCE_ALPHA8UI_EXT:
979 case GL_RGBA32I_EXT:
980 case GL_RGB32I_EXT:
981 case GL_RG32I:
982 case GL_R32I:
983 case GL_ALPHA32I_EXT:
984 case GL_INTENSITY32I_EXT:
985 case GL_LUMINANCE32I_EXT:
986 case GL_LUMINANCE_ALPHA32I_EXT:
987 case GL_RGBA16I_EXT:
988 case GL_RGB16I_EXT:
989 case GL_RG16I:
990 case GL_R16I:
991 case GL_ALPHA16I_EXT:
992 case GL_INTENSITY16I_EXT:
993 case GL_LUMINANCE16I_EXT:
994 case GL_LUMINANCE_ALPHA16I_EXT:
995 case GL_RGBA8I_EXT:
996 case GL_RGB8I_EXT:
997 case GL_RG8I:
998 case GL_R8I:
999 case GL_ALPHA8I_EXT:
1000 case GL_INTENSITY8I_EXT:
1001 case GL_LUMINANCE8I_EXT:
1002 case GL_LUMINANCE_ALPHA8I_EXT:
1003 return GL_TRUE;
1004 default:
1005 return GL_FALSE;
1006 }
1007 }
1008
1009
1010 /**
1011 * Test if an image format is a supported compressed format.
1012 * \param format the internal format token provided by the user.
1013 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1014 */
1015 GLboolean
1016 _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
1017 {
1018 switch (format) {
1019 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1020 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1021 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1022 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1023 return ctx->Extensions.EXT_texture_compression_s3tc;
1024 case GL_RGB_S3TC:
1025 case GL_RGB4_S3TC:
1026 case GL_RGBA_S3TC:
1027 case GL_RGBA4_S3TC:
1028 return ctx->Extensions.S3_s3tc;
1029 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1030 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1031 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1032 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1033 return ctx->Extensions.EXT_texture_sRGB
1034 && ctx->Extensions.EXT_texture_compression_s3tc;
1035 case GL_COMPRESSED_RGB_FXT1_3DFX:
1036 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1037 return ctx->Extensions.TDFX_texture_compression_FXT1;
1038 case GL_COMPRESSED_RED_RGTC1:
1039 case GL_COMPRESSED_SIGNED_RED_RGTC1:
1040 case GL_COMPRESSED_RG_RGTC2:
1041 case GL_COMPRESSED_SIGNED_RG_RGTC2:
1042 return ctx->Extensions.ARB_texture_compression_rgtc;
1043 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
1044 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
1045 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
1046 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
1047 return ctx->Extensions.EXT_texture_compression_latc;
1048 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1049 return ctx->Extensions.ATI_texture_compression_3dc;
1050 #if FEATURE_ES
1051 case GL_PALETTE4_RGB8_OES:
1052 case GL_PALETTE4_RGBA8_OES:
1053 case GL_PALETTE4_R5_G6_B5_OES:
1054 case GL_PALETTE4_RGBA4_OES:
1055 case GL_PALETTE4_RGB5_A1_OES:
1056 case GL_PALETTE8_RGB8_OES:
1057 case GL_PALETTE8_RGBA8_OES:
1058 case GL_PALETTE8_R5_G6_B5_OES:
1059 case GL_PALETTE8_RGBA4_OES:
1060 case GL_PALETTE8_RGB5_A1_OES:
1061 return ctx->API == API_OPENGLES;
1062 #endif
1063 default:
1064 return GL_FALSE;
1065 }
1066 }
1067
1068
1069 /**
1070 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1071 *
1072 * Pixel unpacking/packing parameters are observed according to \p packing.
1073 *
1074 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1075 * \param image starting address of image data
1076 * \param width the image width
1077 * \param height theimage height
1078 * \param format the pixel format
1079 * \param type the pixel data type
1080 * \param packing the pixelstore attributes
1081 * \param img which image in the volume (0 for 1D or 2D images)
1082 * \param row row of pixel in the image (0 for 1D images)
1083 * \param column column of pixel in the image
1084 *
1085 * \return address of pixel on success, or NULL on error.
1086 *
1087 * \sa gl_pixelstore_attrib.
1088 */
1089 GLvoid *
1090 _mesa_image_address( GLuint dimensions,
1091 const struct gl_pixelstore_attrib *packing,
1092 const GLvoid *image,
1093 GLsizei width, GLsizei height,
1094 GLenum format, GLenum type,
1095 GLint img, GLint row, GLint column )
1096 {
1097 GLint alignment; /* 1, 2 or 4 */
1098 GLint pixels_per_row;
1099 GLint rows_per_image;
1100 GLint skiprows;
1101 GLint skippixels;
1102 GLint skipimages; /* for 3-D volume images */
1103 GLubyte *pixel_addr;
1104
1105 ASSERT(dimensions >= 1 && dimensions <= 3);
1106
1107 alignment = packing->Alignment;
1108 if (packing->RowLength > 0) {
1109 pixels_per_row = packing->RowLength;
1110 }
1111 else {
1112 pixels_per_row = width;
1113 }
1114 if (packing->ImageHeight > 0) {
1115 rows_per_image = packing->ImageHeight;
1116 }
1117 else {
1118 rows_per_image = height;
1119 }
1120
1121 skippixels = packing->SkipPixels;
1122 /* Note: SKIP_ROWS _is_ used for 1D images */
1123 skiprows = packing->SkipRows;
1124 /* Note: SKIP_IMAGES is only used for 3D images */
1125 skipimages = (dimensions == 3) ? packing->SkipImages : 0;
1126
1127 if (type == GL_BITMAP) {
1128 /* BITMAP data */
1129 GLint comp_per_pixel; /* components per pixel */
1130 GLint bytes_per_comp; /* bytes per component */
1131 GLint bytes_per_row;
1132 GLint bytes_per_image;
1133
1134 /* Compute bytes per component */
1135 bytes_per_comp = _mesa_sizeof_packed_type( type );
1136 if (bytes_per_comp < 0) {
1137 return NULL;
1138 }
1139
1140 /* Compute number of components per pixel */
1141 comp_per_pixel = _mesa_components_in_format( format );
1142 if (comp_per_pixel < 0) {
1143 return NULL;
1144 }
1145
1146 bytes_per_row = alignment
1147 * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
1148
1149 bytes_per_image = bytes_per_row * rows_per_image;
1150
1151 pixel_addr = (GLubyte *) image
1152 + (skipimages + img) * bytes_per_image
1153 + (skiprows + row) * bytes_per_row
1154 + (skippixels + column) / 8;
1155 }
1156 else {
1157 /* Non-BITMAP data */
1158 GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
1159 GLint topOfImage;
1160
1161 bytes_per_pixel = _mesa_bytes_per_pixel( format, type );
1162
1163 /* The pixel type and format should have been error checked earlier */
1164 assert(bytes_per_pixel > 0);
1165
1166 bytes_per_row = pixels_per_row * bytes_per_pixel;
1167 remainder = bytes_per_row % alignment;
1168 if (remainder > 0)
1169 bytes_per_row += (alignment - remainder);
1170
1171 ASSERT(bytes_per_row % alignment == 0);
1172
1173 bytes_per_image = bytes_per_row * rows_per_image;
1174
1175 if (packing->Invert) {
1176 /* set pixel_addr to the last row */
1177 topOfImage = bytes_per_row * (height - 1);
1178 bytes_per_row = -bytes_per_row;
1179 }
1180 else {
1181 topOfImage = 0;
1182 }
1183
1184 /* compute final pixel address */
1185 pixel_addr = (GLubyte *) image
1186 + (skipimages + img) * bytes_per_image
1187 + topOfImage
1188 + (skiprows + row) * bytes_per_row
1189 + (skippixels + column) * bytes_per_pixel;
1190 }
1191
1192 return (GLvoid *) pixel_addr;
1193 }
1194
1195
1196 GLvoid *
1197 _mesa_image_address1d( const struct gl_pixelstore_attrib *packing,
1198 const GLvoid *image,
1199 GLsizei width,
1200 GLenum format, GLenum type,
1201 GLint column )
1202 {
1203 return _mesa_image_address(1, packing, image, width, 1,
1204 format, type, 0, 0, column);
1205 }
1206
1207
1208 GLvoid *
1209 _mesa_image_address2d( const struct gl_pixelstore_attrib *packing,
1210 const GLvoid *image,
1211 GLsizei width, GLsizei height,
1212 GLenum format, GLenum type,
1213 GLint row, GLint column )
1214 {
1215 return _mesa_image_address(2, packing, image, width, height,
1216 format, type, 0, row, column);
1217 }
1218
1219
1220 GLvoid *
1221 _mesa_image_address3d( const struct gl_pixelstore_attrib *packing,
1222 const GLvoid *image,
1223 GLsizei width, GLsizei height,
1224 GLenum format, GLenum type,
1225 GLint img, GLint row, GLint column )
1226 {
1227 return _mesa_image_address(3, packing, image, width, height,
1228 format, type, img, row, column);
1229 }
1230
1231
1232
1233 /**
1234 * Compute the stride (in bytes) between image rows.
1235 *
1236 * \param packing the pixelstore attributes
1237 * \param width image width.
1238 * \param format pixel format.
1239 * \param type pixel data type.
1240 *
1241 * \return the stride in bytes for the given parameters, or -1 if error
1242 */
1243 GLint
1244 _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
1245 GLint width, GLenum format, GLenum type )
1246 {
1247 GLint bytesPerRow, remainder;
1248
1249 ASSERT(packing);
1250
1251 if (type == GL_BITMAP) {
1252 if (packing->RowLength == 0) {
1253 bytesPerRow = (width + 7) / 8;
1254 }
1255 else {
1256 bytesPerRow = (packing->RowLength + 7) / 8;
1257 }
1258 }
1259 else {
1260 /* Non-BITMAP data */
1261 const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
1262 if (bytesPerPixel <= 0)
1263 return -1; /* error */
1264 if (packing->RowLength == 0) {
1265 bytesPerRow = bytesPerPixel * width;
1266 }
1267 else {
1268 bytesPerRow = bytesPerPixel * packing->RowLength;
1269 }
1270 }
1271
1272 remainder = bytesPerRow % packing->Alignment;
1273 if (remainder > 0) {
1274 bytesPerRow += (packing->Alignment - remainder);
1275 }
1276
1277 if (packing->Invert) {
1278 /* negate the bytes per row (negative row stride) */
1279 bytesPerRow = -bytesPerRow;
1280 }
1281
1282 return bytesPerRow;
1283 }
1284
1285
1286 /*
1287 * Compute the stride between images in a 3D texture (in bytes) for the given
1288 * pixel packing parameters and image width, format and type.
1289 */
1290 GLint
1291 _mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
1292 GLint width, GLint height,
1293 GLenum format, GLenum type )
1294 {
1295 GLint bytesPerRow, bytesPerImage, remainder;
1296
1297 ASSERT(packing);
1298
1299 if (type == GL_BITMAP) {
1300 if (packing->RowLength == 0) {
1301 bytesPerRow = (width + 7) / 8;
1302 }
1303 else {
1304 bytesPerRow = (packing->RowLength + 7) / 8;
1305 }
1306 }
1307 else {
1308 const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
1309
1310 if (bytesPerPixel <= 0)
1311 return -1; /* error */
1312 if (packing->RowLength == 0) {
1313 bytesPerRow = bytesPerPixel * width;
1314 }
1315 else {
1316 bytesPerRow = bytesPerPixel * packing->RowLength;
1317 }
1318 }
1319
1320 remainder = bytesPerRow % packing->Alignment;
1321 if (remainder > 0)
1322 bytesPerRow += (packing->Alignment - remainder);
1323
1324 if (packing->ImageHeight == 0)
1325 bytesPerImage = bytesPerRow * height;
1326 else
1327 bytesPerImage = bytesPerRow * packing->ImageHeight;
1328
1329 return bytesPerImage;
1330 }
1331
1332
1333
1334 /**
1335 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1336 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1337 * "On" bits will set texels to \p onValue.
1338 * "Off" bits will not modify texels.
1339 * \param width src bitmap width in pixels
1340 * \param height src bitmap height in pixels
1341 * \param unpack bitmap unpacking state
1342 * \param bitmap the src bitmap data
1343 * \param destBuffer start of dest buffer
1344 * \param destStride row stride in dest buffer
1345 * \param onValue if bit is 1, set destBuffer pixel to this value
1346 */
1347 void
1348 _mesa_expand_bitmap(GLsizei width, GLsizei height,
1349 const struct gl_pixelstore_attrib *unpack,
1350 const GLubyte *bitmap,
1351 GLubyte *destBuffer, GLint destStride,
1352 GLubyte onValue)
1353 {
1354 const GLubyte *srcRow = (const GLubyte *)
1355 _mesa_image_address2d(unpack, bitmap, width, height,
1356 GL_COLOR_INDEX, GL_BITMAP, 0, 0);
1357 const GLint srcStride = _mesa_image_row_stride(unpack, width,
1358 GL_COLOR_INDEX, GL_BITMAP);
1359 GLint row, col;
1360
1361 #define SET_PIXEL(COL, ROW) \
1362 destBuffer[(ROW) * destStride + (COL)] = onValue;
1363
1364 for (row = 0; row < height; row++) {
1365 const GLubyte *src = srcRow;
1366
1367 if (unpack->LsbFirst) {
1368 /* Lsb first */
1369 GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
1370 for (col = 0; col < width; col++) {
1371
1372 if (*src & mask) {
1373 SET_PIXEL(col, row);
1374 }
1375
1376 if (mask == 128U) {
1377 src++;
1378 mask = 1U;
1379 }
1380 else {
1381 mask = mask << 1;
1382 }
1383 }
1384
1385 /* get ready for next row */
1386 if (mask != 1)
1387 src++;
1388 }
1389 else {
1390 /* Msb first */
1391 GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
1392 for (col = 0; col < width; col++) {
1393
1394 if (*src & mask) {
1395 SET_PIXEL(col, row);
1396 }
1397
1398 if (mask == 1U) {
1399 src++;
1400 mask = 128U;
1401 }
1402 else {
1403 mask = mask >> 1;
1404 }
1405 }
1406
1407 /* get ready for next row */
1408 if (mask != 128)
1409 src++;
1410 }
1411
1412 srcRow += srcStride;
1413 } /* row */
1414
1415 #undef SET_PIXEL
1416 }
1417
1418
1419
1420
1421 /**
1422 * Convert an array of RGBA colors from one datatype to another.
1423 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1424 */
1425 void
1426 _mesa_convert_colors(GLenum srcType, const GLvoid *src,
1427 GLenum dstType, GLvoid *dst,
1428 GLuint count, const GLubyte mask[])
1429 {
1430 GLuint tempBuffer[MAX_WIDTH][4];
1431 const GLboolean useTemp = (src == dst);
1432
1433 ASSERT(srcType != dstType);
1434
1435 switch (srcType) {
1436 case GL_UNSIGNED_BYTE:
1437 if (dstType == GL_UNSIGNED_SHORT) {
1438 const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
1439 GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
1440 GLuint i;
1441 for (i = 0; i < count; i++) {
1442 if (!mask || mask[i]) {
1443 dst2[i][RCOMP] = UBYTE_TO_USHORT(src1[i][RCOMP]);
1444 dst2[i][GCOMP] = UBYTE_TO_USHORT(src1[i][GCOMP]);
1445 dst2[i][BCOMP] = UBYTE_TO_USHORT(src1[i][BCOMP]);
1446 dst2[i][ACOMP] = UBYTE_TO_USHORT(src1[i][ACOMP]);
1447 }
1448 }
1449 if (useTemp)
1450 memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
1451 }
1452 else {
1453 const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
1454 GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
1455 GLuint i;
1456 ASSERT(dstType == GL_FLOAT);
1457 for (i = 0; i < count; i++) {
1458 if (!mask || mask[i]) {
1459 dst4[i][RCOMP] = UBYTE_TO_FLOAT(src1[i][RCOMP]);
1460 dst4[i][GCOMP] = UBYTE_TO_FLOAT(src1[i][GCOMP]);
1461 dst4[i][BCOMP] = UBYTE_TO_FLOAT(src1[i][BCOMP]);
1462 dst4[i][ACOMP] = UBYTE_TO_FLOAT(src1[i][ACOMP]);
1463 }
1464 }
1465 if (useTemp)
1466 memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
1467 }
1468 break;
1469 case GL_UNSIGNED_SHORT:
1470 if (dstType == GL_UNSIGNED_BYTE) {
1471 const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
1472 GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
1473 GLuint i;
1474 for (i = 0; i < count; i++) {
1475 if (!mask || mask[i]) {
1476 dst1[i][RCOMP] = USHORT_TO_UBYTE(src2[i][RCOMP]);
1477 dst1[i][GCOMP] = USHORT_TO_UBYTE(src2[i][GCOMP]);
1478 dst1[i][BCOMP] = USHORT_TO_UBYTE(src2[i][BCOMP]);
1479 dst1[i][ACOMP] = USHORT_TO_UBYTE(src2[i][ACOMP]);
1480 }
1481 }
1482 if (useTemp)
1483 memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
1484 }
1485 else {
1486 const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
1487 GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
1488 GLuint i;
1489 ASSERT(dstType == GL_FLOAT);
1490 for (i = 0; i < count; i++) {
1491 if (!mask || mask[i]) {
1492 dst4[i][RCOMP] = USHORT_TO_FLOAT(src2[i][RCOMP]);
1493 dst4[i][GCOMP] = USHORT_TO_FLOAT(src2[i][GCOMP]);
1494 dst4[i][BCOMP] = USHORT_TO_FLOAT(src2[i][BCOMP]);
1495 dst4[i][ACOMP] = USHORT_TO_FLOAT(src2[i][ACOMP]);
1496 }
1497 }
1498 if (useTemp)
1499 memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
1500 }
1501 break;
1502 case GL_FLOAT:
1503 if (dstType == GL_UNSIGNED_BYTE) {
1504 const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
1505 GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
1506 GLuint i;
1507 for (i = 0; i < count; i++) {
1508 if (!mask || mask[i])
1509 _mesa_unclamped_float_rgba_to_ubyte(dst1[i], src4[i]);
1510 }
1511 if (useTemp)
1512 memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
1513 }
1514 else {
1515 const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
1516 GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
1517 GLuint i;
1518 ASSERT(dstType == GL_UNSIGNED_SHORT);
1519 for (i = 0; i < count; i++) {
1520 if (!mask || mask[i]) {
1521 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][RCOMP], src4[i][RCOMP]);
1522 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][GCOMP], src4[i][GCOMP]);
1523 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][BCOMP], src4[i][BCOMP]);
1524 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][ACOMP], src4[i][ACOMP]);
1525 }
1526 }
1527 if (useTemp)
1528 memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
1529 }
1530 break;
1531 default:
1532 _mesa_problem(NULL, "Invalid datatype in _mesa_convert_colors");
1533 }
1534 }
1535
1536
1537
1538
1539 /**
1540 * Perform basic clipping for glDrawPixels. The image's position and size
1541 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1542 * region is entirely within the window and scissor bounds.
1543 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1544 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1545 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1546 *
1547 * \return GL_TRUE if image is ready for drawing or
1548 * GL_FALSE if image was completely clipped away (draw nothing)
1549 */
1550 GLboolean
1551 _mesa_clip_drawpixels(const struct gl_context *ctx,
1552 GLint *destX, GLint *destY,
1553 GLsizei *width, GLsizei *height,
1554 struct gl_pixelstore_attrib *unpack)
1555 {
1556 const struct gl_framebuffer *buffer = ctx->DrawBuffer;
1557
1558 if (unpack->RowLength == 0) {
1559 unpack->RowLength = *width;
1560 }
1561
1562 ASSERT(ctx->Pixel.ZoomX == 1.0F);
1563 ASSERT(ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F);
1564
1565 /* left clipping */
1566 if (*destX < buffer->_Xmin) {
1567 unpack->SkipPixels += (buffer->_Xmin - *destX);
1568 *width -= (buffer->_Xmin - *destX);
1569 *destX = buffer->_Xmin;
1570 }
1571 /* right clipping */
1572 if (*destX + *width > buffer->_Xmax)
1573 *width -= (*destX + *width - buffer->_Xmax);
1574
1575 if (*width <= 0)
1576 return GL_FALSE;
1577
1578 if (ctx->Pixel.ZoomY == 1.0F) {
1579 /* bottom clipping */
1580 if (*destY < buffer->_Ymin) {
1581 unpack->SkipRows += (buffer->_Ymin - *destY);
1582 *height -= (buffer->_Ymin - *destY);
1583 *destY = buffer->_Ymin;
1584 }
1585 /* top clipping */
1586 if (*destY + *height > buffer->_Ymax)
1587 *height -= (*destY + *height - buffer->_Ymax);
1588 }
1589 else { /* upside down */
1590 /* top clipping */
1591 if (*destY > buffer->_Ymax) {
1592 unpack->SkipRows += (*destY - buffer->_Ymax);
1593 *height -= (*destY - buffer->_Ymax);
1594 *destY = buffer->_Ymax;
1595 }
1596 /* bottom clipping */
1597 if (*destY - *height < buffer->_Ymin)
1598 *height -= (buffer->_Ymin - (*destY - *height));
1599 /* adjust destY so it's the first row to write to */
1600 (*destY)--;
1601 }
1602
1603 if (*height <= 0)
1604 return GL_FALSE;
1605
1606 return GL_TRUE;
1607 }
1608
1609
1610 /**
1611 * Perform clipping for glReadPixels. The image's window position
1612 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1613 * so that the image region is entirely within the window bounds.
1614 * Note: this is different from _mesa_clip_drawpixels() in that the
1615 * scissor box is ignored, and we use the bounds of the current readbuffer
1616 * surface.
1617 *
1618 * \return GL_TRUE if region to read is in bounds
1619 * GL_FALSE if region is completely out of bounds (nothing to read)
1620 */
1621 GLboolean
1622 _mesa_clip_readpixels(const struct gl_context *ctx,
1623 GLint *srcX, GLint *srcY,
1624 GLsizei *width, GLsizei *height,
1625 struct gl_pixelstore_attrib *pack)
1626 {
1627 const struct gl_framebuffer *buffer = ctx->ReadBuffer;
1628
1629 if (pack->RowLength == 0) {
1630 pack->RowLength = *width;
1631 }
1632
1633 /* left clipping */
1634 if (*srcX < 0) {
1635 pack->SkipPixels += (0 - *srcX);
1636 *width -= (0 - *srcX);
1637 *srcX = 0;
1638 }
1639 /* right clipping */
1640 if (*srcX + *width > (GLsizei) buffer->Width)
1641 *width -= (*srcX + *width - buffer->Width);
1642
1643 if (*width <= 0)
1644 return GL_FALSE;
1645
1646 /* bottom clipping */
1647 if (*srcY < 0) {
1648 pack->SkipRows += (0 - *srcY);
1649 *height -= (0 - *srcY);
1650 *srcY = 0;
1651 }
1652 /* top clipping */
1653 if (*srcY + *height > (GLsizei) buffer->Height)
1654 *height -= (*srcY + *height - buffer->Height);
1655
1656 if (*height <= 0)
1657 return GL_FALSE;
1658
1659 return GL_TRUE;
1660 }
1661
1662
1663 /**
1664 * Do clipping for a glCopyTexSubImage call.
1665 * The framebuffer source region might extend outside the framebuffer
1666 * bounds. Clip the source region against the framebuffer bounds and
1667 * adjust the texture/dest position and size accordingly.
1668 *
1669 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1670 */
1671 GLboolean
1672 _mesa_clip_copytexsubimage(const struct gl_context *ctx,
1673 GLint *destX, GLint *destY,
1674 GLint *srcX, GLint *srcY,
1675 GLsizei *width, GLsizei *height)
1676 {
1677 const struct gl_framebuffer *fb = ctx->ReadBuffer;
1678 const GLint srcX0 = *srcX, srcY0 = *srcY;
1679
1680 if (_mesa_clip_to_region(0, 0, fb->Width, fb->Height,
1681 srcX, srcY, width, height)) {
1682 *destX = *destX + *srcX - srcX0;
1683 *destY = *destY + *srcY - srcY0;
1684
1685 return GL_TRUE;
1686 }
1687 else {
1688 return GL_FALSE;
1689 }
1690 }
1691
1692
1693
1694 /**
1695 * Clip the rectangle defined by (x, y, width, height) against the bounds
1696 * specified by [xmin, xmax) and [ymin, ymax).
1697 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1698 */
1699 GLboolean
1700 _mesa_clip_to_region(GLint xmin, GLint ymin,
1701 GLint xmax, GLint ymax,
1702 GLint *x, GLint *y,
1703 GLsizei *width, GLsizei *height )
1704 {
1705 /* left clipping */
1706 if (*x < xmin) {
1707 *width -= (xmin - *x);
1708 *x = xmin;
1709 }
1710
1711 /* right clipping */
1712 if (*x + *width > xmax)
1713 *width -= (*x + *width - xmax);
1714
1715 if (*width <= 0)
1716 return GL_FALSE;
1717
1718 /* bottom (or top) clipping */
1719 if (*y < ymin) {
1720 *height -= (ymin - *y);
1721 *y = ymin;
1722 }
1723
1724 /* top (or bottom) clipping */
1725 if (*y + *height > ymax)
1726 *height -= (*y + *height - ymax);
1727
1728 if (*height <= 0)
1729 return GL_FALSE;
1730
1731 return GL_TRUE;
1732 }
1733
1734
1735 /**
1736 * Clip dst coords against Xmax (or Ymax).
1737 */
1738 static inline void
1739 clip_right_or_top(GLint *srcX0, GLint *srcX1,
1740 GLint *dstX0, GLint *dstX1,
1741 GLint maxValue)
1742 {
1743 GLfloat t, bias;
1744
1745 if (*dstX1 > maxValue) {
1746 /* X1 outside right edge */
1747 ASSERT(*dstX0 < maxValue); /* X0 should be inside right edge */
1748 t = (GLfloat) (maxValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
1749 /* chop off [t, 1] part */
1750 ASSERT(t >= 0.0 && t <= 1.0);
1751 *dstX1 = maxValue;
1752 bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
1753 *srcX1 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
1754 }
1755 else if (*dstX0 > maxValue) {
1756 /* X0 outside right edge */
1757 ASSERT(*dstX1 < maxValue); /* X1 should be inside right edge */
1758 t = (GLfloat) (maxValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
1759 /* chop off [t, 1] part */
1760 ASSERT(t >= 0.0 && t <= 1.0);
1761 *dstX0 = maxValue;
1762 bias = (*srcX0 < *srcX1) ? -0.5F : 0.5F;
1763 *srcX0 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
1764 }
1765 }
1766
1767
1768 /**
1769 * Clip dst coords against Xmin (or Ymin).
1770 */
1771 static inline void
1772 clip_left_or_bottom(GLint *srcX0, GLint *srcX1,
1773 GLint *dstX0, GLint *dstX1,
1774 GLint minValue)
1775 {
1776 GLfloat t, bias;
1777
1778 if (*dstX0 < minValue) {
1779 /* X0 outside left edge */
1780 ASSERT(*dstX1 > minValue); /* X1 should be inside left edge */
1781 t = (GLfloat) (minValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
1782 /* chop off [0, t] part */
1783 ASSERT(t >= 0.0 && t <= 1.0);
1784 *dstX0 = minValue;
1785 bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F; /* flipped??? */
1786 *srcX0 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
1787 }
1788 else if (*dstX1 < minValue) {
1789 /* X1 outside left edge */
1790 ASSERT(*dstX0 > minValue); /* X0 should be inside left edge */
1791 t = (GLfloat) (minValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
1792 /* chop off [0, t] part */
1793 ASSERT(t >= 0.0 && t <= 1.0);
1794 *dstX1 = minValue;
1795 bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
1796 *srcX1 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
1797 }
1798 }
1799
1800
1801 /**
1802 * Do clipping of blit src/dest rectangles.
1803 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1804 * The src rect is just clipped against the buffer bounds.
1805 *
1806 * When either the src or dest rect is clipped, the other is also clipped
1807 * proportionately!
1808 *
1809 * Note that X0 need not be less than X1 (same for Y) for either the source
1810 * and dest rects. That makes the clipping a little trickier.
1811 *
1812 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1813 */
1814 GLboolean
1815 _mesa_clip_blit(struct gl_context *ctx,
1816 GLint *srcX0, GLint *srcY0, GLint *srcX1, GLint *srcY1,
1817 GLint *dstX0, GLint *dstY0, GLint *dstX1, GLint *dstY1)
1818 {
1819 const GLint srcXmin = 0;
1820 const GLint srcXmax = ctx->ReadBuffer->Width;
1821 const GLint srcYmin = 0;
1822 const GLint srcYmax = ctx->ReadBuffer->Height;
1823
1824 /* these include scissor bounds */
1825 const GLint dstXmin = ctx->DrawBuffer->_Xmin;
1826 const GLint dstXmax = ctx->DrawBuffer->_Xmax;
1827 const GLint dstYmin = ctx->DrawBuffer->_Ymin;
1828 const GLint dstYmax = ctx->DrawBuffer->_Ymax;
1829
1830 /*
1831 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1832 *srcX0, *srcX1, *dstX0, *dstX1);
1833 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1834 *srcY0, *srcY1, *dstY0, *dstY1);
1835 */
1836
1837 /* trivial rejection tests */
1838 if (*dstX0 == *dstX1)
1839 return GL_FALSE; /* no width */
1840 if (*dstX0 <= dstXmin && *dstX1 <= dstXmin)
1841 return GL_FALSE; /* totally out (left) of bounds */
1842 if (*dstX0 >= dstXmax && *dstX1 >= dstXmax)
1843 return GL_FALSE; /* totally out (right) of bounds */
1844
1845 if (*dstY0 == *dstY1)
1846 return GL_FALSE;
1847 if (*dstY0 <= dstYmin && *dstY1 <= dstYmin)
1848 return GL_FALSE;
1849 if (*dstY0 >= dstYmax && *dstY1 >= dstYmax)
1850 return GL_FALSE;
1851
1852 if (*srcX0 == *srcX1)
1853 return GL_FALSE;
1854 if (*srcX0 <= srcXmin && *srcX1 <= srcXmin)
1855 return GL_FALSE;
1856 if (*srcX0 >= srcXmax && *srcX1 >= srcXmax)
1857 return GL_FALSE;
1858
1859 if (*srcY0 == *srcY1)
1860 return GL_FALSE;
1861 if (*srcY0 <= srcYmin && *srcY1 <= srcYmin)
1862 return GL_FALSE;
1863 if (*srcY0 >= srcYmax && *srcY1 >= srcYmax)
1864 return GL_FALSE;
1865
1866 /*
1867 * dest clip
1868 */
1869 clip_right_or_top(srcX0, srcX1, dstX0, dstX1, dstXmax);
1870 clip_right_or_top(srcY0, srcY1, dstY0, dstY1, dstYmax);
1871 clip_left_or_bottom(srcX0, srcX1, dstX0, dstX1, dstXmin);
1872 clip_left_or_bottom(srcY0, srcY1, dstY0, dstY1, dstYmin);
1873
1874 /*
1875 * src clip (just swap src/dst values from above)
1876 */
1877 clip_right_or_top(dstX0, dstX1, srcX0, srcX1, srcXmax);
1878 clip_right_or_top(dstY0, dstY1, srcY0, srcY1, srcYmax);
1879 clip_left_or_bottom(dstX0, dstX1, srcX0, srcX1, srcXmin);
1880 clip_left_or_bottom(dstY0, dstY1, srcY0, srcY1, srcYmin);
1881
1882 /*
1883 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1884 *srcX0, *srcX1, *dstX0, *dstX1);
1885 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1886 *srcY0, *srcY1, *dstY0, *dstY1);
1887 */
1888
1889 ASSERT(*dstX0 >= dstXmin);
1890 ASSERT(*dstX0 <= dstXmax);
1891 ASSERT(*dstX1 >= dstXmin);
1892 ASSERT(*dstX1 <= dstXmax);
1893
1894 ASSERT(*dstY0 >= dstYmin);
1895 ASSERT(*dstY0 <= dstYmax);
1896 ASSERT(*dstY1 >= dstYmin);
1897 ASSERT(*dstY1 <= dstYmax);
1898
1899 ASSERT(*srcX0 >= srcXmin);
1900 ASSERT(*srcX0 <= srcXmax);
1901 ASSERT(*srcX1 >= srcXmin);
1902 ASSERT(*srcX1 <= srcXmax);
1903
1904 ASSERT(*srcY0 >= srcYmin);
1905 ASSERT(*srcY0 <= srcYmax);
1906 ASSERT(*srcY1 >= srcYmin);
1907 ASSERT(*srcY1 <= srcYmax);
1908
1909 return GL_TRUE;
1910 }