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