Exemple #1
0
/**
 * Read pixels from 565 format.
 *
 * \param x x-coordinate of the first pixel
 * \param y y-coordinate of the first pixel
 * \param width x-dimension of the pixel rectangle
 * \param height y-dimension of the pixel rectangle
 * \param format format of the pixel data
 * \param type data type of the pixel data
 * \param pixels pixel data
 * \param info hardware buffer info
 */
static void
_readpixels565 (GLint x, GLint y,
		GLsizei width, GLsizei height,
		GLenum format, GLenum type,
		GLvoid *pixels,
		GrLfbInfo_t *info)
{
    const GLint srcStride = info->strideInBytes / 2;
    const GLushort *src = (const GLushort *)info->lfbPtr + y * srcStride + x;
    if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
	/* convert 5R6G5B into 8R8G8B */
	GLint row, col;
	GLint dstStride = image_stride(&ctx_pack, width, 3);
	GLubyte *dst = (GLubyte *)image_address(&ctx_pack, pixels, width, height, 3, 0, 0, 0);
	for (row = 0; row < height; row++) {
	    GLubyte *d = dst;
	    for (col = 0; col < width; col++) {
		const GLushort pixel = src[col];
		GLuint r = (pixel & 0xf800) >> 8;
		GLuint g = (pixel & 0x07e0) >> 3;
		GLuint b = (pixel & 0x001f) << 3;
		*d++ = r | (r >> 5);
		*d++ = g | (g >> 6);
		*d++ = b | (b >> 5);
	    }
	    dst += dstStride;
	    src -= srcStride;
	}
    } else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
Exemple #2
0
void *
tc_encode (const PACKING *unpack,
	   int dst_width, int dst_height,
	   void *dst,
	   GLenum dst_format,
	   int src_width, int src_height,
	   const GLvoid *src,
	   GLenum src_format,
	   GLenum src_type)
{
    TC_ENCODER encoder = NULL;
    int srcStrideInBytes;
    int srcTexelBytes;
    int destRowStride;
    int size;

    if (h == NULL) {
	return NULL;
    }

    if ((src_format != GL_RGB && src_format != GL_RGBA) || (src_type != GL_UNSIGNED_BYTE)) {
	return NULL;
    }
    srcTexelBytes = (src_format == GL_RGB) ? 3 : 4;

    switch (dst_format) {
	case GL_COMPRESSED_RGB_FXT1_3DFX:
	case GL_COMPRESSED_RGBA_FXT1_3DFX:
	    encoder = fxt1_encode;
	    break;
	case GL_RGB_S3TC:
	case GL_RGB4_S3TC:
	case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
	    encoder = dxt1_rgb_encode;
	    break;
	case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
	    encoder = dxt1_rgba_encode;
	    break;
	case GL_RGBA_S3TC:
	case GL_RGBA4_S3TC:
	case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
	    encoder = dxt3_rgba_encode;
	    break;
	case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
	    encoder = dxt5_rgba_encode;
	    break;
	default:
	    return NULL;
    }

    srcStrideInBytes = image_stride(unpack, src_width, srcTexelBytes);
    destRowStride = tc_stride(dst_format, dst_width);
    size = tc_size(dst_format, dst_width, dst_height);

    if (dst == NULL) {
	dst = malloc(size);
    }
    if (dst == NULL) {
	return NULL;
    }

    encoder(src_width, src_height, srcTexelBytes, src, srcStrideInBytes, dst, destRowStride);

    return dst;
}