refactor: Deduplicated BMP header writing in Xtc (#1439) by znelson

This commit is contained in:
jpirnay
2026-04-10 11:29:57 +02:00
parent c42452df8e
commit c97f16b576
4 changed files with 22 additions and 96 deletions
+6 -6
View File
@@ -107,7 +107,7 @@ uint8_t quantize1bit(int gray, int x, int y) {
return (gray >= adjustedThreshold) ? 1 : 0;
}
void createBmpHeader(BmpHeader* bmpHeader, int width, int height) {
void createBmpHeader(BmpHeader* bmpHeader, int width, int height, BmpRowOrder rowOrder) {
if (!bmpHeader) return;
// Zero out the memory to ensure no garbage data if called on uninitialized stack memory
@@ -125,15 +125,15 @@ void createBmpHeader(BmpHeader* bmpHeader, int width, int height) {
bmpHeader->infoHeader.biSize = sizeof(bmpHeader->infoHeader);
bmpHeader->infoHeader.biWidth = width;
bmpHeader->infoHeader.biHeight = height;
bmpHeader->infoHeader.biHeight = (rowOrder == BmpRowOrder::TopDown) ? -height : height;
bmpHeader->infoHeader.biPlanes = 1;
bmpHeader->infoHeader.biBitCount = 1;
bmpHeader->infoHeader.biCompression = 0;
bmpHeader->infoHeader.biSizeImage = imageSize;
bmpHeader->infoHeader.biXPelsPerMeter = 0;
bmpHeader->infoHeader.biYPelsPerMeter = 0;
bmpHeader->infoHeader.biClrUsed = 0;
bmpHeader->infoHeader.biClrImportant = 0;
bmpHeader->infoHeader.biXPelsPerMeter = 2835; // 72 DPI
bmpHeader->infoHeader.biYPelsPerMeter = 2835; // 72 DPI
bmpHeader->infoHeader.biClrUsed = 2;
bmpHeader->infoHeader.biClrImportant = 2;
// Color 0 (black)
bmpHeader->colors[0].rgbBlue = 0;