Fix bug when loading grayscale: make sure info.Channels() is 1.

This commit is contained in:
Ryan Curtin
2024-01-31 09:45:32 -05:00
parent 21b444034c
commit 1accad6c29
+4 -2
View File
@@ -154,14 +154,16 @@ inline bool LoadImage(const std::string& filename,
info.Width() = tempWidth;
info.Height() = tempHeight;
info.Channels() = tempChannels;
// Only set the new number of channels if we didn't force grayscale loading.
if (info.Channels() != 1)
info.Channels() = tempChannels;
// Copy image into armadillo Mat.
matrix = arma::Mat<unsigned char>(image, info.Width() * info.Height() *
info.Channels(), 1, true, true);
// Free the image pointer.
free(image);
stbi_image_free(image);
return true;
}