Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
Created June 6, 2013 10:41
Show Gist options
  • Save hoehrmann/5720668 to your computer and use it in GitHub Desktop.
Save hoehrmann/5720668 to your computer and use it in GitHub Desktop.
Converter for .TEX texture files from SquareSoft's Final Fantasy VII to Windows BMP files.
{ _Add wildcards, parameter comfort, seperate file extraction for manipulation,
graphical output, check for xdim, memory using Speedup for swapping,..._ }
{$Q-}
program TEXfileUnpack;
(* Converts .TEX Files from SquareSoft's Final Fantasy VII TO BMP files *)
(* Copyright (c) 1998 by Bjoern Hoehrmann All rights reserved *)
type
bgrf=record b,g,r,f:byte;end; { Windows Color Table Entry }
TBitmapFileHeader=record { BMP File Header }
bfType : word;
bfSize : longint;
bfReserved1 : word;
bfReserved2 : word;
bfOffBits : longint;
end;
TBitmapInfoHeader=record { BMP Info Header }
biSize : longint;
biWidth : longint;
biHeight : longint;
biPlanes : word;
biBitCount : word;
biCompression : longint;
biSizeImage : longint;
biXPelsPerMeter: longint;
biYPelsPerMeter: longint;
biClrUsed : longint;
biClrImportant : longint;
end;
var TexFile,BmpFile:file; { The LGP and the BMP File }
Pal_In:array[0..255] of bgrf;{ Windows Style Palette }
re1:array[0..235] of byte; { Unknown Data 1 }
buf1:array[0..1023] of byte; { BMP Buffer Data }
i:integer; { Count Variable }
Infohead:TBitmapInfoHeader; { BMP Header }
Filehead:TBitmapFileHeader; { BMP Header }
xdim,ydim:word; { xdim and ydim as word }
w:word; { 2 End bytes }
l:longint; { longint for Offset storing }
s:string; { Filename Prestring }
procedure ShowHelpScreen; { A little HelpScreen for dumbs }
begin
WriteLn(' ');
WriteLn(' Tex2Bmp v1.0 Copyright (c) 1998 by Bjoern Hoehrmann');
WriteLn(' ──────────────────────────────────────────────────────────────────────────────');
WriteLn(' Tex2Bmp is a little utility to convert .Tex files from Squaresoft''s Final ');
WriteLn(' Fantasy VII to 8bit Bmp files. ');
WriteLn(' ──────────────────────────────────────────────────────────────────────────────');
WriteLn(' /? - Shows this little help screen ');
WriteLn(' ──────────────────────────────────────────────────────────────────────────────');
WriteLn(' Usage: TEX2BMP.EXE TEXFILE.TEX ');
WriteLn(' ──────────────────────────────────────────────────────────────────────────────');
WriteLn(' If you have no .Tex files extract them with LGPUNP.EXE. If you have any ');
WriteLn(' FileFormat description of the LGP or the TEX or any other FF7 fileformat, ');
WriteLn(' would I be pleased to get it, to make this program more comfortable. ');
WriteLn(' For any comment or a bug report contact [email protected]. ');
WriteLn(' ──────────────────────────────────────────────────────────────────────────────');
end;
procedure BMPVarSet; { Set the BMP Variables }
begin
xdim:=256; { May be this is sometimes wrong }
ydim:=(filesize(texfile)-filepos(texfile)) div xdim; { Calculate ydim from imgsize }
FileHead.bfType :=19778; { BMP Identifier (BM) }
FileHead.bfSize :=xdim*ydim+1080; { Filesize (fh+fih+pal+img+end) }
FileHead.bfOffBits :=1078; { Full Header bytes (fh+fih+pal) }
InfoHead.biSize :=40; { TFileInfoHeader Size }
InfoHead.biWidth :=xdim; { X-Resolution }
InfoHead.biHeight :=ydim; { Y-Resolution }
InfoHead.biPlanes :=1; { 1 Plane }
InfoHead.biBitCount :=8; { 8bit (256 color) Image }
InfoHead.biCompression :=0; { No Compression }
InfoHead.biSizeImage :=xdim*ydim; { Raw Image Size }
InfoHead.biXPelsPerMeter:=2834; { 28,34cm/pixel (=72inch/pixel) }
InfoHead.biYPelsPerMeter:=2834; { 28,34cm/pixel (=72inch/pixel) }
InfoHead.biClrUsed :=0; { Colors Used 0=all used }
InfoHead.biClrImportant :=0; { Important Colors 0=all Important }
end; { End of BMPVarSet }
begin { Main Program Begin }
ShowHelpScreen;
s:=Paramstr(1);
i:=pos('.',s); { Position of '.' in s }
if i<>0 then delete(s,i,length(s)-i+1); { If there is a extension, del it }
filemode:=2;
assign(TexFile,s+'.TEX'); { Define the .TEX File }
reset(TexFile,1);
assign(bmpfile,s+'.BMP'); { Define the .BMP File }
rewrite(bmpfile,1);
blockread(texFile,re1,sizeof(re1)); { Read re1 }
blockread(TexFile,Pal_In,sizeof(Pal_In)); { Read the Palette }
BMPVarSet; { Set BMP Variables }
BlockWrite(bmpfile,FileHead,sizeof(fileHead)); { Write the FileHeader }
BlockWrite(bmpfile,infoHead,sizeof(infoHead)); { Write the FileInfo }
Blockwrite(BmpFile,Pal_In,sizeof(Pal_In)); { Write the Palette }
for i:=ydim downto 1 do begin { Horizontal swap of the image }
seek(texfile,(i-1)*xdim+1260); { Seek the i-th line }
blockread(texfile,buf1,xdim); { Read it }
BlockWrite(bmpfile,buf1,xdim); { Write it in the BMP }
end; { End of Swap }
blockwrite(bmpfile,w,2); { Write the 2 end bytes }
close(TexFile); { Close the .TEX File }
close(BmpFile); { Close the .BMP File }
end. { The end of this fine proggi }
{ NO UNAUTHORISED MODIFIKATION, OR YOUR COMPUTER WILL EXPLODE. THANKS }
{ LAST EDIT: WEDNESDAY, 21ST OCTOBER 1998 }
@chrcoluk
Copy link

its a pas file not executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment