ReactOS  0.4.12-dev-75-g00dd17e
pack.c File Reference
#include <precomp.h>
#include "pack_tmp.h"
Include dependency graph for pack.c:

Go to the source code of this file.

Macros

#define SRC_TYPE   GLuint
 
#define DST_TYPE   GLuint
 
#define SRC_CONVERT(x)   (x)
 
#define FN_NAME   pack_uint_from_uint_rgba
 
#define DST_TYPE   GLushort
 
#define SRC_CONVERT(x)   MIN2(x, 0xffff)
 
#define FN_NAME   pack_ushort_from_uint_rgba
 
#define DST_TYPE   GLshort
 
#define SRC_CONVERT(x)   CLAMP((int)x, -32768, 32767)
 
#define FN_NAME   pack_short_from_uint_rgba
 
#define DST_TYPE   GLubyte
 
#define SRC_CONVERT(x)   MIN2(x, 0xff)
 
#define FN_NAME   pack_ubyte_from_uint_rgba
 
#define DST_TYPE   GLbyte
 
#define SRC_CONVERT(x)   CLAMP((int)x, -128, 127)
 
#define FN_NAME   pack_byte_from_uint_rgba
 
#define SWAP2BYTE(VALUE)
 
#define SWAP4BYTE(VALUE)
 
#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT_FLT, DEFAULT_INT, TYPE, CONVERSION)
 
#define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT, TYPE, CONVERSION)
 
#define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT)
 

Functions

static void flip_bytes (GLubyte *p, GLuint n)
 
void _mesa_unpack_polygon_stipple (const GLubyte *pattern, GLuint dest[32], const struct gl_pixelstore_attrib *unpacking)
 
void _mesa_pack_polygon_stipple (const GLuint pattern[32], GLubyte *dest, const struct gl_pixelstore_attrib *packing)
 
GLvoid_mesa_unpack_bitmap (GLint width, GLint height, const GLubyte *pixels, const struct gl_pixelstore_attrib *packing)
 
void _mesa_pack_bitmap (GLint width, GLint height, const GLubyte *source, GLubyte *dest, const struct gl_pixelstore_attrib *packing)
 
static void get_component_indexes (GLenum format, GLint *redIndex, GLint *greenIndex, GLint *blueIndex, GLint *alphaIndex, GLint *luminanceIndex, GLint *intensityIndex)
 
static GLboolean get_type_min_max (GLenum type, GLfloat *min, GLfloat *max)
 
void _mesa_pack_rgba_span_int (struct gl_context *ctx, GLuint n, GLuint rgba[][4], GLenum dstFormat, GLenum dstType, GLvoid *dstAddr)
 
void _mesa_pack_rgba_span_float (struct gl_context *ctx, GLuint n, GLfloat rgba[][4], GLenum dstFormat, GLenum dstType, GLvoid *dstAddr, const struct gl_pixelstore_attrib *dstPacking, GLbitfield transferOps)
 
static void extract_uint_indexes (GLuint n, GLuint indexes[], GLenum srcFormat, GLenum srcType, const GLvoid *src, const struct gl_pixelstore_attrib *unpack)
 
static void get_component_mapping (GLenum format, GLint *rSrc, GLint *gSrc, GLint *bSrc, GLint *aSrc, GLint *rDst, GLint *gDst, GLint *bDst, GLint *aDst)
 
static void extract_float_rgba (GLuint n, GLfloat rgba[][4], GLenum srcFormat, GLenum srcType, const GLvoid *src, GLboolean swapBytes)
 
static GLuint clamp_float_to_uint (GLfloat f)
 
static void extract_uint_rgba (GLuint n, GLuint rgba[][4], GLenum srcFormat, GLenum srcType, const GLvoid *src, GLboolean swapBytes)
 
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)
 
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)
 
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)
 
void _mesa_unpack_index_span (struct gl_context *ctx, GLuint n, GLenum dstType, GLvoid *dest, GLenum srcType, const GLvoid *source, const struct gl_pixelstore_attrib *srcPacking, GLbitfield transferOps)
 
void _mesa_pack_index_span (struct gl_context *ctx, GLuint n, GLenum dstType, GLvoid *dest, const GLuint *source, const struct gl_pixelstore_attrib *dstPacking, GLbitfield transferOps)
 
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)
 
void _mesa_pack_stencil_span (struct gl_context *ctx, GLuint n, GLenum dstType, GLvoid *dest, const GLubyte *source, const struct gl_pixelstore_attrib *dstPacking)
 
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)
 
void _mesa_pack_depth_span (struct gl_context *ctx, GLuint n, GLvoid *dest, GLenum dstType, const GLfloat *depthSpan, const struct gl_pixelstore_attrib *dstPacking)
 
void_mesa_unpack_image (GLuint dimensions, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *unpack)
 
void _mesa_rebase_rgba_float (GLuint n, GLfloat rgba[][4], GLenum baseFormat)
 
void _mesa_rebase_rgba_uint (GLuint n, GLuint rgba[][4], GLenum baseFormat)
 

Detailed Description

Image and pixel span packing and unpacking.

Definition in file pack.c.

Macro Definition Documentation

◆ DEPTH_VALUES

#define DEPTH_VALUES (   GLTYPE,
  GLTYPE2FLOAT 
)
Value:
do { \
GLuint i; \
const GLTYPE *src = (const GLTYPE *)source; \
for (i = 0; i < n; i++) { \
GLTYPE value = src[i]; \
if (srcPacking->SwapBytes) { \
if (sizeof(GLTYPE) == 2) { \
SWAP2BYTE(value); \
} else if (sizeof(GLTYPE) == 4) { \
SWAP4BYTE(value); \
} \
} \
depthValues[i] = GLTYPE2FLOAT(value); \
} \
} while (0)
Definition: get.c:139
GLuint n
Definition: s_context.h:57
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14

Definition at line 4031 of file pack.c.

Referenced by _mesa_unpack_depth_span().

◆ DST_TYPE [1/5]

#define DST_TYPE   GLuint

Definition at line 469 of file pack.c.

◆ DST_TYPE [2/5]

#define DST_TYPE   GLushort

Definition at line 469 of file pack.c.

◆ DST_TYPE [3/5]

#define DST_TYPE   GLshort

Definition at line 469 of file pack.c.

◆ DST_TYPE [4/5]

#define DST_TYPE   GLubyte

Definition at line 469 of file pack.c.

◆ DST_TYPE [5/5]

#define DST_TYPE   GLbyte

Definition at line 469 of file pack.c.

◆ FN_NAME [1/5]

#define FN_NAME   pack_uint_from_uint_rgba

Definition at line 471 of file pack.c.

◆ FN_NAME [2/5]

#define FN_NAME   pack_ushort_from_uint_rgba

Definition at line 471 of file pack.c.

◆ FN_NAME [3/5]

#define FN_NAME   pack_short_from_uint_rgba

Definition at line 471 of file pack.c.

◆ FN_NAME [4/5]

#define FN_NAME   pack_ubyte_from_uint_rgba

Definition at line 471 of file pack.c.

◆ FN_NAME [5/5]

#define FN_NAME   pack_byte_from_uint_rgba

Definition at line 471 of file pack.c.

◆ PROCESS [1/2]

#define PROCESS (   SRC_INDEX,
  DST_INDEX,
  DEFAULT_FLT,
  DEFAULT_INT,
  TYPE,
  CONVERSION 
)

◆ PROCESS [2/2]

#define PROCESS (   SRC_INDEX,
  DST_INDEX,
  DEFAULT,
  TYPE,
  CONVERSION 
)
Value:
if ((SRC_INDEX) < 0) { \
GLuint i; \
for (i = 0; i < n; i++) { \
rgba[i][DST_INDEX] = DEFAULT; \
} \
} \
else if (swapBytes) { \
const TYPE *s = (const TYPE *) src; \
GLuint i; \
for (i = 0; i < n; i++) { \
TYPE value = s[SRC_INDEX]; \
if (sizeof(TYPE) == 2) { \
SWAP2BYTE(value); \
} \
else if (sizeof(TYPE) == 4) { \
SWAP4BYTE(value); \
} \
rgba[i][DST_INDEX] = CONVERSION(value); \
s += stride; \
} \
} \
else { \
const TYPE *s = (const TYPE *) src; \
GLuint i; \
for (i = 0; i < n; i++) { \
rgba[i][DST_INDEX] = CONVERSION(s[SRC_INDEX]); \
s += stride; \
} \
}
Definition: get.c:139
GLuint n
Definition: s_context.h:57
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define DEFAULT
Definition: ruserpass.c:31
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLsizei stride
Definition: glext.h:5848
GLdouble s
Definition: gl.h:2039
TYPE
Definition: eventcreate.c:651

◆ SRC_CONVERT [1/5]

#define SRC_CONVERT (   x)    (x)

Definition at line 470 of file pack.c.

Referenced by FN_NAME().

◆ SRC_CONVERT [2/5]

#define SRC_CONVERT (   x)    MIN2(x, 0xffff)

Definition at line 470 of file pack.c.

◆ SRC_CONVERT [3/5]

#define SRC_CONVERT (   x)    CLAMP((int)x, -32768, 32767)

Definition at line 470 of file pack.c.

◆ SRC_CONVERT [4/5]

#define SRC_CONVERT (   x)    MIN2(x, 0xff)

Definition at line 470 of file pack.c.

◆ SRC_CONVERT [5/5]

#define SRC_CONVERT (   x)    CLAMP((int)x, -128, 127)

Definition at line 470 of file pack.c.

◆ SRC_TYPE

#define SRC_TYPE   GLuint

Definition at line 435 of file pack.c.

◆ SWAP2BYTE

#define SWAP2BYTE (   VALUE)
Value:
{ \
GLubyte *bytes = (GLubyte *) &(VALUE); \
GLubyte tmp = bytes[0]; \
bytes[0] = bytes[1]; \
bytes[1] = tmp; \
}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
unsigned char GLubyte
Definition: gl.h:157

Definition at line 1810 of file pack.c.

Referenced by extract_float_rgba(), extract_uint_indexes(), and extract_uint_rgba().

◆ SWAP4BYTE

#define SWAP4BYTE (   VALUE)
Value:
{ \
GLubyte *bytes = (GLubyte *) &(VALUE); \
GLubyte tmp = bytes[0]; \
bytes[0] = bytes[3]; \
bytes[3] = tmp; \
tmp = bytes[1]; \
bytes[1] = bytes[2]; \
bytes[2] = tmp; \
}
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
unsigned char GLubyte
Definition: gl.h:157

Definition at line 1818 of file pack.c.

Referenced by extract_uint_indexes().

Function Documentation

◆ _mesa_pack_bitmap()

void _mesa_pack_bitmap ( GLint  width,
GLint  height,
const GLubyte source,
GLubyte dest,
const struct gl_pixelstore_attrib packing 
)

Definition at line 222 of file pack.c.

Referenced by _mesa_pack_polygon_stipple().

224 {
225  GLint row, width_in_bytes;
226  const GLubyte *src;
227 
228  if (!source)
229  return;
230 
231  width_in_bytes = CEILING( width, 8 );
232  src = source;
233  for (row = 0; row < height; row++) {
234  GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,
235  width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0);
236  if (!dst)
237  return;
238 
239  if ((packing->SkipPixels & 7) == 0) {
240  memcpy( dst, src, width_in_bytes );
241  if (packing->LsbFirst) {
242  flip_bytes( dst, width_in_bytes );
243  }
244  }
245  else {
246  /* handling SkipPixels is a bit tricky (no pun intended!) */
247  GLint i;
248  if (packing->LsbFirst) {
249  GLubyte srcMask = 128;
250  GLubyte dstMask = 1 << (packing->SkipPixels & 0x7);
251  const GLubyte *s = src;
252  GLubyte *d = dst;
253  *d = 0;
254  for (i = 0; i < width; i++) {
255  if (*s & srcMask) {
256  *d |= dstMask;
257  }
258  if (srcMask == 1) {
259  srcMask = 128;
260  s++;
261  }
262  else {
263  srcMask = srcMask >> 1;
264  }
265  if (dstMask == 128) {
266  dstMask = 1;
267  d++;
268  *d = 0;
269  }
270  else {
271  dstMask = dstMask << 1;
272  }
273  }
274  }
275  else {
276  GLubyte srcMask = 128;
277  GLubyte dstMask = 128 >> (packing->SkipPixels & 0x7);
278  const GLubyte *s = src;
279  GLubyte *d = dst;
280  *d = 0;
281  for (i = 0; i < width; i++) {
282  if (*s & srcMask) {
283  *d |= dstMask;
284  }
285  if (srcMask == 1) {
286  srcMask = 128;
287  s++;
288  }
289  else {
290  srcMask = srcMask >> 1;
291  }
292  if (dstMask == 1) {
293  dstMask = 128;
294  d++;
295  *d = 0;
296  }
297  else {
298  dstMask = dstMask >> 1;
299  }
300  }
301  }
302  }
303  src += width_in_bytes;
304  }
305 }
GLint GLint GLsizei width
Definition: gl.h:1546
GLvoid * _mesa_image_address2d(const struct gl_pixelstore_attrib *packing, const GLvoid *image, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint row, GLint column)
Definition: image.c:1098
#define GL_BITMAP
Definition: gl.h:497
GLboolean LsbFirst
Definition: mtypes.h:1155
static void flip_bytes(GLubyte *p, GLuint n)
Definition: pack.c:46
#define CEILING(A, B)
Definition: macros.h:673
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define d
Definition: ke_i.h:81
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
GLuint GLuint dstMask
Definition: glext.h:9513
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
unsigned char GLubyte
Definition: gl.h:157
#define GL_COLOR_INDEX
Definition: gl.h:479
GLsizei GLsizei GLchar * source
Definition: glext.h:6048
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
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

◆ _mesa_pack_depth_span()

void _mesa_pack_depth_span ( struct gl_context ctx,
GLuint  n,
GLvoid dest,
GLenum  dstType,
const GLfloat depthSpan,
const struct gl_pixelstore_attrib dstPacking 
)

Definition at line 4214 of file pack.c.

Referenced by get_tex_depth(), and read_depth_pixels().

4217 {
4218  GLfloat *depthCopy = (GLfloat *) malloc(n * sizeof(GLfloat));
4219  if (!depthCopy) {
4220  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
4221  return;
4222  }
4223 
4224  if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
4225  memcpy(depthCopy, depthSpan, n * sizeof(GLfloat));
4226  _mesa_scale_and_bias_depth(ctx, n, depthCopy);
4227  depthSpan = depthCopy;
4228  }
4229 
4230  switch (dstType) {
4231  case GL_UNSIGNED_BYTE:
4232  {
4233  GLubyte *dst = (GLubyte *) dest;
4234  GLuint i;
4235  for (i = 0; i < n; i++) {
4236  dst[i] = FLOAT_TO_UBYTE( depthSpan[i] );
4237  }
4238  }
4239  break;
4240  case GL_BYTE:
4241  {
4242  GLbyte *dst = (GLbyte *) dest;
4243  GLuint i;
4244  for (i = 0; i < n; i++) {
4245  dst[i] = FLOAT_TO_BYTE( depthSpan[i] );
4246  }
4247  }
4248  break;
4249  case GL_UNSIGNED_SHORT:
4250  {
4251  GLushort *dst = (GLushort *) dest;
4252  GLuint i;
4253  for (i = 0; i < n; i++) {
4254  CLAMPED_FLOAT_TO_USHORT(dst[i], depthSpan[i]);
4255  }
4256  if (dstPacking->SwapBytes) {
4257  _mesa_swap2( (GLushort *) dst, n );
4258  }
4259  }
4260  break;
4261  case GL_SHORT:
4262  {
4263  GLshort *dst = (GLshort *) dest;
4264  GLuint i;
4265  for (i = 0; i < n; i++) {
4266  dst[i] = FLOAT_TO_SHORT( depthSpan[i] );
4267  }
4268  if (dstPacking->SwapBytes) {
4269  _mesa_swap2( (GLushort *) dst, n );
4270  }
4271  }
4272  break;
4273  case GL_UNSIGNED_INT:
4274  {
4275  GLuint *dst = (GLuint *) dest;
4276  GLuint i;
4277  for (i = 0; i < n; i++) {
4278  dst[i] = FLOAT_TO_UINT( depthSpan[i] );
4279  }
4280  if (dstPacking->SwapBytes) {
4281  _mesa_swap4( (GLuint *) dst, n );
4282  }
4283  }
4284  break;
4285  case GL_INT:
4286  {
4287  GLint *dst = (GLint *) dest;
4288  GLuint i;
4289  for (i = 0; i < n; i++) {
4290  dst[i] = FLOAT_TO_INT( depthSpan[i] );
4291  }
4292  if (dstPacking->SwapBytes) {
4293  _mesa_swap4( (GLuint *) dst, n );
4294  }
4295  }
4296  break;
4297  case GL_FLOAT:
4298  {
4299  GLfloat *dst = (GLfloat *) dest;
4300  GLuint i;
4301  for (i = 0; i < n; i++) {
4302  dst[i] = depthSpan[i];
4303  }
4304  if (dstPacking->SwapBytes) {
4305  _mesa_swap4( (GLuint *) dst, n );
4306  }
4307  }
4308  break;
4309  default:
4310  _mesa_problem(ctx, "bad type in _mesa_pack_depth_span");
4311  }
4312 
4313  free(depthCopy);
4314 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define FLOAT_TO_BYTE(X)
Definition: macros.h:54
#define free
Definition: debug_ros.c:5
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct gl_pixel_attrib Pixel
Definition: mtypes.h:1827
short GLshort
Definition: gl.h:155
#define FLOAT_TO_UINT(X)
Definition: macros.h:95
void _mesa_scale_and_bias_depth(const struct gl_context *ctx, GLuint n, GLfloat depthValues[])
void _mesa_swap2(GLushort *p, GLuint n)
Definition: image.c:70
#define GL_UNSIGNED_INT
Definition: gl.h:182
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
float GLfloat
Definition: gl.h:161
#define FLOAT_TO_INT(X)
Definition: macros.h:106
GLboolean SwapBytes
Definition: mtypes.h:1154
unsigned short GLushort
Definition: gl.h:158
signed char GLbyte
Definition: gl.h:154
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void _mesa_swap4(GLuint *p, GLuint n)
Definition: image.c:84
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
#define CLAMPED_FLOAT_TO_USHORT(us, f)
Definition: macros.h:133
unsigned int GLuint
Definition: gl.h:159
#define FLOAT_TO_SHORT(X)
Definition: macros.h:78
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define malloc
Definition: debug_ros.c:4
#define FLOAT_TO_UBYTE(X)
Definition: macros.h:47
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_pack_index_span()

void _mesa_pack_index_span ( struct gl_context ctx,
GLuint  n,
GLenum  dstType,
GLvoid dest,
const GLuint source,
const struct gl_pixelstore_attrib dstPacking,
GLbitfield  transferOps 
)

Definition at line 3677 of file pack.c.

