From fc8f0e341b2b33d8f116e215b180b8474c7fb537 Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Sun, 27 Jul 2014 17:09:05 +0300 Subject: [PATCH 1/2] adding support for 16-bit 4 channel tiffs - when IMREAD_UNCHANGED is set in flags, the tiff is read with 4 channels - adding test for read/write --- modules/imgcodecs/src/grfmt_tiff.cpp | 17 ++++++++++++++++- modules/imgcodecs/test/test_grfmt.cpp | 6 ++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 9013c39d11..3ec68c8669 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -158,7 +158,7 @@ bool TiffDecoder::readHeader() m_type = CV_MAKETYPE(CV_8U, photometric > 1 ? wanted_channels : 1); break; case 16: - m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? 3 : 1); + m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? wanted_channels : 1); break; case 32: @@ -326,6 +326,21 @@ bool TiffDecoder::readData( Mat& img ) (ushort*)(data + img.step*i) + x*3, 0, cvSize(tile_width,1) ); } + else if (ncn == 4) + { + if (wanted_channels == 4) + { + icvCvt_BGRA2RGBA_16u_C4R(buffer16 + i*tile_width0*ncn, 0, + (ushort*)(data + img.step*i) + x * 4, 0, + cvSize(tile_width, 1)); + } + else + { + icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, + (ushort*)(data + img.step*i) + x * 3, 0, + cvSize(tile_width, 1), 2); + } + } else { icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index 9b06c5744c..37c9bf879c 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -139,9 +139,6 @@ public: string filename = cv::tempfile(".jpg"); imwrite(filename, img); - img = imread(filename, IMREAD_UNCHANGED); - - filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + ".jpg"); ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str()); Mat img_test = imread(filename, IMREAD_UNCHANGED); @@ -160,8 +157,9 @@ public: #endif #ifdef HAVE_TIFF - for (int num_channels = 1; num_channels <= 3; num_channels+=2) + for (int num_channels = 1; num_channels <= 4; num_channels++) { + if (num_channels == 2) continue; // tiff ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_16U, num_channels, ".tiff"); Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_16U, num_channels), Scalar::all(0)); From 6cac76bfe4400c56bcdc622d15fb4cb3f3f50f36 Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Sun, 27 Jul 2014 17:14:54 +0300 Subject: [PATCH 2/2] fixes tab indentation - replacing with 4 spaces --- modules/imgcodecs/src/grfmt_tiff.cpp | 32 +++++++++++++-------------- modules/imgcodecs/test/test_grfmt.cpp | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 3ec68c8669..06b2ab6a15 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -158,7 +158,7 @@ bool TiffDecoder::readHeader() m_type = CV_MAKETYPE(CV_8U, photometric > 1 ? wanted_channels : 1); break; case 16: - m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? wanted_channels : 1); + m_type = CV_MAKETYPE(CV_16U, photometric > 1 ? wanted_channels : 1); break; case 32: @@ -326,21 +326,21 @@ bool TiffDecoder::readData( Mat& img ) (ushort*)(data + img.step*i) + x*3, 0, cvSize(tile_width,1) ); } - else if (ncn == 4) - { - if (wanted_channels == 4) - { - icvCvt_BGRA2RGBA_16u_C4R(buffer16 + i*tile_width0*ncn, 0, - (ushort*)(data + img.step*i) + x * 4, 0, - cvSize(tile_width, 1)); - } - else - { - icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, - (ushort*)(data + img.step*i) + x * 3, 0, - cvSize(tile_width, 1), 2); - } - } + else if (ncn == 4) + { + if (wanted_channels == 4) + { + icvCvt_BGRA2RGBA_16u_C4R(buffer16 + i*tile_width0*ncn, 0, + (ushort*)(data + img.step*i) + x * 4, 0, + cvSize(tile_width, 1)); + } + else + { + icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, + (ushort*)(data + img.step*i) + x * 3, 0, + cvSize(tile_width, 1), 2); + } + } else { icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0, diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index 37c9bf879c..02e84d67f5 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -159,7 +159,7 @@ public: #ifdef HAVE_TIFF for (int num_channels = 1; num_channels <= 4; num_channels++) { - if (num_channels == 2) continue; + if (num_channels == 2) continue; // tiff ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_16U, num_channels, ".tiff"); Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_16U, num_channels), Scalar::all(0));