Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibTIFF4/tif_jpeg.c view on Meta::CPAN
std_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{
JPEGState* sp = (JPEGState*) cinfo;
if (num_bytes > 0) {
if ((size_t)num_bytes > sp->src.bytes_in_buffer) {
/* oops, buffer overrun */
(void) std_fill_input_buffer(cinfo);
} else {
sp->src.next_input_byte += (size_t) num_bytes;
sp->src.bytes_in_buffer -= (size_t) num_bytes;
}
}
}
static void
std_term_source(j_decompress_ptr cinfo)
{
/* No work necessary here */
(void) cinfo;
}
static void
TIFFjpeg_data_src(JPEGState* sp, TIFF* tif)
{
(void) tif;
sp->cinfo.d.src = &sp->src;
sp->src.init_source = std_init_source;
sp->src.fill_input_buffer = std_fill_input_buffer;
sp->src.skip_input_data = std_skip_input_data;
sp->src.resync_to_restart = jpeg_resync_to_restart;
sp->src.term_source = std_term_source;
sp->src.bytes_in_buffer = 0; /* for safety */
sp->src.next_input_byte = NULL;
}
/*
* Alternate source manager for reading from JPEGTables.
* We can share all the code except for the init routine.
*/
static void
tables_init_source(j_decompress_ptr cinfo)
{
JPEGState* sp = (JPEGState*) cinfo;
sp->src.next_input_byte = (const JOCTET*) sp->jpegtables;
sp->src.bytes_in_buffer = (size_t) sp->jpegtables_length;
}
static void
TIFFjpeg_tables_src(JPEGState* sp, TIFF* tif)
{
TIFFjpeg_data_src(sp, tif);
sp->src.init_source = tables_init_source;
}
/*
* Allocate downsampled-data buffers needed for downsampled I/O.
* We use values computed in jpeg_start_compress or jpeg_start_decompress.
* We use libjpeg's allocator so that buffers will be released automatically
* when done with strip/tile.
* This is also a handy place to compute samplesperclump, bytesperline.
*/
static int
alloc_downsampled_buffers(TIFF* tif, jpeg_component_info* comp_info,
int num_components)
{
JPEGState* sp = JState(tif);
int ci;
jpeg_component_info* compptr;
JSAMPARRAY buf;
int samples_per_clump = 0;
for (ci = 0, compptr = comp_info; ci < num_components;
ci++, compptr++) {
samples_per_clump += compptr->h_samp_factor *
compptr->v_samp_factor;
buf = TIFFjpeg_alloc_sarray(sp, JPOOL_IMAGE,
compptr->width_in_blocks * DCTSIZE,
(JDIMENSION) (compptr->v_samp_factor*DCTSIZE));
if (buf == NULL)
return (0);
sp->ds_buffer[ci] = buf;
}
sp->samplesperclump = samples_per_clump;
return (1);
}
/*
* JPEG Decoding.
*/
#ifdef CHECK_JPEG_YCBCR_SUBSAMPLING
#define JPEG_MARKER_SOF0 0xC0
#define JPEG_MARKER_SOF1 0xC1
#define JPEG_MARKER_SOF2 0xC2
#define JPEG_MARKER_SOF9 0xC9
#define JPEG_MARKER_SOF10 0xCA
#define JPEG_MARKER_DHT 0xC4
#define JPEG_MARKER_SOI 0xD8
#define JPEG_MARKER_SOS 0xDA
#define JPEG_MARKER_DQT 0xDB
#define JPEG_MARKER_DRI 0xDD
#define JPEG_MARKER_APP0 0xE0
#define JPEG_MARKER_COM 0xFE
struct JPEGFixupTagsSubsamplingData
{
TIFF* tif;
void* buffer;
uint32 buffersize;
uint8* buffercurrentbyte;
uint32 bufferbytesleft;
uint64 fileoffset;
uint64 filebytesleft;
uint8 filepositioned;
};
static void JPEGFixupTagsSubsampling(TIFF* tif);
static int JPEGFixupTagsSubsamplingSec(struct JPEGFixupTagsSubsamplingData* data);
( run in 0.524 second using v1.01-cache-2.11-cpan-e93a5daba3e )