Skip to content

Commit

Permalink
TIFF: Hardcode codecs with vcpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Baryshev committed Mar 20, 2021
1 parent 20dff53 commit daf5955
Showing 1 changed file with 76 additions and 63 deletions.
139 changes: 76 additions & 63 deletions src/sail-codecs/tiff/tiff.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,70 +41,83 @@ macro(sail_codec_post_add)

# Check if we can actually write defined compressions
#
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${sail_tiff_include_dirs})
set(CMAKE_REQUIRED_LIBRARIES ${sail_tiff_libs})

check_c_source_runs(
"
#include <stdlib.h>
#include <string.h>
#include <tiffio.h>
int main(int argc, char *argv[]) {
TIFF *tiff = TIFFOpen(\"file.tiff\", \"w\");
if (tiff == NULL) {
return 1;
}
TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, 1);
TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, 1);
TIFFSetField(tiff, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tiff, TIFFTAG_COMPRESSION, COMPRESSION_${tiff_codec});
TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, (uint32)-1));
unsigned char *scan = malloc(4);
memset(scan, 255, 4);
if (TIFFWriteScanline(tiff, scan, 0, 0) < 0) {
return 2;
}
TIFFClose(tiff);
free(scan);
return 0;
}
"
SAIL_HAVE_TIFF_WRITE_${tiff_codec}
)
cmake_pop_check_state()

if (SAIL_HAVE_TIFF_WRITE_${tiff_codec})
# Match the SAIL namings
if (SAIL_VCPKG)
# Hardcode compressions as check_c_source_runs() fails in VCPKG mode.
# It fails because it cannot find tiff.dll.
#
string(REPLACE "_" "-" tiff_codec_fixed ${tiff_codec})
string(REPLACE "CCITTRLE" "CCITT-RLE" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "CCITTRLEW" "CCITT-RLEW" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8BL" "IT8-BL" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8CTPAD" "IT8-CTPAD" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8LW" "IT8-LW" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8MP" "IT8-MP" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "JP2000" "JPEG2000" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "PIXARLOG" "PIXAR-LOG" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "PIXARFILM" "PIXAR-FILM" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "SGILOG24" "SGI-LOG24" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "SGILOG" "SGI-LOG" tiff_codec_fixed ${tiff_codec_fixed})
list(APPEND CODEC_INFO_COMPRESSIONS ${tiff_codec_fixed})

target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_${tiff_codec})
set(CODEC_INFO_COMPRESSIONS ADOBE-DEFLATE DEFLATE JPEG LZW NONE PACKBITS)
target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_ADOBE_DEFLATE)
target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_DEFLATE)
target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_JPEG)
target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_LZW)
target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_NONE)
target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_PACKBITS)
else()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${sail_tiff_include_dirs})
set(CMAKE_REQUIRED_LIBRARIES ${sail_tiff_libs})

check_c_source_runs(
"
#include <stdlib.h>
#include <string.h>
#include <tiffio.h>
int main(int argc, char *argv[]) {
TIFF *tiff = TIFFOpen(\"file.tiff\", \"w\");
if (tiff == NULL) {
return 1;
}
TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, 1);
TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, 1);
TIFFSetField(tiff, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tiff, TIFFTAG_COMPRESSION, COMPRESSION_${tiff_codec});
TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tiff, (uint32)-1));
unsigned char *scan = malloc(4);
memset(scan, 255, 4);
if (TIFFWriteScanline(tiff, scan, 0, 0) < 0) {
return 2;
}
TIFFClose(tiff);
free(scan);
return 0;
}
"
SAIL_HAVE_TIFF_WRITE_${tiff_codec}
)
cmake_pop_check_state()

if (SAIL_HAVE_TIFF_WRITE_${tiff_codec})
# Match the SAIL namings
#
string(REPLACE "_" "-" tiff_codec_fixed ${tiff_codec})
string(REPLACE "CCITTRLE" "CCITT-RLE" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "CCITTRLEW" "CCITT-RLEW" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8BL" "IT8-BL" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8CTPAD" "IT8-CTPAD" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8LW" "IT8-LW" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "IT8MP" "IT8-MP" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "JP2000" "JPEG2000" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "PIXARLOG" "PIXAR-LOG" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "PIXARFILM" "PIXAR-FILM" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "SGILOG24" "SGI-LOG24" tiff_codec_fixed ${tiff_codec_fixed})
string(REPLACE "SGILOG" "SGI-LOG" tiff_codec_fixed ${tiff_codec_fixed})
list(APPEND CODEC_INFO_COMPRESSIONS ${tiff_codec_fixed})

target_compile_definitions(${TARGET} PRIVATE SAIL_HAVE_TIFF_WRITE_${tiff_codec})
endif()
endif()
endforeach()

Expand Down

0 comments on commit daf5955

Please sign in to comment.