3681 {
3682  GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
3683 
3684  if (!indexes) {
3685  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
3686  return;
3687  }
3688 
3689  transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
3690 
3691  if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) {
3692  /* make a copy of input */
3693  memcpy(indexes, source, n * sizeof(GLuint));
3694  _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
3695  source = indexes;
3696  }
3697 
3698  switch (dstType) {
3699  case GL_UNSIGNED_BYTE:
3700  {
3701  GLubyte *dst = (GLubyte *) dest;
3702  GLuint i;
3703  for (i = 0; i < n; i++) {
3704  *dst++ = (GLubyte) source[i];
3705  }
3706  }
3707  break;
3708  case GL_BYTE:
3709  {
3710  GLbyte *dst = (GLbyte *) dest;
3711  GLuint i;
3712  for (i = 0; i < n; i++) {
3713  dst[i] = (GLbyte) source[i];
3714  }
3715  }
3716  break;
3717  case GL_UNSIGNED_SHORT:
3718  {
3719  GLushort *dst = (GLushort *) dest;
3720  GLuint i;
3721  for (i = 0; i < n; i++) {
3722  dst[i] = (GLushort) source[i];
3723  }
3724  if (dstPacking->SwapBytes) {
3725  _mesa_swap2( (GLushort *) dst, n );
3726  }
3727  }
3728  break;
3729  case GL_SHORT:
3730  {
3731  GLshort *dst = (GLshort *) dest;
3732  GLuint i;
3733  for (i = 0; i < n; i++) {
3734  dst[i] = (GLshort) source[i];
3735  }
3736  if (dstPacking->SwapBytes) {
3737  _mesa_swap2( (GLushort *) dst, n );
3738  }
3739  }
3740  break;
3741  case GL_UNSIGNED_INT:
3742  {
3743  GLuint *dst = (GLuint *) dest;
3744  GLuint i;
3745  for (i = 0; i < n; i++) {
3746  dst[i] = (GLuint) source[i];
3747  }
3748  if (dstPacking->SwapBytes) {
3749  _mesa_swap4( (GLuint *) dst, n );
3750  }
3751  }
3752  break;
3753  case GL_INT:
3754  {
3755  GLint *dst = (GLint *) dest;
3756  GLuint i;
3757  for (i = 0; i < n; i++) {
3758  dst[i] = (GLint) source[i];
3759  }
3760  if (dstPacking->SwapBytes) {
3761  _mesa_swap4( (GLuint *) dst, n );
3762  }
3763  }
3764  break;
3765  case GL_FLOAT:
3766  {
3767  GLfloat *dst = (GLfloat *) dest;
3768  GLuint i;
3769  for (i = 0; i < n; i++) {
3770  dst[i] = (GLfloat) source[i];
3771  }
3772  if (dstPacking->SwapBytes) {
3773  _mesa_swap4( (GLuint *) dst, n );
3774  }
3775  }
3776  break;
3777  default:
3778  _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
3779  }
3780 
3781  free(indexes);
3782 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
void _mesa_apply_ci_transfer_ops(const struct gl_context *ctx, GLbitfield transferOps, GLuint n, GLuint indexes[])
#define free
Definition: debug_ros.c:5
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
short GLshort
Definition: gl.h:155
void _mesa_swap2(GLushort *p, GLuint n)
Definition: image.c:70
#define GL_UNSIGNED_INT
Definition: gl.h:182
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
float GLfloat
Definition: gl.h:161
GLboolean SwapBytes
Definition: mtypes.h:1154
unsigned short GLushort
Definition: gl.h:158
signed char GLbyte
Definition: gl.h:154
#define IMAGE_SHIFT_OFFSET_BIT
Definition: mtypes.h:1573
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void _mesa_swap4(GLuint *p, GLuint n)
Definition: image.c:84
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
unsigned int GLuint
Definition: gl.h:159
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define IMAGE_MAP_COLOR_BIT
Definition: mtypes.h:1574
#define malloc
Definition: debug_ros.c:4
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_pack_polygon_stipple()

void _mesa_pack_polygon_stipple ( const GLuint  pattern[32],
GLubyte dest,
const struct gl_pixelstore_attrib packing 
)

Definition at line 97 of file pack.c.

Referenced by _mesa_PolygonMode().

