@@ -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