-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for reading/writing 1 bit (black/white) BMP images? #727
Comments
I was able to get a little further using the following #include <boost/gil.hpp>
#include <boost/gil/extension/io/bmp.hpp>
#include <fstream>
namespace gil = boost::gil;
int main()
{
std::ifstream infile("test1bpp.bmp", std::ios::binary);
gil::rgba8_image_t img;
gil::read_image(infile, img, gil::bmp_tag()); // <-- Doesn't throw exception now
// Now write the image to another bmp file
auto v = gil::view(img);
auto writer = gil::make_writer("test1bpp_output.bmp", gil::bmp_tag());
gil::write_view(writer, v); // <-- This creates a 24 bpp image, not a 1 bpp image
} However, the code to write the image to a second bmp file results in the file being 24 bits-per-pixel, and not the original 1-bit-per-pixel as was the source image. I debugged the code, and it seems that the write_view multiplies the number of channels by 8. I am not sure this will work for 1-bit-per-pixel. So I am stuck as to how to write the destination bmp using the same 1-bpp as the source image. The ultimate goal is to be able to convert a 1-bpp bmp to a Group3 or Group4 TIFF, which only supports 1-bit-per-pixel image data. So far, I am able to read the data, but not able to produce a duplicate of the image, even if the image type is the same, source and destination. |
@dynarithmic: But let's get back to the first example using #include <boost/gil.hpp>
#include <boost/gil/extension/io/bmp.hpp>
#include <fstream>
namespace gil = boost::gil;
int main()
{
std::ifstream infile("test1bpp.bmp", std::ios::binary);
gil::rgb8_image_t img;
gil::read_and_convert_image(infile, img, gil::bmp_tag());
} The advantage of As far as writing BMP images is concerned, GIL currently only supports writing of 24 bit RGB and 32 bit RGBA bitmaps. At least that is how I interpret that code: gil/include/boost/gil/extension/io/bmp/detail/supported_types.hpp Lines 88 to 106 in 8994c2f
|
Actual behavior
Attempting to read the attached monochrome BMP image using gil will result in an "Image types aren't compatible" exception being thrown from io_error() in error.hpp.
Expected behavior
Valid load of a valid 1-bit BMP image on the gil::read_image() call;
C++ Minimal Working Example
I am new to gil, and more than likely, the img type is not correct, which is not surprising. However I was not able to use any of the other types that are predefined without compilation error from the template compile checks, or if the compilation succeeds, the same exception being thrown at runtime ("Image types not compatible").
So I am not sure if 1-bpp images are supported in gil, and/or what should be done in the existing gil library to read the attached image.
Environment
<boost/version.hpp>
): 1.81test1bpp.zip
The text was updated successfully, but these errors were encountered: