diff --git a/dlib/image_saver/save_jxl.h b/dlib/image_saver/save_jxl.h index 5569b59ab9..a2c07bf328 100644 --- a/dlib/image_saver/save_jxl.h +++ b/dlib/image_saver/save_jxl.h @@ -78,20 +78,28 @@ namespace dlib } else { + // This is probably a single-channel float image resulting from some matrix operation. + if (depth == 1) + { + array2d temp; + assign_image(temp, img); + auto data = reinterpret_cast(image_data(temp)); + impl::impl_save_jxl(filename, data, width, height, 1, quality); + } // This is some other kind of color image so just save it as an RGB image. - if (pixel_traits::has_alpha) + else if (pixel_traits::has_alpha) { array2d temp; assign_image(temp, img); auto data = reinterpret_cast(image_data(temp)); - impl::impl_save_jxl(filename, data, width, height, depth, quality); + impl::impl_save_jxl(filename, data, width, height, 4, quality); } else { array2d temp; assign_image(temp, img); auto data = reinterpret_cast(image_data(temp)); - impl::impl_save_jxl(filename, data, width, height, depth, quality); + impl::impl_save_jxl(filename, data, width, height, 3, quality); } } }