Skip to content

Commit dfbee6d

Browse files
authored
Fix saving JXL generic grayscale images (#3032)
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.
1 parent 3924095 commit dfbee6d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

dlib/image_saver/save_jxl.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,28 @@ namespace dlib
7878
}
7979
else
8080
{
81+
// This is probably a single-channel float image resulting from some matrix operation.
82+
if (depth == 1)
83+
{
84+
array2d<unsigned char> temp;
85+
assign_image(temp, img);
86+
auto data = reinterpret_cast<const uint8_t*>(image_data(temp));
87+
impl::impl_save_jxl(filename, data, width, height, 1, quality);
88+
}
8189
// This is some other kind of color image so just save it as an RGB image.
82-
if (pixel_traits<pixel_type>::has_alpha)
90+
else if (pixel_traits<pixel_type>::has_alpha)
8391
{
8492
array2d<rgb_alpha_pixel> temp;
8593
assign_image(temp, img);
8694
auto data = reinterpret_cast<const uint8_t*>(image_data(temp));
87-
impl::impl_save_jxl(filename, data, width, height, depth, quality);
95+
impl::impl_save_jxl(filename, data, width, height, 4, quality);
8896
}
8997
else
9098
{
9199
array2d<rgb_pixel> temp;
92100
assign_image(temp, img);
93101
auto data = reinterpret_cast<const uint8_t*>(image_data(temp));
94-
impl::impl_save_jxl(filename, data, width, height, depth, quality);
102+
impl::impl_save_jxl(filename, data, width, height, 3, quality);
95103
}
96104
}
97105
}

0 commit comments

Comments
 (0)