Skip to content

Instantly share code, notes, and snippets.

@ssg
Created September 6, 2024 21:04
Show Gist options
  • Save ssg/c240d22df1adc60260daf7b10d7787d1 to your computer and use it in GitHub Desktop.
Save ssg/c240d22df1adc60260daf7b10d7787d1 to your computer and use it in GitHub Desktop.
A tool I coded back in early 1990's to see the structure of a BMP file
{ BMP Header Dumper }
uses Objects,XIO,XTypes;
(*
type
TBitmapFileHeader = record
bfType: Word;
bfSize: Longint;
bfReserved1: Word;
bfReserved2: Word;
bfOffBits: Longint;
end;
TRGBQuad = record
rgbBlue: Byte;
rgbGreen: Byte;
rgbRed: Byte;
rgbReserved: Byte;
end;
TRGBTriple = record
rgbtBlue: Byte;
rgbtGreen: Byte;
rgbtRed: Byte;
end;
TBitmapCoreHeader = record
bcSize: Longint; { used to get to color table }
bcWidth: longint;
bcHeight: longint;
bcPlanes: Word;
bcBitCount: Word;
end;
TBitmapInfoHeader = record
biCompression: Longint;
biSizeImage: Longint;
biXPelsPerMeter: Longint;
biYPelsPerMeter: Longint;
biClrUsed: Longint;
biClrImportant: Longint;
end;*)
var
T:TDosStream;
s:FNameStr;
TBH:TBMPCore;
TBS:TBMPSimple;
TBX:TBMPExtra;
begin
XAppInit('BMP Dump','1.00d','SSG',1,'filename[.BMP]');
s := XAddExt(paramstr(1),'.BMP');
T.Init(s,stOpenRead);
if T.Status <> stOk then XAbort('unable to read bitmap');
T.Read(TBH,SizeOf(TBH));
if TBH.HdrSize > 12 then
with TBH do begin
writeln(' FILE HEADER');
writeln;
writeln('Bitmap file size = ',FSize);
writeln('Reserved word 1 = ',Unknown1);
writeln('Image offset = ',DataStart);
writeln;
writeln(' CORE HEADER (New Bitmap Format)');
writeln;
writeln('Header size = ',HdrSize);
writeln('Image width = ',SizeX);
writeln('Image height = ',SizeY);
writeln('Number of planes = ',Planes);
writeln('Bits per pixel = ',BitCount,' (',1 shl BitCount,' colors)');
end else
with TBS do begin
T.Seek(0);
T.Read(TBS,SizeOf(TBS));
writeln(' FILE HEADER');
writeln;
writeln('Bitmap file size = ',FSize);
writeln('Reserved word 1 = ',Unknown1);
writeln('Image offset = ',DataStart);
writeln;
writeln(' CORE HEADER (Old Bitmap Format)');
writeln;
writeln('Header size = ',HdrSize);
writeln('Image width = ',SizeX);
writeln('Image height = ',SizeY);
writeln('Number of planes = ',Planes);
writeln('Bits per pixel = ',BitCount,' (',1 shl BitCount,' colors)');
end;
write('Palette type = ');
if TBH.HdrSize > 12 then begin
writeln('Quad');
writeln;
T.Read(TBX,SizeOf(TBX));
with TBX do begin
writeln(' EXTRA INFORMATION');
writeln;
writeln('Compression = ',Compression);
writeln('Image size = ',ImageSize);
writeln('XPels per meter = ',XPelspermeter);
writeln('YPels per meter = ',YPelspermeter);
writeln('Used colors = ',ColorUsed);
writeln('Important colors = ',ColorImportant);
end;
end else writeln('RGB');
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment