Skip to content

Commit

Permalink
GeoRaster driver: fix build without JPEG
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 6, 2022
1 parent 84cec57 commit db434b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
8 changes: 6 additions & 2 deletions frmts/georaster/georaster_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
// JPEG compression support
// ---------------------------------------------------------------------------

#ifdef JPEG_SUPPORTED
CPL_C_START
#include <jpeglib.h>
CPL_C_END

void jpeg_vsiio_src (j_decompress_ptr cinfo, VSILFILE * infile);
void jpeg_vsiio_dest (j_compress_ptr cinfo, VSILFILE * outfile);
#endif

// ---------------------------------------------------------------------------
// JPEG2000 support - Install the Virtual File System handler to OCI LOB
Expand Down Expand Up @@ -358,14 +360,16 @@ class GeoRasterWrapper

void UnpackNBits( GByte* pabyData );
void PackNBits( GByte* pabyData ) const;
#ifdef JPEG_SUPPORTED
unsigned long CompressJpeg();
unsigned long CompressDeflate();
void UncompressJpeg( unsigned long nBufferSize );
bool UncompressDeflate( unsigned long nBufferSize );

struct jpeg_decompress_struct sDInfo;
struct jpeg_compress_struct sCInfo;
struct jpeg_error_mgr sJErr;
#endif
unsigned long CompressDeflate();
bool UncompressDeflate( unsigned long nBufferSize );

void GetSpatialReference();

Expand Down
34 changes: 29 additions & 5 deletions frmts/georaster/georaster_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ GeoRasterWrapper::GeoRasterWrapper() :
nPyramidMaxLevel = 0;
nBlockCount = 0L;
nGDALBlockBytes = 0L;
#ifdef JPEG_SUPPORTED
sDInfo.global_state = 0;
sCInfo.global_state = 0;
memset(&sCInfo, 0, sizeof(sCInfo));
memset(&sDInfo, 0, sizeof(sDInfo));
memset(&sJErr, 0, sizeof(sJErr));
#endif
bHasBitmapMask = false;
nBlockBytes = 0L;
bFlushBlock = false;
Expand All @@ -109,9 +114,6 @@ GeoRasterWrapper::GeoRasterWrapper() :
pasGCPList = nullptr;
nGCPCount = 0;
bFlushGCP = false;
memset(&sCInfo, 0, sizeof(sCInfo));
memset(&sDInfo, 0, sizeof(sDInfo));
memset(&sJErr, 0, sizeof(sJErr));
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -159,7 +161,7 @@ GeoRasterWrapper::~GeoRasterWrapper()
}

CPLDestroyXMLNode( phMetadata );

#ifdef JPEG_SUPPORTED
if( sDInfo.global_state )
{
jpeg_destroy_decompress( &sDInfo );
Expand All @@ -169,7 +171,7 @@ GeoRasterWrapper::~GeoRasterWrapper()
{
jpeg_destroy_compress( &sCInfo );
}

#endif
if( poConnection )
{
delete poConnection;
Expand Down Expand Up @@ -1155,8 +1157,10 @@ void GeoRasterWrapper::PrepareToOverwrite( void )
bCreateObjectTable = false;
nPyramidMaxLevel = 0;
nBlockCount = 0L;
#ifdef JPEG_SUPPORTED
sDInfo.global_state = 0;
sCInfo.global_state = 0;
#endif
bHasBitmapMask = false;
bWriteOnly = false;
bBlocking = true;
Expand Down Expand Up @@ -1975,7 +1979,13 @@ bool GeoRasterWrapper::GetDataBlock( int nBand,

if( STARTS_WITH_CI(sCompressionType.c_str(), "JPEG") )
{
#ifdef JPEG_SUPPORTED
UncompressJpeg( nBytesRead );
#else
CPLError(CE_Failure, CPLE_NotSupported,
"JPEG compression not supported in this build of the GeoRaster driver");
return false;
#endif
}
else if ( EQUAL( sCompressionType.c_str(), "DEFLATE" ) )
{
Expand Down Expand Up @@ -2116,7 +2126,13 @@ bool GeoRasterWrapper::SetDataBlock( int nBand,

if( STARTS_WITH_CI(sCompressionType.c_str(), "JPEG") )
{
#ifdef JPEG_SUPPORTED
UncompressJpeg( nBytesRead );
#else
CPLError(CE_Failure, CPLE_NotSupported,
"JPEG compression not supported in this build of the GeoRaster driver");
return false;
#endif
}
else if ( EQUAL( sCompressionType.c_str(), "DEFLATE" ) )
{
Expand Down Expand Up @@ -2205,7 +2221,13 @@ bool GeoRasterWrapper::FlushBlock( long nCacheBlock )
{
if( STARTS_WITH_CI(sCompressionType.c_str(), "JPEG") )
{
#ifdef JPEG_SUPPORTED
nFlushBlockSize = CompressJpeg();
#else
CPLError(CE_Failure, CPLE_NotSupported,
"JPEG compression not supported in this build of the GeoRaster driver");
return false;
#endif
}
else if ( EQUAL( sCompressionType.c_str(), "DEFLATE" ) )
{
Expand Down Expand Up @@ -3984,6 +4006,7 @@ void GeoRasterWrapper::PackNBits( GByte* pabyData ) const
CPLFree( pabyBuffer );
}

#ifdef JPEG_SUPPORTED
// ---------------------------------------------------------------------------
// UncompressJpeg()
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -4270,6 +4293,7 @@ unsigned long GeoRasterWrapper::CompressJpeg( void )

return (unsigned long) nSize;
}
#endif

// ---------------------------------------------------------------------------
// UncompressDeflate()
Expand Down

0 comments on commit db434b2

Please sign in to comment.