skip unknown data in bmp between header and data

This commit is contained in:
Adam D. Ruppe 2025-09-15 10:32:02 -04:00
parent f4eb75a1d9
commit 93fb163d73
1 changed files with 10 additions and 7 deletions

17
bmp.d
View File

@ -112,6 +112,9 @@ MemoryImage readBmpIndirect(scope void delegate(void*, size_t) fread, bool lookF
throw new Exception("didn't get expected int value " /*~ to!string(got)*/, __FILE__, line); throw new Exception("didn't get expected int value " /*~ to!string(got)*/, __FILE__, line);
} }
uint offsetToBits;
int offsetToBitsAfterHeader;
if(lookForFileHeader) { if(lookForFileHeader) {
require1('B'); require1('B');
require1('M'); require1('M');
@ -120,7 +123,7 @@ MemoryImage readBmpIndirect(scope void delegate(void*, size_t) fread, bool lookF
require2(0); // reserved require2(0); // reserved
require2(0); // reserved require2(0); // reserved
auto offsetToBits = read4(); offsetToBits = read4();
version(arsd_debug_bitmap_loader) { import core.stdc.stdio; printf("pixel data offset: 0x%08x\n", cast(uint)offsetToBits); } version(arsd_debug_bitmap_loader) { import core.stdc.stdio; printf("pixel data offset: 0x%08x\n", cast(uint)offsetToBits); }
} }
@ -129,6 +132,9 @@ MemoryImage readBmpIndirect(scope void delegate(void*, size_t) fread, bool lookF
version(arsd_debug_bitmap_loader) { import core.stdc.stdio; printf("size of bitmap info header: %d\n", cast(uint)sizeOfBitmapInfoHeader); } version(arsd_debug_bitmap_loader) { import core.stdc.stdio; printf("size of bitmap info header: %d\n", cast(uint)sizeOfBitmapInfoHeader); }
if(offsetToBits > sizeOfBitmapInfoHeader + 14 /* 14 is the size size of file header */)
offsetToBitsAfterHeader = offsetToBits - sizeOfBitmapInfoHeader - 14;
int width, height, rdheight; int width, height, rdheight;
if (sizeOfBitmapInfoHeader == 12) { if (sizeOfBitmapInfoHeader == 12) {
@ -425,12 +431,9 @@ MemoryImage readBmpIndirect(scope void delegate(void*, size_t) fread, bool lookF
// true color image // true color image
auto img = new TrueColorImage(width, height); auto img = new TrueColorImage(width, height);
if(compression == 3) foreach(counter; 0 .. offsetToBitsAfterHeader) {
foreach(idx; 0 .. 3) { // so tbh I don't know what this actually is, but we can know to skip it at least
// so tbh I don't know what this actually is, it looks like an rgb mask, but why is it here? read1();
// is this common or just the one file i happen to have?
// is there some header byte im missing?
read4();
} }
// no palette, so straight into the data // no palette, so straight into the data