99 {
100  /* Convert pattern from GLuints to GLubytes to handle big/little
101  * endian differences.
102  */
103  GLubyte ptrn[32*4];
104  GLint i;
105  for (i = 0; i < 32; i++) {
106  ptrn[i * 4 + 0] = (GLubyte) ((pattern[i] >> 24) & 0xff);
107  ptrn[i * 4 + 1] = (GLubyte) ((pattern[i] >> 16) & 0xff);
108  ptrn[i * 4 + 2] = (GLubyte) ((pattern[i] >> 8 ) & 0xff);
109  ptrn[i * 4 + 3] = (GLubyte) ((pattern[i] ) & 0xff);
110  }
111 
112  _mesa_pack_bitmap(32, 32, ptrn, dest, packing);
113 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
void _mesa_pack_bitmap(GLint width, GLint height, const GLubyte *source, GLubyte *dest, const struct gl_pixelstore_attrib *packing)
Definition: pack.c:222
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
unsigned char GLubyte
Definition: gl.h:157
GLubyte * pattern
Definition: glext.h:7787
const GLint const GLsizei GLint
Definition: dispatch.h:5271

◆ _mesa_pack_rgba_span_float()

void _mesa_pack_rgba_span_float ( struct gl_context ctx,
GLuint  n,
GLfloat  rgba[][4],
GLenum  dstFormat,
GLenum  dstType,
GLvoid dstAddr,
const struct gl_pixelstore_attrib dstPacking,
GLbitfield  transferOps 
)

Used to pack an array [][4] of RGBA float colors as specified by the dstFormat, dstType and dstPacking. Used by glReadPixels. Historically, the RGBA values were in [0,1] and rescaled to fit into GLubytes, etc. But with new integer formats, the RGBA values may have any value and we don't always rescale when converting to integers.

Note: the rgba values will be modified by this function when any pixel transfer ops are enabled.

Definition at line 521 of file pack.c.

Referenced by get_tex_rgba_uncompressed(), and slow_read_rgba_pixels().

526 {
527  GLfloat *luminance;
528  const GLint comps = _mesa_components_in_format(dstFormat);
529  const GLboolean intDstFormat = _mesa_is_integer_format(dstFormat);
530  GLuint i;
531 
532  if (dstFormat == GL_LUMINANCE ||
533  dstFormat == GL_LUMINANCE_ALPHA ||
534  dstFormat == GL_LUMINANCE_INTEGER_EXT ||
535  dstFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT) {
536  luminance = (GLfloat *) malloc(n * sizeof(GLfloat));
537  if (!luminance) {
538  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
539  return;
540  }
541  }
542  else {
543  luminance = NULL;
544  }
545 
546  /* EXT_texture_integer specifies no transfer ops on integer
547  * types in the resolved issues section. Just set them to 0
548  * for integer surfaces.
549  */
550  if (intDstFormat)
551  transferOps = 0;
552 
553  if (transferOps) {
554  _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
555  }
556 
557  /*
558  * Component clamping (besides clamping to [0,1] in
559  * _mesa_apply_rgba_transfer_ops()).
560  */
561  if (intDstFormat) {
562  /* clamping to dest type's min/max values */
563  GLfloat min, max;
564  if (get_type_min_max(dstType, &min, &max)) {
565  for (i = 0; i < n; i++) {
566  rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], min, max);
567  rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], min, max);
568  rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], min, max);
569  rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], min, max);
570  }
571  }
572  }
573  else if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
574  /* compute luminance values */
575  if (transferOps & IMAGE_CLAMP_BIT) {
576  for (i = 0; i < n; i++) {
577  GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
578  luminance[i] = CLAMP(sum, 0.0F, 1.0F);
579  }
580  }
581  else {
582  for (i = 0; i < n; i++) {
583  luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
584  }
585  }
586  }
587 
588  /*
589  * Pack/store the pixels. Ugh! Lots of cases!!!
590  */
591  switch (dstType) {
592  case GL_UNSIGNED_BYTE:
593  {
594  GLubyte *dst = (GLubyte *) dstAddr;
595  switch (dstFormat) {
596  case GL_RED:
597  for (i=0;i<n;i++)
598  dst[i] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
599  break;
600  case GL_GREEN:
601  for (i=0;i<n;i++)
602  dst[i] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
603  break;
604  case GL_BLUE:
605  for (i=0;i<n;i++)
606  dst[i] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
607  break;
608  case GL_ALPHA:
609  for (i=0;i<n;i++)
610  dst[i] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
611  break;
612  case GL_LUMINANCE:
613  for (i=0;i<n;i++)
614  dst[i] = FLOAT_TO_UBYTE(luminance[i]);
615  break;
616  case GL_LUMINANCE_ALPHA:
617  for (i=0;i<n;i++) {
618  dst[i*2+0] = FLOAT_TO_UBYTE(luminance[i]);
619  dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
620  }
621  break;
622  case GL_RG:
623  for (i=0;i<n;i++) {
624  dst[i*2+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
625  dst[i*2+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
626  }
627  break;
628  case GL_RGB:
629  for (i=0;i<n;i++) {
630  dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
631  dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
632  dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
633  }
634  break;
635  case GL_RGBA:
636  for (i=0;i<n;i++) {
637  dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
638  dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
639  dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
640  dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
641  }
642  break;
643  case GL_BGR:
644  for (i=0;i<n;i++) {
645  dst[i*3+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
646  dst[i*3+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
647  dst[i*3+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
648  }
649  break;
650  case GL_BGRA:
651  for (i=0;i<n;i++) {
652  dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
653  dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
654  dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
655  dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
656  }
657  break;
658  case GL_ABGR_EXT:
659  for (i=0;i<n;i++) {
660  dst[i*4+0] = FLOAT_TO_UBYTE(rgba[i][ACOMP]);
661  dst[i*4+1] = FLOAT_TO_UBYTE(rgba[i][BCOMP]);
662  dst[i*4+2] = FLOAT_TO_UBYTE(rgba[i][GCOMP]);
663  dst[i*4+3] = FLOAT_TO_UBYTE(rgba[i][RCOMP]);
664  }
665  break;
666  case GL_RED_INTEGER_EXT:
667  for (i=0;i<n;i++) {
668  dst[i] = (GLubyte) rgba[i][RCOMP];
669  }
670  break;
672  for (i=0;i<n;i++) {
673  dst[i] = (GLubyte) rgba[i][GCOMP];
674  }
675  break;
676  case GL_BLUE_INTEGER_EXT:
677  for (i=0;i<n;i++) {
678  dst[i] = (GLubyte) rgba[i][BCOMP];
679  }
680  break;
682  for (i=0;i<n;i++) {
683  dst[i] = (GLubyte) rgba[i][ACOMP];
684  }
685  break;
686  case GL_RG_INTEGER:
687  for (i=0;i<n;i++) {
688  dst[i*2+0] = (GLubyte) rgba[i][RCOMP];
689  dst[i*2+1] = (GLubyte) rgba[i][GCOMP];
690  }
691  break;
692  case GL_RGB_INTEGER_EXT:
693  for (i=0;i<n;i++) {
694  dst[i*3+0] = (GLubyte) rgba[i][RCOMP];
695  dst[i*3+1] = (GLubyte) rgba[i][GCOMP];
696  dst[i*3+2] = (GLubyte) rgba[i][BCOMP];
697  }
698  break;
699  case GL_RGBA_INTEGER_EXT:
700  for (i=0;i<n;i++) {
701  dst[i*4+0] = (GLubyte) rgba[i][RCOMP];
702  dst[i*4+1] = (GLubyte) rgba[i][GCOMP];
703  dst[i*4+2] = (GLubyte) rgba[i][BCOMP];
704  dst[i*4+3] = (GLubyte) rgba[i][ACOMP];
705  }
706  break;
707  case GL_BGR_INTEGER_EXT:
708  for (i=0;i<n;i++) {
709  dst[i*3+0] = (GLubyte) rgba[i][BCOMP];
710  dst[i*3+1] = (GLubyte) rgba[i][GCOMP];
711  dst[i*3+2] = (GLubyte) rgba[i][RCOMP];
712  }
713  break;
714  case GL_BGRA_INTEGER_EXT:
715  for (i=0;i<n;i++) {
716  dst[i*4+0] = (GLubyte) rgba[i][BCOMP];
717  dst[i*4+1] = (GLubyte) rgba[i][GCOMP];
718  dst[i*4+2] = (GLubyte) rgba[i][RCOMP];
719  dst[i*4+3] = (GLubyte) rgba[i][ACOMP];
720  }
721  break;
723  for (i=0;i<n;i++) {
724  dst[i*2+0] = (GLubyte) (rgba[i][RCOMP] +
725  rgba[i][GCOMP] +
726  rgba[i][BCOMP]);
727  dst[i*2+1] = (GLubyte) rgba[i][ACOMP];
728  }
729  break;
731  for (i=0;i<n;i++) {
732  dst[i] = (GLubyte) (rgba[i][RCOMP] +
733  rgba[i][GCOMP] +
734  rgba[i][BCOMP]);
735  }
736  break;
737  default:
738  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
739  }
740  }
741  break;
742  case GL_BYTE:
743  {
744  GLbyte *dst = (GLbyte *) dstAddr;
745  switch (dstFormat) {
746  case GL_RED:
747  for (i=0;i<n;i++)
748  dst[i] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
749  break;
750  case GL_GREEN:
751  for (i=0;i<n;i++)
752  dst[i] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
753  break;
754  case GL_BLUE:
755  for (i=0;i<n;i++)
756  dst[i] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
757  break;
758  case GL_ALPHA:
759  for (i=0;i<n;i++)
760  dst[i] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
761  break;
762  case GL_LUMINANCE:
763  for (i=0;i<n;i++)
764  dst[i] = FLOAT_TO_BYTE(luminance[i]);
765  break;
766  case GL_LUMINANCE_ALPHA:
767  for (i=0;i<n;i++) {
768  dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]);
769  dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
770  }
771  break;
772  case GL_RG:
773  for (i=0;i<n;i++) {
774  dst[i*2+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
775  dst[i*2+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
776  }
777  break;
778  case GL_RGB:
779  for (i=0;i<n;i++) {
780  dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
781  dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
782  dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
783  }
784  break;
785  case GL_RGBA:
786  for (i=0;i<n;i++) {
787  dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
788  dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
789  dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
790  dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
791  }
792  break;
793  case GL_BGR:
794  for (i=0;i<n;i++) {
795  dst[i*3+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
796  dst[i*3+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
797  dst[i*3+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
798  }
799  break;
800  case GL_BGRA:
801  for (i=0;i<n;i++) {
802  dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
803  dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
804  dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
805  dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
806  }
807  break;
808  case GL_ABGR_EXT:
809  for (i=0;i<n;i++) {
810  dst[i*4+0] = FLOAT_TO_BYTE(rgba[i][ACOMP]);
811  dst[i*4+1] = FLOAT_TO_BYTE(rgba[i][BCOMP]);
812  dst[i*4+2] = FLOAT_TO_BYTE(rgba[i][GCOMP]);
813  dst[i*4+3] = FLOAT_TO_BYTE(rgba[i][RCOMP]);
814  }
815  break;
816  case GL_RED_INTEGER_EXT:
817  for (i=0;i<n;i++) {
818  dst[i] = (GLbyte) rgba[i][RCOMP];
819  }
820  break;
822  for (i=0;i<n;i++) {
823  dst[i] = (GLbyte) rgba[i][GCOMP];
824  }
825  break;
826  case GL_BLUE_INTEGER_EXT:
827  for (i=0;i<n;i++) {
828  dst[i] = (GLbyte) rgba[i][BCOMP];
829  }
830  break;
832  for (i=0;i<n;i++) {
833  dst[i] = (GLbyte) rgba[i][ACOMP];
834  }
835  break;
836  case GL_RG_INTEGER:
837  for (i=0;i<n;i++) {
838  dst[i*2+0] = (GLbyte) rgba[i][RCOMP];
839  dst[i*2+1] = (GLbyte) rgba[i][GCOMP];
840  }
841  break;
842  case GL_RGB_INTEGER_EXT:
843  for (i=0;i<n;i++) {
844  dst[i*3+0] = (GLbyte) rgba[i][RCOMP];
845  dst[i*3+1] = (GLbyte) rgba[i][GCOMP];
846  dst[i*3+2] = (GLbyte) rgba[i][BCOMP];
847  }
848  break;
849  case GL_RGBA_INTEGER_EXT:
850  for (i=0;i<n;i++) {
851  dst[i*4+0] = (GLbyte) rgba[i][RCOMP];
852  dst[i*4+1] = (GLbyte) rgba[i][GCOMP];
853  dst[i*4+2] = (GLbyte) rgba[i][BCOMP];
854  dst[i*4+3] = (GLbyte) rgba[i][ACOMP];
855  }
856  break;
857  case GL_BGR_INTEGER_EXT:
858  for (i=0;i<n;i++) {
859  dst[i*3+0] = (GLbyte) rgba[i][BCOMP];
860  dst[i*3+1] = (GLbyte) rgba[i][GCOMP];
861  dst[i*3+2] = (GLbyte) rgba[i][RCOMP];
862  }
863  break;
864  case GL_BGRA_INTEGER_EXT:
865  for (i=0;i<n;i++) {
866  dst[i*4+0] = (GLbyte) rgba[i][BCOMP];
867  dst[i*4+1] = (GLbyte) rgba[i][GCOMP];
868  dst[i*4+2] = (GLbyte) rgba[i][RCOMP];
869  dst[i*4+3] = (GLbyte) rgba[i][ACOMP];
870  }
871  break;
873  for (i=0;i<n;i++) {
874  dst[i*2+0] = (GLbyte) (rgba[i][RCOMP] +
875  rgba[i][GCOMP] +
876  rgba[i][BCOMP]);
877  dst[i*2+1] = (GLbyte) rgba[i][ACOMP];
878  }
879  break;
881  for (i=0;i<n;i++) {
882  dst[i] = (GLbyte) (rgba[i][RCOMP] +
883  rgba[i][GCOMP] +
884  rgba[i][BCOMP]);
885  }
886  break;
887  default:
888  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
889  }
890  }
891  break;
892  case GL_UNSIGNED_SHORT:
893  {
894  GLushort *dst = (GLushort *) dstAddr;
895  switch (dstFormat) {
896  case GL_RED:
897  for (i=0;i<n;i++)
898  CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][RCOMP]);
899  break;
900  case GL_GREEN:
901  for (i=0;i<n;i++)
902  CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][GCOMP]);
903  break;
904  case GL_BLUE:
905  for (i=0;i<n;i++)
906  CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][BCOMP]);
907  break;
908  case GL_ALPHA:
909  for (i=0;i<n;i++)
910  CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][ACOMP]);
911  break;
912  case GL_LUMINANCE:
913  for (i=0;i<n;i++)
914  UNCLAMPED_FLOAT_TO_USHORT(dst[i], luminance[i]);
915  break;
916  case GL_LUMINANCE_ALPHA:
917  for (i=0;i<n;i++) {
918  UNCLAMPED_FLOAT_TO_USHORT(dst[i*2+0], luminance[i]);
919  CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][ACOMP]);
920  }
921  break;
922  case GL_RG:
923  for (i=0;i<n;i++) {
924  CLAMPED_FLOAT_TO_USHORT(dst[i*2+0], rgba[i][RCOMP]);
925  CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][GCOMP]);
926  }
927  break;
928  case GL_RGB:
929  for (i=0;i<n;i++) {
930  CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][RCOMP]);
931  CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
932  CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][BCOMP]);
933  }
934  break;
935  case GL_RGBA:
936  for (i=0;i<n;i++) {
937  CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][RCOMP]);
938  CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
939  CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][BCOMP]);
940  CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
941  }
942  break;
943  case GL_BGR:
944  for (i=0;i<n;i++) {
945  CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][BCOMP]);
946  CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
947  CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][RCOMP]);
948  }
949  break;
950  case GL_BGRA:
951  for (i=0;i<n;i++) {
952  CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][BCOMP]);
953  CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
954  CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][RCOMP]);
955  CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
956  }
957  break;
958  case GL_ABGR_EXT:
959  for (i=0;i<n;i++) {
960  CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][ACOMP]);
961  CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][BCOMP]);
962  CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][GCOMP]);
963  CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][RCOMP]);
964  }
965  break;
966  case GL_RED_INTEGER_EXT:
967  for (i=0;i<n;i++) {
968  dst[i] = (GLushort) rgba[i][RCOMP];
969  }
970  break;
972  for (i=0;i<n;i++) {
973  dst[i] = (GLushort) rgba[i][GCOMP];
974  }
975  break;
976  case GL_BLUE_INTEGER_EXT:
977  for (i=0;i<n;i++) {
978  dst[i] = (GLushort) rgba[i][BCOMP];
979  }
980  break;
982  for (i=0;i<n;i++) {
983  dst[i] = (GLushort) rgba[i][ACOMP];
984  }
985  break;
986  case GL_RG_INTEGER:
987  for (i=0;i<n;i++) {
988  dst[i*2+0] = (GLushort) rgba[i][RCOMP];
989  dst[i*2+1] = (GLushort) rgba[i][GCOMP];
990  }
991  break;
992  case GL_RGB_INTEGER_EXT:
993  for (i=0;i<n;i++) {
994  dst[i*3+0] = (GLushort) rgba[i][RCOMP];
995  dst[i*3+1] = (GLushort) rgba[i][GCOMP];
996  dst[i*3+2] = (GLushort) rgba[i][BCOMP];
997  }
998  break;
999  case GL_RGBA_INTEGER_EXT:
1000  for (i=0;i<n;i++) {
1001  dst[i*4+0] = (GLushort) rgba[i][RCOMP];
1002  dst[i*4+1] = (GLushort) rgba[i][GCOMP];
1003  dst[i*4+2] = (GLushort) rgba[i][BCOMP];
1004  dst[i*4+3] = (GLushort) rgba[i][ACOMP];
1005  }
1006  break;
1007  case GL_BGR_INTEGER_EXT:
1008  for (i=0;i<n;i++) {
1009  dst[i*3+0] = (GLushort) rgba[i][BCOMP];
1010  dst[i*3+1] = (GLushort) rgba[i][GCOMP];
1011  dst[i*3+2] = (GLushort) rgba[i][RCOMP];
1012  }
1013  break;
1014  case GL_BGRA_INTEGER_EXT:
1015  for (i=0;i<n;i++) {
1016  dst[i*4+0] = (GLushort) rgba[i][BCOMP];
1017  dst[i*4+1] = (GLushort) rgba[i][GCOMP];
1018  dst[i*4+2] = (GLushort) rgba[i][RCOMP];
1019  dst[i*4+3] = (GLushort) rgba[i][ACOMP];
1020  }
1021  break;
1023  for (i=0;i<n;i++) {
1024  dst[i*2+0] = (GLushort) (rgba[i][RCOMP] +
1025  rgba[i][GCOMP] +
1026  rgba[i][BCOMP]);
1027  dst[i*2+1] = (GLushort) rgba[i][ACOMP];
1028  }
1029  break;
1031  for (i=0;i<n;i++) {
1032  dst[i] = (GLushort) (rgba[i][RCOMP] +
1033  rgba[i][GCOMP] +
1034  rgba[i][BCOMP]);
1035  }
1036  break;
1037  default:
1038  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
1039  }
1040  }
1041  break;
1042  case GL_SHORT:
1043  {
1044  GLshort *dst = (GLshort *) dstAddr;
1045  switch (dstFormat) {
1046  case GL_RED:
1047  for (i=0;i<n;i++)
1048  dst[i] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1049  break;
1050  case GL_GREEN:
1051  for (i=0;i<n;i++)
1052  dst[i] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1053  break;
1054  case GL_BLUE:
1055  for (i=0;i<n;i++)
1056  dst[i] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
1057  break;
1058  case GL_ALPHA:
1059  for (i=0;i<n;i++)
1060  dst[i] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
1061  break;
1062  case GL_LUMINANCE:
1063  for (i=0;i<n;i++)
1064  dst[i] = FLOAT_TO_SHORT(luminance[i]);
1065  break;
1066  case GL_LUMINANCE_ALPHA:
1067  for (i=0;i<n;i++) {
1068  dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]);
1069  dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
1070  }
1071  break;
1072  case GL_RG:
1073  for (i=0;i<n;i++) {
1074  dst[i*2+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1075  dst[i*2+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1076  }
1077  break;
1078  case GL_RGB:
1079  for (i=0;i<n;i++) {
1080  dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1081  dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1082  dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
1083  }
1084  break;
1085  case GL_RGBA:
1086  for (i=0;i<n;i++) {
1087  dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1088  dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1089  dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
1090  dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
1091  }
1092  break;
1093  case GL_BGR:
1094  for (i=0;i<n;i++) {
1095  dst[i*3+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
1096  dst[i*3+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1097  dst[i*3+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1098  }
1099  break;
1100  case GL_BGRA:
1101  for (i=0;i<n;i++) {
1102  dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
1103  dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1104  dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1105  dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
1106  }
1107  break;
1108  case GL_ABGR_EXT:
1109  for (i=0;i<n;i++) {
1110  dst[i*4+0] = FLOAT_TO_SHORT(rgba[i][ACOMP]);
1111  dst[i*4+1] = FLOAT_TO_SHORT(rgba[i][BCOMP]);
1112  dst[i*4+2] = FLOAT_TO_SHORT(rgba[i][GCOMP]);
1113  dst[i*4+3] = FLOAT_TO_SHORT(rgba[i][RCOMP]);
1114  }
1115  break;
1116  case GL_RED_INTEGER_EXT:
1117  for (i=0;i<n;i++) {
1118  dst[i] = (GLshort) rgba[i][RCOMP];
1119  }
1120  break;
1121  case GL_GREEN_INTEGER_EXT:
1122  for (i=0;i<n;i++) {
1123  dst[i] = (GLshort) rgba[i][GCOMP];
1124  }
1125  break;
1126  case GL_BLUE_INTEGER_EXT:
1127  for (i=0;i<n;i++) {
1128  dst[i] = (GLshort) rgba[i][BCOMP];
1129  }
1130  break;
1131  case GL_ALPHA_INTEGER_EXT:
1132  for (i=0;i<n;i++) {
1133  dst[i] = (GLshort) rgba[i][ACOMP];
1134  }
1135  break;
1136  case GL_RG_INTEGER:
1137  for (i=0;i<n;i++) {
1138  dst[i*2+0] = (GLshort) rgba[i][RCOMP];
1139  dst[i*2+1] = (GLshort) rgba[i][GCOMP];
1140  }
1141  break;
1142  case GL_RGB_INTEGER_EXT:
1143  for (i=0;i<n;i++) {
1144  dst[i*3+0] = (GLshort) rgba[i][RCOMP];
1145  dst[i*3+1] = (GLshort) rgba[i][GCOMP];
1146  dst[i*3+2] = (GLshort) rgba[i][BCOMP];
1147  }
1148  break;
1149  case GL_RGBA_INTEGER_EXT:
1150  for (i=0;i<n;i++) {
1151  dst[i*4+0] = (GLshort) rgba[i][RCOMP];
1152  dst[i*4+1] = (GLshort) rgba[i][GCOMP];
1153  dst[i*4+2] = (GLshort) rgba[i][BCOMP];
1154  dst[i*4+3] = (GLshort) rgba[i][ACOMP];
1155  }
1156  break;
1157  case GL_BGR_INTEGER_EXT:
1158  for (i=0;i<n;i++) {
1159  dst[i*3+0] = (GLshort) rgba[i][BCOMP];
1160  dst[i*3+1] = (GLshort) rgba[i][GCOMP];
1161  dst[i*3+2] = (GLshort) rgba[i][RCOMP];
1162  }
1163  break;
1164  case GL_BGRA_INTEGER_EXT:
1165  for (i=0;i<n;i++) {
1166  dst[i*4+0] = (GLshort) rgba[i][BCOMP];
1167  dst[i*4+1] = (GLshort) rgba[i][GCOMP];
1168  dst[i*4+2] = (GLshort) rgba[i][RCOMP];
1169  dst[i*4+3] = (GLshort) rgba[i][ACOMP];
1170  }
1171  break;
1173  for (i=0;i<n;i++) {
1174  dst[i*2+0] = (GLshort) (rgba[i][RCOMP] +
1175  rgba[i][GCOMP] +
1176  rgba[i][BCOMP]);
1177  dst[i*2+1] = (GLshort) rgba[i][ACOMP];
1178  }
1179  break;
1181  for (i=0;i<n;i++) {
1182  dst[i] = (GLshort) (rgba[i][RCOMP] +
1183  rgba[i][GCOMP] +
1184  rgba[i][BCOMP]);
1185  }
1186  break;
1187  default:
1188  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
1189  }
1190  }
1191  break;
1192  case GL_UNSIGNED_INT:
1193  {
1194  GLuint *dst = (GLuint *) dstAddr;
1195  switch (dstFormat) {
1196  case GL_RED:
1197  for (i=0;i<n;i++)
1198  dst[i] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1199  break;
1200  case GL_GREEN:
1201  for (i=0;i<n;i++)
1202  dst[i] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1203  break;
1204  case GL_BLUE:
1205  for (i=0;i<n;i++)
1206  dst[i] = FLOAT_TO_UINT(rgba[i][BCOMP]);
1207  break;
1208  case GL_ALPHA:
1209  for (i=0;i<n;i++)
1210  dst[i] = FLOAT_TO_UINT(rgba[i][ACOMP]);
1211  break;
1212  case GL_LUMINANCE:
1213  for (i=0;i<n;i++)
1214  dst[i] = FLOAT_TO_UINT(luminance[i]);
1215  break;
1216  case GL_LUMINANCE_ALPHA:
1217  for (i=0;i<n;i++) {
1218  dst[i*2+0] = FLOAT_TO_UINT(luminance[i]);
1219  dst[i*2+1] = FLOAT_TO_UINT(rgba[i][ACOMP]);
1220  }
1221  break;
1222  case GL_RG:
1223  for (i=0;i<n;i++) {
1224  dst[i*2+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1225  dst[i*2+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1226  }
1227  break;
1228  case GL_RGB:
1229  for (i=0;i<n;i++) {
1230  dst[i*3+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1231  dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1232  dst[i*3+2] = FLOAT_TO_UINT(rgba[i][BCOMP]);
1233  }
1234  break;
1235  case GL_RGBA:
1236  for (i=0;i<n;i++) {
1237  dst[i*4+0] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1238  dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1239  dst[i*4+2] = FLOAT_TO_UINT(rgba[i][BCOMP]);
1240  dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]);
1241  }
1242  break;
1243  case GL_BGR:
1244  for (i=0;i<n;i++) {
1245  dst[i*3+0] = FLOAT_TO_UINT(rgba[i][BCOMP]);
1246  dst[i*3+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1247  dst[i*3+2] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1248  }
1249  break;
1250  case GL_BGRA:
1251  for (i=0;i<n;i++) {
1252  dst[i*4+0] = FLOAT_TO_UINT(rgba[i][BCOMP]);
1253  dst[i*4+1] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1254  dst[i*4+2] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1255  dst[i*4+3] = FLOAT_TO_UINT(rgba[i][ACOMP]);
1256  }
1257  break;
1258  case GL_ABGR_EXT:
1259  for (i=0;i<n;i++) {
1260  dst[i*4+0] = FLOAT_TO_UINT(rgba[i][ACOMP]);
1261  dst[i*4+1] = FLOAT_TO_UINT(rgba[i][BCOMP]);
1262  dst[i*4+2] = FLOAT_TO_UINT(rgba[i][GCOMP]);
1263  dst[i*4+3] = FLOAT_TO_UINT(rgba[i][RCOMP]);
1264  }
1265  break;
1266  case GL_RED_INTEGER_EXT:
1267  for (i=0;i<n;i++) {
1268  dst[i] = (GLuint) rgba[i][RCOMP];
1269  }
1270  break;
1271  case GL_GREEN_INTEGER_EXT:
1272  for (i=0;i<n;i++) {
1273  dst[i] = (GLuint) rgba[i][GCOMP];
1274  }
1275  break;
1276  case GL_BLUE_INTEGER_EXT:
1277  for (i=0;i<n;i++) {
1278  dst[i] = (GLuint) rgba[i][BCOMP];
1279  }
1280  break;
1281  case GL_ALPHA_INTEGER_EXT:
1282  for (i=0;i<n;i++) {
1283  dst[i] = (GLuint) rgba[i][ACOMP];
1284  }
1285  break;
1286  case GL_RG_INTEGER:
1287  for (i=0;i<n;i++) {
1288  dst[i*2+0] = (GLuint) rgba[i][RCOMP];
1289  dst[i*2+1] = (GLuint) rgba[i][GCOMP];
1290  }
1291  break;
1292  case GL_RGB_INTEGER_EXT:
1293  for (i=0;i<n;i++) {
1294  dst[i*3+0] = (GLuint) rgba[i][RCOMP];
1295  dst[i*3+1] = (GLuint) rgba[i][GCOMP];
1296  dst[i*3+2] = (GLuint) rgba[i][BCOMP];
1297  }
1298  break;
1299  case GL_RGBA_INTEGER_EXT:
1300  for (i=0;i<n;i++) {
1301  dst[i*4+0] = (GLuint) rgba[i][RCOMP];
1302  dst[i*4+1] = (GLuint) rgba[i][GCOMP];
1303  dst[i*4+2] = (GLuint) rgba[i][BCOMP];
1304  dst[i*4+3] = (GLuint) rgba[i][ACOMP];
1305  }
1306  break;
1307  case GL_BGR_INTEGER_EXT:
1308  for (i=0;i<n;i++) {
1309  dst[i*3+0] = (GLuint) rgba[i][BCOMP];
1310  dst[i*3+1] = (GLuint) rgba[i][GCOMP];
1311  dst[i*3+2] = (GLuint) rgba[i][RCOMP];
1312  }
1313  break;
1314  case GL_BGRA_INTEGER_EXT:
1315  for (i=0;i<n;i++) {
1316  dst[i*4+0] = (GLuint) rgba[i][BCOMP];
1317  dst[i*4+1] = (GLuint) rgba[i][GCOMP];
1318  dst[i*4+2] = (GLuint) rgba[i][RCOMP];
1319  dst[i*4+3] = (GLuint) rgba[i][ACOMP];
1320  }
1321  break;
1323  for (i=0;i<n;i++) {
1324  dst[i*2+0] = (GLuint) (rgba[i][RCOMP] +
1325  rgba[i][GCOMP] +
1326  rgba[i][BCOMP]);
1327  dst[i*2+1] = (GLuint) rgba[i][ACOMP];
1328  }
1329  break;
1331  for (i=0;i<n;i++) {
1332  dst[i] = (GLuint) (rgba[i][RCOMP] +
1333  rgba[i][GCOMP] +
1334  rgba[i][BCOMP]);
1335  }
1336  break;
1337  default:
1338  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
1339  }
1340  }
1341  break;
1342  case GL_INT:
1343  {
1344  GLint *dst = (GLint *) dstAddr;
1345  switch (dstFormat) {
1346  case GL_RED:
1347  for (i=0;i<n;i++)
1348  dst[i] = FLOAT_TO_INT(rgba[i][RCOMP]);
1349  break;
1350  case GL_GREEN:
1351  for (i=0;i<n;i++)
1352  dst[i] = FLOAT_TO_INT(rgba[i][GCOMP]);
1353  break;
1354  case GL_BLUE:
1355  for (i=0;i<n;i++)
1356  dst[i] = FLOAT_TO_INT(rgba[i][BCOMP]);
1357  break;
1358  case GL_ALPHA:
1359  for (i=0;i<n;i++)
1360  dst[i] = FLOAT_TO_INT(rgba[i][ACOMP]);
1361  break;
1362  case GL_LUMINANCE:
1363  for (i=0;i<n;i++)
1364  dst[i] = FLOAT_TO_INT(luminance[i]);
1365  break;
1366  case GL_LUMINANCE_ALPHA:
1367  for (i=0;i<n;i++) {
1368  dst[i*2+0] = FLOAT_TO_INT(luminance[i]);
1369  dst[i*2+1] = FLOAT_TO_INT(rgba[i][ACOMP]);
1370  }
1371  break;
1372  case GL_RG:
1373  for (i=0;i<n;i++) {
1374  dst[i*2+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
1375  dst[i*2+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
1376  }
1377  break;
1378  case GL_RGB:
1379  for (i=0;i<n;i++) {
1380  dst[i*3+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
1381  dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
1382  dst[i*3+2] = FLOAT_TO_INT(rgba[i][BCOMP]);
1383  }
1384  break;
1385  case GL_RGBA:
1386  for (i=0;i<n;i++) {
1387  dst[i*4+0] = FLOAT_TO_INT(rgba[i][RCOMP]);
1388  dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
1389  dst[i*4+2] = FLOAT_TO_INT(rgba[i][BCOMP]);
1390  dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]);
1391  }
1392  break;
1393  case GL_BGR:
1394  for (i=0;i<n;i++) {
1395  dst[i*3+0] = FLOAT_TO_INT(rgba[i][BCOMP]);
1396  dst[i*3+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
1397  dst[i*3+2] = FLOAT_TO_INT(rgba[i][RCOMP]);
1398  }
1399  break;
1400  case GL_BGRA:
1401  for (i=0;i<n;i++) {
1402  dst[i*4+0] = FLOAT_TO_INT(rgba[i][BCOMP]);
1403  dst[i*4+1] = FLOAT_TO_INT(rgba[i][GCOMP]);
1404  dst[i*4+2] = FLOAT_TO_INT(rgba[i][RCOMP]);
1405  dst[i*4+3] = FLOAT_TO_INT(rgba[i][ACOMP]);
1406  }
1407  break;
1408  case GL_ABGR_EXT:
1409  for (i=0;i<n;i++) {
1410  dst[i*4+0] = FLOAT_TO_INT(rgba[i][ACOMP]);
1411  dst[i*4+1] = FLOAT_TO_INT(rgba[i][BCOMP]);
1412  dst[i*4+2] = FLOAT_TO_INT(rgba[i][GCOMP]);
1413  dst[i*4+3] = FLOAT_TO_INT(rgba[i][RCOMP]);
1414  }
1415  break;
1416  case GL_RED_INTEGER_EXT:
1417  for (i=0;i<n;i++) {
1418  dst[i] = (GLint) rgba[i][RCOMP];
1419  }
1420  break;
1421  case GL_GREEN_INTEGER_EXT:
1422  for (i=0;i<n;i++) {
1423  dst[i] = (GLint) rgba[i][GCOMP];
1424  }
1425  break;
1426  case GL_BLUE_INTEGER_EXT:
1427  for (i=0;i<n;i++) {
1428  dst[i] = (GLint) rgba[i][BCOMP];
1429  }
1430  break;
1431  case GL_ALPHA_INTEGER_EXT:
1432  for (i=0;i<n;i++) {
1433  dst[i] = (GLint) rgba[i][ACOMP];
1434  }
1435  break;
1436  case GL_RG_INTEGER:
1437  for (i=0;i<n;i++) {
1438  dst[i*2+0] = (GLint) rgba[i][RCOMP];
1439  dst[i*2+1] = (GLint) rgba[i][GCOMP];
1440  }
1441  break;
1442  case GL_RGB_INTEGER_EXT:
1443  for (i=0;i<n;i++) {
1444  dst[i*3+0] = (GLint) rgba[i][RCOMP];
1445  dst[i*3+1] = (GLint) rgba[i][GCOMP];
1446  dst[i*3+2] = (GLint) rgba[i][BCOMP];
1447  }
1448  break;
1449  case GL_RGBA_INTEGER_EXT:
1450  for (i=0;i<n;i++) {
1451  dst[i*4+0] = (GLint) rgba[i][RCOMP];
1452  dst[i*4+1] = (GLint) rgba[i][GCOMP];
1453  dst[i*4+2] = (GLint) rgba[i][BCOMP];
1454  dst[i*4+3] = (GLint) rgba[i][ACOMP];
1455  }
1456  break;
1457  case GL_BGR_INTEGER_EXT:
1458  for (i=0;i<n;i++) {
1459  dst[i*3+0] = (GLint) rgba[i][BCOMP];
1460  dst[i*3+1] = (GLint) rgba[i][GCOMP];
1461  dst[i*3+2] = (GLint) rgba[i][RCOMP];
1462  }
1463  break;
1464  case GL_BGRA_INTEGER_EXT:
1465  for (i=0;i<n;i++) {
1466  dst[i*4+0] = (GLint) rgba[i][BCOMP];
1467  dst[i*4+1] = (GLint) rgba[i][GCOMP];
1468  dst[i*4+2] = (GLint) rgba[i][RCOMP];
1469  dst[i*4+3] = (GLint) rgba[i][ACOMP];
1470  }
1471  break;
1473  for (i=0;i<n;i++) {
1474  dst[i*2+0] = (GLint) (rgba[i][RCOMP] +
1475  rgba[i][GCOMP] +
1476  rgba[i][BCOMP]);
1477  dst[i*2+1] = (GLint) rgba[i][ACOMP];
1478  }
1479  break;
1481  for (i=0;i<n;i++) {
1482  dst[i] = (GLint) (rgba[i][RCOMP] +
1483  rgba[i][GCOMP] +
1484  rgba[i][BCOMP]);
1485  }
1486  break;
1487  default:
1488  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
1489  }
1490  }
1491  break;
1492  case GL_FLOAT:
1493  {
1494  GLfloat *dst = (GLfloat *) dstAddr;
1495  switch (dstFormat) {
1496  case GL_RED:
1497  for (i=0;i<n;i++)
1498  dst[i] = rgba[i][RCOMP];
1499  break;
1500  case GL_GREEN:
1501  for (i=0;i<n;i++)
1502  dst[i] = rgba[i][GCOMP];
1503  break;
1504  case GL_BLUE:
1505  for (i=0;i<n;i++)
1506  dst[i] = rgba[i][BCOMP];
1507  break;
1508  case GL_ALPHA:
1509  for (i=0;i<n;i++)
1510  dst[i] = rgba[i][ACOMP];
1511  break;
1512  case GL_LUMINANCE:
1513  for (i=0;i<n;i++)
1514  dst[i] = luminance[i];
1515  break;
1516  case GL_LUMINANCE_ALPHA:
1517  for (i=0;i<n;i++) {
1518  dst[i*2+0] = luminance[i];
1519  dst[i*2+1] = rgba[i][ACOMP];
1520  }
1521  break;
1522  case GL_RG:
1523  for (i=0;i<n;i++) {
1524  dst[i*2+0] = rgba[i][RCOMP];
1525  dst[i*2+1] = rgba[i][GCOMP];
1526  }
1527  break;
1528  case GL_RGB:
1529  for (i=0;i<n;i++) {
1530  dst[i*3+0] = rgba[i][RCOMP];
1531  dst[i*3+1] = rgba[i][GCOMP];
1532  dst[i*3+2] = rgba[i][BCOMP];
1533  }
1534  break;
1535  case GL_RGBA:
1536  for (i=0;i<n;i++) {
1537  dst[i*4+0] = rgba[i][RCOMP];
1538  dst[i*4+1] = rgba[i][GCOMP];
1539  dst[i*4+2] = rgba[i][BCOMP];
1540  dst[i*4+3] = rgba[i][ACOMP];
1541  }
1542  break;
1543  case GL_BGR:
1544  for (i=0;i<n;i++) {
1545  dst[i*3+0] = rgba[i][BCOMP];
1546  dst[i*3+1] = rgba[i][GCOMP];
1547  dst[i*3+2] = rgba[i][RCOMP];
1548  }
1549  break;
1550  case GL_BGRA:
1551  for (i=0;i<n;i++) {
1552  dst[i*4+0] = rgba[i][BCOMP];
1553  dst[i*4+1] = rgba[i][GCOMP];
1554  dst[i*4+2] = rgba[i][RCOMP];
1555  dst[i*4+3] = rgba[i][ACOMP];
1556  }
1557  break;
1558  case GL_ABGR_EXT:
1559  for (i=0;i<n;i++) {
1560  dst[i*4+0] = rgba[i][ACOMP];
1561  dst[i*4+1] = rgba[i][BCOMP];
1562  dst[i*4+2] = rgba[i][GCOMP];
1563  dst[i*4+3] = rgba[i][RCOMP];
1564  }
1565  break;
1566  default:
1567  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
1568  }
1569  }
1570  break;
1572  if (dstFormat == GL_RGB) {
1573  GLubyte *dst = (GLubyte *) dstAddr;
1574  for (i=0;i<n;i++) {
1575  dst[i] = (IROUND(rgba[i][RCOMP] * 7.0F) << 5)
1576  | (IROUND(rgba[i][GCOMP] * 7.0F) << 2)
1577  | (IROUND(rgba[i][BCOMP] * 3.0F) );
1578  }
1579  }
1580  break;
1582  if (dstFormat == GL_RGB) {
1583  GLubyte *dst = (GLubyte *) dstAddr;
1584  for (i=0;i<n;i++) {
1585  dst[i] = (IROUND(rgba[i][RCOMP] * 7.0F) )
1586  | (IROUND(rgba[i][GCOMP] * 7.0F) << 3)
1587  | (IROUND(rgba[i][BCOMP] * 3.0F) << 6);
1588  }
1589  }
1590  break;
1592  if (dstFormat == GL_RGB) {
1593  GLushort *dst = (GLushort *) dstAddr;
1594  for (i=0;i<n;i++) {
1595  dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) << 11)
1596  | (IROUND(rgba[i][GCOMP] * 63.0F) << 5)
1597  | (IROUND(rgba[i][BCOMP] * 31.0F) );
1598  }
1599  }
1600  break;
1602  if (dstFormat == GL_RGB) {
1603  GLushort *dst = (GLushort *) dstAddr;
1604  for (i=0;i<n;i++) {
1605  dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) )
1606  | (IROUND(rgba[i][GCOMP] * 63.0F) << 5)
1607  | (IROUND(rgba[i][BCOMP] * 31.0F) << 11);
1608  }
1609  }
1610  break;
1612  if (dstFormat == GL_RGBA) {
1613  GLushort *dst = (GLushort *) dstAddr;
1614  for (i=0;i<n;i++) {
1615  dst[i] = (IROUND(rgba[i][RCOMP] * 15.0F) << 12)
1616  | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
1617  | (IROUND(rgba[i][BCOMP] * 15.0F) << 4)
1618  | (IROUND(rgba[i][ACOMP] * 15.0F) );
1619  }
1620  }
1621  else if (dstFormat == GL_BGRA) {
1622  GLushort *dst = (GLushort *) dstAddr;
1623  for (i=0;i<n;i++) {
1624  dst[i] = (IROUND(rgba[i][BCOMP] * 15.0F) << 12)
1625  | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
1626  | (IROUND(rgba[i][RCOMP] * 15.0F) << 4)
1627  | (IROUND(rgba[i][ACOMP] * 15.0F) );
1628  }
1629  }
1630  else if (dstFormat == GL_ABGR_EXT) {
1631  GLushort *dst = (GLushort *) dstAddr;
1632  for (i=0;i<n;i++) {
1633  dst[i] = (IROUND(rgba[i][ACOMP] * 15.0F) << 12)
1634  | (IROUND(rgba[i][BCOMP] * 15.0F) << 8)
1635  | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
1636  | (IROUND(rgba[i][RCOMP] * 15.0F) );
1637  }
1638  }
1639  break;
1641  if (dstFormat == GL_RGBA) {
1642  GLushort *dst = (GLushort *) dstAddr;
1643  for (i=0;i<n;i++) {
1644  dst[i] = (IROUND(rgba[i][RCOMP] * 15.0F) )
1645  | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
1646  | (IROUND(rgba[i][BCOMP] * 15.0F) << 8)
1647  | (IROUND(rgba[i][ACOMP] * 15.0F) << 12);
1648  }
1649  }
1650  else if (dstFormat == GL_BGRA) {
1651  GLushort *dst = (GLushort *) dstAddr;
1652  for (i=0;i<n;i++) {
1653  dst[i] = (IROUND(rgba[i][BCOMP] * 15.0F) )
1654  | (IROUND(rgba[i][GCOMP] * 15.0F) << 4)
1655  | (IROUND(rgba[i][RCOMP] * 15.0F) << 8)
1656  | (IROUND(rgba[i][ACOMP] * 15.0F) << 12);
1657  }
1658  }
1659  else if (dstFormat == GL_ABGR_EXT) {
1660  GLushort *dst = (GLushort *) dstAddr;
1661  for (i=0;i<n;i++) {
1662  dst[i] = (IROUND(rgba[i][ACOMP] * 15.0F) )
1663  | (IROUND(rgba[i][BCOMP] * 15.0F) << 4)
1664  | (IROUND(rgba[i][GCOMP] * 15.0F) << 8)
1665  | (IROUND(rgba[i][RCOMP] * 15.0F) << 12);
1666  }
1667  }
1668  break;
1670  if (dstFormat == GL_RGBA) {
1671  GLushort *dst = (GLushort *) dstAddr;
1672  for (i=0;i<n;i++) {
1673  dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) << 11)
1674  | (IROUND(rgba[i][GCOMP] * 31.0F) << 6)
1675  | (IROUND(rgba[i][BCOMP] * 31.0F) << 1)
1676  | (IROUND(rgba[i][ACOMP] * 1.0F) );
1677  }
1678  }
1679  else if (dstFormat == GL_BGRA) {
1680  GLushort *dst = (GLushort *) dstAddr;
1681  for (i=0;i<n;i++) {
1682  dst[i] = (IROUND(rgba[i][BCOMP] * 31.0F) << 11)
1683  | (IROUND(rgba[i][GCOMP] * 31.0F) << 6)
1684  | (IROUND(rgba[i][RCOMP] * 31.0F) << 1)
1685  | (IROUND(rgba[i][ACOMP] * 1.0F) );
1686  }
1687  }
1688  else if (dstFormat == GL_ABGR_EXT) {
1689  GLushort *dst = (GLushort *) dstAddr;
1690  for (i=0;i<n;i++) {
1691  dst[i] = (IROUND(rgba[i][ACOMP] * 31.0F) << 11)
1692  | (IROUND(rgba[i][BCOMP] * 31.0F) << 6)
1693  | (IROUND(rgba[i][GCOMP] * 31.0F) << 1)
1694  | (IROUND(rgba[i][RCOMP] * 1.0F) );
1695  }
1696  }
1697  break;
1699  if (dstFormat == GL_RGBA) {
1700  GLushort *dst = (GLushort *) dstAddr;
1701  for (i=0;i<n;i++) {
1702  dst[i] = (IROUND(rgba[i][RCOMP] * 31.0F) )
1703  | (IROUND(rgba[i][GCOMP] * 31.0F) << 5)
1704  | (IROUND(rgba[i][BCOMP] * 31.0F) << 10)
1705  | (IROUND(rgba[i][ACOMP] * 1.0F) << 15);
1706  }
1707  }
1708  else if (dstFormat == GL_BGRA) {
1709  GLushort *dst = (GLushort *) dstAddr;
1710  for (i=0;i<n;i++) {
1711  dst[i] = (IROUND(rgba[i][BCOMP] * 31.0F) )
1712  | (IROUND(rgba[i][GCOMP] * 31.0F) << 5)
1713  | (IROUND(rgba[i][RCOMP] * 31.0F) << 10)
1714  | (IROUND(rgba[i][ACOMP] * 1.0F) << 15);
1715  }
1716  }
1717  else if (dstFormat == GL_ABGR_EXT) {
1718  GLushort *dst = (GLushort *) dstAddr;
1719  for (i=0;i<n;i++) {
1720  dst[i] = (IROUND(rgba[i][ACOMP] * 31.0F) )
1721  | (IROUND(rgba[i][BCOMP] * 31.0F) << 5)
1722  | (IROUND(rgba[i][GCOMP] * 31.0F) << 10)
1723  | (IROUND(rgba[i][RCOMP] * 1.0F) << 15);
1724  }
1725  }
1726  break;
1728  if (dstFormat == GL_RGBA) {
1729  GLuint *dst = (GLuint *) dstAddr;
1730  for (i=0;i<n;i++) {
1731  dst[i] = (IROUND(rgba[i][RCOMP] * 255.F) << 24)
1732  | (IROUND(rgba[i][GCOMP] * 255.F) << 16)
1733  | (IROUND(rgba[i][BCOMP] * 255.F) << 8)
1734  | (IROUND(rgba[i][ACOMP] * 255.F) );
1735  }
1736  }
1737  else if (dstFormat == GL_BGRA) {
1738  GLuint *dst = (GLuint *) dstAddr;
1739  for (i=0;i<n;i++) {
1740  dst[i] = (IROUND(rgba[i][BCOMP] * 255.F) << 24)
1741  | (IROUND(rgba[i][GCOMP] * 255.F) << 16)
1742  | (IROUND(rgba[i][RCOMP] * 255.F) << 8)
1743  | (IROUND(rgba[i][ACOMP] * 255.F) );
1744  }
1745  }
1746  else if (dstFormat == GL_ABGR_EXT) {
1747  GLuint *dst = (GLuint *) dstAddr;
1748  for (i=0;i<n;i++) {
1749  dst[i] = (IROUND(rgba[i][ACOMP] * 255.F) << 24)
1750  | (IROUND(rgba[i][BCOMP] * 255.F) << 16)
1751  | (IROUND(rgba[i][GCOMP] * 255.F) << 8)
1752  | (IROUND(rgba[i][RCOMP] * 255.F) );
1753  }
1754  }
1755  break;
1757  if (dstFormat == GL_RGBA) {
1758  GLuint *dst = (GLuint *) dstAddr;
1759  for (i=0;i<n;i++) {
1760  dst[i] = (IROUND(rgba[i][RCOMP] * 255.0F) )
1761  | (IROUND(rgba[i][GCOMP] * 255.0F) << 8)
1762  | (IROUND(rgba[i][BCOMP] * 255.0F) << 16)
1763  | (IROUND(rgba[i][ACOMP] * 255.0F) << 24);
1764  }
1765  }
1766  else if (dstFormat == GL_BGRA) {
1767  GLuint *dst = (GLuint *) dstAddr;
1768  for (i=0;i<n;i++) {
1769  dst[i] = (IROUND(rgba[i][BCOMP] * 255.0F) )
1770  | (IROUND(rgba[i][GCOMP] * 255.0F) << 8)
1771  | (IROUND(rgba[i][RCOMP] * 255.0F) << 16)
1772  | (IROUND(rgba[i][ACOMP] * 255.0F) << 24);
1773  }
1774  }
1775  else if (dstFormat == GL_ABGR_EXT) {
1776  GLuint *dst = (GLuint *) dstAddr;
1777  for (i=0;i<n;i++) {
1778  dst[i] = (IROUND(rgba[i][ACOMP] * 255.0F) )
1779  | (IROUND(rgba[i][BCOMP] * 255.0F) << 8)
1780  | (IROUND(rgba[i][GCOMP] * 255.0F) << 16)
1781  | (IROUND(rgba[i][RCOMP] * 255.0F) << 24);
1782  }
1783  }
1784  break;
1785  default:
1786  _mesa_problem(ctx, "bad type in _mesa_pack_rgba_span_float");
1787  free(luminance);
1788  return;
1789  }
1790 
1791  if (dstPacking->SwapBytes) {
1792  GLint swapSize = _mesa_sizeof_packed_type(dstType);
1793  if (swapSize == 2) {
1794  if (dstPacking->SwapBytes) {
1795  _mesa_swap2((GLushort *) dstAddr, n * comps);
1796  }
1797  }
1798  else if (swapSize == 4) {
1799  if (dstPacking->SwapBytes) {
1800  _mesa_swap4((GLuint *) dstAddr, n * comps);
1801  }
1802  }
1803  }
1804 
1805  free(luminance);
1806 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define IROUND(f)
Definition: imports.h:321
#define GL_GREEN_INTEGER_EXT
Definition: glext.h:4802
#define max(a, b)
Definition: svc.c:63
GLboolean _mesa_is_integer_format(GLenum format)
Definition: image.c:777
#define GL_RED
Definition: gl.h:480
#define GL_UNSIGNED_BYTE_2_3_3_REV
Definition: gl.h:1487
#define GL_RG
Definition: glext.h:1817
#define FLOAT_TO_BYTE(X)
Definition: macros.h:54
#define free
Definition: debug_ros.c:5
#define GL_ALPHA
Definition: gl.h:483
#define GL_RG_INTEGER
Definition: glext.h:1818
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_RGBA_INTEGER_EXT
Definition: glext.h:4806
#define GL_FLOAT
Definition: gl.h:183
#define GL_LUMINANCE_INTEGER_EXT
Definition: glext.h:4809
#define GL_BGRA
Definition: gl.h:1485
#define GL_SHORT
Definition: gl.h:179
GLint _mesa_sizeof_packed_type(GLenum type)
Definition: image.c:141
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define BCOMP
Definition: txc_dxtn.h:35
short GLshort
Definition: gl.h:155
#define GL_UNSIGNED_INT_8_8_8_8
Definition: gl.h:1494
#define CLAMP(f, min, max)
Definition: tif_color.c:179
unsigned char GLboolean
Definition: gl.h:151
#define FLOAT_TO_UINT(X)
Definition: macros.h:95
#define GL_ALPHA_INTEGER_EXT
Definition: glext.h:4804
smooth NULL
Definition: ftsmooth.c:416
#define GCOMP
Definition: txc_dxtn.h:34
#define GL_BGR
Definition: gl.h:1484
#define GL_ABGR_EXT
Definition: glext.h:2403
#define RCOMP
Definition: txc_dxtn.h:33
void _mesa_swap2(GLushort *p, GLuint n)
Definition: image.c:70
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define IMAGE_CLAMP_BIT
Definition: mtypes.h:1575
#define GL_UNSIGNED_SHORT_1_5_5_5_REV
Definition: gl.h:1493
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
float GLfloat
Definition: gl.h:161
#define GL_UNSIGNED_SHORT_5_6_5_REV
Definition: gl.h:1489
#define FLOAT_TO_INT(X)
Definition: macros.h:106
void _mesa_apply_rgba_transfer_ops(struct gl_context *ctx, GLbitfield transferOps, GLuint n, GLfloat rgba[][4])
#define GL_UNSIGNED_SHORT_5_6_5
Definition: gl.h:1488
#define GL_UNSIGNED_SHORT_5_5_5_1
Definition: gl.h:1492
GLboolean SwapBytes
Definition: mtypes.h:1154
#define UNCLAMPED_FLOAT_TO_USHORT(us, f)
Definition: macros.h:131
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
GLint _mesa_components_in_format(GLenum format)
Definition: image.c:192
unsigned short GLushort
Definition: gl.h:158
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: gl.h:1495
#define GL_RED_INTEGER_EXT
Definition: glext.h:4801
#define GL_UNSIGNED_SHORT_4_4_4_4
Definition: gl.h:1490
signed char GLbyte
Definition: gl.h:154
#define GL_BGRA_INTEGER_EXT
Definition: glext.h:4808
#define GL_RGB
Definition: gl.h:502
#define GL_BLUE
Definition: gl.h:482
void _mesa_swap4(GLuint *p, GLuint n)
Definition: image.c:84
#define GL_UNSIGNED_BYTE_3_3_2
Definition: gl.h:1486
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
#define CLAMPED_FLOAT_TO_USHORT(us, f)
Definition: macros.h:133
#define GL_LUMINANCE
Definition: gl.h:484
unsigned int GLuint
Definition: gl.h:159
#define FLOAT_TO_SHORT(X)
Definition: macros.h:78
#define GL_GREEN
Definition: gl.h:481
#define GL_BGR_INTEGER_EXT
Definition: glext.h:4807
#define min(a, b)
Definition: monoChain.cc:55
#define GL_RGB_INTEGER_EXT
Definition: glext.h:4805
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_UNSIGNED_SHORT_4_4_4_4_REV
Definition: gl.h:1491
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define malloc
Definition: debug_ros.c:4
#define GL_RGBA
Definition: gl.h:503
#define GL_LUMINANCE_ALPHA_INTEGER_EXT
Definition: glext.h:4810
static GLboolean get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
Definition: pack.c:408
#define GL_BLUE_INTEGER_EXT
Definition: glext.h:4803
#define FLOAT_TO_UBYTE(X)
Definition: macros.h:47
#define ACOMP
Definition: txc_dxtn.h:36
#define F(x, y, z)
Definition: md5.c:51
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_pack_rgba_span_int()

