From bbfded21ac3876f1e297024621bbf4fc06714e70 Mon Sep 17 00:00:00 2001 From: Kumataro Date: Sat, 23 Mar 2024 10:16:30 +0900 Subject: [PATCH] imgcodecs: tiff: to avoid using TIFFTAG_* directly for imwrite() params. Normaly, we sets IMWRITE_* flags for imwrite() params. But imgcodecs expects to use some TIFFTAG_* directory. This patch introduce IMWRITE_TIFF_ROWSPERSTRIP and IMWRITE_TIFF_PREDICTOR instead of TIFFTAG_*. --- modules/imgcodecs/include/opencv2/imgcodecs.hpp | 2 ++ modules/imgcodecs/src/grfmt_tiff.cpp | 4 ++-- modules/imgcodecs/test/test_tiff.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/imgcodecs/include/opencv2/imgcodecs.hpp b/modules/imgcodecs/include/opencv2/imgcodecs.hpp index e815dc4e9b..85ddb838f5 100644 --- a/modules/imgcodecs/include/opencv2/imgcodecs.hpp +++ b/modules/imgcodecs/include/opencv2/imgcodecs.hpp @@ -104,6 +104,8 @@ enum ImwriteFlags { IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI IMWRITE_TIFF_YDPI = 258,//!< For TIFF, use to specify the Y direction DPI IMWRITE_TIFF_COMPRESSION = 259,//!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default. + IMWRITE_TIFF_ROWSPERSTRIP = 278,//!< For TIFF, use to specify the number of rows per strip. + IMWRITE_TIFF_PREDICTOR = 317,//!< For TIFF, use to specify predictor. IMWRITE_JPEG2000_COMPRESSION_X1000 = 272,//!< For JPEG2000, use to specify the target compression rate (multiplied by 1000). The value can be from 0 to 1000. Default is 1000. IMWRITE_AVIF_QUALITY = 512,//!< For AVIF, it can be a quality between 0 and 100 (the higher the better). Default is 95. IMWRITE_AVIF_DEPTH = 513,//!< For AVIF, it can be 8, 10 or 12. If >8, it is stored/read as CV_32F. Default is 8. diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index e35113c449..3094bcc25c 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -1229,7 +1229,7 @@ bool TiffEncoder::writeLibTiff( const std::vector& img_vec, const std::vect int resUnit = -1, dpiX = -1, dpiY = -1; readParam(params, IMWRITE_TIFF_COMPRESSION, compression); - readParam(params, TIFFTAG_PREDICTOR, predictor); + readParam(params, IMWRITE_TIFF_PREDICTOR, predictor); readParam(params, IMWRITE_TIFF_RESUNIT, resUnit); readParam(params, IMWRITE_TIFF_XDPI, dpiX); readParam(params, IMWRITE_TIFF_YDPI, dpiY); @@ -1318,7 +1318,7 @@ bool TiffEncoder::writeLibTiff( const std::vector& img_vec, const std::vect CV_Assert(fileStep > 0); int rowsPerStrip = (int)((1 << 13) / fileStep); - readParam(params, TIFFTAG_ROWSPERSTRIP, rowsPerStrip); + readParam(params, IMWRITE_TIFF_ROWSPERSTRIP, rowsPerStrip); rowsPerStrip = std::max(1, std::min(height, rowsPerStrip)); int colorspace = channels > 1 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK; diff --git a/modules/imgcodecs/test/test_tiff.cpp b/modules/imgcodecs/test/test_tiff.cpp index 4b248fd5e1..bd815c02a0 100644 --- a/modules/imgcodecs/test/test_tiff.cpp +++ b/modules/imgcodecs/test/test_tiff.cpp @@ -28,7 +28,7 @@ TEST(Imgcodecs_Tiff, decode_tile16384x16384) string file4 = cv::tempfile(".tiff"); std::vector params; - params.push_back(TIFFTAG_ROWSPERSTRIP); + params.push_back(IMWRITE_TIFF_ROWSPERSTRIP); params.push_back(big.rows); EXPECT_NO_THROW(cv::imwrite(file4, big, params)); EXPECT_NO_THROW(cv::imwrite(file3, big.colRange(0, big.cols - 1), params)); @@ -767,7 +767,7 @@ TEST(Imgcodecs_Tiff, readWrite_32FC3_RAW) std::vector params; params.push_back(IMWRITE_TIFF_COMPRESSION); - params.push_back(1/*COMPRESSION_NONE*/); + params.push_back(COMPRESSION_NONE); ASSERT_TRUE(cv::imwrite(filenameOutput, img, params)); const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED); @@ -824,9 +824,9 @@ TEST(Imgcodecs_Tiff, readWrite_predictor) string out = cv::tempfile(".tif"); std::vector params; - params.push_back(TIFFTAG_COMPRESSION); + params.push_back(IMWRITE_TIFF_COMPRESSION); params.push_back(methods[i]); - params.push_back(TIFFTAG_PREDICTOR); + params.push_back(IMWRITE_TIFF_PREDICTOR); params.push_back(PREDICTOR_HORIZONTAL); EXPECT_NO_THROW(cv::imwrite(out, mat, params));