Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJPEG/rdtarga.c view on Meta::CPAN
source->block_count = source->dup_pixel_count = 0;
subtype -= 8;
} else {
/* Non-RLE file */
source->read_pixel = read_non_rle_pixel;
}
/* Now should have subtype 1, 2, or 3 */
components = 3; /* until proven different */
cinfo->in_color_space = JCS_RGB;
switch (subtype) {
case 1: /* Colormapped image */
if (source->pixel_size == 1 && cmaptype == 1)
source->get_pixel_rows = get_8bit_row;
else
ERREXIT(cinfo, JERR_TGA_BADPARMS);
TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
break;
case 2: /* RGB image */
switch (source->pixel_size) {
case 2:
source->get_pixel_rows = get_16bit_row;
break;
case 3:
source->get_pixel_rows = get_24bit_row;
break;
case 4:
source->get_pixel_rows = get_32bit_row;
break;
default:
ERREXIT(cinfo, JERR_TGA_BADPARMS);
break;
}
TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
break;
case 3: /* Grayscale image */
components = 1;
cinfo->in_color_space = JCS_GRAYSCALE;
if (source->pixel_size == 1)
source->get_pixel_rows = get_8bit_gray_row;
else
ERREXIT(cinfo, JERR_TGA_BADPARMS);
TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height);
break;
default:
ERREXIT(cinfo, JERR_TGA_BADPARMS);
break;
}
if (is_bottom_up) {
/* Create a virtual array to buffer the upside-down image. */
source->whole_image = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
(JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1);
if (cinfo->progress != NULL) {
cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
progress->total_extra_passes++; /* count file input as separate pass */
}
/* source->pub.buffer will point to the virtual array. */
source->pub.buffer_height = 1; /* in case anyone looks at it */
source->pub.get_pixel_rows = preload_image;
} else {
/* Don't need a virtual array, but do need a one-row input buffer. */
source->whole_image = NULL;
source->pub.buffer = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE,
(JDIMENSION) width * components, (JDIMENSION) 1);
source->pub.buffer_height = 1;
source->pub.get_pixel_rows = source->get_pixel_rows;
}
while (idlen--) /* Throw away ID field */
(void) read_byte(source);
if (maplen > 0) {
if (maplen > 256 || GET_2B(3) != 0)
ERREXIT(cinfo, JERR_TGA_BADCMAP);
/* Allocate space to store the colormap */
source->colormap = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);
/* and read it from the file */
read_colormap(source, (int) maplen, UCH(targaheader[7]));
} else {
if (cmaptype) /* but you promised a cmap! */
ERREXIT(cinfo, JERR_TGA_BADPARMS);
source->colormap = NULL;
}
cinfo->input_components = components;
cinfo->data_precision = 8;
cinfo->image_width = width;
cinfo->image_height = height;
}
/*
* Finish up at the end of the file.
*/
METHODDEF(void)
finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
{
/* no work */
}
/*
* The module selection routine for Targa format input.
*/
GLOBAL(cjpeg_source_ptr)
jinit_read_targa (j_compress_ptr cinfo)
{
tga_source_ptr source;
/* Create module interface object */
source = (tga_source_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(tga_source_struct));
source->cinfo = cinfo; /* make back link for subroutines */
( run in 0.555 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )