summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libtiff/libtiff/tif_jpeg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/libtiff/libtiff/tif_jpeg.c')
-rw-r--r--src/3rdparty/libtiff/libtiff/tif_jpeg.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/3rdparty/libtiff/libtiff/tif_jpeg.c b/src/3rdparty/libtiff/libtiff/tif_jpeg.c
index 93ae2ea..6711137 100644
--- a/src/3rdparty/libtiff/libtiff/tif_jpeg.c
+++ b/src/3rdparty/libtiff/libtiff/tif_jpeg.c
@@ -466,7 +466,8 @@ std_empty_output_buffer(j_compress_ptr cinfo)
}
#endif
- TIFFFlushData1(tif);
+ if( !TIFFFlushData1(tif) )
+ return FALSE;
sp->dest.next_output_byte = (JOCTET*) tif->tif_rawdata;
sp->dest.free_in_buffer = (size_t) tif->tif_rawdatasize;
@@ -937,7 +938,10 @@ JPEGFixupTagsSubsamplingReadByte(struct JPEGFixupTagsSubsamplingData* data, uint
return(0);
if (!data->filepositioned)
{
- TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET);
+ if (TIFFSeekFile(data->tif,data->fileoffset,SEEK_SET) == (toff_t)-1)
+ {
+ return 0;
+ }
data->filepositioned=1;
}
m=data->buffersize;
@@ -1206,35 +1210,37 @@ JPEGPreDecode(TIFF* tif, uint16 s)
/* store for all coefficients */
/* See call to jinit_d_coef_controller() from master_selection() */
/* in libjpeg */
- toff_t nRequiredMemory = (toff_t)sp->cinfo.d.image_width *
- sp->cinfo.d.image_height *
- sp->cinfo.d.num_components *
- ((td->td_bitspersample+7)/8);
- /* BLOCK_SMOOTHING_SUPPORTED is generally defined, so we need */
- /* to replicate the logic of jinit_d_coef_controller() */
- if( sp->cinfo.d.progressive_mode )
- nRequiredMemory *= 3;
-
-#ifndef TIFF_LIBJPEG_LARGEST_MEM_ALLOC
-#define TIFF_LIBJPEG_LARGEST_MEM_ALLOC (100 * 1024 * 1024)
-#endif
- if( nRequiredMemory > TIFF_LIBJPEG_LARGEST_MEM_ALLOC &&
+ /* 1 MB for regular libjpeg usage */
+ toff_t nRequiredMemory = 1024 * 1024;
+
+ for (ci = 0; ci < sp->cinfo.d.num_components; ci++) {
+ const jpeg_component_info *compptr = &(sp->cinfo.d.comp_info[ci]);
+ if( compptr->h_samp_factor > 0 && compptr->v_samp_factor > 0 )
+ {
+ nRequiredMemory += (toff_t)(
+ ((compptr->width_in_blocks + compptr->h_samp_factor - 1) / compptr->h_samp_factor)) *
+ ((compptr->height_in_blocks + compptr->v_samp_factor - 1) / compptr->v_samp_factor) *
+ sizeof(JBLOCK);
+ }
+ }
+
+ if( sp->cinfo.d.mem->max_memory_to_use > 0 &&
+ nRequiredMemory > (toff_t)(sp->cinfo.d.mem->max_memory_to_use) &&
getenv("LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC") == NULL )
{
- TIFFErrorExt(tif->tif_clientdata, module,
- "Reading this strip would require libjpeg to allocate "
- "at least %u bytes. "
- "This is disabled since above the %u threshold. "
- "You may override this restriction by defining the "
- "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
- "or recompile libtiff by defining the "
- "TIFF_LIBJPEG_LARGEST_MEM_ALLOC macro to a value greater "
- "than %u",
- (unsigned)nRequiredMemory,
- (unsigned)TIFF_LIBJPEG_LARGEST_MEM_ALLOC,
- (unsigned)TIFF_LIBJPEG_LARGEST_MEM_ALLOC);
- return (0);
+ TIFFErrorExt(tif->tif_clientdata, module,
+ "Reading this image would require libjpeg to allocate "
+ "at least %u bytes. "
+ "This is disabled since above the %u threshold. "
+ "You may override this restriction by defining the "
+ "LIBTIFF_ALLOW_LARGE_LIBJPEG_MEM_ALLOC environment variable, "
+ "or setting the JPEGMEM environment variable to a value greater "
+ "or equal to '%uM'",
+ (unsigned)(nRequiredMemory),
+ (unsigned)(sp->cinfo.d.mem->max_memory_to_use),
+ (unsigned)((nRequiredMemory + 1000000 - 1) / 1000000));
+ return 0;
}
}
@@ -2344,7 +2350,7 @@ JPEGVGetField(TIFF* tif, uint32 tag, va_list ap)
switch (tag) {
case TIFFTAG_JPEGTABLES:
*va_arg(ap, uint32*) = sp->jpegtables_length;
- *va_arg(ap, void**) = sp->jpegtables;
+ *va_arg(ap, const void**) = sp->jpegtables;
break;
case TIFFTAG_JPEGQUALITY:
*va_arg(ap, int*) = sp->jpegquality;
@@ -2479,6 +2485,7 @@ TIFFInitJPEG(TIFF* tif, int scheme)
{
JPEGState* sp;
+ (void)scheme;
assert(scheme == COMPRESSION_JPEG);
/*