diff --git a/modules/imgcodecs/src/grfmt_bmp.cpp b/modules/imgcodecs/src/grfmt_bmp.cpp index 6a56d3ab2d..aca9c7b2ba 100644 --- a/modules/imgcodecs/src/grfmt_bmp.cpp +++ b/modules/imgcodecs/src/grfmt_bmp.cpp @@ -180,7 +180,7 @@ bool BmpDecoder::readHeader() throw; } // in 32 bit case alpha channel is used - so require CV_8UC4 type - m_type = iscolor ? (m_bpp == 32 ? CV_8UC4 : CV_8UC3 ) : CV_8UC1; + m_type = iscolor ? ((m_bpp == 32 && m_rle_code != BMP_RGB) ? CV_8UC4 : CV_8UC3 ) : CV_8UC1; m_origin = m_height > 0 ? IPL_ORIGIN_BL : IPL_ORIGIN_TL; m_height = std::abs(m_height); diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index fa03ef4333..6866c8d092 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -280,6 +280,16 @@ TEST(Imgcodecs_Bmp, read_rle8) EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), rle, ord); } +TEST(Imgcodecs_Bmp, read_32bit_rgb) +{ + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test_32bit_rgb.bmp"; + + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); + ASSERT_FALSE(img.empty()); + ASSERT_EQ(CV_8UC3, img.type()); +} + #ifdef HAVE_IMGCODEC_HDR TEST(Imgcodecs_Hdr, regression) {