Comments (2)
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.
from gil.
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 ...
@dynarithmic:
I am actually surprised that this works, because from my understanding it should not. 🤔 It probably works, because the image is 1700 x 2000 pixels, and that multiplied by one bit for each pixel gives a number that is divisible by 32 but not by 24. Have you checked the data? It may not be what you expect.
But let's get back to the first example using gil::rgb8_image_t
. You can actually make that work by using read_and_convert_image()
instead of read_image()
:
#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 read_and_convert_image()
over read_image()
is that it converts the read image data (in that case: 1 bpp grayscale) to the given image type (in that case: 24 bpp RGB), if GIL can do that, thus potentially avoiding problems with wrong image types.
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
from gil.
Related Issues (20)
- Remove C++11 build jobs from CI HOT 2
- Fix wrong pixel channel truncation in binary threshold and truncate threshold HOT 2
- Consider moving channel_convert_to_unsigned out of detail namespace
- color_convert_hsl / gcc-5~c++14: converting to std::tuple from initializer list would use explicit constructor constexpr std::tuple
- color_convert_rgb / gcc-5~c++14: converting to std::tuple from initializer list would use explicit constructor constexpr std::tuple
- color_convert_hsl.cpp and color_convert_rgb.cpp error: no matching constructor for initialization of std::vector<color_t>
- Allow implicit conversion from gray8_ptr_t to gray8_step_ptr_t HOT 3
- g++ 12.1.1 fails to compile Boost.GIL with -std=c++20 HOT 3
- unsued variable warning
- Convolution2d seems to be not correct. HOT 1
- stream device "tell" method absent! HOT 2
- Alpha-blending HOT 4
- Overflow in channel convertion HOT 2
- heap-buffer-overflow when using io-related functions HOT 1
- Running the convolve_2d.cpp test causes an alignment error on ARM
- About Enterprise Managed Users - GitHub Enterprise Cloud Docs
- https://docs.github.com/es/[email protected]/admin/monitoring-managing-and-updating-your-instance/updating-the-virtual-machine-and-physical-resources/upgrading-github-enterprise-server HOT 1
- CMake: Dependency on Boost::filesystem is wrong HOT 5
- Use of min and max in Gil conflicts with Win32-API on Windows/MSVC HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gil.