void _mesa_pack_rgba_span_int ( struct gl_context ctx,
GLuint  n,
GLuint  rgba[][4],
GLenum  dstFormat,
GLenum  dstType,
GLvoid dstAddr 
)

Definition at line 478 of file pack.c.

Referenced by get_tex_rgba_uncompressed(), and slow_read_rgba_pixels().

481 {
482  switch(dstType) {
483  case GL_UNSIGNED_INT:
484  pack_uint_from_uint_rgba(dstAddr, dstFormat, rgba, n);
485  break;
486  case GL_INT:
487  /* No conversion necessary. */
488  pack_uint_from_uint_rgba(dstAddr, dstFormat, rgba, n);
489  break;
490  case GL_UNSIGNED_SHORT:
491  pack_ushort_from_uint_rgba(dstAddr, dstFormat, rgba, n);
492  break;
493  case GL_SHORT:
494  pack_short_from_uint_rgba(dstAddr, dstFormat, rgba, n);
495  break;
496  case GL_UNSIGNED_BYTE:
497  pack_ubyte_from_uint_rgba(dstAddr, dstFormat, rgba, n);
498  break;
499  case GL_BYTE:
500  pack_byte_from_uint_rgba(dstAddr, dstFormat, rgba, n);
501  break;
502  default:
503  assert(0);
504  return;
505  }
506 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define assert(x)
Definition: debug.h:53
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define GL_BYTE
Definition: gl.h:177

◆ _mesa_pack_stencil_span()

void _mesa_pack_stencil_span ( struct gl_context ctx,
GLuint  n,
GLenum  dstType,
GLvoid dest,
const GLubyte source,
const struct gl_pixelstore_attrib dstPacking 
)

Definition at line 3900 of file pack.c.

Referenced by read_stencil_pixels().

3903 {
3904  GLubyte *stencil = (GLubyte *) malloc(n * sizeof(GLubyte));
3905 
3906  if (!stencil) {
3907  _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil packing");
3908  return;
3909  }
3910 
3911  if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset ||
3912  ctx->Pixel.MapStencilFlag) {
3913  /* make a copy of input */
3914  memcpy(stencil, source, n * sizeof(GLubyte));
3915  _mesa_apply_stencil_transfer_ops(ctx, n, stencil);
3916  source = stencil;
3917  }
3918 
3919  switch (dstType) {
3920  case GL_UNSIGNED_BYTE:
3921  memcpy(dest, source, n);
3922  break;
3923  case GL_BYTE:
3924  {
3925  GLbyte *dst = (GLbyte *) dest;
3926  GLuint i;
3927  for (i=0;i<n;i++) {
3928  dst[i] = (GLbyte) (source[i] & 0x7f);
3929  }
3930  }
3931  break;
3932  case GL_UNSIGNED_SHORT:
3933  {
3934  GLushort *dst = (GLushort *) dest;
3935  GLuint i;
3936  for (i=0;i<n;i++) {
3937  dst[i] = (GLushort) source[i];
3938  }
3939  if (dstPacking->SwapBytes) {
3940  _mesa_swap2( (GLushort *) dst, n );
3941  }
3942  }
3943  break;
3944  case GL_SHORT:
3945  {
3946  GLshort *dst = (GLshort *) dest;
3947  GLuint i;
3948  for (i=0;i<n;i++) {
3949  dst[i] = (GLshort) source[i];
3950  }
3951  if (dstPacking->SwapBytes) {
3952  _mesa_swap2( (GLushort *) dst, n );
3953  }
3954  }
3955  break;
3956  case GL_UNSIGNED_INT:
3957  {
3958  GLuint *dst = (GLuint *) dest;
3959  GLuint i;
3960  for (i=0;i<n;i++) {
3961  dst[i] = (GLuint) source[i];
3962  }
3963  if (dstPacking->SwapBytes) {
3964  _mesa_swap4( (GLuint *) dst, n );
3965  }
3966  }
3967  break;
3968  case GL_INT:
3969  {
3970  GLint *dst = (GLint *) dest;
3971  GLuint i;
3972  for (i=0;i<n;i++) {
3973  dst[i] = (GLint) source[i];
3974  }
3975  if (dstPacking->SwapBytes) {
3976  _mesa_swap4( (GLuint *) dst, n );
3977  }
3978  }
3979  break;
3980  case GL_FLOAT:
3981  {
3982  GLfloat *dst = (GLfloat *) dest;
3983  GLuint i;
3984  for (i=0;i<n;i++) {
3985  dst[i] = (GLfloat) source[i];
3986  }
3987  if (dstPacking->SwapBytes) {
3988  _mesa_swap4( (GLuint *) dst, n );
3989  }
3990  }
3991  break;
3992  case GL_BITMAP:
3993  if (dstPacking->LsbFirst) {
3994  GLubyte *dst = (GLubyte *) dest;
3995  GLint shift = 0;
3996  GLuint i;
3997  for (i = 0; i < n; i++) {
3998  if (shift == 0)
3999  *dst = 0;
4000  *dst |= ((source[i] != 0) << shift);
4001  shift++;
4002  if (shift == 8) {
4003  shift = 0;
4004  dst++;
4005  }
4006  }
4007  }
4008  else {
4009  GLubyte *dst = (GLubyte *) dest;
4010  GLint shift = 7;
4011  GLuint i;
4012  for (i = 0; i < n; i++) {
4013  if (shift == 7)
4014  *dst = 0;
4015  *dst |= ((source[i] != 0) << shift);
4016  shift--;
4017  if (shift < 0) {
4018  shift = 7;
4019  dst++;
4020  }
4021  }
4022  }
4023  break;
4024  default:
4025  _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
4026  }
4027 
4028  free(stencil);
4029 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define shift
Definition: input.c:1668
#define GL_BITMAP
Definition: gl.h:497
GLboolean LsbFirst
Definition: mtypes.h:1155
#define free
Definition: debug_ros.c:5
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
#define GL_SHORT
Definition: gl.h:179
GLint GLfloat GLint stencil
Definition: glext.h:6260
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct gl_pixel_attrib Pixel
Definition: mtypes.h:1827
short GLshort
Definition: gl.h:155
void _mesa_swap2(GLushort *p, GLuint n)
Definition: image.c:70
#define GL_UNSIGNED_INT
Definition: gl.h:182
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
float GLfloat
Definition: gl.h:161
GLboolean SwapBytes
Definition: mtypes.h:1154
unsigned short GLushort
Definition: gl.h:158
signed char GLbyte
Definition: gl.h:154
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void _mesa_swap4(GLuint *p, GLuint n)
Definition: image.c:84
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
unsigned int GLuint
Definition: gl.h:159
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define malloc
Definition: debug_ros.c:4
void _mesa_apply_stencil_transfer_ops(const struct gl_context *ctx, GLuint n, GLubyte stencil[])
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_rebase_rgba_float()

void _mesa_rebase_rgba_float ( GLuint  n,
GLfloat  rgba[][4],
GLenum  baseFormat 
)

If we unpack colors from a luminance surface, we'll get pixel colors such as (l, l, l, a). When we call _mesa_pack_rgba_span_float(format=GL_LUMINANCE), that function will compute L=R+G+B before packing. The net effect is we'll accidentally store luminance values = 3*l. This function compensates for that by converting (aka rebasing) (l,l,l,a) to be (l,0,0,a). It's a similar story for other formats such as LUMINANCE_ALPHA, ALPHA and INTENSITY.

Finally, we also need to do this when the actual surface format does not match the logical surface format. For example, suppose the user requests a GL_LUMINANCE texture but the driver stores it as RGBA. Again, we'll get pixel values like (l,l,l,a).

Definition at line 4476 of file pack.c.

Referenced by get_tex_rgba_uncompressed(), and slow_read_rgba_pixels().

4477 {
4478  GLuint i;
4479 
4480  switch (baseFormat) {
4481  case GL_ALPHA:
4482  for (i = 0; i < n; i++) {
4483  rgba[i][RCOMP] = 0.0F;
4484  rgba[i][GCOMP] = 0.0F;
4485  rgba[i][BCOMP] = 0.0F;
4486  }
4487  break;
4488  case GL_INTENSITY:
4489  /* fall-through */
4490  case GL_LUMINANCE:
4491  for (i = 0; i < n; i++) {
4492  rgba[i][GCOMP] = 0.0F;
4493  rgba[i][BCOMP] = 0.0F;
4494  rgba[i][ACOMP] = 1.0F;
4495  }
4496  break;
4497  case GL_LUMINANCE_ALPHA:
4498  for (i = 0; i < n; i++) {
4499  rgba[i][GCOMP] = 0.0F;
4500  rgba[i][BCOMP] = 0.0F;
4501  }
4502  break;
4503  default:
4504  /* no-op */
4505  ;
4506  }
4507 }
#define GL_ALPHA
Definition: gl.h:483
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define BCOMP
Definition: txc_dxtn.h:35
#define GCOMP
Definition: txc_dxtn.h:34
#define RCOMP
Definition: txc_dxtn.h:33
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
#define GL_LUMINANCE
Definition: gl.h:484
unsigned int GLuint
Definition: gl.h:159
#define GL_INTENSITY
Definition: gl.h:747
#define ACOMP
Definition: txc_dxtn.h:36

◆ _mesa_rebase_rgba_uint()

void _mesa_rebase_rgba_uint ( GLuint  n,
GLuint  rgba[][4],
GLenum  baseFormat 
)

As above, but GLuint components.

Definition at line 4514 of file pack.c.

Referenced by get_tex_rgba_uncompressed(), and slow_read_rgba_pixels().

4515 {
4516  GLuint i;
4517 
4518  switch (baseFormat) {
4519  case GL_ALPHA:
4520  for (i = 0; i < n; i++) {
4521  rgba[i][RCOMP] = 0;
4522  rgba[i][GCOMP] = 0;
4523  rgba[i][BCOMP] = 0;
4524  }
4525  break;
4526  case GL_INTENSITY:
4527  /* fall-through */
4528  case GL_LUMINANCE:
4529  for (i = 0; i < n; i++) {
4530  rgba[i][GCOMP] = 0;
4531  rgba[i][BCOMP] = 0;
4532  rgba[i][ACOMP] = 1;
4533  }
4534  break;
4535  case GL_LUMINANCE_ALPHA:
4536  for (i = 0; i < n; i++) {
4537  rgba[i][GCOMP] = 0;
4538  rgba[i][BCOMP] = 0;
4539  }
4540  break;
4541  default:
4542  /* no-op */
4543  ;
4544  }
4545 }
#define GL_ALPHA
Definition: gl.h:483
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define BCOMP
Definition: txc_dxtn.h:35
#define GCOMP
Definition: txc_dxtn.h:34
#define RCOMP
Definition: txc_dxtn.h:33
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
#define GL_LUMINANCE
Definition: gl.h:484
unsigned int GLuint
Definition: gl.h:159
#define GL_INTENSITY
Definition: gl.h:747
#define ACOMP
Definition: txc_dxtn.h:36

◆ _mesa_unpack_bitmap()

GLvoid* _mesa_unpack_bitmap ( GLint  width,
GLint  height,
const GLubyte pixels,
const struct gl_pixelstore_attrib packing 
)

Definition at line 121 of file pack.c.

Referenced by _mesa_unpack_polygon_stipple().

123 {
124  GLint bytes, row, width_in_bytes;
125  GLubyte *buffer, *dst;
126 
127  if (!pixels)
128  return NULL;
129 
130  /* Alloc dest storage */
131  bytes = ((width + 7) / 8 * height);
132  buffer = (GLubyte *) malloc( bytes );
133  if (!buffer)
134  return NULL;
135 
136  width_in_bytes = CEILING( width, 8 );
137  dst = buffer;
138  for (row = 0; row < height; row++) {
139  const GLubyte *src = (const GLubyte *)
140  _mesa_image_address2d(packing, pixels, width, height,
141  GL_COLOR_INDEX, GL_BITMAP, row, 0);
142  if (!src) {
143  free(buffer);
144  return NULL;
145  }
146 
147  if ((packing->SkipPixels & 7) == 0) {
148  memcpy( dst, src, width_in_bytes );
149  if (packing->LsbFirst) {
150  flip_bytes( dst, width_in_bytes );
151  }
152  }
153  else {
154  /* handling SkipPixels is a bit tricky (no pun intended!) */
155  GLint i;
156  if (packing->LsbFirst) {
157  GLubyte srcMask = 1 << (packing->SkipPixels & 0x7);
158  GLubyte dstMask = 128;
159  const GLubyte *s = src;
160  GLubyte *d = dst;
161  *d = 0;
162  for (i = 0; i < width; i++) {
163  if (*s & srcMask) {
164  *d |= dstMask;
165  }
166  if (srcMask == 128) {
167  srcMask = 1;
168  s++;
169  }
170  else {
171  srcMask = srcMask << 1;
172  }
173  if (dstMask == 1) {
174  dstMask = 128;
175  d++;
176  *d = 0;
177  }
178  else {
179  dstMask = dstMask >> 1;
180  }
181  }
182  }
183  else {
184  GLubyte srcMask = 128 >> (packing->SkipPixels & 0x7);
185  GLubyte dstMask = 128;
186  const GLubyte *s = src;
187  GLubyte *d = dst;
188  *d = 0;
189  for (i = 0; i < width; i++) {
190  if (*s & srcMask) {
191  *d |= dstMask;
192  }
193  if (srcMask == 1) {
194  srcMask = 128;
195  s++;
196  }
197  else {
198  srcMask = srcMask >> 1;
199  }
200  if (dstMask == 1) {
201  dstMask = 128;
202  d++;
203  *d = 0;
204  }
205  else {
206  dstMask = dstMask >> 1;
207  }
208  }
209  }
210  }
211  dst += width_in_bytes;
212  }
213 
214  return buffer;
215 }
GLint GLint GLsizei width
Definition: gl.h:1546
GLvoid * _mesa_image_address2d(const struct gl_pixelstore_attrib *packing, const GLvoid *image, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint row, GLint column)
Definition: image.c:1098
#define GL_BITMAP
Definition: gl.h:497
GLboolean LsbFirst
Definition: mtypes.h:1155
static void flip_bytes(GLubyte *p, GLuint n)
Definition: pack.c:46
#define free
Definition: debug_ros.c:5
GLuint buffer
Definition: glext.h:5915
#define CEILING(A, B)
Definition: macros.h:673
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
smooth NULL
Definition: ftsmooth.c:416
#define d
Definition: ke_i.h:81
GLuint GLuint dstMask
Definition: glext.h:9513
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
unsigned char GLubyte
Definition: gl.h:157
#define GL_COLOR_INDEX
Definition: gl.h:479
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define malloc
Definition: debug_ros.c:4
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

◆ _mesa_unpack_color_span_float()

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 
)

