示例#1
0
static void vc_image_to_tga_memory(
	VC_IMAGE_T*			image)
{
	uint16_t			width, height;
	uint16_t			x, y;
	KHRN_IMAGE_WRAP_T	src, dst;
	uint8_t*			src_ptr				= (image->mem_handle != MEM_INVALID_HANDLE) ? (uint8_t*)mem_lock(image->mem_handle) : (uint8_t*)image->image_data;
	bool				tformat				= (image->type == VC_IMAGE_TF_RGBA32 || image->type == VC_IMAGE_TF_RGBX32);
	uint8_t				twelve_bytes[12]	= {0,0,2,0,0,0,0,0,0,0,0,0};
	uint32_t			tga_mempos			= 0;
	
	assert(tga_mem_size >= 18 + 4*image->height*image->width);
	
	/* 0-length image id, no colour map, uncompressed true-color image, (0,0) origin. */
	memcpy(tga_memory, twelve_bytes, 12);
	tga_mempos += 12;
	
	/* Width and height, 16-bit little endian */
	*(tga_memory+tga_mempos++) = image->width & 0xFF;
	*(tga_memory+tga_mempos++) = (image->width & 0xFF00) >> 8;
	*(tga_memory+tga_mempos++) = image->height & 0xFF;
	*(tga_memory+tga_mempos++) = (image->height & 0xFF00) >> 8;
	*(tga_memory+tga_mempos++) = '\x20';
	*(tga_memory+tga_mempos++) = '\x20';
	
	// Swap red and blue. Do t-format conversion if necessary.
	khrn_image_wrap(&src, tformat ? ABGR_8888_TF : ABGR_8888_RSO, image->width, image->height, image->pitch, src_ptr);
	khrn_image_wrap(&dst, ARGB_8888_RSO, image->width, image->height, image->pitch, tga_memory + tga_mempos);
	khrn_image_wrap_convert(&dst, &src, IMAGE_CONV_GL);

	if (image->mem_handle != MEM_INVALID_HANDLE) mem_unlock(image->mem_handle);
}
示例#2
0
static void vc_image_to_RSO_memory(VC_IMAGE_T *image, android_native_buffer_t *buffer, void *bits)
{
    KHRN_IMAGE_FORMAT_T src_format, dst_format;
    KHRN_IMAGE_WRAP_T src, dst;
    uint8_t* src_ptr;
    int conv_width, conv_height;

    dst_format = convert_color_format(buffer->format);

    if (!dst_format)
        return;

    // Swap red and blue. Do t-format conversion if necessary.
    switch (image->type) {
    case VC_IMAGE_TF_RGBA32:
        src_format = ABGR_8888_TF;
        break;
    case VC_IMAGE_TF_RGBX32:
        src_format = XBGR_8888_TF;
        break;
    case VC_IMAGE_TF_RGB565:
        src_format = RGB_565_TF;
        break;
    case VC_IMAGE_TF_RGBA5551:
        src_format = RGBA_5551_TF;
        break;
    case VC_IMAGE_TF_RGBA16:
        src_format = RGBA_4444_TF;
        break;
    case VC_IMAGE_RGBA32:
        src_format = ABGR_8888_RSO;
        break;
    case VC_IMAGE_RGBX32:
        src_format = XBGR_8888_RSO;
        break;
    case VC_IMAGE_RGB565:
        src_format = RGB_565_RSO;
        break;
    default:
        UNREACHABLE();
        src_format = 0;
        break;
    }

    if (!src_format)
        return;

    src_ptr = (image->mem_handle != MEM_INVALID_HANDLE) ? (uint8_t*)mem_lock(image->mem_handle) : (uint8_t*)image->image_data;

    conv_width = (image->width <= buffer->width) ? image->width : buffer->width;
    conv_height = (image->height <= buffer->height) ? image->height : buffer->height;

    khrn_image_wrap(&src, src_format, conv_width, conv_height, image->pitch, src_ptr);
    khrn_image_wrap(&dst, dst_format, conv_width, conv_height, buffer->width * bpp, bits);

    if (src.format == dst.format)
        khrn_image_copy(&dst, &src);
    else
        khrn_image_wrap_convert(&dst, &src, IMAGE_CONV_GL);

    if (image->mem_handle != MEM_INVALID_HANDLE)
        mem_unlock(image->mem_handle);
}