?? bigfile.inc
字號:
{TMT compilee}
{for reading chunks and their contents in bigfile
version 1.0 (2002-02-17)
doesn't include methods for handling sprites and adding/deleting chunks
optionable method to load a GIF file into 2dbuf
global variable bf:TBigFile
bigfile is stream => its content can be held either in file or memory}
{$IFNDEF bigfile}
{$DEFINE bigfile}
{$I STREAM.INC}
{$IFDEF streamgif}
{$I BUF2D.INC}
{$ENDIF}
const
BIGFILEHEADER ='Big File'#13#10#26;
BIGFILEHEADERSIZE =11;
BIGFILEINFOS =16;
type
PChunk=^TChunk;
TChunk=record
s:dword;
d:pointer;
end; {TChunk}
PBigFileHeader=^TBigFileHeader;
TBigFileHeader=record
head:array[0..BIGFILEHEADERSIZE-1] of char;
ver:byte; {1.0 (2.7.2000)}
future:word;
NumberOfSubfiles:word;
end; {TBigFileHeader}
PSubFile=^TSubFile;
TSubFile=record
id:array[0..7] of char;
offset:dword;
size:dword;
end; {TSubFile}
PBigFile=^TBigFile;
TBigFile=object
private
bigfile:TFileStream;
subfiles:word;
public
Constructor Open(bigfilename:string80);
Function FindChunk(_id:string8):boolean;
Function LoadChunk(_id:string8;var chunk:TChunk):boolean;
Function ChunkInfo(_id:string8;var sf:TSubfile):boolean;
Destructor Close;
{$IFDEF streamgif}
Function LoadGifToBuf(_id:string8;var gif:TBuf2d):boolean;
{$ENDIF}
end; {TBigFile}
function ChunkName(subfile:string8):string8;
var
v:string8;
i:dword;
begin
fillchar(v[1],8,'_');
move(subfile[1],v[1],length(subfile));
v[0]:=#8;
for i:=1 to length(v) do
v[i]:=UpCase(v[i]);
result:=v;
end; {ChunkName}
procedure FreeChunk(var chunk:TChunk);
begin
with chunk do if d<>nil then Freemem(d,s);
end; {FreeChunk}
procedure ClearChunk(var chunk:TChunk);
begin
fillchar(chunk,sizeof(chunk),0);
end; {ClearChunk}
Constructor TBigFile.Open(bigfilename:string80);
begin
subfiles:=0;
bigfile.init(bigfilename);
if bigfile.ok then begin
bigfile.seek(BIGFILEINFOS-2);
result:=bigfile.read(subfiles,sizeof(subfiles));
end else fail;
end; {TBigFile.Open}
Destructor TBigFile.Close;
begin
bigfile.done;
end; {TBigFile.Close}
Function TBigFile.FindChunk(_id:string8):boolean;
var
s:string8;
sf:TSubFile;
i:dword;
begin
result:=false;
if not bigfile.opened then exit;
_id:=ChunkName(_id);
bigfile.seek(BIGFILEINFOS);
for i:=1 to subfiles do
with sf do begin
bigfile.read(sf,sizeof(sf));
s[0]:=#8;
move(id,s[1],8);
if s=_id then begin
bigfile.seek(offset);
result:=true;
exit;
end;
end;
end; {TBigFile.FindChunk}
Function TBigFile.LoadChunk(_id:string8;var chunk:TChunk):boolean;
var
s:string8;
sf:TSubFile;
i:dword;
begin
result:=false;
with chunk do begin
if d<>nil then freemem(d,s);
d:=nil;
end;
if not bigfile.opened then exit;
_id:=ChunkName(_id);
bigfile.seek(BIGFILEINFOS);
for i:=1 to subfiles do
with sf do begin
bigfile.read(sf,sizeof(sf));
move(id,s[1],8); s[0]:=#8;
if s=_id then begin
bigfile.seek(offset);
with chunk do begin
s:=size; d:=nil;
getmem(d,s);
if d=nil then exit
else result:=bigfile.read(d^,s);
end;
exit;
end;
end;
end; {TBigFile.LoadChunk}
Function TBigFile.ChunkInfo(_id:string8;var sf:TSubfile):boolean;
var
s:string8;
i:word;
begin
result:=false;
if not bigfile.opened then exit;
_id:=ChunkName(_id);
bigfile.seek(BIGFILEINFOS);
for i:=1 to subfiles do
with sf do begin
bigfile.read(sf,sizeof(sf));
move(id,s[1],8); s[0]:=#8;
if s=_id then begin
bigfile.seek(offset);
result:=true;
exit;
end;
end;
end; {TBigFile.ChunkInfo}
{$IFDEF streamgif}
{$I LOADGIF.INC}
Function TBigFile.LoadGifToBuf(_id:string8;var gif:TBuf2d):boolean;
var
s:string8;
sf:TSubFile;
i:word;
begin
result:=false;
if not bigfile.opened then exit;
_id:=ChunkName(_id);
bigfile.seek(BIGFILEINFOS);
for i:=1 to subfiles do
with sf do begin
bigfile.read(sf,sizeof(sf));
move(id,s[1],8); s[0]:=#8;
if s=_id then begin
bigfile.seek(offset);
loadGif(bigfile,gif);
result:=gif.d<>nil;
exit;
end;
end;
end; {TBigFile.LoadGifToBuf}
{$ENDIF}
{$ENDIF}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -