Skip to content

Commit

Permalink
JPEG: make it plugin capable if using external libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 11, 2023
1 parent ca14115 commit 2f4417c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 24 deletions.
5 changes: 0 additions & 5 deletions frmts/georaster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,3 @@ gdal_target_link_libraries(gdal_GEOR PRIVATE Oracle::OCI)
if (NOT GDAL_USE_ZLIB_INTERNAL)
gdal_target_link_libraries(gdal_GEOR PRIVATE ZLIB::ZLIB)
endif ()

if (GDAL_ENABLE_DRIVER_JPEG AND GDAL_ENABLE_DRIVER_GEOR_PLUGIN)
# A bit ugly to add this file from the JPEG driver !
target_sources(gdal_GEOR PRIVATE ../jpeg/vsidataio.cpp)
endif ()
3 changes: 0 additions & 3 deletions frmts/georaster/georaster_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
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

// ---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions frmts/georaster/georaster_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3935,6 +3935,12 @@ void GeoRasterWrapper::PackNBits(GByte *pabyData) const
}

#ifdef JPEG_SUPPORTED

#define jpeg_vsiio_src GEOR_jpeg_vsiio_src
#define jpeg_vsiio_dest GEOR_jpeg_vsiio_dest
#include "../jpeg/vsidataio.h"
#include "../jpeg/vsidataio.cpp"

// ---------------------------------------------------------------------------
// UncompressJpeg()
// ---------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion frmts/gtiff/gt_jpeg_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ CPLErr GTIFF_DirectCopyFromJPEG(GDALDataset *poDS, GDALDataset *poSrcDS,

#ifdef HAVE_LIBJPEG

#include "vsidataio.h"
#define jpeg_vsiio_src GTIFF_jpeg_vsiio_src
#define jpeg_vsiio_dest GTIFF_jpeg_vsiio_dest
#include "../jpeg/vsidataio.h"
#include "../jpeg/vsidataio.cpp"

#include <setjmp.h>

Expand Down
4 changes: 3 additions & 1 deletion frmts/jpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_gdal_driver(
TARGET gdal_JPEG
SOURCES vsidataio.h jpgdataset.h vsidataio.cpp jpgdataset.cpp
BUILTIN)
PLUGIN_CAPABLE_IF
"NOT GDAL_USE_JPEG_INTERNAL;NOT GDAL_USE_JPEG12_INTERNAL;NOT GDAL_USE_ZLIB_INTERNAL"
)
gdal_standard_includes(gdal_JPEG)

target_include_directories(gdal_JPEG PRIVATE ${GDAL_RASTER_FORMAT_SOURCE_DIR}/mem ${GDAL_RASTER_FORMAT_SOURCE_DIR}/gtiff)
Expand Down
6 changes: 0 additions & 6 deletions frmts/nitf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ if (GDAL_ENABLE_DRIVER_JPEG AND GDAL_USE_JPEG_INTERNAL)
endif()

if (GDAL_ENABLE_DRIVER_JPEG)
if (GDAL_ENABLE_DRIVER_NITF_PLUGIN)
target_sources(gdal_NITF PRIVATE ${GDAL_RASTER_FORMAT_SOURCE_DIR}/jpeg/vsidataio.cpp)
endif()
target_compile_definitions(gdal_NITF PRIVATE -DJPEG_SUPPORTED)
# Include libjpeg first so that if we want to use jpeg-turbo on homebrew
# /usr/local/opt/jpeg-turbo gets included first, before /usr/local/opt
Expand All @@ -55,9 +52,6 @@ if (GDAL_ENABLE_DRIVER_JPEG)
target_compile_definitions(gdal_NITF PRIVATE -DJPEG_DUAL_MODE_8_12)
target_include_directories(gdal_NITF PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
elseif (NOT GDAL_USE_JPEG_INTERNAL AND HAVE_JPEGTURBO_DUAL_MODE_8_12 )
if (GDAL_ENABLE_DRIVER_NITF_PLUGIN)
target_sources(gdal_NITF PRIVATE ${GDAL_RASTER_FORMAT_SOURCE_DIR}/jpeg/vsidataio_12.cpp)
endif()
target_compile_definitions(gdal_NITF PRIVATE JPEG_DUAL_MODE_8_12 HAVE_JPEGTURBO_DUAL_MODE_8_12)
endif ()
endif()
Expand Down
10 changes: 9 additions & 1 deletion frmts/nitf/nitfwritejpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ int NITFWriteJPEGBlock(GDALDataset *poSrcDS, VSILFILE *fp, int nBlockXOff,
int nRestartInterval, GDALProgressFunc pfnProgress,
void *pProgressData);

void jpeg_vsiio_dest(j_compress_ptr cinfo, VSILFILE *outfile);
#ifdef NITFWriteJPEGBlock
#define jpeg_vsiio_src NITF_jpeg_vsiio_src12
#define jpeg_vsiio_dest NITF_jpeg_vsiio_dest12
#else
#define jpeg_vsiio_src NITF_jpeg_vsiio_src
#define jpeg_vsiio_dest NITF_jpeg_vsiio_dest
#endif
#include "../jpeg/vsidataio.h"
#include "../jpeg/vsidataio.cpp"

/************************************************************************/
/* NITFWriteJPEGBlock() */
Expand Down
1 change: 0 additions & 1 deletion frmts/nitf/nitfwritejpeg_12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
#define LIBJPEG_12_PATH "../jpeg/libjpeg12/jpeglib.h"
#endif
#define NITFWriteJPEGBlock NITFWriteJPEGBlock_12
#define jpeg_vsiio_dest jpeg_vsiio_dest_12
#include "nitfwritejpeg.cpp"
#endif /* defined(JPEG_DUAL_MODE_8_12) */
8 changes: 5 additions & 3 deletions gcore/gdal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3914,9 +3914,11 @@ int CPL_DLL GDALReadWorldFile2(const char *pszBaseFilename,
double *padfGeoTransform,
char **papszSiblingFiles,
char **ppszWorldFileNameOut);
int GDALReadTabFile2(const char *pszBaseFilename, double *padfGeoTransform,
char **ppszWKT, int *pnGCPCount, GDAL_GCP **ppasGCPs,
char **papszSiblingFiles, char **ppszTabFileNameOut);
int CPL_DLL GDALReadTabFile2(const char *pszBaseFilename,
double *padfGeoTransform, char **ppszWKT,
int *pnGCPCount, GDAL_GCP **ppasGCPs,
char **papszSiblingFiles,
char **ppszTabFileNameOut);

void CPL_DLL GDALCopyRasterIOExtraArg(GDALRasterIOExtraArg *psDestArg,
GDALRasterIOExtraArg *psSrcArg);
Expand Down
8 changes: 5 additions & 3 deletions port/cpl_md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ struct CPLMD5Context
unsigned char in[64];
};

void CPLMD5Init(struct CPLMD5Context *context);
void CPLMD5Update(struct CPLMD5Context *context, const void *buf, size_t len);
void CPLMD5Final(unsigned char digest[16], struct CPLMD5Context *context);
void CPL_DLL CPLMD5Init(struct CPLMD5Context *context);
void CPL_DLL CPLMD5Update(struct CPLMD5Context *context, const void *buf,
size_t len);
void CPL_DLL CPLMD5Final(unsigned char digest[16],
struct CPLMD5Context *context);
void CPLMD5Transform(GUInt32 buf[4], const unsigned char inraw[64]);

#endif // #ifndef DOXYGEN_SKIP
Expand Down

0 comments on commit 2f4417c

Please sign in to comment.