Now supporting more dib headers to read
This commit is contained in:
parent
4cb9c6d65d
commit
f279ffb50f
@ -12,7 +12,6 @@ namespace Leonetienne::BmpPP {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BMP::BMP(const std::string &filename) {
|
BMP::BMP(const std::string &filename) {
|
||||||
if(!Read(filename))
|
if(!Read(filename))
|
||||||
throw std::runtime_error("Unable to read bmp image!");
|
throw std::runtime_error("Unable to read bmp image!");
|
||||||
|
@ -48,8 +48,8 @@ namespace Leonetienne::BmpPP {
|
|||||||
std::uint32_t height;
|
std::uint32_t height;
|
||||||
std::uint16_t bitsPerPixel;
|
std::uint16_t bitsPerPixel;
|
||||||
|
|
||||||
// Check if what kind of dib header we're dealing with
|
// Check for what kind of dib header we're dealing with.
|
||||||
// These are the two we're supporting (to read, at least).
|
// Is it a BITMAPCOREHEADER or a variant of a BITMAPINFOHEADER?
|
||||||
if (dibHeaderSize == 12) {
|
if (dibHeaderSize == 12) {
|
||||||
// BITMAPCOREHEADER it is
|
// BITMAPCOREHEADER it is
|
||||||
|
|
||||||
@ -68,27 +68,14 @@ namespace Leonetienne::BmpPP {
|
|||||||
// Read the bits per pixel
|
// Read the bits per pixel
|
||||||
ReadBytes(ifs, bitsPerPixel);
|
ReadBytes(ifs, bitsPerPixel);
|
||||||
}
|
}
|
||||||
else if (dibHeaderSize == 40) {
|
else if (
|
||||||
// BITMAPINFOHEADER it is
|
(dibHeaderSize == 40) ||
|
||||||
|
(dibHeaderSize == 52) ||
|
||||||
// Read the width and height (both 4-byte signed ints)
|
(dibHeaderSize == 56) ||
|
||||||
std::int32_t width_4byte_signed;
|
(dibHeaderSize == 124) ||
|
||||||
std::int32_t height_4byte_signed;
|
(dibHeaderSize == 108)
|
||||||
|
) {
|
||||||
ReadBytes(ifs, width_4byte_signed);
|
// This routine should work for all the variants of BITMAPINFOHEADERs
|
||||||
ReadBytes(ifs, height_4byte_signed);
|
|
||||||
|
|
||||||
width = width_4byte_signed;
|
|
||||||
height = height_4byte_signed;
|
|
||||||
|
|
||||||
// Skip two useless bytes
|
|
||||||
ifs.ignore(2);
|
|
||||||
|
|
||||||
// Read the bits per pixel value
|
|
||||||
ReadBytes(ifs, bitsPerPixel);
|
|
||||||
}
|
|
||||||
else if (dibHeaderSize == 124) {
|
|
||||||
// BITMAPV5HEADER it is
|
|
||||||
|
|
||||||
// Read the width and height
|
// Read the width and height
|
||||||
ReadBytes(ifs, width);
|
ReadBytes(ifs, width);
|
||||||
@ -134,9 +121,6 @@ namespace Leonetienne::BmpPP {
|
|||||||
// Calculate how much padding there should be between each row
|
// Calculate how much padding there should be between each row
|
||||||
const std::size_t paddingBytesPerRow = (4 - ((width * numChannels) % 4)) % 4;
|
const std::size_t paddingBytesPerRow = (4 - ((width * numChannels) % 4)) % 4;
|
||||||
|
|
||||||
// Calculate how long bytes we should care about per row (so, excluding padding)
|
|
||||||
const std::size_t rowWidth = width * numChannels;
|
|
||||||
|
|
||||||
// Create the pixel buffer
|
// Create the pixel buffer
|
||||||
std::vector<std::uint8_t> pixelArray;
|
std::vector<std::uint8_t> pixelArray;
|
||||||
pixelArray.resize(width * height * numChannels);
|
pixelArray.resize(width * height * numChannels);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user