ReactOS  r76032
texstore.c
Go to the documentation of this file.
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) 2008-2009 VMware, Inc.
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  * Authors:
28  * Brian Paul
29  */
30 
53 #include <precomp.h>
54 
55 enum {
56  ZERO = 4,
57  ONE = 5
58 };
59 
60 
65 
66 
71 static GLboolean
72 can_swizzle(GLenum logicalBaseFormat)
73 {
74  switch (logicalBaseFormat) {
75  case GL_RGBA:
76  case GL_RGB:
77  case GL_LUMINANCE_ALPHA:
78  case GL_INTENSITY:
79  case GL_ALPHA:
80  case GL_LUMINANCE:
81  case GL_RED:
82  case GL_GREEN:
83  case GL_BLUE:
84  case GL_BGR:
85  case GL_BGRA:
86  case GL_ABGR_EXT:
87  case GL_RG:
88  return GL_TRUE;
89  default:
90  return GL_FALSE;
91  }
92 }
93 
94 
95 
96 enum {
111 };
112 
113 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
114 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
115 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
116 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
117 
118 
119 static const struct {
123 } mappings[MAX_IDX] =
124 {
125  {
127  MAP4(0,0,0,ONE),
128  MAP1(0)
129  },
130 
131  {
132  IDX_ALPHA,
133  MAP4(ZERO, ZERO, ZERO, 0),
134  MAP1(3)
135  },
136 
137  {
139  MAP4(0, 0, 0, 0),
140  MAP1(0),
141  },
142 
143  {
145  MAP4(0,0,0,1),
146  MAP2(0,3)
147  },
148 
149  {
150  IDX_RGB,
151  MAP4(0,1,2,ONE),
152  MAP3(0,1,2)
153  },
154 
155  {
156  IDX_RGBA,
157  MAP4(0,1,2,3),
158  MAP4(0,1,2,3),
159  },
160 
161  {
162  IDX_RED,
163  MAP4(0, ZERO, ZERO, ONE),
164  MAP1(0),
165  },
166 
167  {
168  IDX_GREEN,
169  MAP4(ZERO, 0, ZERO, ONE),
170  MAP1(1),
171  },
172 
173  {
174  IDX_BLUE,
175  MAP4(ZERO, ZERO, 0, ONE),
176  MAP1(2),
177  },
178 
179  {
180  IDX_BGR,
181  MAP4(2,1,0,ONE),
182  MAP3(2,1,0)
183  },
184 
185  {
186  IDX_BGRA,
187  MAP4(2,1,0,3),
188  MAP4(2,1,0,3)
189  },
190 
191  {
192  IDX_ABGR,
193  MAP4(3,2,1,0),
194  MAP4(3,2,1,0)
195  },
196 
197  {
198  IDX_RG,
199  MAP4(0, 1, ZERO, ONE),
200  MAP2(0, 1)
201  },
202 };
203 
204 
205 
209 static int
211 {
212  switch (value) {
213  case GL_LUMINANCE: return IDX_LUMINANCE;
214  case GL_ALPHA: return IDX_ALPHA;
215  case GL_INTENSITY: return IDX_INTENSITY;
217  case GL_RGB: return IDX_RGB;
218  case GL_RGBA: return IDX_RGBA;
219  case GL_RED: return IDX_RED;
220  case GL_GREEN: return IDX_GREEN;
221  case GL_BLUE: return IDX_BLUE;
222  case GL_BGR: return IDX_BGR;
223  case GL_BGRA: return IDX_BGRA;
224  case GL_ABGR_EXT: return IDX_ABGR;
225  case GL_RG: return IDX_RG;
226  default:
227  _mesa_problem(NULL, "Unexpected inFormat");
228  return 0;
229  }
230 }
231 
232 
241 static void
243  GLubyte *map)
244 {
245  const int inFmt = get_map_idx(inFormat);
246  const int outFmt = get_map_idx(outFormat);
247  const GLubyte *in2rgba = mappings[inFmt].to_rgba;
248  const GLubyte *rgba2out = mappings[outFmt].from_rgba;
249  int i;
250 
251  for (i = 0; i < 4; i++)
252  map[i] = in2rgba[rgba2out[i]];
253 
254  map[ZERO] = ZERO;
255  map[ONE] = ONE;
256 
257 #if 0
258  printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
259  inFormat, _mesa_lookup_enum_by_nr(inFormat),
260  outFormat, _mesa_lookup_enum_by_nr(outFormat),
261  map[0],
262  map[1],
263  map[2],
264  map[3],
265  map[4],
266  map[5]);
267 #endif
268 }
269 
270 
294 GLfloat *
296  GLenum logicalBaseFormat,
297  GLenum textureBaseFormat,
298  GLint srcWidth, GLint srcHeight, GLint srcDepth,
299  GLenum srcFormat, GLenum srcType,
300  const GLvoid *srcAddr,
301  const struct gl_pixelstore_attrib *srcPacking,
302  GLbitfield transferOps)
303 {
304  GLfloat *tempImage;
305  const GLint components = _mesa_components_in_format(logicalBaseFormat);
306  const GLint srcStride =
307  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
308  GLfloat *dst;
309  GLint img, row;
310 
311  ASSERT(dims >= 1 && dims <= 3);
312 
313  ASSERT(logicalBaseFormat == GL_RGBA ||
314  logicalBaseFormat == GL_RGB ||
315  logicalBaseFormat == GL_RG ||
316  logicalBaseFormat == GL_RED ||
317  logicalBaseFormat == GL_LUMINANCE_ALPHA ||
318  logicalBaseFormat == GL_LUMINANCE ||
319  logicalBaseFormat == GL_ALPHA ||
320  logicalBaseFormat == GL_INTENSITY ||
321  logicalBaseFormat == GL_DEPTH_COMPONENT);
322 
323  ASSERT(textureBaseFormat == GL_RGBA ||
324  textureBaseFormat == GL_RGB ||
325  textureBaseFormat == GL_RG ||
326  textureBaseFormat == GL_RED ||
327  textureBaseFormat == GL_LUMINANCE_ALPHA ||
328  textureBaseFormat == GL_LUMINANCE ||
329  textureBaseFormat == GL_ALPHA ||
330  textureBaseFormat == GL_INTENSITY ||
331  textureBaseFormat == GL_DEPTH_COMPONENT);
332 
333  tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
334  * components * sizeof(GLfloat));
335  if (!tempImage)
336  return NULL;
337 
338  dst = tempImage;
339  for (img = 0; img < srcDepth; img++) {
340  const GLubyte *src
341  = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
342  srcWidth, srcHeight,
343  srcFormat, srcType,
344  img, 0, 0);
345  for (row = 0; row < srcHeight; row++) {
346  _mesa_unpack_color_span_float(ctx, srcWidth, logicalBaseFormat,
347  dst, srcFormat, srcType, src,
348  srcPacking, transferOps);
349  dst += srcWidth * components;
350  src += srcStride;
351  }
352  }
353 
354  if (logicalBaseFormat != textureBaseFormat) {
355  /* more work */
356  GLint texComponents = _mesa_components_in_format(textureBaseFormat);
357  GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
358  GLfloat *newImage;
359  GLint i, n;
360  GLubyte map[6];
361 
362  /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
363  ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
364  textureBaseFormat == GL_LUMINANCE_ALPHA);
365 
366  /* The actual texture format should have at least as many components
367  * as the logical texture format.
368  */
369  ASSERT(texComponents >= logComponents);
370 
371  newImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
372  * texComponents * sizeof(GLfloat));
373  if (!newImage) {
374  free(tempImage);
375  return NULL;
376  }
377 
378  compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
379 
380  n = srcWidth * srcHeight * srcDepth;
381  for (i = 0; i < n; i++) {
382  GLint k;
383  for (k = 0; k < texComponents; k++) {
384  GLint j = map[k];
385  if (j == ZERO)
386  newImage[i * texComponents + k] = 0.0F;
387  else if (j == ONE)
388  newImage[i * texComponents + k] = 1.0F;
389  else
390  newImage[i * texComponents + k] = tempImage[i * logComponents + j];
391  }
392  }
393 
394  free(tempImage);
395  tempImage = newImage;
396  }
397 
398  return tempImage;
399 }
400 
401 
406 static GLuint *
408  GLenum logicalBaseFormat,
409  GLenum textureBaseFormat,
410  GLint srcWidth, GLint srcHeight, GLint srcDepth,
411  GLenum srcFormat, GLenum srcType,
412  const GLvoid *srcAddr,
413  const struct gl_pixelstore_attrib *srcPacking)
414 {
415  GLuint *tempImage;
416  const GLint components = _mesa_components_in_format(logicalBaseFormat);
417  const GLint srcStride =
418  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
419  GLuint *dst;
420  GLint img, row;
421 
422  ASSERT(dims >= 1 && dims <= 3);
423 
424  ASSERT(logicalBaseFormat == GL_RGBA ||
425  logicalBaseFormat == GL_RGB ||
426  logicalBaseFormat == GL_RG ||
427  logicalBaseFormat == GL_RED ||
428  logicalBaseFormat == GL_LUMINANCE_ALPHA ||
429  logicalBaseFormat == GL_LUMINANCE ||
430  logicalBaseFormat == GL_INTENSITY ||
431  logicalBaseFormat == GL_ALPHA);
432 
433  ASSERT(textureBaseFormat == GL_RGBA ||
434  textureBaseFormat == GL_RGB ||
435  textureBaseFormat == GL_RG ||
436  textureBaseFormat == GL_RED ||
437  textureBaseFormat == GL_LUMINANCE_ALPHA ||
438  textureBaseFormat == GL_LUMINANCE ||
439  textureBaseFormat == GL_INTENSITY ||
440  textureBaseFormat == GL_ALPHA);
441 
442  tempImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
443  * components * sizeof(GLuint));
444  if (!tempImage)
445  return NULL;
446 
447  dst = tempImage;
448  for (img = 0; img < srcDepth; img++) {
449  const GLubyte *src
450  = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
451  srcWidth, srcHeight,
452  srcFormat, srcType,
453  img, 0, 0);
454  for (row = 0; row < srcHeight; row++) {
455  _mesa_unpack_color_span_uint(ctx, srcWidth, logicalBaseFormat,
456  dst, srcFormat, srcType, src,
457  srcPacking);
458  dst += srcWidth * components;
459  src += srcStride;
460  }
461  }
462 
463  if (logicalBaseFormat != textureBaseFormat) {
464  /* more work */
465  GLint texComponents = _mesa_components_in_format(textureBaseFormat);
466  GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
467  GLuint *newImage;
468  GLint i, n;
469  GLubyte map[6];
470 
471  /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
472  ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
473  textureBaseFormat == GL_LUMINANCE_ALPHA);
474 
475  /* The actual texture format should have at least as many components
476  * as the logical texture format.
477  */
478  ASSERT(texComponents >= logComponents);
479 
480  newImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
481  * texComponents * sizeof(GLuint));
482  if (!newImage) {
483  free(tempImage);
484  return NULL;
485  }
486 
487  compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
488 
489  n = srcWidth * srcHeight * srcDepth;
490  for (i = 0; i < n; i++) {
491  GLint k;
492  for (k = 0; k < texComponents; k++) {
493  GLint j = map[k];
494  if (j == ZERO)
495  newImage[i * texComponents + k] = 0;
496  else if (j == ONE)
497  newImage[i * texComponents + k] = 1;
498  else
499  newImage[i * texComponents + k] = tempImage[i * logComponents + j];
500  }
501  }
502 
503  free(tempImage);
504  tempImage = newImage;
505  }
506 
507  return tempImage;
508 }
509 
510 
511 
535 GLubyte *
537  GLenum logicalBaseFormat,
538  GLenum textureBaseFormat,
539  GLint srcWidth, GLint srcHeight, GLint srcDepth,
540  GLenum srcFormat, GLenum srcType,
541  const GLvoid *srcAddr,
542  const struct gl_pixelstore_attrib *srcPacking)
543 {
544  GLuint transferOps = ctx->_ImageTransferState;
545  const GLint components = _mesa_components_in_format(logicalBaseFormat);
546  GLint img, row;
547  GLubyte *tempImage, *dst;
548 
549  ASSERT(dims >= 1 && dims <= 3);
550 
551  ASSERT(logicalBaseFormat == GL_RGBA ||
552  logicalBaseFormat == GL_RGB ||
553  logicalBaseFormat == GL_RG ||
554  logicalBaseFormat == GL_RED ||
555  logicalBaseFormat == GL_LUMINANCE_ALPHA ||
556  logicalBaseFormat == GL_LUMINANCE ||
557  logicalBaseFormat == GL_ALPHA ||
558  logicalBaseFormat == GL_INTENSITY);
559 
560  ASSERT(textureBaseFormat == GL_RGBA ||
561  textureBaseFormat == GL_RGB ||
562  textureBaseFormat == GL_RG ||
563  textureBaseFormat == GL_RED ||
564  textureBaseFormat == GL_LUMINANCE_ALPHA ||
565  textureBaseFormat == GL_LUMINANCE ||
566  textureBaseFormat == GL_ALPHA ||
567  textureBaseFormat == GL_INTENSITY);
568 
569  /* unpack and transfer the source image */
570  tempImage = (GLubyte *) malloc(srcWidth * srcHeight * srcDepth
571  * components * sizeof(GLubyte));
572  if (!tempImage) {
573  return NULL;
574  }
575 
576  dst = tempImage;
577  for (img = 0; img < srcDepth; img++) {
578  const GLint srcStride =
579  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
580  const GLubyte *src =
581  (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
582  srcWidth, srcHeight,
583  srcFormat, srcType,
584  img, 0, 0);
585  for (row = 0; row < srcHeight; row++) {
586  _mesa_unpack_color_span_ubyte(ctx, srcWidth, logicalBaseFormat, dst,
587  srcFormat, srcType, src, srcPacking,
588  transferOps);
589  dst += srcWidth * components;
590  src += srcStride;
591  }
592  }
593 
594  if (logicalBaseFormat != textureBaseFormat) {
595  /* one more conversion step */
596  GLint texComponents = _mesa_components_in_format(textureBaseFormat);
597  GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
598  GLubyte *newImage;
599  GLint i, n;
600  GLubyte map[6];
601 
602  /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
603  ASSERT(textureBaseFormat == GL_RGB || textureBaseFormat == GL_RGBA ||
604  textureBaseFormat == GL_LUMINANCE_ALPHA);
605 
606  /* The actual texture format should have at least as many components
607  * as the logical texture format.
608  */
609  ASSERT(texComponents >= logComponents);
610 
611  newImage = (GLubyte *) malloc(srcWidth * srcHeight * srcDepth
612  * texComponents * sizeof(GLubyte));
613  if (!newImage) {
614  free(tempImage);
615  return NULL;
616  }
617 
618  compute_component_mapping(logicalBaseFormat, textureBaseFormat, map);
619 
620  n = srcWidth * srcHeight * srcDepth;
621  for (i = 0; i < n; i++) {
622  GLint k;
623  for (k = 0; k < texComponents; k++) {
624  GLint j = map[k];
625  if (j == ZERO)
626  newImage[i * texComponents + k] = 0;
627  else if (j == ONE)
628  newImage[i * texComponents + k] = 255;
629  else
630  newImage[i * texComponents + k] = tempImage[i * logComponents + j];
631  }
632  }
633 
634  free(tempImage);
635  tempImage = newImage;
636  }
637 
638  return tempImage;
639 }
640 
641 
653 static void
654 swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src,
655  GLuint srcComponents, const GLubyte *map, GLuint count)
656 {
657 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
658  do { \
659  GLuint i; \
660  for (i = 0; i < count; i++) { \
661  GLuint j; \
662  if (srcComps == 4) { \
663  COPY_4UBV(tmp, src); \
664  } \
665  else { \
666  for (j = 0; j < srcComps; j++) { \
667  tmp[j] = src[j]; \
668  } \
669  } \
670  src += srcComps; \
671  for (j = 0; j < dstComps; j++) { \
672  dst[j] = tmp[map[j]]; \
673  } \
674  dst += dstComps; \
675  } \
676  } while (0)
677 
678  GLubyte tmp[6];
679 
680  tmp[ZERO] = 0x0;
681  tmp[ONE] = 0xff;
682 
683  ASSERT(srcComponents <= 4);
684  ASSERT(dstComponents <= 4);
685 
686  switch (dstComponents) {
687  case 4:
688  switch (srcComponents) {
689  case 4:
690  SWZ_CPY(dst, src, count, 4, 4);
691  break;
692  case 3:
693  SWZ_CPY(dst, src, count, 4, 3);
694  break;
695  case 2:
696  SWZ_CPY(dst, src, count, 4, 2);
697  break;
698  case 1:
699  SWZ_CPY(dst, src, count, 4, 1);
700  break;
701  default:
702  ;
703  }
704  break;
705  case 3:
706  switch (srcComponents) {
707  case 4:
708  SWZ_CPY(dst, src, count, 3, 4);
709  break;
710  case 3:
711  SWZ_CPY(dst, src, count, 3, 3);
712  break;
713  case 2:
714  SWZ_CPY(dst, src, count, 3, 2);
715  break;
716  case 1:
717  SWZ_CPY(dst, src, count, 3, 1);
718  break;
719  default:
720  ;
721  }
722  break;
723  case 2:
724  switch (srcComponents) {
725  case 4:
726  SWZ_CPY(dst, src, count, 2, 4);
727  break;
728  case 3:
729  SWZ_CPY(dst, src, count, 2, 3);
730  break;
731  case 2:
732  SWZ_CPY(dst, src, count, 2, 2);
733  break;
734  case 1:
735  SWZ_CPY(dst, src, count, 2, 1);
736  break;
737  default:
738  ;
739  }
740  break;
741  case 1:
742  switch (srcComponents) {
743  case 4:
744  SWZ_CPY(dst, src, count, 1, 4);
745  break;
746  case 3:
747  SWZ_CPY(dst, src, count, 1, 3);
748  break;
749  case 2:
750  SWZ_CPY(dst, src, count, 1, 2);
751  break;
752  case 1:
753  SWZ_CPY(dst, src, count, 1, 1);
754  break;
755  default:
756  ;
757  }
758  break;
759  default:
760  ;
761  }
762 #undef SWZ_CPY
763 }
764 
765 
766 
767 static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE };
768 static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE };
769 
770 
775 static const GLubyte *
777 {
778  switch (srcType) {
779  case GL_BYTE:
780  case GL_UNSIGNED_BYTE:
781  return map_identity;
786  default:
787  return NULL;
788  }
789 }
790 
791 
796 static const GLubyte *
798  GLenum srcType )
799 {
800  if (!swapBytes)
801  return map_identity;
802 
803  switch (srcType) {
804  case GL_BYTE:
805  case GL_UNSIGNED_BYTE:
806  return map_identity;
809  return map_3210;
810  default:
811  return NULL;
812  }
813 }
814 
815 
816 
820 static void
822  GLuint dimensions,
823  GLenum srcFormat,
824  GLenum srcType,
825 
826  GLenum baseInternalFormat,
827 
828  const GLubyte *rgba2dst,
829  GLuint dstComponents,
830 
831  GLint dstRowStride,
832  GLubyte **dstSlices,
833 
834  GLint srcWidth, GLint srcHeight, GLint srcDepth,
835  const GLvoid *srcAddr,
836  const struct gl_pixelstore_attrib *srcPacking )
837 {
838  GLint srcComponents = _mesa_components_in_format(srcFormat);
839  const GLubyte *srctype2ubyte, *swap;
840  GLubyte map[4], src2base[6], base2rgba[6];
841  GLint i;
842  const GLint srcRowStride =
843  _mesa_image_row_stride(srcPacking, srcWidth,
844  srcFormat, GL_UNSIGNED_BYTE);
845  const GLint srcImageStride
846  = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat,
848  const GLubyte *srcImage
849  = (const GLubyte *) _mesa_image_address(dimensions, srcPacking, srcAddr,
850  srcWidth, srcHeight, srcFormat,
851  GL_UNSIGNED_BYTE, 0, 0, 0);
852 
853  (void) ctx;
854 
855  /* Translate from src->baseInternal->GL_RGBA->dst. This will
856  * correctly deal with RGBA->RGB->RGBA conversions where the final
857  * A value must be 0xff regardless of the incoming alpha values.
858  */
859  compute_component_mapping(srcFormat, baseInternalFormat, src2base);
860  compute_component_mapping(baseInternalFormat, GL_RGBA, base2rgba);
861  swap = byteswap_mapping(srcPacking->SwapBytes, srcType);
862  srctype2ubyte = type_mapping(srcType);
863 
864 
865  for (i = 0; i < 4; i++)
866  map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]];
867 
868 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
869 
870  if (srcComponents == dstComponents &&
871  srcRowStride == dstRowStride &&
872  srcRowStride == srcWidth * srcComponents &&
873  dimensions < 3) {
874  /* 1 and 2D images only */
875  GLubyte *dstImage = dstSlices[0];
876  swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map,
877  srcWidth * srcHeight);
878  }
879  else {
880  GLint img, row;
881  for (img = 0; img < srcDepth; img++) {
882  const GLubyte *srcRow = srcImage;
883  GLubyte *dstRow = dstSlices[img];
884  for (row = 0; row < srcHeight; row++) {
885  swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth);
886  dstRow += dstRowStride;
887  srcRow += srcRowStride;
888  }
889  srcImage += srcImageStride;
890  }
891  }
892 }
893 
894 
900 static void
902  GLuint dimensions,
903  gl_format dstFormat,
904  GLint dstRowStride,
905  GLubyte **dstSlices,
906  GLint srcWidth, GLint srcHeight, GLint srcDepth,
907  GLenum srcFormat, GLenum srcType,
908  const GLvoid *srcAddr,
909  const struct gl_pixelstore_attrib *srcPacking)
910 {
911  const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,
912  srcFormat, srcType);
913  const GLint srcImageStride = _mesa_image_image_stride(srcPacking,
914  srcWidth, srcHeight, srcFormat, srcType);
915  const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,
916  srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);
917  const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
918  const GLint bytesPerRow = srcWidth * texelBytes;
919 
920  if (dstRowStride == srcRowStride &&
921  dstRowStride == bytesPerRow) {
922  /* memcpy image by image */
923  GLint img;
924  for (img = 0; img < srcDepth; img++) {
925  GLubyte *dstImage = dstSlices[img];
926  memcpy(dstImage, srcImage, bytesPerRow * srcHeight);
927  srcImage += srcImageStride;
928  }
929  }
930  else {
931  /* memcpy row by row */
932  GLint img, row;
933  for (img = 0; img < srcDepth; img++) {
934  const GLubyte *srcRow = srcImage;
935  GLubyte *dstRow = dstSlices[img];
936  for (row = 0; row < srcHeight; row++) {
937  memcpy(dstRow, srcRow, bytesPerRow);
938  dstRow += dstRowStride;
939  srcRow += srcRowStride;
940  }
941  srcImage += srcImageStride;
942  }
943  }
944 }
945 
946 
947 
951 static GLboolean
953 {
954  const GLuint depthScale = 0xffffffff;
955  GLenum dstType;
956  (void) dims;
957  ASSERT(dstFormat == MESA_FORMAT_Z32 ||
958  dstFormat == MESA_FORMAT_Z32_FLOAT);
959  ASSERT(_mesa_get_format_bytes(dstFormat) == sizeof(GLuint));
960 
961  if (dstFormat == MESA_FORMAT_Z32)
962  dstType = GL_UNSIGNED_INT;
963  else
964  dstType = GL_FLOAT;
965 
966  if (ctx->Pixel.DepthScale == 1.0f &&
967  ctx->Pixel.DepthBias == 0.0f &&
968  !srcPacking->SwapBytes &&
969  baseInternalFormat == GL_DEPTH_COMPONENT &&
970  srcFormat == GL_DEPTH_COMPONENT &&
971  srcType == dstType) {
972  /* simple memcpy path */
973  memcpy_texture(ctx, dims,
974  dstFormat,
975  dstRowStride, dstSlices,
976  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
977  srcAddr, srcPacking);
978  }
979  else {
980  /* general path */
981  GLint img, row;
982  for (img = 0; img < srcDepth; img++) {
983  GLubyte *dstRow = dstSlices[img];
984  for (row = 0; row < srcHeight; row++) {
985  const GLvoid *src = _mesa_image_address(dims, srcPacking,
986  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
987  _mesa_unpack_depth_span(ctx, srcWidth,
988  dstType, dstRow,
989  depthScale, srcType, src, srcPacking);
990  dstRow += dstRowStride;
991  }
992  }
993  }
994  return GL_TRUE;
995 }
996 
997 
1001 static GLboolean
1003 {
1004  const GLuint depthScale = 0xffffff;
1005 
1006  (void) dims;
1007  ASSERT(dstFormat == MESA_FORMAT_X8_Z24);
1008 
1009  {
1010  /* general path */
1011  GLint img, row;
1012  for (img = 0; img < srcDepth; img++) {
1013  GLubyte *dstRow = dstSlices[img];
1014  for (row = 0; row < srcHeight; row++) {
1015  const GLvoid *src = _mesa_image_address(dims, srcPacking,
1016  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1017  _mesa_unpack_depth_span(ctx, srcWidth,
1018  GL_UNSIGNED_INT, (GLuint *) dstRow,
1019  depthScale, srcType, src, srcPacking);
1020  dstRow += dstRowStride;
1021  }
1022  }
1023  }
1024  return GL_TRUE;
1025 }
1026 
1027 
1031 static GLboolean
1033 {
1034  const GLuint depthScale = 0xffffff;
1035 
1036  (void) dims;
1037  ASSERT(dstFormat == MESA_FORMAT_Z24_X8);
1038 
1039  {
1040  /* general path */
1041  GLint img, row;
1042  for (img = 0; img < srcDepth; img++) {
1043  GLubyte *dstRow = dstSlices[img];
1044  for (row = 0; row < srcHeight; row++) {
1045  const GLvoid *src = _mesa_image_address(dims, srcPacking,
1046  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1047  GLuint *dst = (GLuint *) dstRow;
1048  GLint i;
1049  _mesa_unpack_depth_span(ctx, srcWidth,
1050  GL_UNSIGNED_INT, dst,
1051  depthScale, srcType, src, srcPacking);
1052  for (i = 0; i < srcWidth; i++)
1053  dst[i] <<= 8;
1054  dstRow += dstRowStride;
1055  }
1056  }
1057  }
1058  return GL_TRUE;
1059 }
1060 
1061 
1065 static GLboolean
1067 {
1068  const GLuint depthScale = 0xffff;
1069  (void) dims;
1070  ASSERT(dstFormat == MESA_FORMAT_Z16);
1071  ASSERT(_mesa_get_format_bytes(dstFormat) == sizeof(GLushort));
1072 
1073  if (ctx->Pixel.DepthScale == 1.0f &&
1074  ctx->Pixel.DepthBias == 0.0f &&
1075  !srcPacking->SwapBytes &&
1076  baseInternalFormat == GL_DEPTH_COMPONENT &&
1077  srcFormat == GL_DEPTH_COMPONENT &&
1078  srcType == GL_UNSIGNED_SHORT) {
1079  /* simple memcpy path */
1080  memcpy_texture(ctx, dims,
1081  dstFormat,
1082  dstRowStride, dstSlices,
1083  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1084  srcAddr, srcPacking);
1085  }
1086  else {
1087  /* general path */
1088  GLint img, row;
1089  for (img = 0; img < srcDepth; img++) {
1090  GLubyte *dstRow = dstSlices[img];
1091  for (row = 0; row < srcHeight; row++) {
1092  const GLvoid *src = _mesa_image_address(dims, srcPacking,
1093  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1094  GLushort *dst16 = (GLushort *) dstRow;
1095  _mesa_unpack_depth_span(ctx, srcWidth,
1096  GL_UNSIGNED_SHORT, dst16, depthScale,
1097  srcType, src, srcPacking);
1098  dstRow += dstRowStride;
1099  }
1100  }
1101  }
1102  return GL_TRUE;
1103 }
1104 
1105 
1109 static GLboolean
1111 {
1112  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1113 
1114  ASSERT(dstFormat == MESA_FORMAT_RGB565 ||
1115  dstFormat == MESA_FORMAT_RGB565_REV);
1116  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1117 
1118  if (!ctx->_ImageTransferState &&
1119  !srcPacking->SwapBytes &&
1120  dstFormat == MESA_FORMAT_RGB565 &&
1121  baseInternalFormat == GL_RGB &&
1122  srcFormat == GL_RGB &&
1123  srcType == GL_UNSIGNED_SHORT_5_6_5) {
1124  /* simple memcpy path */
1125  memcpy_texture(ctx, dims,
1126  dstFormat,
1127  dstRowStride, dstSlices,
1128  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1129  srcAddr, srcPacking);
1130  }
1131  else if (!ctx->_ImageTransferState &&
1132  !srcPacking->SwapBytes &&
1133  baseInternalFormat == GL_RGB &&
1134  srcFormat == GL_RGB &&
1135  srcType == GL_UNSIGNED_BYTE &&
1136  dims == 2) {
1137  /* do optimized tex store */
1138  const GLint srcRowStride =
1139  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1140  const GLubyte *src = (const GLubyte *)
1141  _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
1142  srcFormat, srcType, 0, 0, 0);
1143  GLubyte *dst = dstSlices[0];
1144  GLint row, col;
1145  for (row = 0; row < srcHeight; row++) {
1146  const GLubyte *srcUB = (const GLubyte *) src;
1147  GLushort *dstUS = (GLushort *) dst;
1148  /* check for byteswapped format */
1149  if (dstFormat == MESA_FORMAT_RGB565) {
1150  for (col = 0; col < srcWidth; col++) {
1151  dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] );
1152  srcUB += 3;
1153  }
1154  }
1155  else {
1156  for (col = 0; col < srcWidth; col++) {
1157  dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );
1158  srcUB += 3;
1159  }
1160  }
1161  dst += dstRowStride;
1162  src += srcRowStride;
1163  }
1164  }
1165  else {
1166  /* general path */
1167  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1168  baseInternalFormat,
1169  baseFormat,
1170  srcWidth, srcHeight, srcDepth,
1171  srcFormat, srcType, srcAddr,
1172  srcPacking);
1173  const GLubyte *src = tempImage;
1174  GLint img, row, col;
1175  if (!tempImage)
1176  return GL_FALSE;
1177  for (img = 0; img < srcDepth; img++) {
1178  GLubyte *dstRow = dstSlices[img];
1179  for (row = 0; row < srcHeight; row++) {
1180  GLushort *dstUS = (GLushort *) dstRow;
1181  /* check for byteswapped format */
1182  if (dstFormat == MESA_FORMAT_RGB565) {
1183  for (col = 0; col < srcWidth; col++) {
1184  dstUS[col] = PACK_COLOR_565( src[RCOMP],
1185  src[GCOMP],
1186  src[BCOMP] );
1187  src += 3;
1188  }
1189  }
1190  else {
1191  for (col = 0; col < srcWidth; col++) {
1192  dstUS[col] = PACK_COLOR_565_REV( src[RCOMP],
1193  src[GCOMP],
1194  src[BCOMP] );
1195  src += 3;
1196  }
1197  }
1198  dstRow += dstRowStride;
1199  }
1200  }
1201  free((void *) tempImage);
1202  }
1203  return GL_TRUE;
1204 }
1205 
1206 
1210 static GLboolean
1212 {
1213  const GLboolean littleEndian = _mesa_little_endian();
1214  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1215 
1216  ASSERT(dstFormat == MESA_FORMAT_RGBA8888 ||
1217  dstFormat == MESA_FORMAT_RGBA8888_REV ||
1218  dstFormat == MESA_FORMAT_RGBX8888 ||
1219  dstFormat == MESA_FORMAT_RGBX8888_REV);
1220  ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
1221 
1222  if (!ctx->_ImageTransferState &&
1223  !srcPacking->SwapBytes &&
1224  (dstFormat == MESA_FORMAT_RGBA8888 ||
1225  dstFormat == MESA_FORMAT_RGBX8888) &&
1226  baseInternalFormat == GL_RGBA &&
1227  ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
1228  (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
1229  (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
1230  (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && littleEndian))) {
1231  /* simple memcpy path */
1232  memcpy_texture(ctx, dims,
1233  dstFormat,
1234  dstRowStride, dstSlices,
1235  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1236  srcAddr, srcPacking);
1237  }
1238  else if (!ctx->_ImageTransferState &&
1239  !srcPacking->SwapBytes &&
1240  (dstFormat == MESA_FORMAT_RGBA8888_REV ||
1241  dstFormat == MESA_FORMAT_RGBX8888_REV) &&
1242  baseInternalFormat == GL_RGBA &&
1243  ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
1244  (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||
1245  (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
1246  (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {
1247  /* simple memcpy path */
1248  memcpy_texture(ctx, dims,
1249  dstFormat,
1250  dstRowStride, dstSlices,
1251  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1252  srcAddr, srcPacking);
1253  }
1254  else if (!ctx->_ImageTransferState &&
1255  (srcType == GL_UNSIGNED_BYTE ||
1256  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
1257  srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
1258  can_swizzle(baseInternalFormat) &&
1259  can_swizzle(srcFormat)) {
1260 
1261  GLubyte dstmap[4];
1262 
1263  /* dstmap - how to swizzle from RGBA to dst format:
1264  */
1265  if ((littleEndian && (dstFormat == MESA_FORMAT_RGBA8888 ||
1266  dstFormat == MESA_FORMAT_RGBX8888)) ||
1267  (!littleEndian && (dstFormat == MESA_FORMAT_RGBA8888_REV ||
1268  dstFormat == MESA_FORMAT_RGBX8888_REV))) {
1269  dstmap[3] = 0;
1270  dstmap[2] = 1;
1271  dstmap[1] = 2;
1272  dstmap[0] = 3;
1273  }
1274  else {
1275  dstmap[3] = 3;
1276  dstmap[2] = 2;
1277  dstmap[1] = 1;
1278  dstmap[0] = 0;
1279  }
1280 
1281  _mesa_swizzle_ubyte_image(ctx, dims,
1282  srcFormat,
1283  srcType,
1284  baseInternalFormat,
1285  dstmap, 4,
1286  dstRowStride, dstSlices,
1287  srcWidth, srcHeight, srcDepth, srcAddr,
1288  srcPacking);
1289  }
1290  else {
1291  /* general path */
1292  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1293  baseInternalFormat,
1294  baseFormat,
1295  srcWidth, srcHeight, srcDepth,
1296  srcFormat, srcType, srcAddr,
1297  srcPacking);
1298  const GLubyte *src = tempImage;
1299  GLint img, row, col;
1300  if (!tempImage)
1301  return GL_FALSE;
1302  for (img = 0; img < srcDepth; img++) {
1303  GLubyte *dstRow = dstSlices[img];
1304  for (row = 0; row < srcHeight; row++) {
1305  GLuint *dstUI = (GLuint *) dstRow;
1306  if (dstFormat == MESA_FORMAT_RGBA8888 ||
1307  dstFormat == MESA_FORMAT_RGBX8888) {
1308  for (col = 0; col < srcWidth; col++) {
1309  dstUI[col] = PACK_COLOR_8888( src[RCOMP],
1310  src[GCOMP],
1311  src[BCOMP],
1312  src[ACOMP] );
1313  src += 4;
1314  }
1315  }
1316  else {
1317  for (col = 0; col < srcWidth; col++) {
1318  dstUI[col] = PACK_COLOR_8888_REV( src[RCOMP],
1319  src[GCOMP],
1320  src[BCOMP],
1321  src[ACOMP] );
1322  src += 4;
1323  }
1324  }
1325  dstRow += dstRowStride;
1326  }
1327  }
1328  free((void *) tempImage);
1329  }
1330  return GL_TRUE;
1331 }
1332 
1333 
1334 static GLboolean
1336 {
1337  const GLboolean littleEndian = _mesa_little_endian();
1338  const GLenum baseFormat = GL_RGBA;
1339 
1340  ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
1341  dstFormat == MESA_FORMAT_ARGB8888_REV ||
1342  dstFormat == MESA_FORMAT_XRGB8888 ||
1343  dstFormat == MESA_FORMAT_XRGB8888_REV );
1344  ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
1345 
1346  if (!ctx->_ImageTransferState &&
1347  !srcPacking->SwapBytes &&
1348  (dstFormat == MESA_FORMAT_ARGB8888 ||
1349  dstFormat == MESA_FORMAT_XRGB8888) &&
1350  baseInternalFormat == GL_RGBA &&
1351  srcFormat == GL_BGRA &&
1352  ((srcType == GL_UNSIGNED_BYTE && littleEndian) ||
1353  srcType == GL_UNSIGNED_INT_8_8_8_8_REV)) {
1354  /* simple memcpy path (little endian) */
1355  memcpy_texture(ctx, dims,
1356  dstFormat,
1357  dstRowStride, dstSlices,
1358  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1359  srcAddr, srcPacking);
1360  }
1361  else if (!ctx->_ImageTransferState &&
1362  !srcPacking->SwapBytes &&
1363  (dstFormat == MESA_FORMAT_ARGB8888_REV ||
1364  dstFormat == MESA_FORMAT_XRGB8888_REV) &&
1365  baseInternalFormat == GL_RGBA &&
1366  srcFormat == GL_BGRA &&
1367  ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
1368  srcType == GL_UNSIGNED_INT_8_8_8_8)) {
1369  /* simple memcpy path (big endian) */
1370  memcpy_texture(ctx, dims,
1371  dstFormat,
1372  dstRowStride, dstSlices,
1373  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1374  srcAddr, srcPacking);
1375  }
1376  else if (!ctx->_ImageTransferState &&
1377  !srcPacking->SwapBytes &&
1378  (dstFormat == MESA_FORMAT_ARGB8888 ||
1379  dstFormat == MESA_FORMAT_XRGB8888) &&
1380  srcFormat == GL_RGB &&
1381  (baseInternalFormat == GL_RGBA ||
1382  baseInternalFormat == GL_RGB) &&
1383  srcType == GL_UNSIGNED_BYTE) {
1384  int img, row, col;
1385  for (img = 0; img < srcDepth; img++) {
1386  const GLint srcRowStride =
1387  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1388  GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1389  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1390  GLubyte *dstRow = dstSlices[img];
1391  for (row = 0; row < srcHeight; row++) {
1392  GLuint *d4 = (GLuint *) dstRow;
1393  for (col = 0; col < srcWidth; col++) {
1394  d4[col] = PACK_COLOR_8888(0xff,
1395  srcRow[col * 3 + RCOMP],
1396  srcRow[col * 3 + GCOMP],
1397  srcRow[col * 3 + BCOMP]);
1398  }
1399  dstRow += dstRowStride;
1400  srcRow += srcRowStride;
1401  }
1402  }
1403  }
1404  else if (!ctx->_ImageTransferState &&
1405  !srcPacking->SwapBytes &&
1406  dstFormat == MESA_FORMAT_ARGB8888 &&
1407  srcFormat == GL_RGBA &&
1408  baseInternalFormat == GL_RGBA &&
1409  srcType == GL_UNSIGNED_BYTE) {
1410  /* same as above case, but src data has alpha too */
1411  GLint img, row, col;
1412  /* For some reason, streaming copies to write-combined regions
1413  * are extremely sensitive to the characteristics of how the
1414  * source data is retrieved. By reordering the source reads to
1415  * be in-order, the speed of this operation increases by half.
1416  * Strangely the same isn't required for the RGB path, above.
1417  */
1418  for (img = 0; img < srcDepth; img++) {
1419  const GLint srcRowStride =
1420  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1421  GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1422  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1423  GLubyte *dstRow = dstSlices[img];
1424  for (row = 0; row < srcHeight; row++) {
1425  GLuint *d4 = (GLuint *) dstRow;
1426  for (col = 0; col < srcWidth; col++) {
1427  d4[col] = PACK_COLOR_8888(srcRow[col * 4 + ACOMP],
1428  srcRow[col * 4 + RCOMP],
1429  srcRow[col * 4 + GCOMP],
1430  srcRow[col * 4 + BCOMP]);
1431  }
1432  dstRow += dstRowStride;
1433  srcRow += srcRowStride;
1434  }
1435  }
1436  }
1437  else if (!ctx->_ImageTransferState &&
1438  (srcType == GL_UNSIGNED_BYTE ||
1439  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
1440  srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&
1441  can_swizzle(baseInternalFormat) &&
1442  can_swizzle(srcFormat)) {
1443 
1444  GLubyte dstmap[4];
1445 
1446  /* dstmap - how to swizzle from RGBA to dst format:
1447  */
1448  if ((littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
1449  (littleEndian && dstFormat == MESA_FORMAT_XRGB8888) ||
1450  (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
1451  (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV)) {
1452  dstmap[3] = 3; /* alpha */
1453  dstmap[2] = 0; /* red */
1454  dstmap[1] = 1; /* green */
1455  dstmap[0] = 2; /* blue */
1456  }
1457  else {
1458  assert((littleEndian && dstFormat == MESA_FORMAT_ARGB8888_REV) ||
1459  (!littleEndian && dstFormat == MESA_FORMAT_ARGB8888) ||
1460  (littleEndian && dstFormat == MESA_FORMAT_XRGB8888_REV) ||
1461  (!littleEndian && dstFormat == MESA_FORMAT_XRGB8888));
1462  dstmap[3] = 2;
1463  dstmap[2] = 1;
1464  dstmap[1] = 0;
1465  dstmap[0] = 3;
1466  }
1467 
1468  _mesa_swizzle_ubyte_image(ctx, dims,
1469  srcFormat,
1470  srcType,
1471  baseInternalFormat,
1472  dstmap, 4,
1473  dstRowStride,
1474  dstSlices,
1475  srcWidth, srcHeight, srcDepth, srcAddr,
1476  srcPacking);
1477  }
1478  else {
1479  /* general path */
1480  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1481  baseInternalFormat,
1482  baseFormat,
1483  srcWidth, srcHeight, srcDepth,
1484  srcFormat, srcType, srcAddr,
1485  srcPacking);
1486  const GLubyte *src = tempImage;
1487  GLint img, row, col;
1488  if (!tempImage)
1489  return GL_FALSE;
1490  for (img = 0; img < srcDepth; img++) {
1491  GLubyte *dstRow = dstSlices[img];
1492  for (row = 0; row < srcHeight; row++) {
1493  GLuint *dstUI = (GLuint *) dstRow;
1494  if (dstFormat == MESA_FORMAT_ARGB8888) {
1495  for (col = 0; col < srcWidth; col++) {
1496  dstUI[col] = PACK_COLOR_8888( src[ACOMP],
1497  src[RCOMP],
1498  src[GCOMP],
1499  src[BCOMP] );
1500  src += 4;
1501  }
1502  }
1503  else if (dstFormat == MESA_FORMAT_XRGB8888) {
1504  for (col = 0; col < srcWidth; col++) {
1505  dstUI[col] = PACK_COLOR_8888( 0xff,
1506  src[RCOMP],
1507  src[GCOMP],
1508  src[BCOMP] );
1509  src += 4;
1510  }
1511  }
1512  else {
1513  for (col = 0; col < srcWidth; col++) {
1514  dstUI[col] = PACK_COLOR_8888_REV( src[ACOMP],
1515  src[RCOMP],
1516  src[GCOMP],
1517  src[BCOMP] );
1518  src += 4;
1519  }
1520  }
1521  dstRow += dstRowStride;
1522  }
1523  }
1524  free((void *) tempImage);
1525  }
1526  return GL_TRUE;
1527 }
1528 
1529 
1530 static GLboolean
1532 {
1533  const GLboolean littleEndian = _mesa_little_endian();
1534  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1535 
1536  ASSERT(dstFormat == MESA_FORMAT_RGB888);
1537  ASSERT(_mesa_get_format_bytes(dstFormat) == 3);
1538 
1539  if (!ctx->_ImageTransferState &&
1540  !srcPacking->SwapBytes &&
1541  baseInternalFormat == GL_RGB &&
1542  srcFormat == GL_BGR &&
1543  srcType == GL_UNSIGNED_BYTE &&
1544  littleEndian) {
1545  /* simple memcpy path */
1546  memcpy_texture(ctx, dims,
1547  dstFormat,
1548  dstRowStride, dstSlices,
1549  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1550  srcAddr, srcPacking);
1551  }
1552  else if (!ctx->_ImageTransferState &&
1553  !srcPacking->SwapBytes &&
1554  srcFormat == GL_RGBA &&
1555  srcType == GL_UNSIGNED_BYTE) {
1556  /* extract RGB from RGBA */
1557  GLint img, row, col;
1558  for (img = 0; img < srcDepth; img++) {
1559  const GLint srcRowStride =
1560  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1561  GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1562  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1563  GLubyte *dstRow = dstSlices[img];
1564  for (row = 0; row < srcHeight; row++) {
1565  for (col = 0; col < srcWidth; col++) {
1566  dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP];
1567  dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
1568  dstRow[col * 3 + 2] = srcRow[col * 4 + RCOMP];
1569  }
1570  dstRow += dstRowStride;
1571  srcRow += srcRowStride;
1572  }
1573  }
1574  }
1575  else if (!ctx->_ImageTransferState &&
1576  srcType == GL_UNSIGNED_BYTE &&
1577  can_swizzle(baseInternalFormat) &&
1578  can_swizzle(srcFormat)) {
1579 
1580  GLubyte dstmap[4];
1581 
1582  /* dstmap - how to swizzle from RGBA to dst format:
1583  */
1584  dstmap[0] = 2;
1585  dstmap[1] = 1;
1586  dstmap[2] = 0;
1587  dstmap[3] = ONE; /* ? */
1588 
1589  _mesa_swizzle_ubyte_image(ctx, dims,
1590  srcFormat,
1591  srcType,
1592  baseInternalFormat,
1593  dstmap, 3,
1594  dstRowStride, dstSlices,
1595  srcWidth, srcHeight, srcDepth, srcAddr,
1596  srcPacking);
1597  }
1598  else {
1599  /* general path */
1600  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1601  baseInternalFormat,
1602  baseFormat,
1603  srcWidth, srcHeight, srcDepth,
1604  srcFormat, srcType, srcAddr,
1605  srcPacking);
1606  const GLubyte *src = (const GLubyte *) tempImage;
1607  GLint img, row, col;
1608  if (!tempImage)
1609  return GL_FALSE;
1610  for (img = 0; img < srcDepth; img++) {
1611  GLubyte *dstRow = dstSlices[img];
1612  for (row = 0; row < srcHeight; row++) {
1613 #if 0
1614  if (littleEndian) {
1615  for (col = 0; col < srcWidth; col++) {
1616  dstRow[col * 3 + 0] = src[RCOMP];
1617  dstRow[col * 3 + 1] = src[GCOMP];
1618  dstRow[col * 3 + 2] = src[BCOMP];
1619  srcUB += 3;
1620  }
1621  }
1622  else {
1623  for (col = 0; col < srcWidth; col++) {
1624  dstRow[col * 3 + 0] = srcUB[BCOMP];
1625  dstRow[col * 3 + 1] = srcUB[GCOMP];
1626  dstRow[col * 3 + 2] = srcUB[RCOMP];
1627  srcUB += 3;
1628  }
1629  }
1630 #else
1631  for (col = 0; col < srcWidth; col++) {
1632  dstRow[col * 3 + 0] = src[BCOMP];
1633  dstRow[col * 3 + 1] = src[GCOMP];
1634  dstRow[col * 3 + 2] = src[RCOMP];
1635  src += 3;
1636  }
1637 #endif
1638  dstRow += dstRowStride;
1639  }
1640  }
1641  free((void *) tempImage);
1642  }
1643  return GL_TRUE;
1644 }
1645 
1646 
1647 static GLboolean
1649 {
1650  const GLboolean littleEndian = _mesa_little_endian();
1651  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1652 
1653  ASSERT(dstFormat == MESA_FORMAT_BGR888);
1654  ASSERT(_mesa_get_format_bytes(dstFormat) == 3);
1655 
1656  if (!ctx->_ImageTransferState &&
1657  !srcPacking->SwapBytes &&
1658  baseInternalFormat == GL_RGB &&
1659  srcFormat == GL_RGB &&
1660  srcType == GL_UNSIGNED_BYTE &&
1661  littleEndian) {
1662  /* simple memcpy path */
1663  memcpy_texture(ctx, dims,
1664  dstFormat,
1665  dstRowStride, dstSlices,
1666  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1667  srcAddr, srcPacking);
1668  }
1669  else if (!ctx->_ImageTransferState &&
1670  !srcPacking->SwapBytes &&
1671  srcFormat == GL_RGBA &&
1672  srcType == GL_UNSIGNED_BYTE) {
1673  /* extract BGR from RGBA */
1674  int img, row, col;
1675  for (img = 0; img < srcDepth; img++) {
1676  const GLint srcRowStride =
1677  _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1678  GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1679  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1680  GLubyte *dstRow = dstSlices[img];
1681  for (row = 0; row < srcHeight; row++) {
1682  for (col = 0; col < srcWidth; col++) {
1683  dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP];
1684  dstRow[col * 3 + 1] = srcRow[col * 4 + GCOMP];
1685  dstRow[col * 3 + 2] = srcRow[col * 4 + BCOMP];
1686  }
1687  dstRow += dstRowStride;
1688  srcRow += srcRowStride;
1689  }
1690  }
1691  }
1692  else if (!ctx->_ImageTransferState &&
1693  srcType == GL_UNSIGNED_BYTE &&
1694  can_swizzle(baseInternalFormat) &&
1695  can_swizzle(srcFormat)) {
1696 
1697  GLubyte dstmap[4];
1698 
1699  /* dstmap - how to swizzle from RGBA to dst format:
1700  */
1701  dstmap[0] = 0;
1702  dstmap[1] = 1;
1703  dstmap[2] = 2;
1704  dstmap[3] = ONE; /* ? */
1705 
1706  _mesa_swizzle_ubyte_image(ctx, dims,
1707  srcFormat,
1708  srcType,
1709  baseInternalFormat,
1710  dstmap, 3,
1711  dstRowStride, dstSlices,
1712  srcWidth, srcHeight, srcDepth, srcAddr,
1713  srcPacking);
1714  }
1715  else {
1716  /* general path */
1717  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1718  baseInternalFormat,
1719  baseFormat,
1720  srcWidth, srcHeight, srcDepth,
1721  srcFormat, srcType, srcAddr,
1722  srcPacking);
1723  const GLubyte *src = (const GLubyte *) tempImage;
1724  GLint img, row, col;
1725  if (!tempImage)
1726  return GL_FALSE;
1727  for (img = 0; img < srcDepth; img++) {
1728  GLubyte *dstRow = dstSlices[img];
1729  for (row = 0; row < srcHeight; row++) {
1730  for (col = 0; col < srcWidth; col++) {
1731  dstRow[col * 3 + 0] = src[RCOMP];
1732  dstRow[col * 3 + 1] = src[GCOMP];
1733  dstRow[col * 3 + 2] = src[BCOMP];
1734  src += 3;
1735  }
1736  dstRow += dstRowStride;
1737  }
1738  }
1739  free((void *) tempImage);
1740  }
1741  return GL_TRUE;
1742 }
1743 
1744 
1745 static GLboolean
1747 {
1748  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1749 
1750  ASSERT(dstFormat == MESA_FORMAT_ARGB4444 ||
1751  dstFormat == MESA_FORMAT_ARGB4444_REV);
1752  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1753 
1754  if (!ctx->_ImageTransferState &&
1755  !srcPacking->SwapBytes &&
1756  dstFormat == MESA_FORMAT_ARGB4444 &&
1757  baseInternalFormat == GL_RGBA &&
1758  srcFormat == GL_BGRA &&
1759  srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
1760  /* simple memcpy path */
1761  memcpy_texture(ctx, dims,
1762  dstFormat,
1763  dstRowStride, dstSlices,
1764  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1765  srcAddr, srcPacking);
1766  }
1767  else {
1768  /* general path */
1769  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1770  baseInternalFormat,
1771  baseFormat,
1772  srcWidth, srcHeight, srcDepth,
1773  srcFormat, srcType, srcAddr,
1774  srcPacking);
1775  const GLubyte *src = tempImage;
1776  GLint img, row, col;
1777  if (!tempImage)
1778  return GL_FALSE;
1779  for (img = 0; img < srcDepth; img++) {
1780  GLubyte *dstRow = dstSlices[img];
1781  for (row = 0; row < srcHeight; row++) {
1782  GLushort *dstUS = (GLushort *) dstRow;
1783  if (dstFormat == MESA_FORMAT_ARGB4444) {
1784  for (col = 0; col < srcWidth; col++) {
1785  dstUS[col] = PACK_COLOR_4444( src[ACOMP],
1786  src[RCOMP],
1787  src[GCOMP],
1788  src[BCOMP] );
1789  src += 4;
1790  }
1791  }
1792  else {
1793  for (col = 0; col < srcWidth; col++) {
1794  dstUS[col] = PACK_COLOR_4444_REV( src[ACOMP],
1795  src[RCOMP],
1796  src[GCOMP],
1797  src[BCOMP] );
1798  src += 4;
1799  }
1800  }
1801  dstRow += dstRowStride;
1802  }
1803  }
1804  free((void *) tempImage);
1805  }
1806  return GL_TRUE;
1807 }
1808 
1809 static GLboolean
1811 {
1812  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1813 
1814  ASSERT(dstFormat == MESA_FORMAT_RGBA5551);
1815  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1816 
1817  if (!ctx->_ImageTransferState &&
1818  !srcPacking->SwapBytes &&
1819  dstFormat == MESA_FORMAT_RGBA5551 &&
1820  baseInternalFormat == GL_RGBA &&
1821  srcFormat == GL_RGBA &&
1822  srcType == GL_UNSIGNED_SHORT_5_5_5_1) {
1823  /* simple memcpy path */
1824  memcpy_texture(ctx, dims,
1825  dstFormat,
1826  dstRowStride, dstSlices,
1827  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1828  srcAddr, srcPacking);
1829  }
1830  else {
1831  /* general path */
1832  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1833  baseInternalFormat,
1834  baseFormat,
1835  srcWidth, srcHeight, srcDepth,
1836  srcFormat, srcType, srcAddr,
1837  srcPacking);
1838  const GLubyte *src =tempImage;
1839  GLint img, row, col;
1840  if (!tempImage)
1841  return GL_FALSE;
1842  for (img = 0; img < srcDepth; img++) {
1843  GLubyte *dstRow = dstSlices[img];
1844  for (row = 0; row < srcHeight; row++) {
1845  GLushort *dstUS = (GLushort *) dstRow;
1846  for (col = 0; col < srcWidth; col++) {
1847  dstUS[col] = PACK_COLOR_5551( src[RCOMP],
1848  src[GCOMP],
1849  src[BCOMP],
1850  src[ACOMP] );
1851  src += 4;
1852  }
1853  dstRow += dstRowStride;
1854  }
1855  }
1856  free((void *) tempImage);
1857  }
1858  return GL_TRUE;
1859 }
1860 
1861 static GLboolean
1863 {
1864  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1865 
1866  ASSERT(dstFormat == MESA_FORMAT_ARGB1555 ||
1867  dstFormat == MESA_FORMAT_ARGB1555_REV);
1868  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1869 
1870  if (!ctx->_ImageTransferState &&
1871  !srcPacking->SwapBytes &&
1872  dstFormat == MESA_FORMAT_ARGB1555 &&
1873  baseInternalFormat == GL_RGBA &&
1874  srcFormat == GL_BGRA &&
1875  srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
1876  /* simple memcpy path */
1877  memcpy_texture(ctx, dims,
1878  dstFormat,
1879  dstRowStride, dstSlices,
1880  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1881  srcAddr, srcPacking);
1882  }
1883  else {
1884  /* general path */
1885  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1886  baseInternalFormat,
1887  baseFormat,
1888  srcWidth, srcHeight, srcDepth,
1889  srcFormat, srcType, srcAddr,
1890  srcPacking);
1891  const GLubyte *src =tempImage;
1892  GLint img, row, col;
1893  if (!tempImage)
1894  return GL_FALSE;
1895  for (img = 0; img < srcDepth; img++) {
1896  GLubyte *dstRow = dstSlices[img];
1897  for (row = 0; row < srcHeight; row++) {
1898  GLushort *dstUS = (GLushort *) dstRow;
1899  if (dstFormat == MESA_FORMAT_ARGB1555) {
1900  for (col = 0; col < srcWidth; col++) {
1901  dstUS[col] = PACK_COLOR_1555( src[ACOMP],
1902  src[RCOMP],
1903  src[GCOMP],
1904  src[BCOMP] );
1905  src += 4;
1906  }
1907  }
1908  else {
1909  for (col = 0; col < srcWidth; col++) {
1910  dstUS[col] = PACK_COLOR_1555_REV( src[ACOMP],
1911  src[RCOMP],
1912  src[GCOMP],
1913  src[BCOMP] );
1914  src += 4;
1915  }
1916  }
1917  dstRow += dstRowStride;
1918  }
1919  }
1920  free((void *) tempImage);
1921  }
1922  return GL_TRUE;
1923 }
1924 
1928 static GLboolean
1930 {
1931  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1932 
1933  ASSERT(dstFormat == MESA_FORMAT_AL44);
1934  ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
1935 
1936  {
1937  /* general path */
1938  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1939  baseInternalFormat,
1940  baseFormat,
1941  srcWidth, srcHeight, srcDepth,
1942  srcFormat, srcType, srcAddr,
1943  srcPacking);
1944  const GLubyte *src = tempImage;
1945  GLint img, row, col;
1946  if (!tempImage)
1947  return GL_FALSE;
1948  for (img = 0; img < srcDepth; img++) {
1949  GLubyte *dstRow = dstSlices[img];
1950  for (row = 0; row < srcHeight; row++) {
1951  GLubyte *dstUS = (GLubyte *) dstRow;
1952  for (col = 0; col < srcWidth; col++) {
1953  /* src[0] is luminance, src[1] is alpha */
1954  dstUS[col] = PACK_COLOR_44( src[1],
1955  src[0] );
1956  src += 2;
1957  }
1958  dstRow += dstRowStride;
1959  }
1960  }
1961  free((void *) tempImage);
1962  }
1963  return GL_TRUE;
1964 }
1965 
1966 
1970 static GLboolean
1972 {
1973  const GLboolean littleEndian = _mesa_little_endian();
1974  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1975 
1976  ASSERT(dstFormat == MESA_FORMAT_AL88 ||
1977  dstFormat == MESA_FORMAT_AL88_REV);
1978  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1979 
1980  if (!ctx->_ImageTransferState &&
1981  !srcPacking->SwapBytes &&
1982  (dstFormat == MESA_FORMAT_AL88 &&
1983  baseInternalFormat == GL_LUMINANCE_ALPHA &&
1984  srcFormat == GL_LUMINANCE_ALPHA) &&
1985  srcType == GL_UNSIGNED_BYTE &&
1986  littleEndian) {
1987  /* simple memcpy path */
1988  memcpy_texture(ctx, dims,
1989  dstFormat,
1990  dstRowStride, dstSlices,
1991  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1992  srcAddr, srcPacking);
1993  }
1994  else if (!ctx->_ImageTransferState &&
1995  littleEndian &&
1996  srcType == GL_UNSIGNED_BYTE &&
1997  can_swizzle(baseInternalFormat) &&
1998  can_swizzle(srcFormat)) {
1999  GLubyte dstmap[4];
2000 
2001  /* dstmap - how to swizzle from RGBA to dst format:
2002  */
2003  if (dstFormat == MESA_FORMAT_AL88 || dstFormat == MESA_FORMAT_AL88_REV) {
2004  if ((littleEndian && dstFormat == MESA_FORMAT_AL88) ||
2005  (!littleEndian && dstFormat == MESA_FORMAT_AL88_REV)) {
2006  dstmap[0] = 0;
2007  dstmap[1] = 3;
2008  }
2009  else {
2010  dstmap[0] = 3;
2011  dstmap[1] = 0;
2012  }
2013  }
2014  dstmap[2] = ZERO; /* ? */
2015  dstmap[3] = ONE; /* ? */
2016 
2017  _mesa_swizzle_ubyte_image(ctx, dims,
2018  srcFormat,
2019  srcType,
2020  baseInternalFormat,
2021  dstmap, 2,
2022  dstRowStride, dstSlices,
2023  srcWidth, srcHeight, srcDepth, srcAddr,
2024  srcPacking);
2025  }
2026  else {
2027  /* general path */
2028  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2029  baseInternalFormat,
2030  baseFormat,
2031  srcWidth, srcHeight, srcDepth,
2032  srcFormat, srcType, srcAddr,
2033  srcPacking);
2034  const GLubyte *src = tempImage;
2035  GLint img, row, col;
2036  if (!tempImage)
2037  return GL_FALSE;
2038  for (img = 0; img < srcDepth; img++) {
2039  GLubyte *dstRow = dstSlices[img];
2040  for (row = 0; row < srcHeight; row++) {
2041  GLushort *dstUS = (GLushort *) dstRow;
2042  if (dstFormat == MESA_FORMAT_AL88) {
2043  for (col = 0; col < srcWidth; col++) {
2044  /* src[0] is luminance (or R), src[1] is alpha (or G) */
2045  dstUS[col] = PACK_COLOR_88( src[1],
2046  src[0] );
2047  src += 2;
2048  }
2049  }
2050  else {
2051  for (col = 0; col < srcWidth; col++) {
2052  /* src[0] is luminance (or R), src[1] is alpha (or G) */
2053  dstUS[col] = PACK_COLOR_88_REV( src[1],
2054  src[0] );
2055  src += 2;
2056  }
2057  }
2058  dstRow += dstRowStride;
2059  }
2060  }
2061  free((void *) tempImage);
2062  }
2063  return GL_TRUE;
2064 }
2065 
2066 
2070 static GLboolean
2072 {
2073  const GLboolean littleEndian = _mesa_little_endian();
2074  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2075 
2076  ASSERT(dstFormat == MESA_FORMAT_AL1616 ||
2077  dstFormat == MESA_FORMAT_AL1616_REV ||
2078  dstFormat == MESA_FORMAT_RG1616 ||
2079  dstFormat == MESA_FORMAT_RG1616_REV);
2080  ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
2081 
2082  if (!ctx->_ImageTransferState &&
2083  !srcPacking->SwapBytes &&
2084  (dstFormat == MESA_FORMAT_AL1616 &&
2085  baseInternalFormat == GL_LUMINANCE_ALPHA &&
2086  srcFormat == GL_LUMINANCE_ALPHA) &&
2087  srcType == GL_UNSIGNED_SHORT &&
2088  littleEndian) {
2089  /* simple memcpy path */
2090  memcpy_texture(ctx, dims,
2091  dstFormat,
2092  dstRowStride, dstSlices,
2093  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2094  srcAddr, srcPacking);
2095  }
2096  else {
2097  /* general path */
2098  const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
2099  baseInternalFormat,
2100  baseFormat,
2101  srcWidth, srcHeight, srcDepth,
2102  srcFormat, srcType, srcAddr,
2103  srcPacking,
2104  ctx->_ImageTransferState);
2105  const GLfloat *src = tempImage;
2106  GLint img, row, col;
2107  if (!tempImage)
2108  return GL_FALSE;
2109  for (img = 0; img < srcDepth; img++) {
2110  GLubyte *dstRow = dstSlices[img];
2111  for (row = 0; row < srcHeight; row++) {
2112  GLuint *dstUI = (GLuint *) dstRow;
2113  if (dstFormat == MESA_FORMAT_AL1616) {
2114  for (col = 0; col < srcWidth; col++) {
2115  GLushort l, a;
2116 
2117  UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
2118  UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
2119  dstUI[col] = PACK_COLOR_1616(a, l);
2120  src += 2;
2121  }
2122  }
2123  else {
2124  for (col = 0; col < srcWidth; col++) {
2125  GLushort l, a;
2126 
2127  UNCLAMPED_FLOAT_TO_USHORT(l, src[0]);
2128  UNCLAMPED_FLOAT_TO_USHORT(a, src[1]);
2129  dstUI[col] = PACK_COLOR_1616_REV(a, l);
2130  src += 2;
2131  }
2132  }
2133  dstRow += dstRowStride;
2134  }
2135  }
2136  free((void *) tempImage);
2137  }
2138  return GL_TRUE;
2139 }
2140 
2141 
2142 /* Texstore for R16, A16, L16, I16. */
2143 static GLboolean
2145 {
2146  const GLboolean littleEndian = _mesa_little_endian();
2147  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2148 
2149  ASSERT(dstFormat == MESA_FORMAT_R16 ||
2150  dstFormat == MESA_FORMAT_A16 ||
2151  dstFormat == MESA_FORMAT_L16 ||
2152  dstFormat == MESA_FORMAT_I16);
2153  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
2154 
2155  if (!ctx->_ImageTransferState &&
2156  !srcPacking->SwapBytes &&
2157  baseInternalFormat == srcFormat &&
2158  srcType == GL_UNSIGNED_SHORT &&
2159  littleEndian) {
2160  /* simple memcpy path */
2161  memcpy_texture(ctx, dims,
2162  dstFormat,
2163  dstRowStride, dstSlices,
2164  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2165  srcAddr, srcPacking);
2166  }
2167  else {
2168  /* general path */
2169  const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
2170  baseInternalFormat,
2171  baseFormat,
2172  srcWidth, srcHeight, srcDepth,
2173  srcFormat, srcType, srcAddr,
2174  srcPacking,
2175  ctx->_ImageTransferState);
2176  const GLfloat *src = tempImage;
2177  GLint img, row, col;
2178  if (!tempImage)
2179  return GL_FALSE;
2180  for (img = 0; img < srcDepth; img++) {
2181  GLubyte *dstRow = dstSlices[img];
2182  for (row = 0; row < srcHeight; row++) {
2183  GLushort *dstUS = (GLushort *) dstRow;
2184  for (col = 0; col < srcWidth; col++) {
2185  GLushort r;
2186 
2187  UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
2188  dstUS[col] = r;
2189  src += 1;
2190  }
2191  dstRow += dstRowStride;
2192  }
2193  }
2194  free((void *) tempImage);
2195  }
2196  return GL_TRUE;
2197 }
2198 
2199 
2200 static GLboolean
2202 {
2203  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2204 
2205  ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
2206  ASSERT(_mesa_get_format_bytes(dstFormat) == 8);
2207 
2208  if (!ctx->_ImageTransferState &&
2209  !srcPacking->SwapBytes &&
2210  baseInternalFormat == GL_RGBA &&
2211  srcFormat == GL_RGBA &&
2212  srcType == GL_UNSIGNED_SHORT) {
2213  /* simple memcpy path */
2214  memcpy_texture(ctx, dims,
2215  dstFormat,
2216  dstRowStride, dstSlices,
2217  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2218  srcAddr, srcPacking);
2219  }
2220  else {
2221  /* general path */
2222  const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
2223  baseInternalFormat,
2224  baseFormat,
2225  srcWidth, srcHeight, srcDepth,
2226  srcFormat, srcType, srcAddr,
2227  srcPacking,
2228  ctx->_ImageTransferState);
2229  const GLfloat *src = tempImage;
2230  GLint img, row, col;
2231  if (!tempImage)
2232  return GL_FALSE;
2233  for (img = 0; img < srcDepth; img++) {
2234  GLubyte *dstRow = dstSlices[img];
2235  for (row = 0; row < srcHeight; row++) {
2236  GLushort *dstUS = (GLushort *) dstRow;
2237  for (col = 0; col < srcWidth; col++) {
2238  GLushort r, g, b, a;
2239 
2240  UNCLAMPED_FLOAT_TO_USHORT(r, src[0]);
2241  UNCLAMPED_FLOAT_TO_USHORT(g, src[1]);
2242  UNCLAMPED_FLOAT_TO_USHORT(b, src[2]);
2243  UNCLAMPED_FLOAT_TO_USHORT(a, src[3]);
2244  dstUS[col*4+0] = r;
2245  dstUS[col*4+1] = g;
2246  dstUS[col*4+2] = b;
2247  dstUS[col*4+3] = a;
2248  src += 4;
2249  }
2250  dstRow += dstRowStride;
2251  }
2252  }
2253  free((void *) tempImage);
2254  }
2255  return GL_TRUE;
2256 }
2257 
2258 
2259 static GLboolean
2261 {
2262  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2263 
2264  ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGB_16 ||
2265  dstFormat == MESA_FORMAT_SIGNED_RGBA_16);
2266 
2267  if (!ctx->_ImageTransferState &&
2268  !srcPacking->SwapBytes &&
2269  baseInternalFormat == GL_RGBA &&
2270  dstFormat == MESA_FORMAT_SIGNED_RGBA_16 &&
2271  srcFormat == GL_RGBA &&
2272  srcType == GL_SHORT) {
2273  /* simple memcpy path */
2274  memcpy_texture(ctx, dims,
2275  dstFormat,
2276  dstRowStride, dstSlices,
2277  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2278  srcAddr, srcPacking);
2279  }
2280  else {
2281  /* general path */
2282  const GLfloat *tempImage = _mesa_make_temp_float_image(ctx, dims,
2283  baseInternalFormat,
2284  baseFormat,
2285  srcWidth, srcHeight, srcDepth,
2286  srcFormat, srcType, srcAddr,
2287  srcPacking,
2288  ctx->_ImageTransferState);
2289  const GLfloat *src = tempImage;
2290  const GLuint comps = _mesa_get_format_bytes(dstFormat) / 2;
2291  GLint img, row, col;
2292 
2293  if (!tempImage)
2294  return GL_FALSE;
2295 
2296  /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2297  * 3 or 4 components/pixel here.
2298  */
2299  for (img = 0; img < srcDepth; img++) {
2300  GLubyte *dstRow = dstSlices[img];
2301  for (row = 0; row < srcHeight; row++) {
2302  GLshort *dstRowS = (GLshort *) dstRow;
2303  if (dstFormat == MESA_FORMAT_SIGNED_RGBA_16) {
2304  for (col = 0; col < srcWidth; col++) {
2305  GLuint c;
2306  for (c = 0; c < comps; c++) {
2307  GLshort p;
2308  UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 4 + c]);
2309  dstRowS[col * comps + c] = p;
2310  }
2311  }
2312  dstRow += dstRowStride;
2313  src += 4 * srcWidth;
2314  } else {
2315  for (col = 0; col < srcWidth; col++) {
2316  GLuint c;
2317  for (c = 0; c < comps; c++) {
2318  GLshort p;
2319  UNCLAMPED_FLOAT_TO_SHORT(p, src[col * 3 + c]);
2320  dstRowS[col * comps + c] = p;
2321  }
2322  }
2323  dstRow += dstRowStride;
2324  src += 3 * srcWidth;
2325  }
2326  }
2327  }
2328  free((void *) tempImage);
2329  }
2330  return GL_TRUE;
2331 }
2332 
2333 
2334 static GLboolean
2336 {
2337  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2338 
2339  ASSERT(dstFormat == MESA_FORMAT_RGB332);
2340  ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
2341 
2342  if (!ctx->_ImageTransferState &&
2343  !srcPacking->SwapBytes &&
2344  baseInternalFormat == GL_RGB &&
2345  srcFormat == GL_RGB && srcType == GL_UNSIGNED_BYTE_3_3_2) {
2346  /* simple memcpy path */
2347  memcpy_texture(ctx, dims,
2348  dstFormat,
2349  dstRowStride, dstSlices,
2350  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2351  srcAddr, srcPacking);
2352  }
2353  else {
2354  /* general path */
2355  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2356  baseInternalFormat,
2357  baseFormat,
2358  srcWidth, srcHeight, srcDepth,
2359  srcFormat, srcType, srcAddr,
2360  srcPacking);
2361  const GLubyte *src = tempImage;
2362  GLint img, row, col;
2363  if (!tempImage)
2364  return GL_FALSE;
2365  for (img = 0; img < srcDepth; img++) {
2366  GLubyte *dstRow = dstSlices[img];
2367  for (row = 0; row < srcHeight; row++) {
2368  for (col = 0; col < srcWidth; col++) {
2369  dstRow[col] = PACK_COLOR_332( src[RCOMP],
2370  src[GCOMP],
2371  src[BCOMP] );
2372  src += 3;
2373  }
2374  dstRow += dstRowStride;
2375  }
2376  }
2377  free((void *) tempImage);
2378  }
2379  return GL_TRUE;
2380 }
2381 
2382 
2386 static GLboolean
2388 {
2389  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2390 
2391  ASSERT(dstFormat == MESA_FORMAT_A8 ||
2392  dstFormat == MESA_FORMAT_L8 ||
2393  dstFormat == MESA_FORMAT_I8 ||
2394  dstFormat == MESA_FORMAT_R8);
2395  ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
2396 
2397  if (!ctx->_ImageTransferState &&
2398  !srcPacking->SwapBytes &&
2399  baseInternalFormat == srcFormat &&
2400  srcType == GL_UNSIGNED_BYTE) {
2401  /* simple memcpy path */
2402  memcpy_texture(ctx, dims,
2403  dstFormat,
2404  dstRowStride, dstSlices,
2405  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2406  srcAddr, srcPacking);
2407  }
2408  else if (!ctx->_ImageTransferState &&
2409  srcType == GL_UNSIGNED_BYTE &&
2410  can_swizzle(baseInternalFormat) &&
2411  can_swizzle(srcFormat)) {
2412  GLubyte dstmap[4];
2413 
2414  /* dstmap - how to swizzle from RGBA to dst format:
2415  */
2416  if (dstFormat == MESA_FORMAT_A8) {
2417  dstmap[0] = 3;
2418  }
2419  else {
2420  dstmap[0] = 0;
2421  }
2422  dstmap[1] = ZERO; /* ? */
2423  dstmap[2] = ZERO; /* ? */
2424  dstmap[3] = ONE; /* ? */
2425 
2426  _mesa_swizzle_ubyte_image(ctx, dims,
2427  srcFormat,
2428  srcType,
2429  baseInternalFormat,
2430  dstmap, 1,
2431  dstRowStride, dstSlices,
2432  srcWidth, srcHeight, srcDepth, srcAddr,
2433  srcPacking);
2434  }
2435  else {
2436  /* general path */
2437  const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2438  baseInternalFormat,
2439  baseFormat,
2440  srcWidth, srcHeight, srcDepth,
2441  srcFormat, srcType, srcAddr,
2442  srcPacking);
2443  const GLubyte *src = tempImage;
2444  GLint img, row, col;
2445  if (!tempImage)
2446  return GL_FALSE;
2447  for (img = 0; img < srcDepth; img++) {
2448  GLubyte *dstRow = dstSlices[img];
2449  for (row = 0; row < srcHeight; row++) {
2450  for (col = 0; col < srcWidth; col++) {
2451  dstRow[col] = src[col];
2452  }
2453  dstRow += dstRowStride;
2454  src += srcWidth;
2455  }
2456  }
2457  free((void *) tempImage);
2458  }
2459  return GL_TRUE;
2460 }
2461 
2462 
2463 
2467 static GLboolean
2469 {
2470  const GLboolean littleEndian = _mesa_little_endian();
2471 
2472  (void) ctx; (void) dims; (void) baseInternalFormat;
2473 
2474  ASSERT((dstFormat == MESA_FORMAT_YCBCR) ||
2475  (dstFormat == MESA_FORMAT_YCBCR_REV));
2476  ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
2477  ASSERT(ctx->Extensions.MESA_ycbcr_texture);
2478  ASSERT(srcFormat == GL_YCBCR_MESA);
2479  ASSERT((srcType == GL_UNSIGNED_SHORT_8_8_MESA) ||
2480  (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA));
2481  ASSERT(baseInternalFormat == GL_YCBCR_MESA);
2482 
2483  /* always just memcpy since no pixel transfer ops apply */
2484  memcpy_texture(ctx, dims,
2485  dstFormat,
2486  dstRowStride, dstSlices,
2487  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2488  srcAddr, srcPacking);
2489 
2490  /* Check if we need byte swapping */
2491  /* XXX the logic here _might_ be wrong */
2492  if (srcPacking->SwapBytes ^
2493  (srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA) ^
2494  (dstFormat == MESA_FORMAT_YCBCR_REV) ^
2495  !littleEndian) {
2496  GLint img, row;
2497  for (img = 0; img < srcDepth; img++) {
2498  GLubyte *dstRow = dstSlices[img];
2499  for (row = 0; row < srcHeight; row++) {
2500  _mesa_swap2((GLushort *) dstRow, srcWidth);
2501  dstRow += dstRowStride;
2502  }
2503  }
2504  }
2505  return GL_TRUE;
2506 }
2507 
2511 static GLboolean
2513 {
2514  ASSERT(dstFormat == MESA_FORMAT_S8);
2515  ASSERT(srcFormat == GL_STENCIL_INDEX);
2516 
2517  if (!ctx->_ImageTransferState &&
2518  !srcPacking->SwapBytes &&
2519  baseInternalFormat == srcFormat &&
2520  srcType == GL_UNSIGNED_BYTE) {
2521  /* simple memcpy path */
2522  memcpy_texture(ctx, dims,
2523  dstFormat,
2524  dstRowStride, dstSlices,
2525  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2526  srcAddr, srcPacking);
2527  }
2528  else {
2529  const GLint srcRowStride
2530  = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
2531  GLint img, row;
2532 
2533  for (img = 0; img < srcDepth; img++) {
2534  GLubyte *dstRow = dstSlices[img];
2535  const GLubyte *src
2536  = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
2537  srcWidth, srcHeight,
2538  srcFormat, srcType,
2539  img, 0, 0);
2540  for (row = 0; row < srcHeight; row++) {
2542  GLint i;
2543 
2544  /* get the 8-bit stencil values */
2545  _mesa_unpack_stencil_span(ctx, srcWidth,
2546  GL_UNSIGNED_BYTE, /* dst type */
2547  stencil, /* dst addr */
2548  srcType, src, srcPacking,
2549  ctx->_ImageTransferState);
2550  /* merge stencil values into depth values */
2551  for (i = 0; i < srcWidth; i++)
2552  dstRow[i] = stencil[i];
2553 
2554  src += srcRowStride;
2555  dstRow += dstRowStride / sizeof(GLubyte);
2556  }
2557  }
2558 
2559  }
2560 
2561  return GL_TRUE;
2562 }
2563 
2564 
2565 /* non-normalized, signed int8 */
2566 static GLboolean
2568 {
2569  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2570  const GLint components = _mesa_components_in_format(baseFormat);
2571 
2572  ASSERT(dstFormat == MESA_FORMAT_R_INT8 ||
2573  dstFormat == MESA_FORMAT_RG_INT8 ||
2574  dstFormat == MESA_FORMAT_RGB_INT8 ||
2575  dstFormat == MESA_FORMAT_RGBA_INT8 ||
2576  dstFormat == MESA_FORMAT_ALPHA_INT8 ||
2577  dstFormat == MESA_FORMAT_INTENSITY_INT8 ||
2578  dstFormat == MESA_FORMAT_LUMINANCE_INT8 ||
2579  dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT8);
2580  ASSERT(baseInternalFormat == GL_RGBA ||
2581  baseInternalFormat == GL_RGB ||
2582  baseInternalFormat == GL_RG ||
2583  baseInternalFormat == GL_RED ||
2584  baseInternalFormat == GL_ALPHA ||
2585  baseInternalFormat == GL_LUMINANCE ||
2586  baseInternalFormat == GL_LUMINANCE_ALPHA ||
2587  baseInternalFormat == GL_INTENSITY);
2588  ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLbyte));
2589 
2590  /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2591  * to integer formats.
2592  */
2593  if (!srcPacking->SwapBytes &&
2594  baseInternalFormat == srcFormat &&
2595  srcType == GL_BYTE) {
2596  /* simple memcpy path */
2597  memcpy_texture(ctx, dims,
2598  dstFormat,
2599  dstRowStride, dstSlices,
2600  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2601  srcAddr, srcPacking);
2602  }
2603  else {
2604  /* general path */
2605  const GLuint *tempImage = make_temp_uint_image(ctx, dims,
2606  baseInternalFormat,
2607  baseFormat,
2608  srcWidth, srcHeight, srcDepth,
2609  srcFormat, srcType,
2610  srcAddr,
2611  srcPacking);
2612  const GLuint *src = tempImage;
2613  GLint img, row;
2614  if (!tempImage)
2615  return GL_FALSE;
2616  for (img = 0; img < srcDepth; img++) {
2617  GLubyte *dstRow = dstSlices[img];
2618  for (row = 0; row < srcHeight; row++) {
2619  GLbyte *dstTexel = (GLbyte *) dstRow;
2620  GLint i;
2621  for (i = 0; i < srcWidth * components; i++) {
2622  dstTexel[i] = (GLbyte) src[i];
2623  }
2624  dstRow += dstRowStride;
2625  src += srcWidth * components;
2626  }
2627  }
2628 
2629  free((void *) tempImage);
2630  }
2631  return GL_TRUE;
2632 }
2633 
2634 
2635 /* non-normalized, signed int16 */
2636 static GLboolean
2638 {
2639  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2640  const GLint components = _mesa_components_in_format(baseFormat);
2641 
2642  ASSERT(dstFormat == MESA_FORMAT_R_INT16 ||
2643  dstFormat == MESA_FORMAT_RG_INT16 ||
2644  dstFormat == MESA_FORMAT_RGB_INT16 ||
2645  dstFormat == MESA_FORMAT_RGBA_INT16 ||
2646  dstFormat == MESA_FORMAT_ALPHA_INT16 ||
2647  dstFormat == MESA_FORMAT_LUMINANCE_INT16 ||
2648  dstFormat == MESA_FORMAT_INTENSITY_INT16 ||
2649  dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT16);
2650  ASSERT(baseInternalFormat == GL_RGBA ||
2651  baseInternalFormat == GL_RGB ||
2652  baseInternalFormat == GL_RG ||
2653  baseInternalFormat == GL_RED ||
2654  baseInternalFormat == GL_ALPHA ||
2655  baseInternalFormat == GL_LUMINANCE ||
2656  baseInternalFormat == GL_LUMINANCE_ALPHA ||
2657  baseInternalFormat == GL_INTENSITY);
2658  ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLshort));
2659 
2660  /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2661  * to integer formats.
2662  */
2663  if (!srcPacking->SwapBytes &&
2664  baseInternalFormat == srcFormat &&
2665  srcType == GL_SHORT) {
2666  /* simple memcpy path */
2667  memcpy_texture(ctx, dims,
2668  dstFormat,
2669  dstRowStride, dstSlices,
2670  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2671  srcAddr, srcPacking);
2672  }
2673  else {
2674  /* general path */
2675  const GLuint *tempImage = make_temp_uint_image(ctx, dims,
2676  baseInternalFormat,
2677  baseFormat,
2678  srcWidth, srcHeight, srcDepth,
2679  srcFormat, srcType,
2680  srcAddr,
2681  srcPacking);
2682  const GLuint *src = tempImage;
2683  GLint img, row;
2684  if (!tempImage)
2685  return GL_FALSE;
2686  for (img = 0; img < srcDepth; img++) {
2687  GLubyte *dstRow = dstSlices[img];
2688  for (row = 0; row < srcHeight; row++) {
2689  GLshort *dstTexel = (GLshort *) dstRow;
2690  GLint i;
2691  for (i = 0; i < srcWidth * components; i++) {
2692  dstTexel[i] = (GLint) src[i];
2693  }
2694  dstRow += dstRowStride;
2695  src += srcWidth * components;
2696  }
2697  }
2698 
2699  free((void *) tempImage);
2700  }
2701  return GL_TRUE;
2702 }
2703 
2704 
2705 /* non-normalized, signed int32 */
2706 static GLboolean
2708 {
2709  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2710  const GLint components = _mesa_components_in_format(baseFormat);
2711 
2712  ASSERT(dstFormat == MESA_FORMAT_R_INT32 ||
2713  dstFormat == MESA_FORMAT_RG_INT32 ||
2714  dstFormat == MESA_FORMAT_RGB_INT32 ||
2715  dstFormat == MESA_FORMAT_RGBA_INT32 ||
2716  dstFormat == MESA_FORMAT_ALPHA_INT32 ||
2717  dstFormat == MESA_FORMAT_INTENSITY_INT32 ||
2718  dstFormat == MESA_FORMAT_LUMINANCE_INT32 ||
2719  dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT32);
2720  ASSERT(baseInternalFormat == GL_RGBA ||
2721  baseInternalFormat == GL_RGB ||
2722  baseInternalFormat == GL_RG ||
2723  baseInternalFormat == GL_RED ||
2724  baseInternalFormat == GL_ALPHA ||
2725  baseInternalFormat == GL_LUMINANCE ||
2726  baseInternalFormat == GL_LUMINANCE_ALPHA ||
2727  baseInternalFormat == GL_INTENSITY);
2728  ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLint));
2729 
2730  /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2731  * to integer formats.
2732  */
2733  if (!srcPacking->SwapBytes &&
2734  baseInternalFormat == srcFormat &&
2735  srcType == GL_INT) {
2736  /* simple memcpy path */
2737  memcpy_texture(ctx, dims,
2738  dstFormat,
2739  dstRowStride, dstSlices,
2740  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2741  srcAddr, srcPacking);
2742  }
2743  else {
2744  /* general path */
2745  const GLuint *tempImage = make_temp_uint_image(ctx, dims,
2746  baseInternalFormat,
2747  baseFormat,
2748  srcWidth, srcHeight, srcDepth,
2749  srcFormat, srcType,
2750  srcAddr,
2751  srcPacking);
2752  const GLuint *src = tempImage;
2753  GLint img, row;
2754  if (!tempImage)
2755  return GL_FALSE;
2756  for (img = 0; img < srcDepth; img++) {
2757  GLubyte *dstRow = dstSlices[img];
2758  for (row = 0; row < srcHeight; row++) {
2759  GLint *dstTexel = (GLint *) dstRow;
2760  GLint i;
2761  for (i = 0; i < srcWidth * components; i++) {
2762  dstTexel[i] = (GLint) src[i];
2763  }
2764  dstRow += dstRowStride;
2765  src += srcWidth * components;
2766  }
2767  }
2768 
2769  free((void *) tempImage);
2770  }
2771  return GL_TRUE;
2772 }
2773 
2774 
2775 /* non-normalized, unsigned int8 */
2776 static GLboolean
2778 {
2779  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2780  const GLint components = _mesa_components_in_format(baseFormat);
2781 
2782  ASSERT(dstFormat == MESA_FORMAT_R_UINT8 ||
2783  dstFormat == MESA_FORMAT_RG_UINT8 ||
2784  dstFormat == MESA_FORMAT_RGB_UINT8 ||
2785  dstFormat == MESA_FORMAT_RGBA_UINT8 ||
2786  dstFormat == MESA_FORMAT_ALPHA_UINT8 ||
2787  dstFormat == MESA_FORMAT_INTENSITY_UINT8 ||
2788  dstFormat == MESA_FORMAT_LUMINANCE_UINT8 ||
2789  dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT8);
2790  ASSERT(baseInternalFormat == GL_RGBA ||
2791  baseInternalFormat == GL_RGB ||
2792  baseInternalFormat == GL_RG ||
2793  baseInternalFormat == GL_RED ||
2794  baseInternalFormat == GL_ALPHA ||
2795  baseInternalFormat == GL_LUMINANCE ||
2796  baseInternalFormat == GL_LUMINANCE_ALPHA ||
2797  baseInternalFormat == GL_INTENSITY);
2798  ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLubyte));
2799 
2800  /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2801  * to integer formats.
2802  */
2803  if (!srcPacking->SwapBytes &&
2804  baseInternalFormat == srcFormat &&
2805  srcType == GL_UNSIGNED_BYTE) {
2806  /* simple memcpy path */
2807  memcpy_texture(ctx, dims,
2808  dstFormat,
2809  dstRowStride, dstSlices,
2810  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2811  srcAddr, srcPacking);
2812  }
2813  else {
2814  /* general path */
2815  const GLuint *tempImage =
2816  make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
2817  srcWidth, srcHeight, srcDepth,
2818  srcFormat, srcType, srcAddr, srcPacking);
2819  const GLuint *src = tempImage;
2820  GLint img, row;
2821  if (!tempImage)
2822  return GL_FALSE;
2823  for (img = 0; img < srcDepth; img++) {
2824  GLubyte *dstRow = dstSlices[img];
2825  for (row = 0; row < srcHeight; row++) {
2826  GLubyte *dstTexel = (GLubyte *) dstRow;
2827  GLint i;
2828  for (i = 0; i < srcWidth * components; i++) {
2829  dstTexel[i] = (GLubyte) CLAMP(src[i], 0, 0xff);
2830  }
2831  dstRow += dstRowStride;
2832  src += srcWidth * components;
2833  }
2834  }
2835 
2836  free((void *) tempImage);
2837  }
2838  return GL_TRUE;
2839 }
2840 
2841 
2842 /* non-normalized, unsigned int16 */
2843 static GLboolean
2845 {
2846  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2847  const GLint components = _mesa_components_in_format(baseFormat);
2848 
2849  ASSERT(dstFormat == MESA_FORMAT_R_UINT16 ||
2850  dstFormat == MESA_FORMAT_RG_UINT16 ||
2851  dstFormat == MESA_FORMAT_RGB_UINT16 ||
2852  dstFormat == MESA_FORMAT_RGBA_UINT16 ||
2853  dstFormat == MESA_FORMAT_ALPHA_UINT16 ||
2854  dstFormat == MESA_FORMAT_INTENSITY_UINT16 ||
2855  dstFormat == MESA_FORMAT_LUMINANCE_UINT16 ||
2856  dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT16);
2857  ASSERT(baseInternalFormat == GL_RGBA ||
2858  baseInternalFormat == GL_RGB ||
2859  baseInternalFormat == GL_RG ||
2860  baseInternalFormat == GL_RED ||
2861  baseInternalFormat == GL_ALPHA ||
2862  baseInternalFormat == GL_LUMINANCE ||
2863  baseInternalFormat == GL_LUMINANCE_ALPHA ||
2864  baseInternalFormat == GL_INTENSITY);
2865  ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLushort));
2866 
2867  /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2868  * to integer formats.
2869  */
2870  if (!srcPacking->SwapBytes &&
2871  baseInternalFormat == srcFormat &&
2872  srcType == GL_UNSIGNED_SHORT) {
2873  /* simple memcpy path */
2874  memcpy_texture(ctx, dims,
2875  dstFormat,
2876  dstRowStride, dstSlices,
2877  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2878  srcAddr, srcPacking);
2879  }
2880  else {
2881  /* general path */
2882  const GLuint *tempImage =
2883  make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
2884  srcWidth, srcHeight, srcDepth,
2885  srcFormat, srcType, srcAddr, srcPacking);
2886  const GLuint *src = tempImage;
2887  GLint img, row;
2888  if (!tempImage)
2889  return GL_FALSE;
2890  for (img = 0; img < srcDepth; img++) {
2891  GLubyte *dstRow = dstSlices[img];
2892  for (row = 0; row < srcHeight; row++) {
2893  GLushort *dstTexel = (GLushort *) dstRow;
2894  GLint i;
2895  for (i = 0; i < srcWidth * components; i++) {
2896  dstTexel[i] = (GLushort) CLAMP(src[i], 0, 0xffff);
2897  }
2898  dstRow += dstRowStride;
2899  src += srcWidth * components;
2900  }
2901  }
2902 
2903  free((void *) tempImage);
2904  }
2905  return GL_TRUE;
2906 }
2907 
2908 
2909 /* non-normalized, unsigned int32 */
2910 static GLboolean
2912 {
2913  const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2914  const GLint components = _mesa_components_in_format(baseFormat);
2915 
2916  ASSERT(dstFormat == MESA_FORMAT_R_UINT32 ||
2917  dstFormat == MESA_FORMAT_RG_UINT32 ||
2918  dstFormat == MESA_FORMAT_RGB_UINT32 ||
2919  dstFormat == MESA_FORMAT_RGBA_UINT32 ||
2920  dstFormat == MESA_FORMAT_ALPHA_UINT32 ||
2921  dstFormat == MESA_FORMAT_INTENSITY_UINT32 ||
2922  dstFormat == MESA_FORMAT_LUMINANCE_UINT32 ||
2923  dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT32);
2924  ASSERT(baseInternalFormat == GL_RGBA ||
2925  baseInternalFormat == GL_RGB ||
2926  baseInternalFormat == GL_RG ||
2927  baseInternalFormat == GL_RED ||
2928  baseInternalFormat == GL_ALPHA ||
2929  baseInternalFormat == GL_LUMINANCE ||
2930  baseInternalFormat == GL_LUMINANCE_ALPHA ||
2931  baseInternalFormat == GL_INTENSITY);
2932  ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLuint));
2933 
2934  /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
2935  * to integer formats.
2936  */
2937  if (!srcPacking->SwapBytes &&
2938  baseInternalFormat == srcFormat &&
2939  srcType == GL_UNSIGNED_INT) {
2940  /* simple memcpy path */
2941  memcpy_texture(ctx, dims,
2942  dstFormat,
2943  dstRowStride, dstSlices,
2944  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2945  srcAddr, srcPacking);
2946  }
2947  else {
2948  /* general path */
2949  const GLuint *tempImage =
2950  make_temp_uint_image(ctx, dims, baseInternalFormat, baseFormat,
2951  srcWidth, srcHeight, srcDepth,
2952  srcFormat, srcType, srcAddr, srcPacking);
2953  const GLuint *src = tempImage;
2954  GLint img, row;
2955  if (!tempImage)
2956  return GL_FALSE;
2957  for (img = 0; img < srcDepth; img++) {
2958  GLubyte *dstRow = dstSlices[img];
2959  for (row = 0; row < srcHeight; row++) {
2960  GLuint *dstTexel = (GLuint *) dstRow;
2961  GLint i;
2962  for (i = 0; i < srcWidth * components; i++) {
2963  dstTexel[i] = src[i];
2964  }
2965  dstRow += dstRowStride;
2966  src += srcWidth * components;
2967  }
2968  }
2969 
2970  free((void *) tempImage);
2971  }
2972  return GL_TRUE;
2973 }
2974 
2975 static GLboolean
2977 {
2978  (void) ctx; (void) dims;
2979  (void) baseInternalFormat;
2980  (void) dstFormat;
2981  (void) dstRowStride; (void) dstSlices,
2982  (void) srcWidth; (void) srcHeight; (void) srcDepth;
2983  (void) srcFormat; (void) srcType;
2984  (void) srcAddr;
2985  (void) srcPacking;
2986 
2987  /* should never happen */
2988  _mesa_problem(NULL, "_mesa_texstore_null() is called");
2989  return GL_FALSE;
2990 }
2991 
2992 
2996 static StoreTexImageFunc
2998 {
3000  static GLboolean initialized = GL_FALSE;
3001 
3002  if (!initialized) {
3004 
3043 
3050 
3057 
3064 
3071 
3078 
3085 
3086  initialized = GL_TRUE;
3087  }
3088 
3089  ASSERT(table[format]);
3090  return table[format];
3091 }
3092 
3093 
3098 GLboolean
3100 {
3101  StoreTexImageFunc storeImage;
3103 
3104  storeImage = _mesa_get_texstore_func(dstFormat);
3105 
3106  success = storeImage(ctx, dims, baseInternalFormat,
3107  dstFormat,
3108  dstRowStride, dstSlices,
3109  srcWidth, srcHeight, srcDepth,
3110  srcFormat, srcType, srcAddr, srcPacking);
3111  return success;
3112 }
3113 
3114 
3123 static GLbitfield
3124 get_read_write_mode(GLenum userFormat, gl_format texFormat)
3125 {
3127 }
3128 
3129 
3136 static void
3138  struct gl_texture_image *texImage,
3141  GLenum format, GLenum type, const GLvoid *pixels,
3142  const struct gl_pixelstore_attrib *packing,
3143  const char *caller)
3144 
3145 {
3146  const GLbitfield mapMode = get_read_write_mode(format, texImage->TexFormat);
3147  const GLenum target = texImage->TexObject->Target;
3149  GLuint dims, slice, numSlices = 1, sliceOffset = 0;
3150  GLint srcImageStride = 0;
3151  const GLubyte *src;
3152 
3153  assert(xoffset + width <= texImage->Width);
3154  assert(yoffset + height <= texImage->Height);
3155  assert(zoffset + depth <= texImage->Depth);
3156 
3157  switch (target) {
3158  case GL_TEXTURE_1D:
3159  dims = 1;
3160  break;
3161  default:
3162  dims = 2;
3163  }
3164 
3165  /* get pointer to src pixels (may be in a pbo which we'll map here) */
3166  src = (const GLubyte *)pixels;
3167  if (!src)
3168  return;
3169 
3170  /* compute slice info (and do some sanity checks) */
3171  switch (target) {
3172  case GL_TEXTURE_2D:
3173  case GL_TEXTURE_CUBE_MAP:
3174  /* one image slice, nothing special needs to be done */
3175  break;
3176  case GL_TEXTURE_1D:
3177  assert(height == 1);
3178  assert(depth == 1);
3179  assert(yoffset == 0);
3180  assert(zoffset == 0);
3181  break;
3182  default:
3183  _mesa_warning(ctx, "Unexpected target 0x%x in store_texsubimage()", target);
3184  return;
3185  }
3186 
3187  assert(numSlices == 1 || srcImageStride != 0);
3188 
3189  for (slice = 0; slice < numSlices; slice++) {
3190  GLubyte *dstMap;
3191  GLint dstRowStride;
3192 
3193  ctx->Driver.MapTextureImage(ctx, texImage,
3194  slice + sliceOffset,
3195  xoffset, yoffset, width, height,
3196  mapMode, &dstMap, &dstRowStride);
3197  if (dstMap) {
3198  /* Note: we're only storing a 2D (or 1D) slice at a time but we need
3199  * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
3200  * used for 3D images.
3201  */
3202  success = _mesa_texstore(ctx, dims, texImage->_BaseFormat,
3203  texImage->TexFormat,
3204  dstRowStride,
3205  &dstMap,
3206  width, height, 1, /* w, h, d */
3207  format, type, src, packing);
3208 
3209  ctx->Driver.UnmapTextureImage(ctx, texImage, slice + sliceOffset);
3210  }
3211 
3212  src += srcImageStride;
3213 
3214  if (!success)
3215  break;
3216  }
3217 
3218  if (!success)
3219  _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
3220 }
3221 
3222 
3223 
3227 void
3229  struct gl_texture_image *texImage,
3232  GLenum format, GLenum type, const GLvoid *pixels,
3233  const struct gl_pixelstore_attrib *packing)
3234 {
3235  if (width == 0)
3236  return;
3237 
3238  /* allocate storage for texture data */
3239  if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
3240  width, 1, 1)) {
3241  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
3242  return;
3243  }
3244 
3245  store_texsubimage(ctx, texImage,
3246  0, 0, 0, width, 1, 1,
3247  format, type, pixels, packing, "glTexImage1D");
3248 }
3249 
3250 
3254 void
3256  struct gl_texture_image *texImage,
3259  GLenum format, GLenum type, const void *pixels,
3260  const struct gl_pixelstore_attrib *packing)
3261 {
3262  if (width == 0 || height == 0)
3263  return;
3264 
3265  /* allocate storage for texture data */
3266  if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
3267  width, height, 1)) {
3268  _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
3269  return;
3270  }
3271 
3272  store_texsubimage(ctx, texImage,
3273  0, 0, 0, width, height, 1,
3274  format, type, pixels, packing, "glTexImage2D");
3275 }
3276 
3277 
3278 
3279 
3280 /*
3281  * This is the fallback for Driver.TexSubImage1D().
3282  */
3283 void
3285  struct gl_texture_image *texImage,
3287  GLenum format, GLenum type, const void *pixels,
3288  const struct gl_pixelstore_attrib *packing)
3289 {
3290  store_texsubimage(ctx, texImage,
3291  xoffset, 0, 0, width, 1, 1,
3292  format, type, pixels, packing, "glTexSubImage1D");
3293 }
3294 
3295 
3296 
3300 void
3302  struct gl_texture_image *texImage,
3305  GLenum format, GLenum type, const void *pixels,
3306  const struct gl_pixelstore_attrib *packing)
3307 {
3308  store_texsubimage(ctx, texImage,
3309  xoffset, yoffset, 0, width, height, 1,
3310  format, type, pixels, packing, "glTexSubImage2D");
3311 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define MAP1(x)
Definition: texstore.c:113
static const GLubyte * type_mapping(GLenum srcType)
Definition: texstore.c:776
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:656
#define RCOMP
Definition: internal.h:77
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
Definition: get.c:139
gl_format
Definition: formats.h:60
#define GL_RED
Definition: gl.h:480
#define MAX_WIDTH
Definition: config.h:118
static GLboolean _mesa_little_endian(void)
Definition: imports.h:520
#define BCOMP
Definition: internal.h:79
static GLboolean _mesa_texstore_x8_z24(TEXSTORE_PARAMS)
Definition: texstore.c:1002
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
Definition: texstore.c:57
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define GL_RG
Definition: glext.h:1817
#define TEXSTORE_PARAMS
Definition: texstore.h:57
#define GL_FALSE
Definition: gl.h:173
#define free
Definition: debug_ros.c:5
#define GL_ALPHA
Definition: gl.h:483
#define MAP4(x, y, z, w)
Definition: texstore.c:116
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define MAP2(x, y)
Definition: texstore.c:114
static GLboolean _mesa_texstore_rgb565(TEXSTORE_PARAMS)
Definition: texstore.c:1110
#define GL_FLOAT
Definition: gl.h:183
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define assert(x)
Definition: debug.h:53
static GLboolean _mesa_texstore_unorm1616(TEXSTORE_PARAMS)
Definition: texstore.c:2071
static void swap(void *v[], int i, int j)
Definition: quicksort.cc:42
static GLboolean _mesa_texstore_rgba_16(TEXSTORE_PARAMS)
Definition: texstore.c:2201
GLboolean _mesa_texstore(TEXSTORE_PARAMS)
Definition: texstore.c:3099
#define GL_UNSIGNED_SHORT_8_8_MESA
Definition: glext.h:4397
#define GL_BGRA
Definition: gl.h:1485
GLint _mesa_get_format_bytes(gl_format format)
Definition: formats.c:786
GLint GLint GLint yoffset
Definition: gl.h:1547
#define PACK_COLOR_565(X, Y, Z)
Definition: colormac.h:69
#define GL_SHORT
Definition: gl.h:179
GLint GLfloat GLint stencil
Definition: glext.h:6260
GLuint n
Definition: s_context.h:57
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
struct dd_function_table Driver
Definition: mtypes.h:1773
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define PACK_COLOR_88(L, A)
Definition: colormac.h:104
struct gl_texture_object * TexObject
Definition: mtypes.h:907
short GLshort
Definition: gl.h:155
#define GL_TEXTURE_1D
Definition: gl.h:644
#define GL_UNSIGNED_INT_8_8_8_8
Definition: gl.h:1494
void _mesa_store_teximage2d(struct gl_context *ctx, struct gl_texture_image *texImage, GLint internalFormat, GLint width, GLint height, GLint border, GLenum format, GLenum type, const void *pixels, const struct gl_pixelstore_attrib *packing)
Definition: texstore.c:3255
void _mesa_warning(struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:775
#define a
Definition: ke_i.h:78
GLint GLint xoffset
Definition: gl.h:1547
#define CLAMP(f, min, max)
Definition: tif_color.c:179
unsigned char GLboolean
Definition: gl.h:151
void _mesa_unpack_color_span_ubyte(struct gl_context *ctx, GLuint n, GLenum dstFormat, GLubyte dest[], GLenum srcFormat, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking, GLbitfield transferOps)
Definition: pack.c:2988
#define SWZ_CPY(dst, src, count, dstComps, srcComps)
#define PACK_COLOR_1616_REV(L, A)
Definition: colormac.h:113
void _mesa_store_texsubimage1d(struct gl_context *ctx, struct gl_texture_image *texImage, GLint xoffset, GLint width, GLenum format, GLenum type, const void *pixels, const struct gl_pixelstore_attrib *packing)
Definition: texstore.c:3284
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:47
static void swizzle_copy(GLubyte *dst, GLuint dstComponents, const GLubyte *src, GLuint srcComponents, const GLubyte *map, GLuint count)
Definition: texstore.c:654
#define PACK_COLOR_565_REV(X, Y, Z)
Definition: colormac.h:72
static GLboolean _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
Definition: texstore.c:2260
smooth NULL
Definition: ftsmooth.c:557
#define ACOMP
Definition: internal.h:80
#define GL_BGR
Definition: gl.h:1484
#define GL_ABGR_EXT
Definition: glext.h:2403
void _mesa_swap2(GLushort *p, GLuint n)
Definition: image.c:70
Definition: texstore.c:56
gl_format TexFormat
Definition: mtypes.h:893
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define GL_UNSIGNED_SHORT_1_5_5_5_REV
Definition: gl.h:1493
#define PACK_COLOR_4444_REV(R, G, B, A)
Definition: colormac.h:98
#define PACK_COLOR_5551(R, G, B, A)
Definition: colormac.h:75
#define PACK_COLOR_4444(R, G, B, A)
Definition: colormac.h:95
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
static GLboolean _mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
Definition: texstore.c:2567
static int get_map_idx(GLenum value)
Definition: texstore.c:210
static GLboolean _mesa_texstore_null(TEXSTORE_PARAMS)
Definition: texstore.c:2976
static GLboolean _mesa_texstore_z24_x8(TEXSTORE_PARAMS)
Definition: texstore.c:1032
#define b
Definition: ke_i.h:79
float GLfloat
Definition: gl.h:161
#define GL_MAP_WRITE_BIT
Definition: glext.h:1794
static GLuint * make_temp_uint_image(struct gl_context *ctx, GLuint dims, GLenum logicalBaseFormat, GLenum textureBaseFormat, GLint srcWidth, GLint srcHeight, GLint srcDepth, GLenum srcFormat, GLenum srcType, const GLvoid *srcAddr, const struct gl_pixelstore_attrib *srcPacking)
Definition: texstore.c:407
GLvoid * _mesa_image_address(GLuint dimensions, const struct gl_pixelstore_attrib *packing, const GLvoid *image, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint img, GLint row, GLint column)
Definition: image.c:1069
GLubyte to_rgba[6]
Definition: texstore.c:121
r l[0]
Definition: byte_order.h:167
GLboolean GLboolean g
Definition: glext.h:6204
#define GL_UNSIGNED_SHORT_5_6_5
Definition: gl.h:1488
#define GL_UNSIGNED_SHORT_5_5_5_1
Definition: gl.h:1492
static GLboolean _mesa_texstore_s8(TEXSTORE_PARAMS)
Definition: texstore.c:2512
GLboolean SwapBytes
Definition: mtypes.h:1154
#define UNCLAMPED_FLOAT_TO_USHORT(us, f)
Definition: macros.h:131
GLint GLint GLsizei width
Definition: gl.h:1546
static GLboolean _mesa_texstore_z16(TEXSTORE_PARAMS)
Definition: texstore.c:1066
void _mesa_store_texsubimage2d(struct gl_context *ctx, struct gl_texture_image *texImage, GLint xoffset, GLint yoffset, GLint width, GLint height, GLenum format, GLenum type, const void *pixels, const struct gl_pixelstore_attrib *packing)
Definition: texstore.c:3301
GLint GLvoid * img
Definition: gl.h:1956
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define PACK_COLOR_88_REV(L, A)
Definition: colormac.h:107
#define GL_UNSIGNED_SHORT_8_8_REV_MESA
Definition: glext.h:4398
static void _mesa_swizzle_ubyte_image(struct gl_context *ctx, GLuint dimensions, GLenum srcFormat, GLenum srcType, GLenum baseInternalFormat, const GLubyte *rgba2dst, GLuint dstComponents, GLint dstRowStride, GLubyte **dstSlices, GLint srcWidth, GLint srcHeight, GLint srcDepth, const GLvoid *srcAddr, const struct gl_pixelstore_attrib *srcPacking)
Definition: texstore.c:821
GLint _mesa_components_in_format(GLenum format)
Definition: image.c:192
GLint GLint GLsizei GLsizei GLsizei GLint border
Definition: gl.h:1546
static BOOL initialized
Definition: syslog.c:39
unsigned short GLushort
Definition: gl.h:158
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: gl.h:1495
#define GCOMP
Definition: internal.h:78
static StoreTexImageFunc _mesa_get_texstore_func(gl_format format)
Definition: texstore.c:2997
signed char GLbyte
Definition: gl.h:154
static GLboolean _mesa_texstore_z32(TEXSTORE_PARAMS)
Definition: texstore.c:952
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define success(from, fromstr, to, tostr)
Definition: _map.h:44
#define GL_RGB
Definition: gl.h:502
#define GL_STENCIL_INDEX
Definition: gl.h:458
GLenum GLenum GLuint components
Definition: glext.h:9620
#define GL_TEXTURE_CUBE_MAP
Definition: gl.h:1788
static void memcpy_texture(struct gl_context *ctx, GLuint dimensions, gl_format dstFormat, GLint dstRowStride, GLubyte **dstSlices, GLint srcWidth, GLint srcHeight, GLint srcDepth, GLenum srcFormat, GLenum srcType, const GLvoid *srcAddr, const struct gl_pixelstore_attrib *srcPacking)
Definition: texstore.c:901
static GLboolean _mesa_texstore_rgb888(TEXSTORE_PARAMS)
Definition: texstore.c:1531
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
static GLboolean _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS)
Definition: texstore.c:2777
static const GLubyte * byteswap_mapping(GLboolean swapBytes, GLenum srcType)
Definition: texstore.c:797
#define GL_BLUE
Definition: gl.h:482
#define GL_YCBCR_MESA
Definition: glext.h:4399
GLenum _BaseFormat
Definition: mtypes.h:887
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define UNCLAMPED_FLOAT_TO_SHORT(s, f)
Definition: macros.h:136
static void compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map)
Definition: texstore.c:242
static void store_texsubimage(struct gl_context *ctx, struct gl_texture_image *texImage, GLint xoffset, GLint yoffset, GLint zoffset, GLint width, GLint height, GLint depth, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, const char *caller)
Definition: texstore.c:3137
#define PACK_COLOR_8888_REV(X, Y, Z, W)
Definition: colormac.h:63
static GLboolean _mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
Definition: texstore.c:2637
#define PACK_COLOR_1616(L, A)
Definition: colormac.h:110
#define PACK_COLOR_332(R, G, B)
Definition: colormac.h:116
#define GL_UNSIGNED_BYTE_3_3_2
Definition: gl.h:1486
void _mesa_unpack_stencil_span(struct gl_context *ctx, GLuint n, GLenum dstType, GLvoid *dest, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking, GLbitfield transferOps)
Definition: pack.c:3800
unsigned char GLubyte
Definition: gl.h:157
static GLboolean _mesa_texstore_rgb332(TEXSTORE_PARAMS)
Definition: texstore.c:2335
static GLboolean _mesa_texstore_bgr888(TEXSTORE_PARAMS)
Definition: texstore.c:1648
#define GL_BYTE
Definition: gl.h:177
#define GL_LUMINANCE
Definition: gl.h:484
static GLboolean _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS)
Definition: texstore.c:2844
const char * _mesa_lookup_enum_by_nr(int nr)
Definition: enums.c:6332
#define MAP3(x, y, z)
Definition: texstore.c:115
#define GL_DEPTH_COMPONENT
Definition: gl.h:307
unsigned int GLuint
Definition: gl.h:159
#define GL_GREEN
Definition: gl.h:481
static GLboolean _mesa_texstore_unorm16(TEXSTORE_PARAMS)
Definition: texstore.c:2144
GLint GLint GLint GLint zoffset
Definition: gl.h:1547
static GLboolean _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS)
Definition: texstore.c:2911
static GLboolean _mesa_texstore_unorm8(TEXSTORE_PARAMS)
Definition: texstore.c:2387
#define GL_MAP_INVALIDATE_RANGE_BIT
Definition: glext.h:1795
#define GL_TRUE
Definition: gl.h:174
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
#define PACK_COLOR_8888(X, Y, Z, W)
Definition: colormac.h:60
GLboolean(* StoreTexImageFunc)(TEXSTORE_PARAMS)
Definition: texstore.c:64
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
static GLbitfield get_read_write_mode(GLenum userFormat, gl_format texFormat)
Definition: texstore.c:3124
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
GLint _mesa_image_row_stride(const struct gl_pixelstore_attrib *packing, GLint width, GLenum format, GLenum type)
Definition: image.c:1133
unsigned int GLbitfield
Definition: gl.h:152
#define GL_TEXTURE_2D
Definition: gl.h:645
#define GL_UNSIGNED_SHORT_4_4_4_4_REV
Definition: gl.h:1491
static GLboolean _mesa_texstore_rgba5551(TEXSTORE_PARAMS)
Definition: texstore.c:1810
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define PACK_COLOR_1555(A, B, G, R)
Definition: colormac.h:79
static GLboolean _mesa_texstore_unorm44(TEXSTORE_PARAMS)
Definition: texstore.c:1929
static GLboolean _mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
Definition: texstore.c:2707
#define PACK_COLOR_44(L, A)
Definition: colormac.h:101
#define c
Definition: ke_i.h:80
GLint _mesa_image_image_stride(const struct gl_pixelstore_attrib *packing, GLint width, GLint height, GLenum format, GLenum type)
Definition: image.c:1180
static const struct @279 mappings[MAX_IDX]
GLfloat * _mesa_make_temp_float_image(struct gl_context *ctx, GLuint dims, GLenum logicalBaseFormat, GLenum textureBaseFormat, GLint srcWidth, GLint srcHeight, GLint srcDepth, GLenum srcFormat, GLenum srcType, const GLvoid *srcAddr, const struct gl_pixelstore_attrib *srcPacking, GLbitfield transferOps)
Definition: texstore.c:295
#define malloc
Definition: debug_ros.c:4
static const GLubyte map_3210[6]
Definition: texstore.c:768
#define GL_RGBA
Definition: gl.h:503
GLenum _mesa_get_format_base_format(gl_format format)
Definition: formats.c:887
static const GLubyte map_identity[6]
Definition: texstore.c:767
static GLboolean _mesa_texstore_rgba8888(TEXSTORE_PARAMS)
Definition: texstore.c:1211
GLfloat GLfloat p
Definition: glext.h:8902
static GLboolean _mesa_texstore_unorm88(TEXSTORE_PARAMS)
Definition: texstore.c:1971
static GLboolean _mesa_texstore_argb4444(TEXSTORE_PARAMS)
Definition: texstore.c:1746
GLubyte format_idx
Definition: texstore.c:120
#define GL_INTENSITY
Definition: gl.h:747
int k
Definition: mpi.c:3369
GLubyte from_rgba[6]
Definition: texstore.c:122
static GLboolean _mesa_texstore_argb8888(TEXSTORE_PARAMS)
Definition: texstore.c:1335
static GLboolean _mesa_texstore_ycbcr(TEXSTORE_PARAMS)
Definition: texstore.c:2468
void _mesa_unpack_color_span_uint(struct gl_context *ctx, GLuint n, GLenum dstFormat, GLuint *dest, GLenum srcFormat, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking)
Definition: pack.c:3427
void _mesa_store_teximage1d(struct gl_context *ctx, struct gl_texture_image *texImage, GLint internalFormat, GLint width, GLint border, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing)
Definition: texstore.c:3228
void _mesa_unpack_color_span_float(struct gl_context *ctx, GLuint n, GLenum dstFormat, GLfloat dest[], GLenum srcFormat, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking, GLbitfield transferOps)
Definition: pack.c:3229
static GLboolean _mesa_texstore_argb1555(TEXSTORE_PARAMS)
Definition: texstore.c:1862
void _mesa_unpack_depth_span(struct gl_context *ctx, GLuint n, GLenum dstType, GLvoid *dest, GLuint depthMax, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking)
Definition: pack.c:4059
static GLboolean can_swizzle(GLenum logicalBaseFormat)
Definition: texstore.c:72
const GLint const GLsizei GLint
Definition: dispatch.h:5271
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
#define printf
Definition: config.h:203
#define PACK_COLOR_1555_REV(A, B, G, R)
Definition: colormac.h:83
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832
GLbitfield _ImageTransferState
Definition: mtypes.h:1885
GLubyte * _mesa_make_temp_ubyte_image(struct gl_context *ctx, GLuint dims, GLenum logicalBaseFormat, GLenum textureBaseFormat, GLint srcWidth, GLint srcHeight, GLint srcDepth, GLenum srcFormat, GLenum srcType, const GLvoid *srcAddr, const struct gl_pixelstore_attrib *srcPacking)
Definition: texstore.c:536