mirror of
https://github.com/dpethes/rerogue.git
synced 2025-06-07 18:58:32 +02:00
hmt parser: save texture images
This commit is contained in:
parent
c7ee2b0671
commit
59b5e6e4b6
@ -22,6 +22,8 @@ type
|
||||
name_offset: integer;
|
||||
width, height: word;
|
||||
name: array[0..15] of byte;
|
||||
name_string: string;
|
||||
image: TRSImage;
|
||||
end;
|
||||
|
||||
THmtFile = record
|
||||
@ -83,6 +85,7 @@ begin
|
||||
pos := f.Position;
|
||||
f.Seek(tex.name_offset, TSeekOrigin.soBeginning);
|
||||
f.ReadBuffer(tex.name, 16);
|
||||
tex.name_string := NameToString(tex.name);
|
||||
f.Seek(pos, TSeekOrigin.soBeginning);
|
||||
|
||||
description := ImageDescription[image.type_];
|
||||
@ -91,7 +94,7 @@ begin
|
||||
image.width := tex.width;
|
||||
image.height := tex.height;
|
||||
|
||||
writeln(NameToString(tex.name));
|
||||
writeln('name: ', tex.name_string);
|
||||
writeln('size: ', tex.width, 'x', tex.height);
|
||||
writeln('subtype: ', image.type_, ' bpp: ', bpp);
|
||||
writeln('sample bits: ', image.sampleBits);
|
||||
@ -109,6 +112,7 @@ begin
|
||||
|
||||
f.Seek(pos, TSeekOrigin.soBeginning);
|
||||
writeln;
|
||||
tex.image := image;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -2,10 +2,49 @@ program parse_hmt;
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
hmt_parser;
|
||||
sysutils, hmt_parser, rs_image;
|
||||
|
||||
procedure pnm_save(const fname: string; const p: pbyte; const w, h: integer);
|
||||
var
|
||||
f: file;
|
||||
c: PChar;
|
||||
Begin
|
||||
c := PChar(format('P6'#10'%d %d'#10'255'#10, [w, h]));
|
||||
AssignFile (f, fname);
|
||||
Rewrite (f, 1);
|
||||
BlockWrite (f, c^, strlen(c));
|
||||
BlockWrite (f, p^, w * h * 3);
|
||||
CloseFile (f);
|
||||
end;
|
||||
|
||||
procedure pgm_save(fname: string; p: pbyte; w, h: integer) ;
|
||||
var
|
||||
f: file;
|
||||
c: PChar;
|
||||
Begin
|
||||
c := PChar(format('P5'#10'%d %d'#10'255'#10, [w, h]));
|
||||
AssignFile (f, fname);
|
||||
Rewrite (f, 1);
|
||||
BlockWrite (f, c^, strlen(c));
|
||||
BlockWrite (f, p^, w * h);
|
||||
CloseFile (f);
|
||||
end;
|
||||
|
||||
procedure SaveImage(var image: TRSImage; const outname: string);
|
||||
begin
|
||||
case image.type_ of
|
||||
0: pnm_save(outname + '.pnm', image.pixels, image.width, image.height);
|
||||
//3: WriteTga(outname + '.tga', image.pixels, image.width, image.height, image.width * image.height * 4);
|
||||
4: pgm_save(outname + '.pgm', image.pixels, image.width, image.height);
|
||||
else
|
||||
writeln('image type was not saved: ', image.type_);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
fname: string;
|
||||
hmt: THmtFile;
|
||||
i: integer;
|
||||
|
||||
begin
|
||||
if ParamCount < 1 then begin
|
||||
@ -16,7 +55,10 @@ begin
|
||||
fname := ParamStr(1);
|
||||
writeln('parsing file: ', fname);
|
||||
try
|
||||
ParseHmtFile(fname);
|
||||
hmt := ParseHmtFile(fname);
|
||||
writeln('saving textures');
|
||||
for i := 0 to hmt.texture_count - 1 do
|
||||
SaveImage(hmt.textures[i].image, fname + '_' + hmt.textures[i].name_string);
|
||||
except
|
||||
writeln('parsing failed!');
|
||||
end;
|
||||
|
Loading…
x
Reference in New Issue
Block a user