4-bit_palette_color
authorHarvey <harvey@originlab.com.cn>
Mon, 29 Aug 2022 02:21:17 +0000 (10:21 +0800)
committerHarvey <harvey@originlab.com.cn>
Mon, 29 Aug 2022 02:21:17 +0000 (10:21 +0800)
modules/imgcodecs/src/grfmt_tiff.cpp
modules/imgcodecs/test/test_tiff.cpp

index a2b55ea..0ae60e6 100644 (file)
@@ -312,6 +312,18 @@ bool TiffDecoder::readHeader()
                 result = true;
                 break;
             }
+            case 4:
+                //support 4-bit palette.
+                if (photometric == PHOTOMETRIC_PALETTE)
+                {
+                    CV_Check((int)sample_format, sample_format == SAMPLEFORMAT_UINT || sample_format == SAMPLEFORMAT_INT, "");
+                    int depth = sample_format == SAMPLEFORMAT_INT ? CV_8S : CV_8U;
+                    m_type = CV_MAKETYPE(depth, 3);
+                    result = true;
+                }
+                else
+                    CV_Error(cv::Error::StsError, "bitsperpixel value is 4 should be palette.");
+                break;
             case 8:
             {
                 //Palette color, the value of the component is used as an index into the red,
index b7b6b95..76a39c0 100644 (file)
@@ -359,6 +359,16 @@ TEST(Imgcodecs_Tiff, read_palette_color_image)
     ASSERT_EQ(CV_8UC3, img.type());
 }
 
+TEST(Imgcodecs_Tiff, read_4_bit_palette_color_image)
+{
+    const string root = cvtest::TS::ptr()->get_data_path();
+    const string filenameInput = root + "readwrite/4-bit_palette_color.tif";
+
+    const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
+    ASSERT_FALSE(img.empty());
+    ASSERT_EQ(CV_8UC3, img.type());
+}
+
 TEST(Imgcodecs_Tiff, readWrite_predictor)
 {
     /* see issue #21871