From 1de79246946458546de2364d4a411f45d27a45cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= <1671644+arrufat@users.noreply.github.com> Date: Sun, 29 May 2022 23:53:01 +0900 Subject: [PATCH] Fix saving grayscale WebP images (#2591) --- dlib/image_saver/save_webp.h | 4 +++- docs/docs/release_notes.xml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dlib/image_saver/save_webp.h b/dlib/image_saver/save_webp.h index fe736179a..e5c00a716 100644 --- a/dlib/image_saver/save_webp.h +++ b/dlib/image_saver/save_webp.h @@ -76,7 +76,7 @@ namespace dlib auto data = reinterpret_cast(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::rgb_alpha) { if (pixel_traits::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 temp; assign_image(temp, img); + stride = width_step(temp); auto data = reinterpret_cast(image_data(temp)); impl::impl_save_webp(filename, data, width, height, stride, quality, impl::webp_type::rgb); } diff --git a/docs/docs/release_notes.xml b/docs/docs/release_notes.xml index 6c6bcace4..b8ca7bc97 100644 --- a/docs/docs/release_notes.xml +++ b/docs/docs/release_notes.xml @@ -16,6 +16,7 @@ New Features and Improvements: Non-Backwards Compatible Changes: Bug fixes: + - Fix saving grayscale WebP images (PR #2591)