GLboolean _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS) { GLubyte *dst; const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */ const GLubyte *tempImage = NULL; int i, j; int numxpixels, numypixels; const GLubyte *srcaddr; GLubyte srcpixels[4][4]; GLubyte *blkaddr; GLint dstRowDiff; ASSERT(dstFormat == MESA_FORMAT_RG_RGTC2 || dstFormat == MESA_FORMAT_LA_LATC2); ASSERT(dstXoffset % 4 == 0); ASSERT(dstYoffset % 4 == 0); ASSERT(dstZoffset % 4 == 0); (void) dstZoffset; tempImage = _mesa_make_temp_ubyte_image(ctx, dims, baseInternalFormat, _mesa_get_format_base_format(dstFormat), srcWidth, srcHeight, srcDepth, srcFormat, srcType, srcAddr, srcPacking); if (!tempImage) return GL_FALSE; /* out of memory */ dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, dstFormat, texWidth, dstSlices[0]); blkaddr = dst; dstRowDiff = dstRowStride >= (srcWidth * 4) ? dstRowStride - (((srcWidth + 3) & ~3) * 4) : 0; for (j = 0; j < srcHeight; j+=4) { if (srcHeight > j + 3) numypixels = 4; else numypixels = srcHeight - j; srcaddr = tempImage + j * srcWidth * 2; for (i = 0; i < srcWidth; i += 4) { if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2); unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; extractsrc_u(srcpixels, (GLubyte *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2); unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); blkaddr += 8; srcaddr += numxpixels * 2; } blkaddr += dstRowDiff; } if (tempImage) free((void *) tempImage); return GL_TRUE; }
/** * Store user's image in rgba_dxt1 format. */ GLboolean _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS) { const GLubyte *pixels; GLubyte *dst; const GLubyte *tempImage = NULL; ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT1 || dstFormat == MESA_FORMAT_SRGBA_DXT1); if (srcFormat != GL_RGBA || srcType != GL_UNSIGNED_BYTE || ctx->_ImageTransferState || srcPacking->RowLength != srcWidth || srcPacking->SwapBytes) { /* convert image to RGBA/GLubyte */ tempImage = _mesa_make_temp_ubyte_image(ctx, dims, baseInternalFormat, _mesa_get_format_base_format(dstFormat), srcWidth, srcHeight, srcDepth, srcFormat, srcType, srcAddr, srcPacking); if (!tempImage) return GL_FALSE; /* out of memory */ pixels = tempImage; srcFormat = GL_RGBA; } else { pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0); } dst = dstSlices[0]; if (ext_tx_compress_dxtn) { (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, dst, dstRowStride); } else { _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt1"); } free((void*) tempImage); return GL_TRUE; }
GLboolean _mesa_texstore_red_rgtc1(TEXSTORE_PARAMS) { GLubyte *dst; const GLubyte *tempImage = NULL; int i, j; int numxpixels, numypixels; const GLubyte *srcaddr; GLubyte srcpixels[4][4]; GLubyte *blkaddr; GLint dstRowDiff; ASSERT(dstFormat == MESA_FORMAT_R_RGTC1_UNORM || dstFormat == MESA_FORMAT_L_LATC1_UNORM); tempImage = _mesa_make_temp_ubyte_image(ctx, dims, baseInternalFormat, _mesa_get_format_base_format(dstFormat), srcWidth, srcHeight, srcDepth, srcFormat, srcType, srcAddr, srcPacking); if (!tempImage) return GL_FALSE; /* out of memory */ dst = dstSlices[0]; blkaddr = dst; dstRowDiff = dstRowStride >= (srcWidth * 2) ? dstRowStride - (((srcWidth + 3) & ~3) * 2) : 0; for (j = 0; j < srcHeight; j+=4) { if (srcHeight > j + 3) numypixels = 4; else numypixels = srcHeight - j; srcaddr = tempImage + j * srcWidth; for (i = 0; i < srcWidth; i += 4) { if (srcWidth > i + 3) numxpixels = 4; else numxpixels = srcWidth - i; extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1); unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels); srcaddr += numxpixels; blkaddr += 8; } blkaddr += dstRowDiff; } free((void *) tempImage); return GL_TRUE; }