Fix saving grayscale WebP images (#2591)

This commit is contained in:
Adrià Arrufat 2022-05-29 23:53:01 +09:00 committed by GitHub
parent c9a25fda0a
commit 1de7924694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -76,7 +76,7 @@ namespace dlib
auto data = reinterpret_cast<const uint8_t*>(image_data(img));
const int width = img.nc();
const int height = img.nr();
const int stride = width_step(img);
int stride = width_step(img);
if (pixel_traits<pixel_type>::rgb_alpha)
{
if (pixel_traits<pixel_type>::bgr_layout)
@ -94,8 +94,10 @@ namespace dlib
else
{
// This is some other kind of color image so just save it as an RGB image.
// We also need to recompute the stride in case we were given a grayscale image.
array2d<rgb_pixel> temp;
assign_image(temp, img);
stride = width_step(temp);
auto data = reinterpret_cast<const uint8_t*>(image_data(temp));
impl::impl_save_webp(filename, data, width, height, stride, quality, impl::webp_type::rgb);
}

View File

@ -16,6 +16,7 @@ New Features and Improvements:
Non-Backwards Compatible Changes:
Bug fixes:
- Fix saving grayscale WebP images (PR #2591)
</current>
<!-- ************************************************************************************** -->