Skip to content

Commit

Permalink
Merge pull request opencv#22436 from Harvey-Huang:4-bit_palette_color
Browse files Browse the repository at this point in the history
  • Loading branch information
asmorkalov committed Aug 31, 2022
2 parents 70fb1cd + a4b191a commit f376bfe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/imgcodecs/src/grfmt_tiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions modules/imgcodecs/test/test_tiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f376bfe

Please sign in to comment.