From: Gareth H. <ga...@va...> - 2000-10-16 11:53:13
|
I guess the C code might help, although not much... Original: GLboolean _mesa_convert_teximage(MesaIntTexFormat dstFormat, GLint dstWidth, GLint dstHeight, GLvoid *dstImage, GLint dstRowStride, GLint srcWidth, GLint srcHeight, GLenum srcFormat, GLenum srcType, const GLvoid *srcImage, const struct gl_pixelstore_attrib *packing) { const GLint wScale = dstWidth / srcWidth; /* must be power of two */ const GLint hScale = dstHeight / srcHeight; /* must be power of two */ ASSERT(dstWidth >= srcWidth); ASSERT(dstHeight >= srcHeight); ASSERT(dstImage); ASSERT(srcImage); ASSERT(packing); switch (dstFormat) { ... case MESA_A4_R4_G4_B4: /* store as 16-bit texels (GR_TEXFMT_ARGB_4444) */ if (srcFormat == GL_BGRA && srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV){ ... } else if (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE) { /* general case */ if (wScale == 1 && hScale == 1) { const GLubyte *src = _mesa_image_address(packing, srcImage, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0); const GLint srcStride = _mesa_image_row_stride(packing, srcWidth, srcFormat, srcType); GLushort *dst = (GLushort *) dstImage; GLint row; for (row = 0; row < dstHeight; row++) { GLint col, col4; for (col = col4 = 0; col < dstWidth; col++, col4 += 4) { GLubyte r = src[col4 + 0]; GLubyte g = src[col4 + 1]; GLubyte b = src[col4 + 2]; GLubyte a = src[col4 + 3]; dst[col] = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) ) | ((b & 0xf0) >> 4); } src += srcStride; dst = (GLushort *) ((GLubyte *) dst + dstRowStride); } } else { ... } } else { ... } break; ... } return GL_TRUE; } Special case: GLboolean _mesa_convert_teximage_argb_4444(MesaIntTexFormat dstFormat, GLint dstWidth, GLint dstHeight, GLvoid *dstImage, GLint dstRowStride, GLint srcWidth, GLint srcHeight, GLenum srcFormat, GLenum srcType, const GLvoid *srcImage, const struct gl_pixelstore_attrib *packing) { const GLubyte *src = srcImage; const GLint srcStride = srcWidth * 2; GLushort *dst = (GLushort *) dstImage; GLint row; for (row = 0; row < dstHeight; row++) { GLint col, col4; for (col = col4 = 0; col < dstWidth; col++, col4 += 4) { GLubyte r = src[col4 + 0]; GLubyte g = src[col4 + 1]; GLubyte b = src[col4 + 2]; GLubyte a = src[col4 + 3]; dst[col] = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) ) | ((b & 0xf0) >> 4); } src += srcStride; dst = (GLushort *) ((GLubyte *) dst + dstRowStride); } return GL_TRUE; } Figure that one out... |