Skip to content

Commit

Permalink
Fix saving JXL generic grayscale images (#3032)
Browse files Browse the repository at this point in the history
The problem appeared when trying to save the empirical cross-correlation
matrix using the result of a matrix expression.  That path was not taken
into account by the JXL image saver.
  • Loading branch information
arrufat authored Nov 18, 2024
1 parent 3924095 commit dfbee6d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dlib/image_saver/save_jxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,28 @@ namespace dlib
}
else
{
// This is probably a single-channel float image resulting from some matrix operation.
if (depth == 1)
{
array2d<unsigned char> temp;
assign_image(temp, img);
auto data = reinterpret_cast<const uint8_t*>(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<pixel_type>::has_alpha)
else if (pixel_traits<pixel_type>::has_alpha)
{
array2d<rgb_alpha_pixel> temp;
assign_image(temp, img);
auto data = reinterpret_cast<const uint8_t*>(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<rgb_pixel> temp;
assign_image(temp, img);
auto data = reinterpret_cast<const uint8_t*>(image_data(temp));
impl::impl_save_jxl(filename, data, width, height, depth, quality);
impl::impl_save_jxl(filename, data, width, height, 3, quality);
}
}
}
Expand Down

0 comments on commit dfbee6d

Please sign in to comment.