Skip to content

Commit

Permalink
Add compatibility with libjpeg-turbo 1.5.2 that honours max_memory_to…
Browse files Browse the repository at this point in the history
…_use (cf libjpeg-turbo/libjpeg-turbo#162)

git-svn-id: https://svn.osgeo.org/gdal/trunk@40472 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Oct 17, 2017
1 parent 7dff315 commit c515fa7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
24 changes: 17 additions & 7 deletions gdal/frmts/gtiff/libtiff/tif_jpeg.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: tif_jpeg.c,v 1.133 2017-08-29 08:08:10 erouault Exp $ */
/* $Id: tif_jpeg.c,v 1.134 2017-10-17 19:04:47 erouault Exp $ */

/*
* Copyright (c) 1994-1997 Sam Leffler
Expand Down Expand Up @@ -2456,12 +2456,22 @@ static int JPEGInitializeLibJPEG( TIFF * tif, int decompress )
#ifndef TIFF_JPEG_MAX_MEMORY_TO_USE
#define TIFF_JPEG_MAX_MEMORY_TO_USE (10 * 1024 * 1024)
#endif
/* Increase the max memory usable. This helps when creating files */
/* with "big" tile, without using libjpeg temporary files. */
/* For example a 512x512 tile with 3 bands */
/* requires 1.5 MB which is above libjpeg 1MB default */
if( sp->cinfo.c.mem->max_memory_to_use < TIFF_JPEG_MAX_MEMORY_TO_USE )
sp->cinfo.c.mem->max_memory_to_use = TIFF_JPEG_MAX_MEMORY_TO_USE;
/* libjpeg turbo 1.5.2 honours max_memory_to_use, but has no backing */
/* store implementation, so better not set max_memory_to_use ourselves. */
/* See https://github.com/libjpeg-turbo/libjpeg-turbo/issues/162 */
if( sp->cinfo.c.mem->max_memory_to_use > 0 )
{
/* This is to address bug related in ticket GDAL #1795. */
if (getenv("JPEGMEM") == NULL)
{
/* Increase the max memory usable. This helps when creating files */
/* with "big" tile, without using libjpeg temporary files. */
/* For example a 512x512 tile with 3 bands */
/* requires 1.5 MB which is above libjpeg 1MB default */
if( sp->cinfo.c.mem->max_memory_to_use < TIFF_JPEG_MAX_MEMORY_TO_USE )
sp->cinfo.c.mem->max_memory_to_use = TIFF_JPEG_MAX_MEMORY_TO_USE;
}
}
}

sp->cinfo_initialized = TRUE;
Expand Down
20 changes: 13 additions & 7 deletions gdal/frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3174,14 +3174,20 @@ JPGDataset::CreateCopyStage2( const char *pszFilename, GDALDataset *poSrcDS,

jpeg_set_defaults(&sCInfo);

// This is to address bug related in ticket #1795.
if (CPLGetConfigOption("JPEGMEM", NULL) == NULL)
// libjpeg turbo 1.5.2 honours max_memory_to_use, but has no backing
// store implementation, so better not set max_memory_to_use ourselves.
// See https://github.com/libjpeg-turbo/libjpeg-turbo/issues/162
if( sCInfo.mem->max_memory_to_use > 0 )
{
// If the user doesn't provide a value for JPEGMEM, we want to be sure
// that at least 500 MB will be used before creating the temporary file.
const long nMinMemory = 500 * 1024 * 1024;
sCInfo.mem->max_memory_to_use =
std::max(sCInfo.mem->max_memory_to_use, nMinMemory);
// This is to address bug related in ticket #1795.
if (CPLGetConfigOption("JPEGMEM", NULL) == NULL)
{
// If the user doesn't provide a value for JPEGMEM, we want to be sure
// that at least 500 MB will be used before creating the temporary file.
const long nMinMemory = 500 * 1024 * 1024;
sCInfo.mem->max_memory_to_use =
std::max(sCInfo.mem->max_memory_to_use, nMinMemory);
}
}

if( eDT == GDT_UInt16 )
Expand Down

0 comments on commit c515fa7

Please sign in to comment.