Same as _mesa_unpack_color_span_ubyte(), but return GLfloat data instead of GLubyte.

Definition at line 3229 of file pack.c.

Referenced by _mesa_make_temp_float_image(), and draw_rgba_pixels().

3235 {
3236  ASSERT(dstFormat == GL_ALPHA ||
3237  dstFormat == GL_LUMINANCE ||
3238  dstFormat == GL_LUMINANCE_ALPHA ||
3239  dstFormat == GL_INTENSITY ||
3240  dstFormat == GL_RED ||
3241  dstFormat == GL_RG ||
3242  dstFormat == GL_RGB ||
3243  dstFormat == GL_RGBA);
3244 
3245  ASSERT(srcFormat == GL_RED ||
3246  srcFormat == GL_GREEN ||
3247  srcFormat == GL_BLUE ||
3248  srcFormat == GL_ALPHA ||
3249  srcFormat == GL_LUMINANCE ||
3250  srcFormat == GL_LUMINANCE_ALPHA ||
3251  srcFormat == GL_INTENSITY ||
3252  srcFormat == GL_RG ||
3253  srcFormat == GL_RGB ||
3254  srcFormat == GL_BGR ||
3255  srcFormat == GL_RGBA ||
3256  srcFormat == GL_BGRA ||
3257  srcFormat == GL_ABGR_EXT ||
3258  srcFormat == GL_RED_INTEGER_EXT ||
3259  srcFormat == GL_GREEN_INTEGER_EXT ||
3260  srcFormat == GL_BLUE_INTEGER_EXT ||
3261  srcFormat == GL_ALPHA_INTEGER_EXT ||
3262  srcFormat == GL_RG_INTEGER ||
3263  srcFormat == GL_RGB_INTEGER_EXT ||
3264  srcFormat == GL_RGBA_INTEGER_EXT ||
3265  srcFormat == GL_BGR_INTEGER_EXT ||
3266  srcFormat == GL_BGRA_INTEGER_EXT ||
3267  srcFormat == GL_LUMINANCE_INTEGER_EXT ||
3268  srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT ||
3269  srcFormat == GL_COLOR_INDEX);
3270 
3271  ASSERT(srcType == GL_BITMAP ||
3272  srcType == GL_UNSIGNED_BYTE ||
3273  srcType == GL_BYTE ||
3274  srcType == GL_UNSIGNED_SHORT ||
3275  srcType == GL_SHORT ||
3276  srcType == GL_UNSIGNED_INT ||
3277  srcType == GL_INT ||
3278  srcType == GL_HALF_FLOAT_ARB ||
3279  srcType == GL_FLOAT ||
3280  srcType == GL_UNSIGNED_BYTE_3_3_2 ||
3281  srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
3282  srcType == GL_UNSIGNED_SHORT_5_6_5 ||
3283  srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
3284  srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
3285  srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
3286  srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
3287  srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
3288  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
3289  srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
3290  srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
3291  srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
3292 
3293  /* general solution, no special cases, yet */
3294  {
3295  GLint dstComponents;
3296  GLint rDst, gDst, bDst, aDst, lDst, iDst;
3297  GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
3298  GLboolean intFormat = _mesa_is_integer_format(srcFormat);
3299 
3300  if (!rgba) {
3301  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
3302  return;
3303  }
3304 
3305  dstComponents = _mesa_components_in_format( dstFormat );
3306  /* source & dest image formats should have been error checked by now */
3307  assert(dstComponents > 0);
3308 
3309  /* EXT_texture_integer specifies no transfer ops on integer
3310  * types in the resolved issues section. Just set them to 0
3311  * for integer surfaces.
3312  */
3313  if (intFormat)
3314  transferOps = 0;
3315 
3316  /*
3317  * Extract image data and convert to RGBA floats
3318  */
3319  if (srcFormat == GL_COLOR_INDEX) {
3320  GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
3321 
3322  if (!indexes) {
3323  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
3324  free(rgba);
3325  return;
3326  }
3327 
3328  extract_uint_indexes(n, indexes, srcFormat, srcType, source,
3329  srcPacking);
3330 
3331  /* Convert indexes to RGBA */
3332  if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
3333  _mesa_shift_and_offset_ci(ctx, n, indexes);
3334  }
3335  _mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
3336 
3337  /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3338  * with color indexes.
3339  */
3340  transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
3341 
3342  free(indexes);
3343  }
3344  else {
3345  /* non-color index data */
3346  extract_float_rgba(n, rgba, srcFormat, srcType, source,
3347  srcPacking->SwapBytes);
3348  }
3349 
3350  if (transferOps) {
3351  _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
3352  }
3353 
3354  get_component_indexes(dstFormat,
3355  &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
3356 
3357  /* Now pack results in the requested dstFormat */
3358  if (rDst >= 0) {
3359  GLfloat *dst = dest;
3360  GLuint i;
3361  for (i = 0; i < n; i++) {
3362  dst[rDst] = rgba[i][RCOMP];
3363  dst += dstComponents;
3364  }
3365  }
3366 
3367  if (gDst >= 0) {
3368  GLfloat *dst = dest;
3369  GLuint i;
3370  for (i = 0; i < n; i++) {
3371  dst[gDst] = rgba[i][GCOMP];
3372  dst += dstComponents;
3373  }
3374  }
3375 
3376  if (bDst >= 0) {
3377  GLfloat *dst = dest;
3378  GLuint i;
3379  for (i = 0; i < n; i++) {
3380  dst[bDst] = rgba[i][BCOMP];
3381  dst += dstComponents;
3382  }
3383  }
3384 
3385  if (aDst >= 0) {
3386  GLfloat *dst = dest;
3387  GLuint i;
3388  for (i = 0; i < n; i++) {
3389  dst[aDst] = rgba[i][ACOMP];
3390  dst += dstComponents;
3391  }
3392  }
3393 
3394  if (iDst >= 0) {
3395  GLfloat *dst = dest;
3396  GLuint i;
3397  assert(iDst == 0);
3398  assert(dstComponents == 1);
3399  for (i = 0; i < n; i++) {
3400  /* Intensity comes from red channel */
3401  dst[i] = rgba[i][RCOMP];
3402  }
3403  }
3404 
3405  if (lDst >= 0) {
3406  GLfloat *dst = dest;
3407  GLuint i;
3408  assert(lDst == 0);
3409  for (i = 0; i < n; i++) {
3410  /* Luminance comes from red channel */
3411  dst[0] = rgba[i][RCOMP];
3412  dst += dstComponents;
3413  }
3414  }
3415 
3416  free(rgba);
3417  }
3418 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_GREEN_INTEGER_EXT
Definition: glext.h:4802
#define GL_UNSIGNED_INT_5_9_9_9_REV
Definition: glext.h:542
GLboolean _mesa_is_integer_format(GLenum format)
Definition: image.c:777
#define GL_RED
Definition: gl.h:480
#define GL_BITMAP
Definition: gl.h:497
#define GL_UNSIGNED_BYTE_2_3_3_REV
Definition: gl.h:1487
#define GL_RG
Definition: glext.h:1817
#define free
Definition: debug_ros.c:5
#define GL_ALPHA
Definition: gl.h:483
#define GL_UNSIGNED_INT_10F_11F_11F_REV
Definition: glext.h:540
#define GL_RG_INTEGER
Definition: glext.h:1818
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_RGBA_INTEGER_EXT
Definition: glext.h:4806
#define GL_FLOAT
Definition: gl.h:183
#define assert(x)
Definition: debug.h:53
#define GL_LUMINANCE_INTEGER_EXT
Definition: glext.h:4809
static void extract_uint_indexes(GLuint n, GLuint indexes[], GLenum srcFormat, GLenum srcType, const GLvoid *src, const struct gl_pixelstore_attrib *unpack)
Definition: pack.c:1831
#define GL_BGRA
Definition: gl.h:1485
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define BCOMP
Definition: txc_dxtn.h:35
#define GL_UNSIGNED_INT_8_8_8_8
Definition: gl.h:1494
unsigned char GLboolean
Definition: gl.h:151
#define GL_ALPHA_INTEGER_EXT
Definition: glext.h:4804
#define GCOMP
Definition: txc_dxtn.h:34
#define GL_BGR
Definition: gl.h:1484
#define GL_ABGR_EXT
Definition: glext.h:2403
#define RCOMP
Definition: txc_dxtn.h:33
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define GL_UNSIGNED_SHORT_1_5_5_5_REV
Definition: gl.h:1493
float GLfloat
Definition: gl.h:161
#define GL_UNSIGNED_SHORT_5_6_5_REV
Definition: gl.h:1489
void _mesa_apply_rgba_transfer_ops(struct gl_context *ctx, GLbitfield transferOps, GLuint n, GLfloat rgba[][4])
#define GL_UNSIGNED_SHORT_5_6_5
Definition: gl.h:1488
#define GL_UNSIGNED_SHORT_5_5_5_1
Definition: gl.h:1492
GLboolean SwapBytes
Definition: mtypes.h:1154
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
static void get_component_indexes(GLenum format, GLint *redIndex, GLint *greenIndex, GLint *blueIndex, GLint *alphaIndex, GLint *luminanceIndex, GLint *intensityIndex)
Definition: pack.c:314
GLint _mesa_components_in_format(GLenum format)
Definition: image.c:192
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: gl.h:1495
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
#define GL_RED_INTEGER_EXT
Definition: glext.h:4801
#define GL_UNSIGNED_SHORT_4_4_4_4
Definition: gl.h:1490
#define GL_BGRA_INTEGER_EXT
Definition: glext.h:4808
static void extract_float_rgba(GLuint n, GLfloat rgba[][4], GLenum srcFormat, GLenum srcType, const GLvoid *src, GLboolean swapBytes)
Definition: pack.c:2129
#define GL_RGB
Definition: gl.h:502
#define IMAGE_SHIFT_OFFSET_BIT
Definition: mtypes.h:1573
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define GL_BLUE
Definition: gl.h:482
#define GL_HALF_FLOAT_ARB
Definition: glext.h:1629
#define GL_UNSIGNED_BYTE_3_3_2
Definition: gl.h:1486
#define GL_BYTE
Definition: gl.h:177
#define GL_LUMINANCE
Definition: gl.h:484
void _mesa_map_ci_to_rgba(const struct gl_context *ctx, GLuint n, const GLuint index[], GLfloat rgba[][4])
unsigned int GLuint
Definition: gl.h:159
#define GL_GREEN
Definition: gl.h:481
#define GL_COLOR_INDEX
Definition: gl.h:479
#define GL_BGR_INTEGER_EXT
Definition: glext.h:4807
void _mesa_shift_and_offset_ci(const struct gl_context *ctx, GLuint n, GLuint indexes[])
#define GL_RGB_INTEGER_EXT
Definition: glext.h:4805
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_UNSIGNED_SHORT_4_4_4_4_REV
Definition: gl.h:1491
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define IMAGE_MAP_COLOR_BIT
Definition: mtypes.h:1574
#define malloc
Definition: debug_ros.c:4
#define GL_RGBA
Definition: gl.h:503
#define GL_LUMINANCE_ALPHA_INTEGER_EXT
Definition: glext.h:4810
#define IMAGE_SCALE_BIAS_BIT
Definition: mtypes.h:1572
#define GL_BLUE_INTEGER_EXT
Definition: glext.h:4803
#define GL_INTENSITY
Definition: gl.h:747
#define ACOMP
Definition: txc_dxtn.h:36
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_unpack_color_span_ubyte()

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 at line 2988 of file pack.c.

Referenced by _mesa_make_temp_ubyte_image().

2994 {
2995  GLboolean intFormat = _mesa_is_integer_format(srcFormat);
2996  ASSERT(dstFormat == GL_ALPHA ||
2997  dstFormat == GL_LUMINANCE ||
2998  dstFormat == GL_LUMINANCE_ALPHA ||
2999  dstFormat == GL_INTENSITY ||
3000  dstFormat == GL_RED ||
3001  dstFormat == GL_RG ||
3002  dstFormat == GL_RGB ||
3003  dstFormat == GL_RGBA);
3004 
3005  ASSERT(srcFormat == GL_RED ||
3006  srcFormat == GL_GREEN ||
3007  srcFormat == GL_BLUE ||
3008  srcFormat == GL_ALPHA ||
3009  srcFormat == GL_LUMINANCE ||
3010  srcFormat == GL_LUMINANCE_ALPHA ||
3011  srcFormat == GL_INTENSITY ||
3012  srcFormat == GL_RG ||
3013  srcFormat == GL_RGB ||
3014  srcFormat == GL_BGR ||
3015  srcFormat == GL_RGBA ||
3016  srcFormat == GL_BGRA ||
3017  srcFormat == GL_ABGR_EXT ||
3018  srcFormat == GL_COLOR_INDEX);
3019 
3020  ASSERT(srcType == GL_BITMAP ||
3021  srcType == GL_UNSIGNED_BYTE ||
3022  srcType == GL_BYTE ||
3023  srcType == GL_UNSIGNED_SHORT ||
3024  srcType == GL_SHORT ||
3025  srcType == GL_UNSIGNED_INT ||
3026  srcType == GL_INT ||
3027  srcType == GL_HALF_FLOAT_ARB ||
3028  srcType == GL_FLOAT ||
3029  srcType == GL_UNSIGNED_BYTE_3_3_2 ||
3030  srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
3031  srcType == GL_UNSIGNED_SHORT_5_6_5 ||
3032  srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
3033  srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
3034  srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
3035  srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
3036  srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
3037  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
3038  srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
3039  srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
3040  srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
3041 
3042  /* EXT_texture_integer specifies no transfer ops on integer
3043  * types in the resolved issues section. Just set them to 0
3044  * for integer surfaces.
3045  */
3046  if (intFormat)
3047  transferOps = 0;
3048 
3049  /* Try simple cases first */
3050  if (transferOps == 0) {
3051  if (srcType == GL_UNSIGNED_BYTE) {
3052  if (dstFormat == GL_RGBA) {
3053  if (srcFormat == GL_RGBA) {
3054  memcpy( dest, source, n * 4 * sizeof(GLubyte) );
3055  return;
3056  }
3057  else if (srcFormat == GL_RGB) {
3058  GLuint i;
3059  const GLubyte *src = (const GLubyte *) source;
3060  GLubyte *dst = dest;
3061  for (i = 0; i < n; i++) {
3062  dst[0] = src[0];
3063  dst[1] = src[1];
3064  dst[2] = src[2];
3065  dst[3] = 255;
3066  src += 3;
3067  dst += 4;
3068  }
3069  return;
3070  }
3071  }
3072  else if (dstFormat == GL_RGB) {
3073  if (srcFormat == GL_RGB) {
3074  memcpy( dest, source, n * 3 * sizeof(GLubyte) );
3075  return;
3076  }
3077  else if (srcFormat == GL_RGBA) {
3078  GLuint i;
3079  const GLubyte *src = (const GLubyte *) source;
3080  GLubyte *dst = dest;
3081  for (i = 0; i < n; i++) {
3082  dst[0] = src[0];
3083  dst[1] = src[1];
3084  dst[2] = src[2];
3085  src += 4;
3086  dst += 3;
3087  }
3088  return;
3089  }
3090  }
3091  else if (dstFormat == srcFormat) {
3092  GLint comps = _mesa_components_in_format(srcFormat);
3093  assert(comps > 0);
3094  memcpy( dest, source, n * comps * sizeof(GLubyte) );
3095  return;
3096  }
3097  }
3098  }
3099 
3100 
3101  /* general solution begins here */
3102  {
3103  GLint dstComponents;
3104  GLint rDst, gDst, bDst, aDst, lDst, iDst;
3105  GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * n * sizeof(GLfloat));
3106 
3107  if (!rgba) {
3108  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
3109  return;
3110  }
3111 
3112  dstComponents = _mesa_components_in_format( dstFormat );
3113  /* source & dest image formats should have been error checked by now */
3114  assert(dstComponents > 0);
3115 
3116  /*
3117  * Extract image data and convert to RGBA floats
3118  */
3119  if (srcFormat == GL_COLOR_INDEX) {
3120  GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
3121 
3122  if (!indexes) {
3123  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
3124  free(rgba);
3125  return;
3126  }
3127 
3128  extract_uint_indexes(n, indexes, srcFormat, srcType, source,
3129  srcPacking);
3130 
3131  /* Convert indexes to RGBA */
3132  if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
3133  _mesa_shift_and_offset_ci(ctx, n, indexes);
3134  }
3135  _mesa_map_ci_to_rgba(ctx, n, indexes, rgba);
3136 
3137  /* Don't do RGBA scale/bias or RGBA->RGBA mapping if starting
3138  * with color indexes.
3139  */
3140  transferOps &= ~(IMAGE_SCALE_BIAS_BIT | IMAGE_MAP_COLOR_BIT);
3141 
3142  free(indexes);
3143  }
3144  else {
3145  /* non-color index data */
3146  extract_float_rgba(n, rgba, srcFormat, srcType, source,
3147  srcPacking->SwapBytes);
3148  }
3149 
3150  /* Need to clamp if returning GLubytes */
3151  transferOps |= IMAGE_CLAMP_BIT;
3152 
3153  if (transferOps) {
3154  _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
3155  }
3156 
3157  get_component_indexes(dstFormat,
3158  &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
3159 
3160  /* Now return the GLubyte data in the requested dstFormat */
3161  if (rDst >= 0) {
3162  GLubyte *dst = dest;
3163  GLuint i;
3164  for (i = 0; i < n; i++) {
3165  CLAMPED_FLOAT_TO_UBYTE(dst[rDst], rgba[i][RCOMP]);
3166  dst += dstComponents;
3167  }
3168  }
3169 
3170  if (gDst >= 0) {
3171  GLubyte *dst = dest;
3172  GLuint i;
3173  for (i = 0; i < n; i++) {
3174  CLAMPED_FLOAT_TO_UBYTE(dst[gDst], rgba[i][GCOMP]);
3175  dst += dstComponents;
3176  }
3177  }
3178 
3179  if (bDst >= 0) {
3180  GLubyte *dst = dest;
3181  GLuint i;
3182  for (i = 0; i < n; i++) {
3183  CLAMPED_FLOAT_TO_UBYTE(dst[bDst], rgba[i][BCOMP]);
3184  dst += dstComponents;
3185  }
3186  }
3187 
3188  if (aDst >= 0) {
3189  GLubyte *dst = dest;
3190  GLuint i;
3191  for (i = 0; i < n; i++) {
3192  CLAMPED_FLOAT_TO_UBYTE(dst[aDst], rgba[i][ACOMP]);
3193  dst += dstComponents;
3194  }
3195  }
3196 
3197  if (iDst >= 0) {
3198  GLubyte *dst = dest;
3199  GLuint i;
3200  assert(iDst == 0);
3201  assert(dstComponents == 1);
3202  for (i = 0; i < n; i++) {
3203  /* Intensity comes from red channel */
3204  CLAMPED_FLOAT_TO_UBYTE(dst[i], rgba[i][RCOMP]);
3205  }
3206  }
3207 
3208  if (lDst >= 0) {
3209  GLubyte *dst = dest;
3210  GLuint i;
3211  assert(lDst == 0);
3212  for (i = 0; i < n; i++) {
3213  /* Luminance comes from red channel */
3214  CLAMPED_FLOAT_TO_UBYTE(dst[0], rgba[i][RCOMP]);
3215  dst += dstComponents;
3216  }
3217  }
3218 
3219  free(rgba);
3220  }
3221 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_UNSIGNED_INT_5_9_9_9_REV
Definition: glext.h:542
GLboolean _mesa_is_integer_format(GLenum format)
Definition: image.c:777
#define GL_RED
Definition: gl.h:480
#define GL_BITMAP
Definition: gl.h:497
#define GL_UNSIGNED_BYTE_2_3_3_REV
Definition: gl.h:1487
#define CLAMPED_FLOAT_TO_UBYTE(ub, f)
Definition: macros.h:170
#define GL_RG
Definition: glext.h:1817
#define free
Definition: debug_ros.c:5
#define GL_ALPHA
Definition: gl.h:483
#define GL_UNSIGNED_INT_10F_11F_11F_REV
Definition: glext.h:540
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
#define assert(x)
Definition: debug.h:53
static void extract_uint_indexes(GLuint n, GLuint indexes[], GLenum srcFormat, GLenum srcType, const GLvoid *src, const struct gl_pixelstore_attrib *unpack)
Definition: pack.c:1831
#define GL_BGRA
Definition: gl.h:1485
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define BCOMP
Definition: txc_dxtn.h:35
#define GL_UNSIGNED_INT_8_8_8_8
Definition: gl.h:1494
unsigned char GLboolean
Definition: gl.h:151
#define GCOMP
Definition: txc_dxtn.h:34
#define GL_BGR
Definition: gl.h:1484
#define GL_ABGR_EXT
Definition: glext.h:2403
#define RCOMP
Definition: txc_dxtn.h:33
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define IMAGE_CLAMP_BIT
Definition: mtypes.h:1575
#define GL_UNSIGNED_SHORT_1_5_5_5_REV
Definition: gl.h:1493
float GLfloat
Definition: gl.h:161
#define GL_UNSIGNED_SHORT_5_6_5_REV
Definition: gl.h:1489
void _mesa_apply_rgba_transfer_ops(struct gl_context *ctx, GLbitfield transferOps, GLuint n, GLfloat rgba[][4])
#define GL_UNSIGNED_SHORT_5_6_5
Definition: gl.h:1488
#define GL_UNSIGNED_SHORT_5_5_5_1
Definition: gl.h:1492
GLboolean SwapBytes
Definition: mtypes.h:1154
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
static void get_component_indexes(GLenum format, GLint *redIndex, GLint *greenIndex, GLint *blueIndex, GLint *alphaIndex, GLint *luminanceIndex, GLint *intensityIndex)
Definition: pack.c:314
GLint _mesa_components_in_format(GLenum format)
Definition: image.c:192
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: gl.h:1495
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
#define GL_UNSIGNED_SHORT_4_4_4_4
Definition: gl.h:1490
static void extract_float_rgba(GLuint n, GLfloat rgba[][4], GLenum srcFormat, GLenum srcType, const GLvoid *src, GLboolean swapBytes)
Definition: pack.c:2129
#define GL_RGB
Definition: gl.h:502
#define IMAGE_SHIFT_OFFSET_BIT
Definition: mtypes.h:1573
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define GL_BLUE
Definition: gl.h:482
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define GL_HALF_FLOAT_ARB
Definition: glext.h:1629
#define GL_UNSIGNED_BYTE_3_3_2
Definition: gl.h:1486
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
#define GL_LUMINANCE
Definition: gl.h:484
void _mesa_map_ci_to_rgba(const struct gl_context *ctx, GLuint n, const GLuint index[], GLfloat rgba[][4])
unsigned int GLuint
Definition: gl.h:159
#define GL_GREEN
Definition: gl.h:481
#define GL_COLOR_INDEX
Definition: gl.h:479
void _mesa_shift_and_offset_ci(const struct gl_context *ctx, GLuint n, GLuint indexes[])
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_UNSIGNED_SHORT_4_4_4_4_REV
Definition: gl.h:1491
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define IMAGE_MAP_COLOR_BIT
Definition: mtypes.h:1574
#define malloc
Definition: debug_ros.c:4
#define GL_RGBA
Definition: gl.h:503
#define IMAGE_SCALE_BIAS_BIT
Definition: mtypes.h:1572
#define GL_INTENSITY
Definition: gl.h:747
#define ACOMP
Definition: txc_dxtn.h:36
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_unpack_color_span_uint()

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 
)

Same as _mesa_unpack_color_span_ubyte(), but return GLuint data instead of GLubyte. No pixel transfer ops are applied.

Definition at line 3427 of file pack.c.

Referenced by make_temp_uint_image().

3432 {
3433  GLuint (*rgba)[4] = (GLuint (*)[4]) malloc(n * 4 * sizeof(GLfloat));
3434 
3435  if (!rgba) {
3436  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
3437  return;
3438  }
3439 
3440  ASSERT(dstFormat == GL_ALPHA ||
3441  dstFormat == GL_LUMINANCE ||
3442  dstFormat == GL_LUMINANCE_ALPHA ||
3443  dstFormat == GL_INTENSITY ||
3444  dstFormat == GL_RED ||
3445  dstFormat == GL_RG ||
3446  dstFormat == GL_RGB ||
3447  dstFormat == GL_RGBA);
3448 
3449  ASSERT(srcFormat == GL_RED ||
3450  srcFormat == GL_GREEN ||
3451  srcFormat == GL_BLUE ||
3452  srcFormat == GL_ALPHA ||
3453  srcFormat == GL_LUMINANCE ||
3454  srcFormat == GL_LUMINANCE_ALPHA ||
3455  srcFormat == GL_INTENSITY ||
3456  srcFormat == GL_RG ||
3457  srcFormat == GL_RGB ||
3458  srcFormat == GL_BGR ||
3459  srcFormat == GL_RGBA ||
3460  srcFormat == GL_BGRA ||
3461  srcFormat == GL_ABGR_EXT ||
3462  srcFormat == GL_RED_INTEGER_EXT ||
3463  srcFormat == GL_GREEN_INTEGER_EXT ||
3464  srcFormat == GL_BLUE_INTEGER_EXT ||
3465  srcFormat == GL_ALPHA_INTEGER_EXT ||
3466  srcFormat == GL_RG_INTEGER ||
3467  srcFormat == GL_RGB_INTEGER_EXT ||
3468  srcFormat == GL_RGBA_INTEGER_EXT ||
3469  srcFormat == GL_BGR_INTEGER_EXT ||
3470  srcFormat == GL_BGRA_INTEGER_EXT ||
3471  srcFormat == GL_LUMINANCE_INTEGER_EXT ||
3472  srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
3473 
3474  ASSERT(srcType == GL_UNSIGNED_BYTE ||
3475  srcType == GL_BYTE ||
3476  srcType == GL_UNSIGNED_SHORT ||
3477  srcType == GL_SHORT ||
3478  srcType == GL_UNSIGNED_INT ||
3479  srcType == GL_INT ||
3480  srcType == GL_HALF_FLOAT_ARB ||
3481  srcType == GL_FLOAT ||
3482  srcType == GL_UNSIGNED_BYTE_3_3_2 ||
3483  srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
3484  srcType == GL_UNSIGNED_SHORT_5_6_5 ||
3485  srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
3486  srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
3487  srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
3488  srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
3489  srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
3490  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
3491  srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
3492  srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
3493  srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
3494 
3495 
3496  /* Extract image data as uint[4] pixels */
3497  extract_uint_rgba(n, rgba, srcFormat, srcType, source,
3498  srcPacking->SwapBytes);
3499 
3500  if (dstFormat == GL_RGBA) {
3501  /* simple case */
3502  memcpy(dest, rgba, 4 * sizeof(GLuint) * n);
3503  }
3504  else {
3505  /* general case */
3506  GLint rDst, gDst, bDst, aDst, lDst, iDst;
3507  GLint dstComponents = _mesa_components_in_format( dstFormat );
3508 
3509  assert(dstComponents > 0);
3510 
3511  get_component_indexes(dstFormat,
3512  &rDst, &gDst, &bDst, &aDst, &lDst, &iDst);
3513 
3514  /* Now pack values in the requested dest format */
3515  if (rDst >= 0) {
3516  GLuint *dst = dest;
3517  GLuint i;
3518  for (i = 0; i < n; i++) {
3519  dst[rDst] = rgba[i][RCOMP];
3520  dst += dstComponents;
3521  }
3522  }
3523 
3524  if (gDst >= 0) {
3525  GLuint *dst = dest;
3526  GLuint i;
3527  for (i = 0; i < n; i++) {
3528  dst[gDst] = rgba[i][GCOMP];
3529  dst += dstComponents;
3530  }
3531  }
3532 
3533  if (bDst >= 0) {
3534  GLuint *dst = dest;
3535  GLuint i;
3536  for (i = 0; i < n; i++) {
3537  dst[bDst] = rgba[i][BCOMP];
3538  dst += dstComponents;
3539  }
3540  }
3541 
3542  if (aDst >= 0) {
3543  GLuint *dst = dest;
3544  GLuint i;
3545  for (i = 0; i < n; i++) {
3546  dst[aDst] = rgba[i][ACOMP];
3547  dst += dstComponents;
3548  }
3549  }
3550 
3551  if (iDst >= 0) {
3552  GLuint *dst = dest;
3553  GLuint i;
3554  assert(iDst == 0);
3555  assert(dstComponents == 1);
3556  for (i = 0; i < n; i++) {
3557  /* Intensity comes from red channel */
3558  dst[i] = rgba[i][RCOMP];
3559  }
3560  }
3561 
3562  if (lDst >= 0) {
3563  GLuint *dst = dest;
3564  GLuint i;
3565  assert(lDst == 0);
3566  for (i = 0; i < n; i++) {
3567  /* Luminance comes from red channel */
3568  dst[0] = rgba[i][RCOMP];
3569  dst += dstComponents;
3570  }
3571  }
3572  }
3573 
3574  free(rgba);
3575 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_GREEN_INTEGER_EXT
Definition: glext.h:4802
#define GL_UNSIGNED_INT_5_9_9_9_REV
Definition: glext.h:542
#define GL_RED
Definition: gl.h:480
#define GL_UNSIGNED_BYTE_2_3_3_REV
Definition: gl.h:1487
#define GL_RG
Definition: glext.h:1817
#define free
Definition: debug_ros.c:5
#define GL_ALPHA
Definition: gl.h:483
#define GL_UNSIGNED_INT_10F_11F_11F_REV
Definition: glext.h:540
#define GL_RG_INTEGER
Definition: glext.h:1818
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_RGBA_INTEGER_EXT
Definition: glext.h:4806
#define GL_FLOAT
Definition: gl.h:183
#define assert(x)
Definition: debug.h:53
#define GL_LUMINANCE_INTEGER_EXT
Definition: glext.h:4809
#define GL_BGRA
Definition: gl.h:1485
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define BCOMP
Definition: txc_dxtn.h:35
#define GL_UNSIGNED_INT_8_8_8_8
Definition: gl.h:1494
#define GL_ALPHA_INTEGER_EXT
Definition: glext.h:4804
#define GCOMP
Definition: txc_dxtn.h:34
#define GL_BGR
Definition: gl.h:1484
#define GL_ABGR_EXT
Definition: glext.h:2403
#define RCOMP
Definition: txc_dxtn.h:33
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define GL_UNSIGNED_SHORT_1_5_5_5_REV
Definition: gl.h:1493
float GLfloat
Definition: gl.h:161
#define GL_UNSIGNED_SHORT_5_6_5_REV
Definition: gl.h:1489
#define GL_UNSIGNED_SHORT_5_6_5
Definition: gl.h:1488
#define GL_UNSIGNED_SHORT_5_5_5_1
Definition: gl.h:1492
GLboolean SwapBytes
Definition: mtypes.h:1154
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
static void get_component_indexes(GLenum format, GLint *redIndex, GLint *greenIndex, GLint *blueIndex, GLint *alphaIndex, GLint *luminanceIndex, GLint *intensityIndex)
Definition: pack.c:314
GLint _mesa_components_in_format(GLenum format)
Definition: image.c:192
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: gl.h:1495
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
#define GL_RED_INTEGER_EXT
Definition: glext.h:4801
#define GL_UNSIGNED_SHORT_4_4_4_4
Definition: gl.h:1490
#define GL_BGRA_INTEGER_EXT
Definition: glext.h:4808
#define GL_RGB
Definition: gl.h:502
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define GL_BLUE
Definition: gl.h:482
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define GL_HALF_FLOAT_ARB
Definition: glext.h:1629
#define GL_UNSIGNED_BYTE_3_3_2
Definition: gl.h:1486
#define GL_BYTE
Definition: gl.h:177
#define GL_LUMINANCE
Definition: gl.h:484
unsigned int GLuint
Definition: gl.h:159
#define GL_GREEN
Definition: gl.h:481
#define GL_BGR_INTEGER_EXT
Definition: glext.h:4807
#define GL_RGB_INTEGER_EXT
Definition: glext.h:4805
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_UNSIGNED_SHORT_4_4_4_4_REV
Definition: gl.h:1491
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define malloc
Definition: debug_ros.c:4
#define GL_RGBA
Definition: gl.h:503
#define GL_LUMINANCE_ALPHA_INTEGER_EXT
Definition: glext.h:4810
#define GL_BLUE_INTEGER_EXT
Definition: glext.h:4803
#define GL_INTENSITY
Definition: gl.h:747
#define ACOMP
Definition: txc_dxtn.h:36
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832
static void extract_uint_rgba(GLuint n, GLuint rgba[][4], GLenum srcFormat, GLenum srcType, const GLvoid *src, GLboolean swapBytes)
Definition: pack.c:2603

◆ _mesa_unpack_depth_span()

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 
)

Unpack a row of depth/z values from memory, returning GLushort, GLuint or GLfloat values. The glPixelTransfer (scale/bias) params will be applied.

Parameters
dstTypeone of GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_FLOAT
depthMaxmax value for returned GLushort or GLuint values (ignored for GLfloat).

Definition at line 4059 of file pack.c.

Referenced by _mesa_texstore_x8_z24(), _mesa_texstore_z16(), _mesa_texstore_z24_x8(), _mesa_texstore_z32(), and draw_depth_pixels().

4063 {
4064  GLfloat *depthTemp = NULL, *depthValues;
4065  GLboolean needClamp = GL_FALSE;
4066 
4067  /* Look for special cases first.
4068  * Not only are these faster, they're less prone to numeric conversion
4069  * problems. Otherwise, converting from an int type to a float then
4070  * back to an int type can introduce errors that will show up as
4071  * artifacts in things like depth peeling which uses glCopyTexImage.
4072  */
4073  if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
4074  if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
4075  const GLuint *src = (const GLuint *) source;
4076  GLushort *dst = (GLushort *) dest;
4077  GLuint i;
4078  for (i = 0; i < n; i++) {
4079  dst[i] = src[i] >> 16;
4080  }
4081  return;
4082  }
4083  if (srcType == GL_UNSIGNED_SHORT
4084  && dstType == GL_UNSIGNED_INT
4085  && depthMax == 0xffffffff) {
4086  const GLushort *src = (const GLushort *) source;
4087  GLuint *dst = (GLuint *) dest;
4088  GLuint i;
4089  for (i = 0; i < n; i++) {
4090  dst[i] = src[i] | (src[i] << 16);
4091  }
4092  return;
4093  }
4094  /* XXX may want to add additional cases here someday */
4095  }
4096 
4097  /* general case path follows */
4098 
4099  if (dstType == GL_FLOAT) {
4100  depthValues = (GLfloat *) dest;
4101  }
4102  else {
4103  depthTemp = (GLfloat *) malloc(n * sizeof(GLfloat));
4104  if (!depthTemp) {
4105  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
4106  return;
4107  }
4108 
4109  depthValues = depthTemp;
4110  }
4111 
4112  /* Convert incoming values to GLfloat. Some conversions will require
4113  * clamping, below.
4114  */
4115  switch (srcType) {
4116  case GL_BYTE:
4118  needClamp = GL_TRUE;
4119  break;
4120  case GL_UNSIGNED_BYTE:
4122  break;
4123  case GL_SHORT:
4125  needClamp = GL_TRUE;
4126  break;
4127  case GL_UNSIGNED_SHORT:
4129  break;
4130  case GL_INT:
4132  needClamp = GL_TRUE;
4133  break;
4134  case GL_UNSIGNED_INT:
4136  break;
4137  case GL_FLOAT:
4138  DEPTH_VALUES(GLfloat, 1*);
4139  needClamp = GL_TRUE;
4140  break;
4141  default:
4142  _mesa_problem(NULL, "bad type in _mesa_unpack_depth_span()");
4143  free(depthTemp);
4144  return;
4145  }
4146 
4147  /* apply depth scale and bias */
4148  {
4149  const GLfloat scale = ctx->Pixel.DepthScale;
4150  const GLfloat bias = ctx->Pixel.DepthBias;
4151  if (scale != 1.0 || bias != 0.0) {
4152  GLuint i;
4153  for (i = 0; i < n; i++) {
4154  depthValues[i] = depthValues[i] * scale + bias;
4155  }
4156  needClamp = GL_TRUE;
4157  }
4158  }
4159 
4160  /* clamp to [0, 1] */
4161  if (needClamp) {
4162  GLuint i;
4163  for (i = 0; i < n; i++) {
4164  depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0);
4165  }
4166  }
4167 
4168  /*
4169  * Convert values to dstType
4170  */
4171  if (dstType == GL_UNSIGNED_INT) {
4172  GLuint *zValues = (GLuint *) dest;
4173  GLuint i;
4174  if (depthMax <= 0xffffff) {
4175  /* no overflow worries */
4176  for (i = 0; i < n; i++) {
4177  zValues[i] = (GLuint) (depthValues[i] * (GLfloat) depthMax);
4178  }
4179  }
4180  else {
4181  /* need to use double precision to prevent overflow problems */
4182  for (i = 0; i < n; i++) {
4183  GLdouble z = depthValues[i] * (GLfloat) depthMax;
4184  if (z >= (GLdouble) 0xffffffff)
4185  zValues[i] = 0xffffffff;
4186  else
4187  zValues[i] = (GLuint) z;
4188  }
4189  }
4190  }
4191  else if (dstType == GL_UNSIGNED_SHORT) {
4192  GLushort *zValues = (GLushort *) dest;
4193  GLuint i;
4194  ASSERT(depthMax <= 0xffff);
4195  for (i = 0; i < n; i++) {
4196  zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax);
4197  }
4198  }
4199  else if (dstType == GL_FLOAT) {
4200  /* Nothing to do. depthValues is pointing to dest. */
4201  }
4202  else {
4203  ASSERT(0);
4204  }
4205 
4206  free(depthTemp);
4207 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
double GLdouble
Definition: gl.h:163
#define SHORT_TO_FLOATZ(S)
Definition: macros.h:81
#define GL_FALSE
Definition: gl.h:173
#define INT_TO_FLOAT(I)
Definition: macros.h:99
#define free
Definition: debug_ros.c:5
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
#define BYTE_TO_FLOATZ(B)
Definition: macros.h:58
#define GL_SHORT
Definition: gl.h:179
GLfloat scale
Definition: m_xform.h:122
GLuint n
Definition: s_context.h:57
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct gl_pixel_attrib Pixel
Definition: mtypes.h:1827
short GLshort
Definition: gl.h:155
#define CLAMP(f, min, max)
Definition: tif_color.c:179
unsigned char GLboolean
Definition: gl.h:151
GLdouble GLdouble z
Definition: glext.h:5874
GLfloat bias
Definition: glext.h:7909
smooth NULL
Definition: ftsmooth.c:416
#define GL_UNSIGNED_INT
Definition: gl.h:182
#define USHORT_TO_FLOAT(S)
Definition: macros.h:68
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
float GLfloat
Definition: gl.h:161
unsigned short GLushort
Definition: gl.h:158
signed char GLbyte
Definition: gl.h:154
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
unsigned int GLuint
Definition: gl.h:159
#define GL_TRUE
Definition: gl.h:174
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define malloc
Definition: debug_ros.c:4
#define UINT_TO_FLOAT(U)
Definition: macros.h:92
#define DEPTH_VALUES(GLTYPE, GLTYPE2FLOAT)
Definition: pack.c:4031
#define UBYTE_TO_FLOAT(u)
Definition: macros.h:44
const GLint const GLsizei GLint
Definition: dispatch.h:5271
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_unpack_image()

void* _mesa_unpack_image ( GLuint  dimensions,
GLsizei  width,
GLsizei  height,
GLsizei  depth,
GLenum  format,
GLenum  type,
const GLvoid pixels,
const struct gl_pixelstore_attrib unpack 
)

Unpack image data. Apply byte swapping, byte flipping (bitmap). Return all image data in a contiguous block. This is used when we compile glDrawPixels, glTexImage, etc into a display list. We need a copy of the data in a standard format.

Definition at line 4325 of file pack.c.

4329 {
4330  GLint bytesPerRow, compsPerRow;
4331  GLboolean flipBytes, swap2, swap4;
4332 
4333  if (!pixels)
4334  return NULL; /* not necessarily an error */
4335 
4336  if (width <= 0 || height <= 0 || depth <= 0)
4337  return NULL; /* generate error later */
4338 
4339  if (type == GL_BITMAP) {
4340  bytesPerRow = (width + 7) >> 3;
4341  flipBytes = unpack->LsbFirst;
4342  swap2 = swap4 = GL_FALSE;
4343  compsPerRow = 0;
4344  }
4345  else {
4346  const GLint bytesPerPixel = _mesa_bytes_per_pixel(format, type);
4348  GLint bytesPerComp;
4349 
4350  if (_mesa_type_is_packed(type))
4351  components = 1;
4352 
4353  if (bytesPerPixel <= 0 || components <= 0)
4354  return NULL; /* bad format or type. generate error later */
4355  bytesPerRow = bytesPerPixel * width;
4356  bytesPerComp = bytesPerPixel / components;
4357  flipBytes = GL_FALSE;
4358  swap2 = (bytesPerComp == 2) && unpack->SwapBytes;
4359  swap4 = (bytesPerComp == 4) && unpack->SwapBytes;
4360  compsPerRow = components * width;
4361  assert(compsPerRow >= width);
4362  }
4363 
4364  {
4365  GLubyte *destBuffer
4366  = (GLubyte *) malloc(bytesPerRow * height * depth);
4367  GLubyte *dst;
4368  GLint img, row;
4369  if (!destBuffer)
4370  return NULL; /* generate GL_OUT_OF_MEMORY later */
4371 
4372  dst = destBuffer;
4373  for (img = 0; img < depth; img++) {
4374  for (row = 0; row < height; row++) {
4375  const GLvoid *src = _mesa_image_address(dimensions, unpack, pixels,
4376  width, height, format, type, img, row, 0);
4377 
4378  if ((type == GL_BITMAP) && (unpack->SkipPixels & 0x7)) {
4379  GLint i;
4380  flipBytes = GL_FALSE;
4381  if (unpack->LsbFirst) {
4382  GLubyte srcMask = 1 << (unpack->SkipPixels & 0x7);
4383  GLubyte dstMask = 128;
4384  const GLubyte *s = src;
4385  GLubyte *d = dst;
4386  *d = 0;
4387  for (i = 0; i < width; i++) {
4388  if (*s & srcMask) {
4389  *d |= dstMask;
4390  }
4391  if (srcMask == 128) {
4392  srcMask = 1;
4393  s++;
4394  }
4395  else {
4396  srcMask = srcMask << 1;
4397  }
4398  if (dstMask == 1) {
4399  dstMask = 128;
4400  d++;
4401  *d = 0;
4402  }
4403  else {
4404  dstMask = dstMask >> 1;
4405  }
4406  }
4407  }
4408  else {
4409  GLubyte srcMask = 128 >> (unpack->SkipPixels & 0x7);
4410  GLubyte dstMask = 128;
4411  const GLubyte *s = src;
4412  GLubyte *d = dst;
4413  *d = 0;
4414  for (i = 0; i < width; i++) {
4415  if (*s & srcMask) {
4416  *d |= dstMask;
4417  }
4418  if (srcMask == 1) {
4419  srcMask = 128;
4420  s++;
4421  }
4422  else {
4423  srcMask = srcMask >> 1;
4424  }
4425  if (dstMask == 1) {
4426  dstMask = 128;
4427  d++;
4428  *d = 0;
4429  }
4430  else {
4431  dstMask = dstMask >> 1;
4432  }
4433  }
4434  }
4435  }
4436  else {
4437  memcpy(dst, src, bytesPerRow);
4438  }
4439 
4440  /* byte flipping/swapping */
4441  if (flipBytes) {
4442  flip_bytes((GLubyte *) dst, bytesPerRow);
4443  }
4444  else if (swap2) {
4445  _mesa_swap2((GLushort*) dst, compsPerRow);
4446  }
4447  else if (swap4) {
4448  _mesa_swap4((GLuint*) dst, compsPerRow);
4449  }
4450  dst += bytesPerRow;
4451  }
4452  }
4453  return destBuffer;
4454  }
4455 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define GL_BITMAP
Definition: gl.h:497
GLboolean LsbFirst
Definition: mtypes.h:1155
static void flip_bytes(GLubyte *p, GLuint n)
Definition: pack.c:46
#define GL_FALSE
Definition: gl.h:173
#define assert(x)
Definition: debug.h:53
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
unsigned char GLboolean
Definition: gl.h:151
GLint _mesa_bytes_per_pixel(GLenum format, GLenum type)
Definition: image.c:246
smooth NULL
Definition: ftsmooth.c:416
void _mesa_swap2(GLushort *p, GLuint n)
Definition: image.c:70
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
GLboolean SwapBytes
Definition: mtypes.h:1154
#define d
Definition: ke_i.h:81
GLint GLvoid * img
Definition: gl.h:1956
GLint _mesa_components_in_format(GLenum format)
Definition: image.c:192
unsigned short GLushort
Definition: gl.h:158
UCHAR bytesPerPixel(ULONG Format)
Definition: vgavideo.c:25
GLenum GLenum GLuint components
Definition: glext.h:9620
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLuint GLuint dstMask
Definition: glext.h:9513
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
void _mesa_swap4(GLuint *p, GLuint n)
Definition: image.c:84
unsigned char GLubyte
Definition: gl.h:157
unsigned int GLuint
Definition: gl.h:159
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
GLboolean _mesa_type_is_packed(GLenum type)
Definition: image.c:37
#define malloc
Definition: debug_ros.c:4
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

◆ _mesa_unpack_index_span()

void _mesa_unpack_index_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 at line 3593 of file pack.c.

3598 {
3599  ASSERT(srcType == GL_BITMAP ||
3600  srcType == GL_UNSIGNED_BYTE ||
3601  srcType == GL_BYTE ||
3602  srcType == GL_UNSIGNED_SHORT ||
3603  srcType == GL_SHORT ||
3604  srcType == GL_UNSIGNED_INT ||
3605  srcType == GL_INT ||
3606  srcType == GL_HALF_FLOAT_ARB ||
3607  srcType == GL_FLOAT);
3608 
3609  ASSERT(dstType == GL_UNSIGNED_BYTE ||
3610  dstType == GL_UNSIGNED_SHORT ||
3611  dstType == GL_UNSIGNED_INT);
3612 
3613 
3614  transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
3615 
3616  /*
3617  * Try simple cases first
3618  */
3619  if (transferOps == 0 && srcType == GL_UNSIGNED_BYTE
3620  && dstType == GL_UNSIGNED_BYTE) {
3621  memcpy(dest, source, n * sizeof(GLubyte));
3622  }
3623  else if (transferOps == 0 && srcType == GL_UNSIGNED_INT
3624  && dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) {
3625  memcpy(dest, source, n * sizeof(GLuint));
3626  }
3627  else {
3628  /*
3629  * general solution
3630  */
3631  GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
3632 
3633  if (!indexes) {
3634  _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
3635  return;
3636  }
3637 
3638  extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
3639  srcPacking);
3640 
3641  if (transferOps)
3642  _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
3643 
3644  /* convert to dest type */
3645  switch (dstType) {
3646  case GL_UNSIGNED_BYTE:
3647  {
3648  GLubyte *dst = (GLubyte *) dest;
3649  GLuint i;
3650  for (i = 0; i < n; i++) {
3651  dst[i] = (GLubyte) (indexes[i] & 0xff);
3652  }
3653  }
3654  break;
3655  case GL_UNSIGNED_SHORT:
3656  {
3657  GLuint *dst = (GLuint *) dest;
3658  GLuint i;
3659  for (i = 0; i < n; i++) {
3660  dst[i] = (GLushort) (indexes[i] & 0xffff);
3661  }
3662  }
3663  break;
3664  case GL_UNSIGNED_INT:
3665  memcpy(dest, indexes, n * sizeof(GLuint));
3666  break;
3667  default:
3668  _mesa_problem(ctx, "bad dstType in _mesa_unpack_index_span");
3669  }
3670 
3671  free(indexes);
3672  }
3673 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_BITMAP
Definition: gl.h:497
void _mesa_apply_ci_transfer_ops(const struct gl_context *ctx, GLbitfield transferOps, GLuint n, GLuint indexes[])
#define free
Definition: debug_ros.c:5
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
static void extract_uint_indexes(GLuint n, GLuint indexes[], GLenum srcFormat, GLenum srcType, const GLvoid *src, const struct gl_pixelstore_attrib *unpack)
Definition: pack.c:1831
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define GL_UNSIGNED_INT
Definition: gl.h:182
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
GLboolean SwapBytes
Definition: mtypes.h:1154
unsigned short GLushort
Definition: gl.h:158
#define IMAGE_SHIFT_OFFSET_BIT
Definition: mtypes.h:1573
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define GL_HALF_FLOAT_ARB
Definition: glext.h:1629
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
unsigned int GLuint
Definition: gl.h:159
#define GL_COLOR_INDEX
Definition: gl.h:479
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define IMAGE_MAP_COLOR_BIT
Definition: mtypes.h:1574
#define malloc
Definition: debug_ros.c:4
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ _mesa_unpack_polygon_stipple()

void _mesa_unpack_polygon_stipple ( const GLubyte pattern,
GLuint  dest[32],
const struct gl_pixelstore_attrib unpacking 
)

Definition at line 70 of file pack.c.

Referenced by _mesa_PolygonMode().

72 {
73  GLubyte *ptrn = (GLubyte *) _mesa_unpack_bitmap(32, 32, pattern, unpacking);
74  if (ptrn) {
75  /* Convert pattern from GLubytes to GLuints and handle big/little
76  * endian differences
77  */
78  GLubyte *p = ptrn;
79  GLint i;
80  for (i = 0; i < 32; i++) {
81  dest[i] = (p[0] << 24)
82  | (p[1] << 16)
83  | (p[2] << 8)
84  | (p[3] );
85  p += 4;
86  }
87  free(ptrn);
88  }
89 }
#define free
Definition: debug_ros.c:5
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLfloat CONST GLvector4f CONST GLfloat GLvector4f * dest
Definition: m_xform.h:122
unsigned char GLubyte
Definition: gl.h:157
GLvoid * _mesa_unpack_bitmap(GLint width, GLint height, const GLubyte *pixels, const struct gl_pixelstore_attrib *packing)
Definition: pack.c:121
GLfloat GLfloat p
Definition: glext.h:8902
GLubyte * pattern
Definition: glext.h:7787
const GLint const GLsizei GLint
Definition: dispatch.h:5271

◆ _mesa_unpack_stencil_span()

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 at line 3800 of file pack.c.

Referenced by _mesa_texstore_s8(), and draw_stencil_pixels().

3805 {
3806  ASSERT(srcType == GL_BITMAP ||
3807  srcType == GL_UNSIGNED_BYTE ||
3808  srcType == GL_BYTE ||
3809  srcType == GL_UNSIGNED_SHORT ||
3810  srcType == GL_SHORT ||
3811  srcType == GL_UNSIGNED_INT ||
3812  srcType == GL_INT ||
3813  srcType == GL_HALF_FLOAT_ARB ||
3814  srcType == GL_FLOAT);
3815 
3816  ASSERT(dstType == GL_UNSIGNED_BYTE ||
3817  dstType == GL_UNSIGNED_SHORT ||
3818  dstType == GL_UNSIGNED_INT);
3819 
3820  /* only shift and offset apply to stencil */
3821  transferOps &= IMAGE_SHIFT_OFFSET_BIT;
3822 
3823  /*
3824  * Try simple cases first
3825  */
3826  if (transferOps == 0 &&
3827  !ctx->Pixel.MapStencilFlag &&
3828  srcType == GL_UNSIGNED_BYTE &&
3829  dstType == GL_UNSIGNED_BYTE) {
3830  memcpy(dest, source, n * sizeof(GLubyte));
3831  }
3832  else if (transferOps == 0 &&
3833  !ctx->Pixel.MapStencilFlag &&
3834  srcType == GL_UNSIGNED_INT &&
3835  dstType == GL_UNSIGNED_INT &&
3836  !srcPacking->SwapBytes) {
3837  memcpy(dest, source, n * sizeof(GLuint));
3838  }
3839  else {
3840  /*
3841  * general solution
3842  */
3843  GLuint *indexes = (GLuint *) malloc(n * sizeof(GLuint));
3844 
3845  if (!indexes) {
3846  _mesa_error(ctx, GL_OUT_OF_MEMORY, "stencil unpacking");
3847  return;
3848  }
3849 
3850  extract_uint_indexes(n, indexes, GL_STENCIL_INDEX, srcType, source,
3851  srcPacking);
3852 
3853  if (transferOps & IMAGE_SHIFT_OFFSET_BIT) {
3854  /* shift and offset indexes */
3855  _mesa_shift_and_offset_ci(ctx, n, indexes);
3856  }
3857 
3858  if (ctx->Pixel.MapStencilFlag) {
3859  /* Apply stencil lookup table */
3860  const GLuint mask = ctx->PixelMaps.StoS.Size - 1;
3861  GLuint i;
3862  for (i = 0; i < n; i++) {
3863  indexes[i] = (GLuint)ctx->PixelMaps.StoS.Map[ indexes[i] & mask ];
3864  }
3865  }
3866 
3867  /* convert to dest type */
3868  switch (dstType) {
3869  case GL_UNSIGNED_BYTE:
3870  {
3871  GLubyte *dst = (GLubyte *) dest;
3872  GLuint i;
3873  for (i = 0; i < n; i++) {
3874  dst[i] = (GLubyte) (indexes[i] & 0xff);
3875  }
3876  }
3877  break;
3878  case GL_UNSIGNED_SHORT:
3879  {
3880  GLuint *dst = (GLuint *) dest;
3881  GLuint i;
3882  for (i = 0; i < n; i++) {
3883  dst[i] = (GLushort) (indexes[i] & 0xffff);
3884  }
3885  }
3886  break;
3887  case GL_UNSIGNED_INT:
3888  memcpy(dest, indexes, n * sizeof(GLuint));
3889  break;
3890  default:
3891  _mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span");
3892  }
3893 
3894  free(indexes);
3895  }
3896 }
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_BITMAP
Definition: gl.h:497
#define free
Definition: debug_ros.c:5
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
#define GL_FLOAT
Definition: gl.h:183
static void extract_uint_indexes(GLuint n, GLuint indexes[], GLenum srcFormat, GLenum srcType, const GLvoid *src, const struct gl_pixelstore_attrib *unpack)
Definition: pack.c:1831
#define GL_SHORT
Definition: gl.h:179
GLuint n
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLenum GLint GLuint mask
Definition: glext.h:6028
struct gl_pixel_attrib Pixel
Definition: mtypes.h:1827
#define GL_UNSIGNED_INT
Definition: gl.h:182
void _mesa_problem(const struct gl_context *ctx, const char *fmtString,...)
Definition: imports.c:798
GLboolean SwapBytes
Definition: mtypes.h:1154
unsigned short GLushort
Definition: gl.h:158
struct gl_pixelmaps PixelMaps
Definition: mtypes.h:1854
#define IMAGE_SHIFT_OFFSET_BIT
Definition: mtypes.h:1573
#define GL_STENCIL_INDEX
Definition: gl.h:458
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define GL_HALF_FLOAT_ARB
Definition: glext.h:1629
unsigned char GLubyte
Definition: gl.h:157
#define GL_BYTE
Definition: gl.h:177
unsigned int GLuint
Definition: gl.h:159
void _mesa_shift_and_offset_ci(const struct gl_context *ctx, GLuint n, GLuint indexes[])
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define malloc
Definition: debug_ros.c:4
void _mesa_error(struct gl_context *ctx, GLenum error, const char *fmtString,...)
Definition: imports.c:832

◆ clamp_float_to_uint()

static GLuint clamp_float_to_uint ( GLfloat  f)
inlinestatic

Definition at line 2594 of file pack.c.

Referenced by extract_uint_rgba().

2595 {
2596  return f < 0.0F ? 0 : IROUND(f);
2597 }
#define IROUND(f)
Definition: imports.h:321
GLfloat f
Definition: glext.h:7540

◆ extract_float_rgba()

static void extract_float_rgba ( GLuint  n,
GLfloat  rgba[][4],
GLenum  srcFormat,
GLenum  srcType,
const GLvoid src,
GLboolean  swapBytes 
)
static

Definition at line 2129 of file pack.c.

Referenced by _mesa_unpack_color_span_float(), and _mesa_unpack_color_span_ubyte().

2132 {
2133  GLint rSrc, gSrc, bSrc, aSrc;
2134  GLint stride;
2135  GLint rDst, bDst, gDst, aDst;
2136  GLboolean intFormat;
2137  GLfloat rs = 1.0f, gs = 1.0f, bs = 1.0f, as = 1.0f; /* scale factors */
2138 
2139  ASSERT(srcFormat == GL_RED ||
2140  srcFormat == GL_GREEN ||
2141  srcFormat == GL_BLUE ||
2142  srcFormat == GL_ALPHA ||
2143  srcFormat == GL_LUMINANCE ||
2144  srcFormat == GL_LUMINANCE_ALPHA ||
2145  srcFormat == GL_INTENSITY ||
2146  srcFormat == GL_RG ||
2147  srcFormat == GL_RGB ||
2148  srcFormat == GL_BGR ||
2149  srcFormat == GL_RGBA ||
2150  srcFormat == GL_BGRA ||
2151  srcFormat == GL_ABGR_EXT ||
2152  srcFormat == GL_RED_INTEGER_EXT ||
2153  srcFormat == GL_GREEN_INTEGER_EXT ||
2154  srcFormat == GL_BLUE_INTEGER_EXT ||
2155  srcFormat == GL_ALPHA_INTEGER_EXT ||
2156  srcFormat == GL_RG_INTEGER ||
2157  srcFormat == GL_RGB_INTEGER_EXT ||
2158  srcFormat == GL_RGBA_INTEGER_EXT ||
2159  srcFormat == GL_BGR_INTEGER_EXT ||
2160  srcFormat == GL_BGRA_INTEGER_EXT ||
2161  srcFormat == GL_LUMINANCE_INTEGER_EXT ||
2162  srcFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT);
2163 
2164  ASSERT(srcType == GL_UNSIGNED_BYTE ||
2165  srcType == GL_BYTE ||
2166  srcType == GL_UNSIGNED_SHORT ||
2167  srcType == GL_SHORT ||
2168  srcType == GL_UNSIGNED_INT ||
2169  srcType == GL_INT ||
2170  srcType == GL_HALF_FLOAT_ARB ||
2171  srcType == GL_FLOAT ||
2172  srcType == GL_UNSIGNED_BYTE_3_3_2 ||
2173  srcType == GL_UNSIGNED_BYTE_2_3_3_REV ||
2174  srcType == GL_UNSIGNED_SHORT_5_6_5 ||
2175  srcType == GL_UNSIGNED_SHORT_5_6_5_REV ||
2176  srcType == GL_UNSIGNED_SHORT_4_4_4_4 ||
2177  srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ||
2178  srcType == GL_UNSIGNED_SHORT_5_5_5_1 ||
2179  srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ||
2180  srcType == GL_UNSIGNED_INT_8_8_8_8 ||
2181  srcType == GL_UNSIGNED_INT_8_8_8_8_REV ||
2182  srcType == GL_UNSIGNED_INT_5_9_9_9_REV ||
2183  srcType == GL_UNSIGNED_INT_10F_11F_11F_REV);
2184 
2185  get_component_mapping(srcFormat,
2186  &rSrc, &gSrc, &bSrc, &aSrc,
2187  &rDst, &gDst, &bDst, &aDst);
2188 
2189  stride = _mesa_components_in_format(srcFormat);
2190 
2191  intFormat = _mesa_is_integer_format(srcFormat);
2192 
2193 #define PROCESS(SRC_INDEX, DST_INDEX, DEFAULT_FLT, DEFAULT_INT, TYPE, CONVERSION) \
2194  if ((SRC_INDEX) < 0) { \
2195  GLuint i; \
2196  if (intFormat) { \
2197  for (i = 0; i < n; i++) { \
2198  rgba[i][DST_INDEX] = DEFAULT_INT; \
2199  } \
2200  } \
2201  else { \
2202  for (i = 0; i < n; i++) { \
2203  rgba[i][DST_INDEX] = DEFAULT_FLT; \
2204  } \
2205  } \
2206  } \
2207  else if (swapBytes) { \
2208  const TYPE *s = (const TYPE *) src; \
2209  GLuint i; \
2210  for (i = 0; i < n; i++) { \
2211  TYPE value = s[SRC_INDEX]; \
2212  if (sizeof(TYPE) == 2) { \
2213  SWAP2BYTE(value); \
2214  } \
2215  else if (sizeof(TYPE) == 4) { \
2216  SWAP4BYTE(value); \
2217  } \
2218  if (intFormat) \
2219  rgba[i][DST_INDEX] = (GLfloat) value; \
2220  else \
2221  rgba[i][DST_INDEX] = (GLfloat) CONVERSION(value); \
2222  s += stride; \
2223  } \
2224  } \
2225  else { \
2226  const TYPE *s = (const TYPE *) src; \
2227  GLuint i; \
2228  if (intFormat) { \
2229  for (i = 0; i < n; i++) { \
2230  rgba[i][DST_INDEX] = (GLfloat) s[SRC_INDEX]; \
2231  s += stride; \
2232  } \
2233  } \
2234  else { \
2235  for (i = 0; i < n; i++) { \
2236  rgba[i][DST_INDEX] = (GLfloat) CONVERSION(s[SRC_INDEX]); \
2237  s += stride; \
2238  } \
2239  } \
2240  }
2241 
2242  switch (srcType) {
2243  case GL_UNSIGNED_BYTE:
2244  PROCESS(rSrc, RCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
2245  PROCESS(gSrc, GCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
2246  PROCESS(bSrc, BCOMP, 0.0F, 0, GLubyte, UBYTE_TO_FLOAT);
2247  PROCESS(aSrc, ACOMP, 1.0F, 255, GLubyte, UBYTE_TO_FLOAT);
2248  break;
2249  case GL_BYTE:
2250  PROCESS(rSrc, RCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
2251  PROCESS(gSrc, GCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
2252  PROCESS(bSrc, BCOMP, 0.0F, 0, GLbyte, BYTE_TO_FLOATZ);
2253  PROCESS(aSrc, ACOMP, 1.0F, 127, GLbyte, BYTE_TO_FLOATZ);
2254  break;
2255  case GL_UNSIGNED_SHORT:
2256  PROCESS(rSrc, RCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
2257  PROCESS(gSrc, GCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
2258  PROCESS(bSrc, BCOMP, 0.0F, 0, GLushort, USHORT_TO_FLOAT);
2259  PROCESS(aSrc, ACOMP, 1.0F, 0xffff, GLushort, USHORT_TO_FLOAT);
2260  break;
2261  case GL_SHORT:
2262  PROCESS(rSrc, RCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
2263  PROCESS(gSrc, GCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
2264  PROCESS(bSrc, BCOMP, 0.0F, 0, GLshort, SHORT_TO_FLOATZ);
2265  PROCESS(aSrc, ACOMP, 1.0F, 32767, GLshort, SHORT_TO_FLOATZ);
2266  break;
2267  case GL_UNSIGNED_INT:
2268  PROCESS(rSrc, RCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
2269  PROCESS(gSrc, GCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
2270  PROCESS(bSrc, BCOMP, 0.0F, 0, GLuint, UINT_TO_FLOAT);
2271  PROCESS(aSrc, ACOMP, 1.0F, 0xffffffff, GLuint, UINT_TO_FLOAT);
2272  break;
2273  case GL_INT:
2274  PROCESS(rSrc, RCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
2275  PROCESS(gSrc, GCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
2276  PROCESS(bSrc, BCOMP, 0.0F, 0, GLint, INT_TO_FLOAT);
2277  PROCESS(aSrc, ACOMP, 1.0F, 2147483647, GLint, INT_TO_FLOAT);
2278  break;
2279  case GL_FLOAT:
2280  PROCESS(rSrc, RCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
2281  PROCESS(gSrc, GCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
2282  PROCESS(bSrc, BCOMP, 0.0F, 0.0F, GLfloat, (GLfloat));
2283  PROCESS(aSrc, ACOMP, 1.0F, 1.0F, GLfloat, (GLfloat));
2284  break;
2286  {
2287  const GLubyte *ubsrc = (const GLubyte *) src;
2288  GLuint i;
2289  if (!intFormat) {
2290  rs = 1.0F / 7.0F;
2291  gs = 1.0F / 7.0F;
2292  bs = 1.0F / 3.0F;
2293  }
2294  for (i = 0; i < n; i ++) {
2295  GLubyte p = ubsrc[i];
2296  rgba[i][rDst] = ((p >> 5) ) * rs;
2297  rgba[i][gDst] = ((p >> 2) & 0x7) * gs;
2298  rgba[i][bDst] = ((p ) & 0x3) * bs;
2299  rgba[i][aDst] = 1.0F;
2300  }
2301  }
2302  break;
2304  {
2305  const GLubyte *ubsrc = (const GLubyte *) src;
2306  GLuint i;
2307  if (!intFormat) {
2308  rs = 1.0F / 7.0F;
2309  gs = 1.0F / 7.0F;
2310  bs = 1.0F / 3.0F;
2311  }
2312  for (i = 0; i < n; i ++) {
2313  GLubyte p = ubsrc[i];
2314  rgba[i][rDst] = ((p ) & 0x7) * rs;
2315  rgba[i][gDst] = ((p >> 3) & 0x7) * gs;
2316  rgba[i][bDst] = ((p >> 6) ) * bs;
2317  rgba[i][aDst] = 1.0F;
2318  }
2319  }
2320  break;
2322  if (!intFormat) {
2323  rs = 1.0F / 31.0F;
2324  gs = 1.0F / 63.0F;
2325  bs = 1.0F / 31.0F;
2326  }
2327  if (swapBytes) {
2328  const GLushort *ussrc = (const GLushort *) src;
2329  GLuint i;
2330  for (i = 0; i < n; i ++) {
2331  GLushort p = ussrc[i];
2332  SWAP2BYTE(p);
2333  rgba[i][rDst] = ((p >> 11) ) * rs;
2334  rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
2335  rgba[i][bDst] = ((p ) & 0x1f) * bs;
2336  rgba[i][aDst] = 1.0F;
2337  }
2338  }
2339  else {
2340  const GLushort *ussrc = (const GLushort *) src;
2341  GLuint i;
2342  for (i = 0; i < n; i ++) {
2343  GLushort p = ussrc[i];
2344  rgba[i][rDst] = ((p >> 11) ) * rs;
2345  rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
2346  rgba[i][bDst] = ((p ) & 0x1f) * bs;
2347  rgba[i][aDst] = 1.0F;
2348  }
2349  }
2350  break;
2352  if (!intFormat) {
2353  rs = 1.0F / 31.0F;
2354  gs = 1.0F / 63.0F;
2355  bs = 1.0F / 31.0F;
2356  }
2357  if (swapBytes) {
2358  const GLushort *ussrc = (const GLushort *) src;
2359  GLuint i;
2360  for (i = 0; i < n; i ++) {
2361  GLushort p = ussrc[i];
2362  SWAP2BYTE(p);
2363  rgba[i][rDst] = ((p ) & 0x1f) * rs;
2364  rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
2365  rgba[i][bDst] = ((p >> 11) ) * bs;
2366  rgba[i][aDst] = 1.0F;
2367  }
2368  }
2369  else {
2370  const GLushort *ussrc = (const GLushort *) src;
2371  GLuint i;
2372  for (i = 0; i < n; i ++) {
2373  GLushort p = ussrc[i];
2374  rgba[i][rDst] = ((p ) & 0x1f) * rs;
2375  rgba[i][gDst] = ((p >> 5) & 0x3f) * gs;
2376  rgba[i][bDst] = ((p >> 11) ) * bs;
2377  rgba[i][aDst] = 1.0F;
2378  }
2379  }
2380  break;
2382  if (!intFormat) {
2383  rs = gs = bs = as = 1.0F / 15.0F;
2384  }
2385  if (swapBytes) {
2386  const GLushort *ussrc = (const GLushort *) src;
2387  GLuint i;
2388  for (i = 0; i < n; i ++) {
2389  GLushort p = ussrc[i];
2390  SWAP2BYTE(p);
2391  rgba[i][rDst] = ((p >> 12) ) * rs;
2392  rgba[i][gDst] = ((p >> 8) & 0xf) * gs;
2393  rgba[i][bDst] = ((p >> 4) & 0xf) * bs;
2394  rgba[i][aDst] = ((p ) & 0xf) * as;
2395  }
2396  }
2397  else {
2398  const GLushort *ussrc = (const GLushort *) src;
2399  GLuint i;
2400  for (i = 0; i < n; i ++) {
2401  GLushort p = ussrc[i];
2402  rgba[i][rDst] = ((p >> 12) ) * rs;
2403  rgba[i][gDst] = ((p >> 8) & 0xf) * gs;
2404  rgba[i][bDst] = ((p >> 4) & 0xf) * bs;
2405  rgba[i][aDst] = ((p ) & 0xf) * as;
2406  }
2407  }
2408  break;
2410  if (!intFormat) {
2411  rs = gs = bs = as = 1.0F / 15.0F;
2412  }
2413  if (swapBytes) {
2414  const GLushort *ussrc = (const GLushort *) src;
2415  GLuint i;
2416  for (i = 0; i < n; i ++) {
2417  GLushort p = ussrc[i];
2418  SWAP2BYTE(p);
2419  rgba[i][rDst] = ((p ) & 0xf) * rs;
2420  rgba[i][gDst] = ((p >> 4) & 0xf) * gs;
2421  rgba[i][bDst] = ((p >> 8) & 0xf) * bs;
2422  rgba[i][aDst] = ((p >> 12) ) * as;
2423  }
2424  }
2425  else {
2426  const GLushort *ussrc = (const GLushort *) src;
2427  GLuint i;
2428  for (i = 0; i < n; i ++) {
2429  GLushort p = ussrc[i];
2430  rgba[i][rDst] = ((p ) & 0xf) * rs;
2431  rgba[i][gDst] = ((p >> 4) & 0xf) * gs;
2432  rgba[i][bDst] = ((p >> 8) & 0xf) * bs;
2433  rgba[i][aDst] = ((p >> 12) ) * as;
2434  }
2435  }
2436  break;
2438  if (!intFormat) {
2439  rs = gs = bs = 1.0F / 31.0F;
2440  }
2441  if (swapBytes) {
2442  const GLushort *ussrc = (const GLushort *) src;
2443  GLuint i;
2444  for (i = 0; i < n; i ++) {
2445  GLushort p = ussrc[i];
2446  SWAP2BYTE(p);
2447  rgba[i][rDst] = ((p >> 11) ) * rs;
2448  rgba[i][gDst] = ((p >> 6) & 0x1f) * gs;
2449  rgba[i][bDst] = ((p >> 1) & 0x1f) * bs;
2450  rgba[i][aDst] = ((p ) & 0x1) * as;
2451  }
2452  }
2453  else {
2454  const GLushort *ussrc = (const GLushort *) src;
2455  GLuint i;
2456  for (i = 0; i < n; i ++) {
2457  GLushort p = ussrc[i];
2458  rgba[i][rDst] = ((p >> 11) ) * rs;
2459  rgba[i][gDst] = ((p >> 6) & 0x1f) * gs;
2460  rgba[i][bDst] = ((p >> 1) & 0x1f) * bs;
2461  rgba[i][aDst] = ((p ) & 0x1) * as;
2462  }
2463  }
2464  break;
2466  if (!intFormat) {
2467  rs = gs = bs = 1.0F / 31.0F;
2468  }
2469  if (swapBytes) {
2470  const GLushort *ussrc = (const GLushort *) src;
2471  GLuint i;
2472  for (i = 0; i < n; i ++) {
2473  GLushort p = ussrc[i];
2474