AlloSphere-Research-Group / allolib

Library for interactive multimedia application development
BSD 3-Clause "New" or "Revised" License
36 stars 14 forks source link

Image::saveImage assumes the number of image channels as 3 #39

Closed sihwapark closed 4 years ago

sihwapark commented 4 years ago

This issue also happens with the devel branch commit 8a9ece2

When Image saves image data with Image::saveImage(), the saved image is corrupted because of wrongly specified stride bytes.

It is because the Image class assumes the data being saved has 3 channels whereas Image loads an image as 4 channels RGBA.

// in al_Image.cpp

bool Image::saveImage(std::string fileName, unsigned char *pixs, int width,
                      int height, bool flipVertically) {

  al_stbSetFlipVertically(flipVertically);
  return al_stbWriteImage(fileName.c_str(), pixs, width, height);
}
...

// in al_stb_image.cpp
bool al_stbWriteImage(const char *fileName, const unsigned char *data,
                      int width, int height) {
  return stbi_write_png(fileName, width, height, 3, data, width * 3) == 0;
}

Above are the actual functions called. I think saveImage and al_stbWriteImage need to have a parameter for the number of channels instead of hard-coded "3"s inside the function.

mantaraya36 commented 4 years ago

Thanks. I had assumed that this would be mostly used for RGB buffer captures, but I've now added an option to have an alpha channel ba439b995f984dbb5a4fede89492cb2643077312