File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -2121,19 +2121,19 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
2121
2121
if (WebPGetFeatures (static_cast <const uint8_t *>(data), dataLen, &config.input ) != VP8_STATUS_OK) break ;
2122
2122
if (config.input .width == 0 || config.input .height == 0 ) break ;
2123
2123
2124
- config.output .colorspace = MODE_RGBA ;
2125
- _renderFormat = Texture2D::PixelFormat::RGBA8888;
2124
+ config.output .colorspace = config. input . has_alpha ?MODE_rgbA:MODE_RGB ;
2125
+ _renderFormat = config. input . has_alpha ? Texture2D::PixelFormat::RGBA8888:Texture2D::PixelFormat::RGB888 ;
2126
2126
_width = config.input .width ;
2127
2127
_height = config.input .height ;
2128
2128
2129
- // webp doesn't have premultipliedAlpha
2130
- _hasPremultipliedAlpha = false ;
2129
+ // we ask webp to give data with premultiplied alpha
2130
+ _hasPremultipliedAlpha = config. input . has_alpha ;
2131
2131
2132
- _dataLen = _width * _height * 4 ;
2132
+ _dataLen = _width * _height * (config. input . has_alpha ? 4 : 3 ) ;
2133
2133
_data = static_cast <unsigned char *>(malloc (_dataLen * sizeof (unsigned char )));
2134
2134
2135
2135
config.output .u .RGBA .rgba = static_cast <uint8_t *>(_data);
2136
- config.output .u .RGBA .stride = _width * 4 ;
2136
+ config.output .u .RGBA .stride = _width * (config. input . has_alpha ? 4 : 3 ) ;
2137
2137
config.output .u .RGBA .size = _dataLen;
2138
2138
config.output .is_external_memory = 1 ;
2139
2139
You can’t perform that action at this time.
0 commit comments