mesa: Include R/RG integer textures in _mesa_is_integer_format.
[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 case GL_UNSIGNED_BYTE_3_3_2:
549 case GL_UNSIGNED_BYTE_2_3_3_REV:
550 case GL_UNSIGNED_SHORT_5_6_5:
551 case GL_UNSIGNED_SHORT_5_6_5_REV:
552 return ctx->Extensions.EXT_texture_integer;
553 default:
554 return GL_FALSE;
555 }
556
557 case GL_BGR_INTEGER_EXT:
558 switch (type) {
559 case GL_BYTE:
560 case GL_UNSIGNED_BYTE:
561 case GL_SHORT:
562 case GL_UNSIGNED_SHORT:
563 case GL_INT:
564 case GL_UNSIGNED_INT:
565 /* NOTE: no packed formats w/ BGR format */
566 return ctx->Extensions.EXT_texture_integer;
567 default:
568 return GL_FALSE;
569 }
570
571 case GL_RGBA_INTEGER_EXT:
572 case GL_BGRA_INTEGER_EXT:
573 switch (type) {
574 case GL_BYTE:
575 case GL_UNSIGNED_BYTE:
576 case GL_SHORT:
577 case GL_UNSIGNED_SHORT:
578 case GL_INT:
579 case GL_UNSIGNED_INT:
580 case GL_UNSIGNED_SHORT_4_4_4_4:
581 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
582 case GL_UNSIGNED_SHORT_5_5_5_1:
583 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
584 case GL_UNSIGNED_INT_8_8_8_8:
585 case GL_UNSIGNED_INT_8_8_8_8_REV:
586 case GL_UNSIGNED_INT_10_10_10_2:
587 case GL_UNSIGNED_INT_2_10_10_10_REV:
588 return ctx->Extensions.EXT_texture_integer;
589 default:
590 return GL_FALSE;
591 }
592
593 case GL_LUMINANCE_INTEGER_EXT:
594 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
595 switch (type) {
596 case GL_BYTE:
597 case GL_UNSIGNED_BYTE:
598 case GL_SHORT:
599 case GL_UNSIGNED_SHORT:
600 case GL_INT:
601 case GL_UNSIGNED_INT:
602 return ctx->Extensions.EXT_texture_integer;
603 default:
604 return GL_FALSE;
605 }
606
607 default:
608 ; /* fall-through */
609 }
610 return GL_FALSE;
611 }
612
613
614 /**
615 * Test if the given image format is a color/RGBA format (i.e., not color
616 * index, depth, stencil, etc).
617 * \param format the image format value (may by an internal texture format)
618 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
619 */
620 GLboolean
621 _mesa_is_color_format(GLenum format)
622 {
623 switch (format) {
624 case GL_RED:
625 case GL_GREEN:
626 case GL_BLUE:
627 case GL_ALPHA:
628 case GL_ALPHA4:
629 case GL_ALPHA8:
630 case GL_ALPHA12:
631 case GL_ALPHA16:
632 case 1:
633 case GL_LUMINANCE:
634 case GL_LUMINANCE4:
635 case GL_LUMINANCE8:
636 case GL_LUMINANCE12:
637 case GL_LUMINANCE16:
638 case 2:
639 case GL_LUMINANCE_ALPHA:
640 case GL_LUMINANCE4_ALPHA4:
641 case GL_LUMINANCE6_ALPHA2:
642 case GL_LUMINANCE8_ALPHA8:
643 case GL_LUMINANCE12_ALPHA4:
644 case GL_LUMINANCE12_ALPHA12:
645 case GL_LUMINANCE16_ALPHA16:
646 case GL_INTENSITY:
647 case GL_INTENSITY4:
648 case GL_INTENSITY8:
649 case GL_INTENSITY12:
650 case GL_INTENSITY16:
651 case GL_R8:
652 case GL_R16:
653 case GL_RG:
654 case GL_RG8:
655 case GL_RG16:
656 case 3:
657 case GL_RGB:
658 case GL_BGR:
659 case GL_R3_G3_B2:
660 case GL_RGB4:
661 case GL_RGB5:
662 case GL_RGB8:
663 case GL_RGB10:
664 case GL_RGB12:
665 case GL_RGB16:
666 case 4:
667 case GL_ABGR_EXT:
668 case GL_RGBA:
669 case GL_BGRA:
670 case GL_RGBA2:
671 case GL_RGBA4:
672 case GL_RGB5_A1:
673 case GL_RGBA8:
674 case GL_RGB10_A2:
675 case GL_RGBA12:
676 case GL_RGBA16:
677 /* float texture formats */
678 case GL_ALPHA16F_ARB:
679 case GL_ALPHA32F_ARB:
680 case GL_LUMINANCE16F_ARB:
681 case GL_LUMINANCE32F_ARB:
682 case GL_LUMINANCE_ALPHA16F_ARB:
683 case GL_LUMINANCE_ALPHA32F_ARB:
684 case GL_INTENSITY16F_ARB:
685 case GL_INTENSITY32F_ARB:
686 case GL_R16F:
687 case GL_R32F:
688 case GL_RG16F:
689 case GL_RG32F:
690 case GL_RGB16F_ARB:
691 case GL_RGB32F_ARB:
692 case GL_RGBA16F_ARB:
693 case GL_RGBA32F_ARB:
694 /* compressed formats */
695 case GL_COMPRESSED_ALPHA:
696 case GL_COMPRESSED_LUMINANCE:
697 case GL_COMPRESSED_LUMINANCE_ALPHA:
698 case GL_COMPRESSED_INTENSITY:
699 case GL_COMPRESSED_RED:
700 case GL_COMPRESSED_RG:
701 case GL_COMPRESSED_RGB:
702 case GL_COMPRESSED_RGBA:
703 case GL_RGB_S3TC:
704 case GL_RGB4_S3TC:
705 case GL_RGBA_S3TC:
706 case GL_RGBA4_S3TC:
707 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
708 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
709 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
710 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
711 case GL_COMPRESSED_RGB_FXT1_3DFX:
712 case GL_COMPRESSED_RGBA_FXT1_3DFX:
713 #if FEATURE_EXT_texture_sRGB
714 case GL_SRGB_EXT:
715 case GL_SRGB8_EXT:
716 case GL_SRGB_ALPHA_EXT:
717 case GL_SRGB8_ALPHA8_EXT:
718 case GL_SLUMINANCE_ALPHA_EXT:
719 case GL_SLUMINANCE8_ALPHA8_EXT:
720 case GL_SLUMINANCE_EXT:
721 case GL_SLUMINANCE8_EXT:
722 case GL_COMPRESSED_SRGB_EXT:
723 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
724 case GL_COMPRESSED_SRGB_ALPHA_EXT:
725 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
726 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
727 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
728 case GL_COMPRESSED_SLUMINANCE_EXT:
729 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
730 #endif /* FEATURE_EXT_texture_sRGB */
731 case GL_COMPRESSED_RED_RGTC1:
732 case GL_COMPRESSED_SIGNED_RED_RGTC1:
733 case GL_COMPRESSED_RG_RGTC2:
734 case GL_COMPRESSED_SIGNED_RG_RGTC2:
735 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
736 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
737 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
738 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
739 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
740 /* generic integer formats */
741 case GL_RED_INTEGER_EXT:
742 case GL_GREEN_INTEGER_EXT:
743 case GL_BLUE_INTEGER_EXT:
744 case GL_ALPHA_INTEGER_EXT:
745 case GL_RGB_INTEGER_EXT:
746 case GL_RGBA_INTEGER_EXT:
747 case GL_BGR_INTEGER_EXT:
748 case GL_BGRA_INTEGER_EXT:
749 case GL_LUMINANCE_INTEGER_EXT:
750 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
751 /* sized integer formats */
752 case GL_RGBA32UI_EXT:
753 case GL_RGB32UI_EXT:
754 case GL_ALPHA32UI_EXT:
755 case GL_INTENSITY32UI_EXT:
756 case GL_LUMINANCE32UI_EXT:
757 case GL_LUMINANCE_ALPHA32UI_EXT:
758 case GL_RGBA16UI_EXT:
759 case GL_RGB16UI_EXT:
760 case GL_ALPHA16UI_EXT:
761 case GL_INTENSITY16UI_EXT:
762 case GL_LUMINANCE16UI_EXT:
763 case GL_LUMINANCE_ALPHA16UI_EXT:
764 case GL_RGBA8UI_EXT:
765 case GL_RGB8UI_EXT:
766 case GL_ALPHA8UI_EXT:
767 case GL_INTENSITY8UI_EXT:
768 case GL_LUMINANCE8UI_EXT:
769 case GL_LUMINANCE_ALPHA8UI_EXT:
770 case GL_RGBA32I_EXT:
771 case GL_RGB32I_EXT:
772 case GL_ALPHA32I_EXT:
773 case GL_INTENSITY32I_EXT:
774 case GL_LUMINANCE32I_EXT:
775 case GL_LUMINANCE_ALPHA32I_EXT:
776 case GL_RGBA16I_EXT:
777 case GL_RGB16I_EXT:
778 case GL_ALPHA16I_EXT:
779 case GL_INTENSITY16I_EXT:
780 case GL_LUMINANCE16I_EXT:
781 case GL_LUMINANCE_ALPHA16I_EXT:
782 case GL_RGBA8I_EXT:
783 case GL_RGB8I_EXT:
784 case GL_ALPHA8I_EXT:
785 case GL_INTENSITY8I_EXT:
786 case GL_LUMINANCE8I_EXT:
787 case GL_LUMINANCE_ALPHA8I_EXT:
788 /* signed, normalized texture formats */
789 case GL_RED_SNORM:
790 case GL_R8_SNORM:
791 case GL_R16_SNORM:
792 case GL_RG_SNORM:
793 case GL_RG8_SNORM:
794 case GL_RG16_SNORM:
795 case GL_RGB_SNORM:
796 case GL_RGB8_SNORM:
797 case GL_RGB16_SNORM:
798 case GL_RGBA_SNORM:
799 case GL_RGBA8_SNORM:
800 case GL_RGBA16_SNORM:
801 case GL_ALPHA_SNORM:
802 case GL_ALPHA8_SNORM:
803 case GL_ALPHA16_SNORM:
804 case GL_LUMINANCE_SNORM:
805 case GL_LUMINANCE8_SNORM:
806 case GL_LUMINANCE16_SNORM:
807 case GL_LUMINANCE_ALPHA_SNORM:
808 case GL_LUMINANCE8_ALPHA8_SNORM:
809 case GL_LUMINANCE16_ALPHA16_SNORM:
810 case GL_INTENSITY_SNORM:
811 case GL_INTENSITY8_SNORM:
812 case GL_INTENSITY16_SNORM:
813 case GL_RGB9_E5:
814 case GL_R11F_G11F_B10F:
815 return GL_TRUE;
816 case GL_YCBCR_MESA: /* not considered to be RGB */
817 /* fall-through */
818 default:
819 return GL_FALSE;
820 }
821 }
822
823
824 /**
825 * Test if the given image format is a depth component format.
826 */
827 GLboolean
828 _mesa_is_depth_format(GLenum format)
829 {
830 switch (format) {
831 case GL_DEPTH_COMPONENT:
832 case GL_DEPTH_COMPONENT16:
833 case GL_DEPTH_COMPONENT24:
834 case GL_DEPTH_COMPONENT32:
835 case GL_DEPTH_COMPONENT32F:
836 return GL_TRUE;
837 default:
838 return GL_FALSE;
839 }
840 }
841
842
843 /**
844 * Test if the given image format is a stencil format.
845 */
846 GLboolean
847 _mesa_is_stencil_format(GLenum format)
848 {
849 switch (format) {
850 case GL_STENCIL_INDEX:
851 case GL_DEPTH_STENCIL:
852 return GL_TRUE;
853 default:
854 return GL_FALSE;
855 }
856 }
857
858
859 /**
860 * Test if the given image format is a YCbCr format.
861 */
862 GLboolean
863 _mesa_is_ycbcr_format(GLenum format)
864 {
865 switch (format) {
866 case GL_YCBCR_MESA:
867 return GL_TRUE;
868 default:
869 return GL_FALSE;
870 }
871 }
872
873
874 /**
875 * Test if the given image format is a depth+stencil format.
876 */
877 GLboolean
878 _mesa_is_depthstencil_format(GLenum format)
879 {
880 switch (format) {
881 case GL_DEPTH24_STENCIL8_EXT:
882 case GL_DEPTH_STENCIL_EXT:
883 case GL_DEPTH32F_STENCIL8:
884 return GL_TRUE;
885 default:
886 return GL_FALSE;
887 }
888 }
889
890
891 /**
892 * Test if the given image format is a depth or stencil format.
893 */
894 GLboolean
895 _mesa_is_depth_or_stencil_format(GLenum format)
896 {
897 switch (format) {
898 case GL_DEPTH_COMPONENT:
899 case GL_DEPTH_COMPONENT16:
900 case GL_DEPTH_COMPONENT24:
901 case GL_DEPTH_COMPONENT32:
902 case GL_STENCIL_INDEX:
903 case GL_STENCIL_INDEX1_EXT:
904 case GL_STENCIL_INDEX4_EXT:
905 case GL_STENCIL_INDEX8_EXT:
906 case GL_STENCIL_INDEX16_EXT:
907 case GL_DEPTH_STENCIL_EXT:
908 case GL_DEPTH24_STENCIL8_EXT:
909 case GL_DEPTH_COMPONENT32F:
910 case GL_DEPTH32F_STENCIL8:
911 return GL_TRUE;
912 default:
913 return GL_FALSE;
914 }
915 }
916
917
918 /**
919 * Test if the given image format is a dudv format.
920 */
921 GLboolean
922 _mesa_is_dudv_format(GLenum format)
923 {
924 switch (format) {
925 case GL_DUDV_ATI:
926 case GL_DU8DV8_ATI:
927 return GL_TRUE;
928 default:
929 return GL_FALSE;
930 }
931 }
932
933
934 /**
935 * Test if the given format is an integer (non-normalized) format.
936 */
937 GLboolean
938 _mesa_is_integer_format(GLenum format)
939 {
940 switch (format) {
941 /* generic integer formats */
942 case GL_RED_INTEGER_EXT:
943 case GL_GREEN_INTEGER_EXT:
944 case GL_BLUE_INTEGER_EXT:
945 case GL_ALPHA_INTEGER_EXT:
946 case GL_RGB_INTEGER_EXT:
947 case GL_RGBA_INTEGER_EXT:
948 case GL_BGR_INTEGER_EXT:
949 case GL_BGRA_INTEGER_EXT:
950 case GL_LUMINANCE_INTEGER_EXT:
951 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
952 /* specific integer formats */
953 case GL_RGBA32UI_EXT:
954 case GL_RGB32UI_EXT:
955 case GL_RG32UI:
956 case GL_R32UI:
957 case GL_ALPHA32UI_EXT:
958 case GL_INTENSITY32UI_EXT:
959 case GL_LUMINANCE32UI_EXT:
960 case GL_LUMINANCE_ALPHA32UI_EXT:
961 case GL_RGBA16UI_EXT:
962 case GL_RGB16UI_EXT:
963 case GL_RG16UI:
964 case GL_R16UI:
965 case GL_ALPHA16UI_EXT:
966 case GL_INTENSITY16UI_EXT:
967 case GL_LUMINANCE16UI_EXT:
968 case GL_LUMINANCE_ALPHA16UI_EXT:
969 case GL_RGBA8UI_EXT:
970 case GL_RGB8UI_EXT:
971 case GL_RG8UI:
972 case GL_R8UI:
973 case GL_ALPHA8UI_EXT:
974 case GL_INTENSITY8UI_EXT:
975 case GL_LUMINANCE8UI_EXT:
976 case GL_LUMINANCE_ALPHA8UI_EXT:
977 case GL_RGBA32I_EXT:
978 case GL_RGB32I_EXT:
979 case GL_RG32I:
980 case GL_R32I:
981 case GL_ALPHA32I_EXT:
982 case GL_INTENSITY32I_EXT:
983 case GL_LUMINANCE32I_EXT:
984 case GL_LUMINANCE_ALPHA32I_EXT:
985 case GL_RGBA16I_EXT:
986 case GL_RGB16I_EXT:
987 case GL_RG16I:
988 case GL_R16I:
989 case GL_ALPHA16I_EXT:
990 case GL_INTENSITY16I_EXT:
991 case GL_LUMINANCE16I_EXT:
992 case GL_LUMINANCE_ALPHA16I_EXT:
993 case GL_RGBA8I_EXT:
994 case GL_RGB8I_EXT:
995 case GL_RG8I:
996 case GL_R8I:
997 case GL_ALPHA8I_EXT:
998 case GL_INTENSITY8I_EXT:
999 case GL_LUMINANCE8I_EXT:
1000 case GL_LUMINANCE_ALPHA8I_EXT:
1001 return GL_TRUE;
1002 default:
1003 return GL_FALSE;
1004 }
1005 }
1006
1007
1008 /**
1009 * Test if an image format is a supported compressed format.
1010 * \param format the internal format token provided by the user.
1011 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1012 */
1013 GLboolean
1014 _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
1015 {
1016 switch (format) {
1017 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1018 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1019 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1020 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1021 return ctx->Extensions.EXT_texture_compression_s3tc;
1022 case GL_RGB_S3TC:
1023 case GL_RGB4_S3TC:
1024 case GL_RGBA_S3TC:
1025 case GL_RGBA4_S3TC:
1026 return ctx->Extensions.S3_s3tc;
1027 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1028 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1029 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1030 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1031 return ctx->Extensions.EXT_texture_sRGB
1032 && ctx->Extensions.EXT_texture_compression_s3tc;
1033 case GL_COMPRESSED_RGB_FXT1_3DFX:
1034 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1035 return ctx->Extensions.TDFX_texture_compression_FXT1;
1036 case GL_COMPRESSED_RED_RGTC1:
1037 case GL_COMPRESSED_SIGNED_RED_RGTC1:
1038 case GL_COMPRESSED_RG_RGTC2:
1039 case GL_COMPRESSED_SIGNED_RG_RGTC2:
1040 return ctx->Extensions.ARB_texture_compression_rgtc;
1041 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
1042 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
1043 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
1044 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
1045 return ctx->Extensions.EXT_texture_compression_latc;
1046 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1047 return ctx->Extensions.ATI_texture_compression_3dc;
1048 #if FEATURE_ES
1049 case GL_PALETTE4_RGB8_OES:
1050 case GL_PALETTE4_RGBA8_OES:
1051 case GL_PALETTE4_R5_G6_B5_OES:
1052 case GL_PALETTE4_RGBA4_OES:
1053 case GL_PALETTE4_RGB5_A1_OES:
1054 case GL_PALETTE8_RGB8_OES:
1055 case GL_PALETTE8_RGBA8_OES:
1056 case GL_PALETTE8_R5_G6_B5_OES:
1057 case GL_PALETTE8_RGBA4_OES:
1058 case GL_PALETTE8_RGB5_A1_OES:
1059 return ctx->API == API_OPENGLES;
1060 #endif
1061 default:
1062 return GL_FALSE;
1063 }
1064 }
1065
1066
1067 /**
1068 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1069 *
1070 * Pixel unpacking/packing parameters are observed according to \p packing.
1071 *
1072 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1073 * \param image starting address of image data
1074 * \param width the image width
1075 * \param height theimage height
1076 * \param format the pixel format
1077 * \param type the pixel data type
1078 * \param packing the pixelstore attributes
1079 * \param img which image in the volume (0 for 1D or 2D images)
1080 * \param row row of pixel in the image (0 for 1D images)
1081 * \param column column of pixel in the image
1082 *
1083 * \return address of pixel on success, or NULL on error.
1084 *
1085 * \sa gl_pixelstore_attrib.
1086 */
1087 GLvoid *
1088 _mesa_image_address( GLuint dimensions,
1089 const struct gl_pixelstore_attrib *packing,
1090 const GLvoid *image,
1091 GLsizei width, GLsizei height,
1092 GLenum format, GLenum type,
1093 GLint img, GLint row, GLint column )
1094 {
1095 GLint alignment; /* 1, 2 or 4 */
1096 GLint pixels_per_row;
1097 GLint rows_per_image;
1098 GLint skiprows;
1099 GLint skippixels;
1100 GLint skipimages; /* for 3-D volume images */
1101 GLubyte *pixel_addr;
1102
1103 ASSERT(dimensions >= 1 && dimensions <= 3);
1104
1105 alignment = packing->Alignment;
1106 if (packing->RowLength > 0) {
1107 pixels_per_row = packing->RowLength;
1108 }
1109 else {
1110 pixels_per_row = width;
1111 }
1112 if (packing->ImageHeight > 0) {
1113 rows_per_image = packing->ImageHeight;
1114 }
1115 else {
1116 rows_per_image = height;
1117 }
1118
1119 skippixels = packing->SkipPixels;
1120 /* Note: SKIP_ROWS _is_ used for 1D images */
1121 skiprows = packing->SkipRows;
1122 /* Note: SKIP_IMAGES is only used for 3D images */
1123 skipimages = (dimensions == 3) ? packing->SkipImages : 0;
1124
1125 if (type == GL_BITMAP) {
1126 /* BITMAP data */
1127 GLint comp_per_pixel; /* components per pixel */
1128 GLint bytes_per_comp; /* bytes per component */
1129 GLint bytes_per_row;
1130 GLint bytes_per_image;
1131
1132 /* Compute bytes per component */
1133 bytes_per_comp = _mesa_sizeof_packed_type( type );
1134 if (bytes_per_comp < 0) {
1135 return NULL;
1136 }
1137
1138 /* Compute number of components per pixel */
1139 comp_per_pixel = _mesa_components_in_format( format );
1140 if (comp_per_pixel < 0) {
1141 return NULL;
1142 }
1143
1144 bytes_per_row = alignment
1145 * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
1146
1147 bytes_per_image = bytes_per_row * rows_per_image;
1148
1149 pixel_addr = (GLubyte *) image
1150 + (skipimages + img) * bytes_per_image
1151 + (skiprows + row) * bytes_per_row
1152 + (skippixels + column) / 8;
1153 }
1154 else {
1155 /* Non-BITMAP data */
1156 GLint bytes_per_pixel, bytes_per_row, remainder, bytes_per_image;
1157 GLint topOfImage;
1158
1159 bytes_per_pixel = _mesa_bytes_per_pixel( format, type );
1160
1161 /* The pixel type and format should have been error checked earlier */
1162 assert(bytes_per_pixel > 0);
1163
1164 bytes_per_row = pixels_per_row * bytes_per_pixel;
1165 remainder = bytes_per_row % alignment;
1166 if (remainder > 0)
1167 bytes_per_row += (alignment - remainder);
1168
1169 ASSERT(bytes_per_row % alignment == 0);
1170
1171 bytes_per_image = bytes_per_row * rows_per_image;
1172
1173 if (packing->Invert) {
1174 /* set pixel_addr to the last row */
1175 topOfImage = bytes_per_row * (height - 1);
1176 bytes_per_row = -bytes_per_row;
1177 }
1178 else {
1179 topOfImage = 0;
1180 }
1181
1182 /* compute final pixel address */
1183 pixel_addr = (GLubyte *) image
1184 + (skipimages + img) * bytes_per_image
1185 + topOfImage
1186 + (skiprows + row) * bytes_per_row
1187 + (skippixels + column) * bytes_per_pixel;
1188 }
1189
1190 return (GLvoid *) pixel_addr;
1191 }
1192
1193
1194 GLvoid *
1195 _mesa_image_address1d( const struct gl_pixelstore_attrib *packing,
1196 const GLvoid *image,
1197 GLsizei width,
1198 GLenum format, GLenum type,
1199 GLint column )
1200 {
1201 return _mesa_image_address(1, packing, image, width, 1,
1202 format, type, 0, 0, column);
1203 }
1204
1205
1206 GLvoid *
1207 _mesa_image_address2d( const struct gl_pixelstore_attrib *packing,
1208 const GLvoid *image,
1209 GLsizei width, GLsizei height,
1210 GLenum format, GLenum type,
1211 GLint row, GLint column )
1212 {
1213 return _mesa_image_address(2, packing, image, width, height,
1214 format, type, 0, row, column);
1215 }
1216
1217
1218 GLvoid *
1219 _mesa_image_address3d( const struct gl_pixelstore_attrib *packing,
1220 const GLvoid *image,
1221 GLsizei width, GLsizei height,
1222 GLenum format, GLenum type,
1223 GLint img, GLint row, GLint column )
1224 {
1225 return _mesa_image_address(3, packing, image, width, height,
1226 format, type, img, row, column);
1227 }
1228
1229
1230
1231 /**
1232 * Compute the stride (in bytes) between image rows.
1233 *
1234 * \param packing the pixelstore attributes
1235 * \param width image width.
1236 * \param format pixel format.
1237 * \param type pixel data type.
1238 *
1239 * \return the stride in bytes for the given parameters, or -1 if error
1240 */
1241 GLint
1242 _mesa_image_row_stride( const struct gl_pixelstore_attrib *packing,
1243 GLint width, GLenum format, GLenum type )
1244 {
1245 GLint bytesPerRow, remainder;
1246
1247 ASSERT(packing);
1248
1249 if (type == GL_BITMAP) {
1250 if (packing->RowLength == 0) {
1251 bytesPerRow = (width + 7) / 8;
1252 }
1253 else {
1254 bytesPerRow = (packing->RowLength + 7) / 8;
1255 }
1256 }
1257 else {
1258 /* Non-BITMAP data */
1259 const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
1260 if (bytesPerPixel <= 0)
1261 return -1; /* error */
1262 if (packing->RowLength == 0) {
1263 bytesPerRow = bytesPerPixel * width;
1264 }
1265 else {
1266 bytesPerRow = bytesPerPixel * packing->RowLength;
1267 }
1268 }
1269
1270 remainder = bytesPerRow % packing->Alignment;
1271 if (remainder > 0) {
1272 bytesPerRow += (packing->Alignment - remainder);
1273 }
1274
1275 if (packing->Invert) {
1276 /* negate the bytes per row (negative row stride) */
1277 bytesPerRow = -bytesPerRow;
1278 }
1279
1280 return bytesPerRow;
1281 }
1282
1283
1284 /*
1285 * Compute the stride between images in a 3D texture (in bytes) for the given
1286 * pixel packing parameters and image width, format and type.
1287 */
1288 GLint
1289 _mesa_image_image_stride( const struct gl_pixelstore_attrib *packing,
1290 GLint width, GLint height,
1291 GLenum format, GLenum type )
1292 {
1293 GLint bytesPerRow, bytesPerImage, remainder;
1294
1295 ASSERT(packing);
1296
1297 if (type == GL_BITMAP) {
1298 if (packing->RowLength == 0) {
1299 bytesPerRow = (width + 7) / 8;
1300 }
1301 else {
1302 bytesPerRow = (packing->RowLength + 7) / 8;
1303 }
1304 }
1305 else {
1306 const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
1307
1308 if (bytesPerPixel <= 0)
1309 return -1; /* error */
1310 if (packing->RowLength == 0) {
1311 bytesPerRow = bytesPerPixel * width;
1312 }
1313 else {
1314 bytesPerRow = bytesPerPixel * packing->RowLength;
1315 }
1316 }
1317
1318 remainder = bytesPerRow % packing->Alignment;
1319 if (remainder > 0)
1320 bytesPerRow += (packing->Alignment - remainder);
1321
1322 if (packing->ImageHeight == 0)
1323 bytesPerImage = bytesPerRow * height;
1324 else
1325 bytesPerImage = bytesPerRow * packing->ImageHeight;
1326
1327 return bytesPerImage;
1328 }
1329
1330
1331
1332 /**
1333 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1334 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1335 * "On" bits will set texels to \p onValue.
1336 * "Off" bits will not modify texels.
1337 * \param width src bitmap width in pixels
1338 * \param height src bitmap height in pixels
1339 * \param unpack bitmap unpacking state
1340 * \param bitmap the src bitmap data
1341 * \param destBuffer start of dest buffer
1342 * \param destStride row stride in dest buffer
1343 * \param onValue if bit is 1, set destBuffer pixel to this value
1344 */
1345 void
1346 _mesa_expand_bitmap(GLsizei width, GLsizei height,
1347 const struct gl_pixelstore_attrib *unpack,
1348 const GLubyte *bitmap,
1349 GLubyte *destBuffer, GLint destStride,
1350 GLubyte onValue)
1351 {
1352 const GLubyte *srcRow = (const GLubyte *)
1353 _mesa_image_address2d(unpack, bitmap, width, height,
1354 GL_COLOR_INDEX, GL_BITMAP, 0, 0);
1355 const GLint srcStride = _mesa_image_row_stride(unpack, width,
1356 GL_COLOR_INDEX, GL_BITMAP);
1357 GLint row, col;
1358
1359 #define SET_PIXEL(COL, ROW) \
1360 destBuffer[(ROW) * destStride + (COL)] = onValue;
1361
1362 for (row = 0; row < height; row++) {
1363 const GLubyte *src = srcRow;
1364
1365 if (unpack->LsbFirst) {
1366 /* Lsb first */
1367 GLubyte mask = 1U << (unpack->SkipPixels & 0x7);
1368 for (col = 0; col < width; col++) {
1369
1370 if (*src & mask) {
1371 SET_PIXEL(col, row);
1372 }
1373
1374 if (mask == 128U) {
1375 src++;
1376 mask = 1U;
1377 }
1378 else {
1379 mask = mask << 1;
1380 }
1381 }
1382
1383 /* get ready for next row */
1384 if (mask != 1)
1385 src++;
1386 }
1387 else {
1388 /* Msb first */
1389 GLubyte mask = 128U >> (unpack->SkipPixels & 0x7);
1390 for (col = 0; col < width; col++) {
1391
1392 if (*src & mask) {
1393 SET_PIXEL(col, row);
1394 }
1395
1396 if (mask == 1U) {
1397 src++;
1398 mask = 128U;
1399 }
1400 else {
1401 mask = mask >> 1;
1402 }
1403 }
1404
1405 /* get ready for next row */
1406 if (mask != 128)
1407 src++;
1408 }
1409
1410 srcRow += srcStride;
1411 } /* row */
1412
1413 #undef SET_PIXEL
1414 }
1415
1416
1417
1418
1419 /**
1420 * Convert an array of RGBA colors from one datatype to another.
1421 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1422 */
1423 void
1424 _mesa_convert_colors(GLenum srcType, const GLvoid *src,
1425 GLenum dstType, GLvoid *dst,
1426 GLuint count, const GLubyte mask[])
1427 {
1428 GLuint tempBuffer[MAX_WIDTH][4];
1429 const GLboolean useTemp = (src == dst);
1430
1431 ASSERT(srcType != dstType);
1432
1433 switch (srcType) {
1434 case GL_UNSIGNED_BYTE:
1435 if (dstType == GL_UNSIGNED_SHORT) {
1436 const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
1437 GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
1438 GLuint i;
1439 for (i = 0; i < count; i++) {
1440 if (!mask || mask[i]) {
1441 dst2[i][RCOMP] = UBYTE_TO_USHORT(src1[i][RCOMP]);
1442 dst2[i][GCOMP] = UBYTE_TO_USHORT(src1[i][GCOMP]);
1443 dst2[i][BCOMP] = UBYTE_TO_USHORT(src1[i][BCOMP]);
1444 dst2[i][ACOMP] = UBYTE_TO_USHORT(src1[i][ACOMP]);
1445 }
1446 }
1447 if (useTemp)
1448 memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
1449 }
1450 else {
1451 const GLubyte (*src1)[4] = (const GLubyte (*)[4]) src;
1452 GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
1453 GLuint i;
1454 ASSERT(dstType == GL_FLOAT);
1455 for (i = 0; i < count; i++) {
1456 if (!mask || mask[i]) {
1457 dst4[i][RCOMP] = UBYTE_TO_FLOAT(src1[i][RCOMP]);
1458 dst4[i][GCOMP] = UBYTE_TO_FLOAT(src1[i][GCOMP]);
1459 dst4[i][BCOMP] = UBYTE_TO_FLOAT(src1[i][BCOMP]);
1460 dst4[i][ACOMP] = UBYTE_TO_FLOAT(src1[i][ACOMP]);
1461 }
1462 }
1463 if (useTemp)
1464 memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
1465 }
1466 break;
1467 case GL_UNSIGNED_SHORT:
1468 if (dstType == GL_UNSIGNED_BYTE) {
1469 const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
1470 GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
1471 GLuint i;
1472 for (i = 0; i < count; i++) {
1473 if (!mask || mask[i]) {
1474 dst1[i][RCOMP] = USHORT_TO_UBYTE(src2[i][RCOMP]);
1475 dst1[i][GCOMP] = USHORT_TO_UBYTE(src2[i][GCOMP]);
1476 dst1[i][BCOMP] = USHORT_TO_UBYTE(src2[i][BCOMP]);
1477 dst1[i][ACOMP] = USHORT_TO_UBYTE(src2[i][ACOMP]);
1478 }
1479 }
1480 if (useTemp)
1481 memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
1482 }
1483 else {
1484 const GLushort (*src2)[4] = (const GLushort (*)[4]) src;
1485 GLfloat (*dst4)[4] = (GLfloat (*)[4]) (useTemp ? tempBuffer : dst);
1486 GLuint i;
1487 ASSERT(dstType == GL_FLOAT);
1488 for (i = 0; i < count; i++) {
1489 if (!mask || mask[i]) {
1490 dst4[i][RCOMP] = USHORT_TO_FLOAT(src2[i][RCOMP]);
1491 dst4[i][GCOMP] = USHORT_TO_FLOAT(src2[i][GCOMP]);
1492 dst4[i][BCOMP] = USHORT_TO_FLOAT(src2[i][BCOMP]);
1493 dst4[i][ACOMP] = USHORT_TO_FLOAT(src2[i][ACOMP]);
1494 }
1495 }
1496 if (useTemp)
1497 memcpy(dst, tempBuffer, count * 4 * sizeof(GLfloat));
1498 }
1499 break;
1500 case GL_FLOAT:
1501 if (dstType == GL_UNSIGNED_BYTE) {
1502 const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
1503 GLubyte (*dst1)[4] = (GLubyte (*)[4]) (useTemp ? tempBuffer : dst);
1504 GLuint i;
1505 for (i = 0; i < count; i++) {
1506 if (!mask || mask[i])
1507 _mesa_unclamped_float_rgba_to_ubyte(dst1[i], src4[i]);
1508 }
1509 if (useTemp)
1510 memcpy(dst, tempBuffer, count * 4 * sizeof(GLubyte));
1511 }
1512 else {
1513 const GLfloat (*src4)[4] = (const GLfloat (*)[4]) src;
1514 GLushort (*dst2)[4] = (GLushort (*)[4]) (useTemp ? tempBuffer : dst);
1515 GLuint i;
1516 ASSERT(dstType == GL_UNSIGNED_SHORT);
1517 for (i = 0; i < count; i++) {
1518 if (!mask || mask[i]) {
1519 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][RCOMP], src4[i][RCOMP]);
1520 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][GCOMP], src4[i][GCOMP]);
1521 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][BCOMP], src4[i][BCOMP]);
1522 UNCLAMPED_FLOAT_TO_USHORT(dst2[i][ACOMP], src4[i][ACOMP]);
1523 }
1524 }
1525 if (useTemp)
1526 memcpy(dst, tempBuffer, count * 4 * sizeof(GLushort));
1527 }
1528 break;
1529 default:
1530 _mesa_problem(NULL, "Invalid datatype in _mesa_convert_colors");
1531 }
1532 }
1533
1534
1535
1536
1537 /**
1538 * Perform basic clipping for glDrawPixels. The image's position and size
1539 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1540 * region is entirely within the window and scissor bounds.
1541 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1542 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1543 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1544 *
1545 * \return GL_TRUE if image is ready for drawing or
1546 * GL_FALSE if image was completely clipped away (draw nothing)
1547 */
1548 GLboolean
1549 _mesa_clip_drawpixels(const struct gl_context *ctx,
1550 GLint *destX, GLint *destY,
1551 GLsizei *width, GLsizei *height,
1552 struct gl_pixelstore_attrib *unpack)
1553 {
1554 const struct gl_framebuffer *buffer = ctx->DrawBuffer;
1555
1556 if (unpack->RowLength == 0) {
1557 unpack->RowLength = *width;
1558 }
1559
1560 ASSERT(ctx->Pixel.ZoomX == 1.0F);
1561 ASSERT(ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F);
1562
1563 /* left clipping */
1564 if (*destX < buffer->_Xmin) {
1565 unpack->SkipPixels += (buffer->_Xmin - *destX);
1566 *width -= (buffer->_Xmin - *destX);
1567 *destX = buffer->_Xmin;
1568 }
1569 /* right clipping */
1570 if (*destX + *width > buffer->_Xmax)
1571 *width -= (*destX + *width - buffer->_Xmax);
1572
1573 if (*width <= 0)
1574 return GL_FALSE;
1575
1576 if (ctx->Pixel.ZoomY == 1.0F) {
1577 /* bottom clipping */
1578 if (*destY < buffer->_Ymin) {
1579 unpack->SkipRows += (buffer->_Ymin - *destY);
1580 *height -= (buffer->_Ymin - *destY);
1581 *destY = buffer->_Ymin;
1582 }
1583 /* top clipping */
1584 if (*destY + *height > buffer->_Ymax)
1585 *height -= (*destY + *height - buffer->_Ymax);
1586 }
1587 else { /* upside down */
1588 /* top clipping */
1589 if (*destY > buffer->_Ymax) {
1590 unpack->SkipRows += (*destY - buffer->_Ymax);
1591 *height -= (*destY - buffer->_Ymax);
1592 *destY = buffer->_Ymax;
1593 }
1594 /* bottom clipping */
1595 if (*destY - *height < buffer->_Ymin)
1596 *height -= (buffer->_Ymin - (*destY - *height));
1597 /* adjust destY so it's the first row to write to */
1598 (*destY)--;
1599 }
1600
1601 if (*height <= 0)
1602 return GL_FALSE;
1603
1604 return GL_TRUE;
1605 }
1606
1607
1608 /**
1609 * Perform clipping for glReadPixels. The image's window position
1610 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1611 * so that the image region is entirely within the window bounds.
1612 * Note: this is different from _mesa_clip_drawpixels() in that the
1613 * scissor box is ignored, and we use the bounds of the current readbuffer
1614 * surface.
1615 *
1616 * \return GL_TRUE if region to read is in bounds
1617 * GL_FALSE if region is completely out of bounds (nothing to read)
1618 */
1619 GLboolean
1620 _mesa_clip_readpixels(const struct gl_context *ctx,
1621 GLint *srcX, GLint *srcY,
1622 GLsizei *width, GLsizei *height,
1623 struct gl_pixelstore_attrib *pack)
1624 {
1625 const struct gl_framebuffer *buffer = ctx->ReadBuffer;
1626
1627 if (pack->RowLength == 0) {
1628 pack->RowLength = *width;
1629 }
1630
1631 /* left clipping */
1632 if (*srcX < 0) {
1633 pack->SkipPixels += (0 - *srcX);
1634 *width -= (0 - *srcX);
1635 *srcX = 0;
1636 }
1637 /* right clipping */
1638 if (*srcX + *width > (GLsizei) buffer->Width)
1639 *width -= (*srcX + *width - buffer->Width);
1640
1641 if (*width <= 0)
1642 return GL_FALSE;
1643
1644 /* bottom clipping */
1645 if (*srcY < 0) {
1646 pack->SkipRows += (0 - *srcY);
1647 *height -= (0 - *srcY);
1648 *srcY = 0;
1649 }
1650 /* top clipping */
1651 if (*srcY + *height > (GLsizei) buffer->Height)
1652 *height -= (*srcY + *height - buffer->Height);
1653
1654 if (*height <= 0)
1655 return GL_FALSE;
1656
1657 return GL_TRUE;
1658 }
1659
1660
1661 /**
1662 * Do clipping for a glCopyTexSubImage call.
1663 * The framebuffer source region might extend outside the framebuffer
1664 * bounds. Clip the source region against the framebuffer bounds and
1665 * adjust the texture/dest position and size accordingly.
1666 *
1667 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1668 */
1669 GLboolean
1670 _mesa_clip_copytexsubimage(const struct gl_context *ctx,
1671 GLint *destX, GLint *destY,
1672 GLint *srcX, GLint *srcY,
1673 GLsizei *width, GLsizei *height)
1674 {
1675 const struct gl_framebuffer *fb = ctx->ReadBuffer;
1676 const GLint srcX0 = *srcX, srcY0 = *srcY;
1677
1678 if (_mesa_clip_to_region(0, 0, fb->Width, fb->Height,
1679 srcX, srcY, width, height)) {
1680 *destX = *destX + *srcX - srcX0;
1681 *destY = *destY + *srcY - srcY0;
1682
1683 return GL_TRUE;
1684 }
1685 else {
1686 return GL_FALSE;
1687 }
1688 }
1689
1690
1691
1692 /**
1693 * Clip the rectangle defined by (x, y, width, height) against the bounds
1694 * specified by [xmin, xmax) and [ymin, ymax).
1695 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1696 */
1697 GLboolean
1698 _mesa_clip_to_region(GLint xmin, GLint ymin,
1699 GLint xmax, GLint ymax,
1700 GLint *x, GLint *y,
1701 GLsizei *width, GLsizei *height )
1702 {
1703 /* left clipping */
1704 if (*x < xmin) {
1705 *width -= (xmin - *x);
1706 *x = xmin;
1707 }
1708
1709 /* right clipping */
1710 if (*x + *width > xmax)
1711 *width -= (*x + *width - xmax);
1712
1713 if (*width <= 0)
1714 return GL_FALSE;
1715
1716 /* bottom (or top) clipping */
1717 if (*y < ymin) {
1718 *height -= (ymin - *y);
1719 *y = ymin;
1720 }
1721
1722 /* top (or bottom) clipping */
1723 if (*y + *height > ymax)
1724 *height -= (*y + *height - ymax);
1725
1726 if (*height <= 0)
1727 return GL_FALSE;
1728
1729 return GL_TRUE;
1730 }
1731
1732
1733 /**
1734 * Clip dst coords against Xmax (or Ymax).
1735 */
1736 static inline void
1737 clip_right_or_top(GLint *srcX0, GLint *srcX1,
1738 GLint *dstX0, GLint *dstX1,
1739 GLint maxValue)
1740 {
1741 GLfloat t, bias;
1742
1743 if (*dstX1 > maxValue) {
1744 /* X1 outside right edge */
1745 ASSERT(*dstX0 < maxValue); /* X0 should be inside right edge */
1746 t = (GLfloat) (maxValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
1747 /* chop off [t, 1] part */
1748 ASSERT(t >= 0.0 && t <= 1.0);
1749 *dstX1 = maxValue;
1750 bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
1751 *srcX1 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
1752 }
1753 else if (*dstX0 > maxValue) {
1754 /* X0 outside right edge */
1755 ASSERT(*dstX1 < maxValue); /* X1 should be inside right edge */
1756 t = (GLfloat) (maxValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
1757 /* chop off [t, 1] part */
1758 ASSERT(t >= 0.0 && t <= 1.0);
1759 *dstX0 = maxValue;
1760 bias = (*srcX0 < *srcX1) ? -0.5F : 0.5F;
1761 *srcX0 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
1762 }
1763 }
1764
1765
1766 /**
1767 * Clip dst coords against Xmin (or Ymin).
1768 */
1769 static inline void
1770 clip_left_or_bottom(GLint *srcX0, GLint *srcX1,
1771 GLint *dstX0, GLint *dstX1,
1772 GLint minValue)
1773 {
1774 GLfloat t, bias;
1775
1776 if (*dstX0 < minValue) {
1777 /* X0 outside left edge */
1778 ASSERT(*dstX1 > minValue); /* X1 should be inside left edge */
1779 t = (GLfloat) (minValue - *dstX0) / (GLfloat) (*dstX1 - *dstX0);
1780 /* chop off [0, t] part */
1781 ASSERT(t >= 0.0 && t <= 1.0);
1782 *dstX0 = minValue;
1783 bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F; /* flipped??? */
1784 *srcX0 = *srcX0 + (GLint) (t * (*srcX1 - *srcX0) + bias);
1785 }
1786 else if (*dstX1 < minValue) {
1787 /* X1 outside left edge */
1788 ASSERT(*dstX0 > minValue); /* X0 should be inside left edge */
1789 t = (GLfloat) (minValue - *dstX1) / (GLfloat) (*dstX0 - *dstX1);
1790 /* chop off [0, t] part */
1791 ASSERT(t >= 0.0 && t <= 1.0);
1792 *dstX1 = minValue;
1793 bias = (*srcX0 < *srcX1) ? 0.5F : -0.5F;
1794 *srcX1 = *srcX1 + (GLint) (t * (*srcX0 - *srcX1) + bias);
1795 }
1796 }
1797
1798
1799 /**
1800 * Do clipping of blit src/dest rectangles.
1801 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1802 * The src rect is just clipped against the buffer bounds.
1803 *
1804 * When either the src or dest rect is clipped, the other is also clipped
1805 * proportionately!
1806 *
1807 * Note that X0 need not be less than X1 (same for Y) for either the source
1808 * and dest rects. That makes the clipping a little trickier.
1809 *
1810 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1811 */
1812 GLboolean
1813 _mesa_clip_blit(struct gl_context *ctx,
1814 GLint *srcX0, GLint *srcY0, GLint *srcX1, GLint *srcY1,
1815 GLint *dstX0, GLint *dstY0, GLint *dstX1, GLint *dstY1)
1816 {
1817 const GLint srcXmin = 0;
1818 const GLint srcXmax = ctx->ReadBuffer->Width;
1819 const GLint srcYmin = 0;
1820 const GLint srcYmax = ctx->ReadBuffer->Height;
1821
1822 /* these include scissor bounds */
1823 const GLint dstXmin = ctx->DrawBuffer->_Xmin;
1824 const GLint dstXmax = ctx->DrawBuffer->_Xmax;
1825 const GLint dstYmin = ctx->DrawBuffer->_Ymin;
1826 const GLint dstYmax = ctx->DrawBuffer->_Ymax;
1827
1828 /*
1829 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1830 *srcX0, *srcX1, *dstX0, *dstX1);
1831 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1832 *srcY0, *srcY1, *dstY0, *dstY1);
1833 */
1834
1835 /* trivial rejection tests */
1836 if (*dstX0 == *dstX1)
1837 return GL_FALSE; /* no width */
1838 if (*dstX0 <= dstXmin && *dstX1 <= dstXmin)
1839 return GL_FALSE; /* totally out (left) of bounds */
1840 if (*dstX0 >= dstXmax && *dstX1 >= dstXmax)
1841 return GL_FALSE; /* totally out (right) of bounds */
1842
1843 if (*dstY0 == *dstY1)
1844 return GL_FALSE;
1845 if (*dstY0 <= dstYmin && *dstY1 <= dstYmin)
1846 return GL_FALSE;
1847 if (*dstY0 >= dstYmax && *dstY1 >= dstYmax)
1848 return GL_FALSE;
1849
1850 if (*srcX0 == *srcX1)
1851 return GL_FALSE;
1852 if (*srcX0 <= srcXmin && *srcX1 <= srcXmin)
1853 return GL_FALSE;
1854 if (*srcX0 >= srcXmax && *srcX1 >= srcXmax)
1855 return GL_FALSE;
1856
1857 if (*srcY0 == *srcY1)
1858 return GL_FALSE;
1859 if (*srcY0 <= srcYmin && *srcY1 <= srcYmin)
1860 return GL_FALSE;
1861 if (*srcY0 >= srcYmax && *srcY1 >= srcYmax)
1862 return GL_FALSE;
1863
1864 /*
1865 * dest clip
1866 */
1867 clip_right_or_top(srcX0, srcX1, dstX0, dstX1, dstXmax);
1868 clip_right_or_top(srcY0, srcY1, dstY0, dstY1, dstYmax);
1869 clip_left_or_bottom(srcX0, srcX1, dstX0, dstX1, dstXmin);
1870 clip_left_or_bottom(srcY0, srcY1, dstY0, dstY1, dstYmin);
1871
1872 /*
1873 * src clip (just swap src/dst values from above)
1874 */
1875 clip_right_or_top(dstX0, dstX1, srcX0, srcX1, srcXmax);
1876 clip_right_or_top(dstY0, dstY1, srcY0, srcY1, srcYmax);
1877 clip_left_or_bottom(dstX0, dstX1, srcX0, srcX1, srcXmin);
1878 clip_left_or_bottom(dstY0, dstY1, srcY0, srcY1, srcYmin);
1879
1880 /*
1881 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1882 *srcX0, *srcX1, *dstX0, *dstX1);
1883 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1884 *srcY0, *srcY1, *dstY0, *dstY1);
1885 */
1886
1887 ASSERT(*dstX0 >= dstXmin);
1888 ASSERT(*dstX0 <= dstXmax);
1889 ASSERT(*dstX1 >= dstXmin);
1890 ASSERT(*dstX1 <= dstXmax);
1891
1892 ASSERT(*dstY0 >= dstYmin);
1893 ASSERT(*dstY0 <= dstYmax);
1894 ASSERT(*dstY1 >= dstYmin);
1895 ASSERT(*dstY1 <= dstYmax);
1896
1897 ASSERT(*srcX0 >= srcXmin);
1898 ASSERT(*srcX0 <= srcXmax);
1899 ASSERT(*srcX1 >= srcXmin);
1900 ASSERT(*srcX1 <= srcXmax);
1901
1902 ASSERT(*srcY0 >= srcYmin);
1903 ASSERT(*srcY0 <= srcYmax);
1904 ASSERT(*srcY1 >= srcYmin);
1905 ASSERT(*srcY1 <= srcYmax);
1906
1907 return GL_TRUE;
1908 }