Browse Source

bitmap alignment issue in linux fixed

refactor
suhrke 5 years ago
parent
commit
6655198818
  1. 24
      source/Bitmap.h
  2. 24
      source/Decoder.cpp

24
source/Bitmap.h

@ -20,13 +20,33 @@ @@ -20,13 +20,33 @@
#include <cstdint>
#define BI_RGB 16 //bitmap value for uncompressed color data
#define BI_RGB 0 //bitmap value for uncompressed color data
#define CHAR_BM 19778
//Padding specific to compiler - must account for padded bfType
// and little-endian order when overlaying struct on buffer
typedef struct OverlayBitmapFileHeader {
uint16_t bfType = CHAR_BM; //filetype, must be 'BM'
uint8_t bfSize0;
uint8_t bfSize1;
uint8_t bfSize2;
uint8_t bfSize3;
uint16_t bfReserved1 = 0;
uint16_t bfReserved2 = 0;
uint8_t bfOffBits0;
uint8_t bfOffBits1;
uint8_t bfOffBits2;
uint8_t bfOffBits3;
} OverlayBitmapFileHeader;
typedef struct BITMAPFILEHEADER {
uint16_t bfType = 19778; //filetype, must be 'BM' (19778)
uint16_t bfType = CHAR_BM;//filetype, must be 'BM'
uint32_t bfSize; //size in bytes of bitmap file
uint16_t bfReserved1 = 0; //unused, except to keep alignment
uint16_t bfReserved2 = 0; //unused, except to keep alignment

24
source/Decoder.cpp

@ -1081,10 +1081,30 @@ int Decodebitmap(const std::string &fileName) { @@ -1081,10 +1081,30 @@ int Decodebitmap(const std::string &fileName) {
fclose(f);
return -1;
};
#ifdef _WIN32
pbfh=(BITMAPFILEHEADER *)buf;
pbih=(BITMAPINFOHEADER *)(buf+sizeof(BITMAPFILEHEADER));
std::cout << "Size of bmp file header: " << sizeof(*pbfh) << std::endl;
std::cout << "Size of bmp info header: " << sizeof(*pbih) << std::endl;
#elif __linux__
//Padding different in GCC, cannot overlay directly
//Use smaller types and bitwise ops to get the data
OverlayBitmapFileHeader *temp;
temp=(OverlayBitmapFileHeader *)buf;
pbfh = (BITMAPFILEHEADER*)malloc(sizeof(BITMAPFILEHEADER));
pbfh->bfType = temp->bfType;
pbfh->bfSize = temp->bfSize3 << 24;
pbfh->bfSize |= temp->bfSize2 << 16;
pbfh->bfSize |= temp->bfSize1 << 8;
pbfh->bfSize |= temp->bfSize0;
pbfh->bfReserved1 = temp->bfReserved1;
pbfh->bfReserved2 = temp->bfReserved2;
pbfh->bfOffBits = temp->bfOffBits3 << 24;
pbfh->bfOffBits |= temp->bfOffBits2 << 16;
pbfh->bfOffBits |= temp->bfOffBits1 << 8;
pbfh->bfOffBits |= temp->bfOffBits0;
pbih=(BITMAPINFOHEADER *)(buf+sizeof(OverlayBitmapFileHeader));
#endif
std::cout //<< pbfh << "\n"
<< pbfh -> bfType << ", " << &pbfh -> bfType <<"\n"

Loading…
Cancel
Save