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