Skip to content

Commit c4d4248

Browse files
committed
Merge pull request opencv#8639 from berak:fix_webp_grayscale
2 parents 96aaac1 + cbda9b3 commit c4d4248

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

modules/imgcodecs/src/grfmt_webp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ bool WebPDecoder::readData(Mat &img)
162162
{
163163
if( m_width > 0 && m_height > 0 )
164164
{
165+
bool convert_grayscale = (img.type() == CV_8UC1); // IMREAD_GRAYSCALE requested
166+
165167
if (img.cols != m_width || img.rows != m_height || img.type() != m_type)
166168
{
167169
img.create(m_height, m_width, m_type);
@@ -184,6 +186,10 @@ bool WebPDecoder::readData(Mat &img)
184186

185187
if(res_ptr == out_data)
186188
{
189+
if (convert_grayscale)
190+
{
191+
cvtColor(img, img, COLOR_BGR2GRAY);
192+
}
187193
return true;
188194
}
189195
}

0 commit comments

Comments
 (0)