From f279ffb50f69cb5c649506dd5b7f7911bb056a15 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Sun, 6 Mar 2022 02:08:34 +0100 Subject: [PATCH] Now supporting more dib headers to read --- Src/BMP.cpp | 1 - Src/BmpReader.cpp | 36 ++++++++++-------------------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/Src/BMP.cpp b/Src/BMP.cpp index a013695..d1d5fee 100644 --- a/Src/BMP.cpp +++ b/Src/BMP.cpp @@ -12,7 +12,6 @@ namespace Leonetienne::BmpPP { return; } - BMP::BMP(const std::string &filename) { if(!Read(filename)) throw std::runtime_error("Unable to read bmp image!"); diff --git a/Src/BmpReader.cpp b/Src/BmpReader.cpp index 1e59761..8fd1cb4 100644 --- a/Src/BmpReader.cpp +++ b/Src/BmpReader.cpp @@ -48,8 +48,8 @@ namespace Leonetienne::BmpPP { std::uint32_t height; std::uint16_t bitsPerPixel; - // Check if what kind of dib header we're dealing with - // These are the two we're supporting (to read, at least). + // Check for what kind of dib header we're dealing with. + // Is it a BITMAPCOREHEADER or a variant of a BITMAPINFOHEADER? if (dibHeaderSize == 12) { // BITMAPCOREHEADER it is @@ -68,27 +68,14 @@ namespace Leonetienne::BmpPP { // Read the bits per pixel ReadBytes(ifs, bitsPerPixel); } - else if (dibHeaderSize == 40) { - // BITMAPINFOHEADER it is - - // Read the width and height (both 4-byte signed ints) - std::int32_t width_4byte_signed; - std::int32_t height_4byte_signed; - - ReadBytes(ifs, width_4byte_signed); - 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 + else if ( + (dibHeaderSize == 40) || + (dibHeaderSize == 52) || + (dibHeaderSize == 56) || + (dibHeaderSize == 124) || + (dibHeaderSize == 108) + ) { + // This routine should work for all the variants of BITMAPINFOHEADERs // Read the width and height ReadBytes(ifs, width); @@ -134,9 +121,6 @@ namespace Leonetienne::BmpPP { // Calculate how much padding there should be between each row 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 std::vector pixelArray; pixelArray.resize(width * height * numChannels);