1 Star 0 Fork 0

johntao/mir4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Wil.pas 22.95 KB
一键复制 编辑 原始数据 按行查看 历史
johntao 提交于 2024-05-06 23:52 . 提交
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
unit Wil;
interface
uses
Classes, Windows, Graphics, SysUtils, Textures, dib, GameImages;
type
TWMImageHeader = record
Title: string[40]; //'WEMADE Entertainment inc.'
ImageCount: Integer;
ColorCount: Integer;
PaletteSize: Integer;
VerFlag: Integer;
end;
PTWMImageHeader = ^TWMImageHeader;
TWMImageInfo = record
nWidth: SmallInt;
nHeight: SmallInt;
px: SmallInt;
py: SmallInt;
bits: PByte;
end;
PTWMImageInfo = ^TWMImageInfo;
TWMIndexHeader = record
Title: string[40]; //'WEMADE Entertainment inc.'
IndexCount: integer;
VerFlag: integer;
end;
PTWMIndexHeader = ^TWMIndexHeader;
TWMIndexInfo = record
Position: Integer;
Size: Integer;
end;
PTWMIndexInfo = ^TWMIndexInfo;
pTWilImages = ^TWilImages;
TWilImages = class(TGameImages)
private
btVersion: Byte;
FHeader: TWMImageHeader;
procedure LoadPalette;
procedure LoadIndex(sIdxFile: string);
procedure LoadDxImage(Position: Integer; DXImage: pTDXImage);
procedure LoadDxBitmap(Position: Integer; DXImage: pTDXImage);
protected
function GetCachedSurface(Index: Integer): TTexture; override;
function GetCachedBitmap(Index: Integer): TBitmap; override;
public
m_IndexList: TList;
m_FileStream: TFileStream; //TMapStream; //TFileStream;
MainPalette: TRGBQuads;
constructor Create(); override;
destructor Destroy; override;
procedure Initialize; override;
procedure Finalize; override;
function GetCachedImage(Index: Integer; var PX, PY: Integer): TTexture; override;
function GetBitmap(Index: Integer; var PX, PY: Integer): TBitmap; override;
end;
implementation
function ExtractFilePath(const FileName: string): string;
var
I: integer;
begin
I := LastDelimiter(PathDelim + DriveDelim, FileName);
Result := Copy(FileName, 1, I);
end;
function ExtractFileNameOnly(const fname: string): string;
var
extpos: integer;
ext, fn: string;
begin
ext := ExtractFileExt(fname);
fn := ExtractFileName(fname);
if ext <> '' then
begin
extpos := Pos(ext, fn);
Result := Copy(fn, 1, extpos - 1);
end
else
Result := fn;
end;
function _MIN(N1, N2: integer): integer;
begin
if N1 < N2 then
Result := N1
else
Result := N2;
end;
function _MAX(N1, N2: integer): integer;
begin
if N1 > N2 then
Result := N1
else
Result := N2;
end;
function IncPointer(P: Pointer; Size: Integer): Pointer;
begin
Result := Pointer(Integer(P) + Size);
end;
constructor TWilImages.Create();
begin
inherited;
//FLoadMode := lmAutoWil;
btVersion := 0;
m_FileStream := nil;
m_IndexList := TList.Create;
end;
destructor TWilImages.Destroy;
begin
m_IndexList.Free;
inherited;
end;
procedure TextOutStr(Msg: string);
var
flname: string;
fhandle: TextFile;
begin
flname := '.\Text.txt';
if FileExists(flname) then
begin
AssignFile(fhandle, flname);
Append(fhandle);
end
else
begin
AssignFile(fhandle, flname);
Rewrite(fhandle);
end;
Writeln(fhandle, TimeToStr(Time) + ' ' + Msg);
CloseFile(fhandle);
end;
procedure TWilImages.Initialize;
var
idxfile, sFileName, sFileExt: string;
begin
if not Initialized then
begin
if FileExists(FileName) then
begin
m_FileStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
m_FileStream.Read(FHeader, SizeOf(TWMImageHeader));
if (FHeader.VerFlag = 0) or (FHeader.ColorCount = 65536) then
begin
btVersion := 1;
m_FileStream.Seek(-4, soFromCurrent);
end;
case FHeader.ColorCount of
256:
BitCount := 8;
65536:
BitCount := 16;
16777216:
BitCount := 24;
else
BitCount := 32;
end;
ImageCount := FHeader.ImageCount;
m_ImgArr := AllocMem(SizeOf(TDXImage) * ImageCount); //开辟空间 置0
idxfile := ExtractFilePath(FileName) + ExtractFileNameOnly(FileName) + '.WIX';
LoadPalette;
LoadIndex(idxfile);
Initialized := True;
end;
end;
end;
procedure TWilImages.Finalize;
var
I: Integer;
begin
if Initialized then
begin
Initialized := False;
IndexList.Clear;
if m_ImgArr <> nil then
begin
for I := 0 to ImageCount - 1 do
begin
if m_ImgArr[I].Texture <> nil then
begin
m_ImgArr[I].Texture.Free;
m_ImgArr[I].Texture := nil;
end;
if m_ImgArr[I].Bitmap <> nil then
begin
m_ImgArr[I].Bitmap.Free;
m_ImgArr[I].Bitmap := nil;
end;
end;
FreeMem(m_ImgArr);
end;
m_ImgArr := nil;
ImageCount := 0;
if m_FileStream <> nil then
FreeAndNil(m_FileStream);
end;
end;
procedure TWilImages.LoadPalette;
begin
if btVersion <> 0 then
m_FileStream.Seek(SizeOf(TWMImageHeader) - 4, 0)
else
m_FileStream.Seek(SizeOf(TWMImageHeader), 0);
m_FileStream.Read(MainPalette, SizeOf(TRGBQuad) * 256);
end;
procedure TWilImages.LoadIndex(sIdxFile: string);
var
FHandle, I, Value: integer;
Header: TWMIndexHeader;
PValue: PInteger;
begin
m_IndexList.Clear;
if FileExists(sIdxFile) then
begin
FHandle := FileOpen(sIdxFile, fmOpenRead or fmShareDenyNone);
if FHandle > 0 then
begin
if btVersion <> 0 then
FileRead(FHandle, Header, SizeOf(TWMIndexHeader) - 4)
else
FileRead(FHandle, Header, SizeOf(TWMIndexHeader));
GetMem(PValue, 4 * Header.IndexCount);
FileRead(FHandle, PValue^, 4 * Header.IndexCount);
for I := 0 to Header.IndexCount - 1 do
begin
Value := PInteger(Integer(PValue) + 4 * I)^;
m_IndexList.Add(Pointer(Value));
end;
FreeMem(PValue);
FileClose(FHandle);
end;
end;
end;
{----------------- Private Variables ---------------------}
function WidthBytes(w: integer): integer;
begin
Result := (((w * 8) + 31) div 32) * 4;
end;
procedure TWilImages.LoadDxImage(Position: Integer; DXImage: pTDXImage);
const
RGB565_MASK_RED = $F800;
RGB555_MASK_RED = $07C0;
var
ImageInfo: TWMImageInfo;
nPitch: Integer;
nWidth, nSize: Integer;
I, J: Integer;
S: Pointer;
SrcP: PByte;
DesP: Pointer;
RGB: TRGBQuad;
Source: TDIB;
begin
//try
m_FileStream.Position := Position;
if btVersion <> 0 then
m_FileStream.Read(ImageInfo, SizeOf(TWMImageInfo) - 4)
else
m_FileStream.Read(ImageInfo, SizeOf(TWMImageInfo));
if ImageInfo.nWidth * ImageInfo.nHeight <= 0 then
Exit;
if BitCount = 8 then
nSize := WidthBytes(ImageInfo.nWidth) * ImageInfo.nHeight
else
nSize := ImageInfo.nWidth * ImageInfo.nHeight * (BitCount div 8);
GetMem(S, nSize);
m_FileStream.Read(S^, nSize);
SrcP := S;
//ImageInfo := IncPointer(m_FileStream.Memory, Position);
//if ImageInfo.nWidth * ImageInfo.nHeight <= 0 then Exit;
//if btVersion <> 0 then SrcP := IncPointer(ImageInfo, SizeOf(TWMImageInfo) - 4)
//else SrcP := IncPointer(ImageInfo, SizeOf(TWMImageInfo));
case BitCount of
8:
begin
try
Source := TDIB.Create;
Source.SetSize(WidthBytes(ImageInfo.nWidth), ImageInfo.nHeight, 8);
Source.ColorTable := MainPalette;
Source.UpdatePalette;
Source.Canvas.Brush.Color := clblack;
Source.Canvas.FillRect(Source.Canvas.ClipRect);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
DXImage.Texture := TTexture.Create;
DXImage.Texture.SetSize(Source.Width, Source.Height);
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
for I := 0 to DXImage.Texture.Height - 1 do
begin //256色数据转换成16位数据
//DesP := PWord(Integer(DXImage.Texture.PBits) + DXImage.Texture.Pitch * (DXImage.Texture.Height - 1 - I));
//DesP := PWord(Integer(DXImage.Texture.PBits) + DXImage.Texture.Pitch * I);
DesP := DXImage.Texture.ScanLine[I];
SrcP := Source.ScanLine[I];
for J := 0 to DXImage.Texture.Width - 1 do
begin
RGB := MainPalette[SrcP^];
if Integer(RGB) = 0 then
begin
PWord(DesP)^ := 0;
end
else
begin
PWord(DesP)^ := Word((_Max(RGB.rgbRed and $F8, 8) shl 8) or (_Max(RGB.rgbGreen and $FC, 8) shl 3) or (_Max(RGB.rgbBlue and $F8, 8) shr 3)); //565格式
//PWord(DesP)^ := RGBColors[RGB.rgbRed, RGB.rgbGreen, RGB.rgbBlue];
end;
Inc(SrcP);
Inc(PWord(DesP));
end;
end;
finally
Source.Free;
end;
end;
16:
begin
try
Source := TDIB.Create;
Source.PixelFormat := MakeDIBPixelFormat(5, 6, 5);
Source.SetSize(ImageInfo.nWidth, ImageInfo.nHeight, 16);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
{for I := 0 to Source.Height - 1 do begin
DesP := Pointer(Integer(Source.PBits) + I * Source.WidthBytes);
Move(SrcP^, DesP^, ImageInfo.nWidth * 2);
Inc(SrcP, ImageInfo.nWidth * 2);
end;}
DXImage.Texture := TTexture.Create;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Texture.LoadFromDIB(Source);
finally
Source.Free;
end;
{ DXImage.Texture := TTexture.Create;
DXImage.Texture.SetSize(WidthBytes(ImageInfo.nWidth), ImageInfo.nHeight);
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
Move(SrcP^, DXImage.Texture.PBits^, nSize); }
{for I := 0 to DXImage.Texture.Height - 1 do begin
DesP := Pointer(Integer(DXImage.Texture.PBits) + (DXImage.Texture.Height - 1 - I) * DXImage.Texture.Pitch);
Move(SrcP^, DesP^, ImageInfo.nWidth * 2);
Inc(SrcP, ImageInfo.nWidth * 2);
end;}
end;
24:
begin
try
Source := TDIB.Create;
Source.PixelFormat := MakeDIBPixelFormat(8, 8, 8);
Source.SetSize(ImageInfo.nWidth, ImageInfo.nHeight, 24);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
{for I := 0 to Source.Height - 1 do begin
DesP := Pointer(Integer(Source.PBits) + I * Source.WidthBytes);
Move(SrcP^, DesP^, ImageInfo.nWidth * 3);
Inc(SrcP, ImageInfo.nWidth * 3);
end;}
DXImage.Texture := TTexture.Create;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Texture.LoadFromDIB(Source);
finally
Source.Free;
end;
end;
32:
begin
try
Source := TDIB.Create;
Source.PixelFormat := MakeDIBPixelFormat(8, 8, 8);
Source.SetSize(ImageInfo.nWidth, ImageInfo.nHeight, 32);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
{ for I := 0 to Source.Height - 1 do begin
DesP := Pointer(Integer(Source.PBits) + I * Source.WidthBytes);
Move(SrcP^, DesP^, ImageInfo.nWidth * 4);
Inc(SrcP, ImageInfo.nWidth * 4);
end;}
DXImage.Texture := TTexture.Create;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Texture.LoadFromDIB(Source);
finally
Source.Free;
end;
end;
end;
FreeMem(S);
//except
//end;
end;
procedure TWilImages.LoadDxBitmap(Position: Integer; DXImage: pTDXImage);
const
RGB565_MASK_RED = $F800;
RGB555_MASK_RED = $07C0;
var
ImageInfo: TWMImageInfo;
nPitch: Integer;
nWidth, nSize: Integer;
I, J: Integer;
S: Pointer;
SrcP: PByte;
DesP: Pointer;
RGB: TRGBQuad;
Source: TDIB;
begin
//try
m_FileStream.Position := Position;
if btVersion <> 0 then
m_FileStream.Read(ImageInfo, SizeOf(TWMImageInfo) - 4)
else
m_FileStream.Read(ImageInfo, SizeOf(TWMImageInfo));
if ImageInfo.nWidth * ImageInfo.nHeight <= 0 then
Exit;
if BitCount = 8 then
nSize := WidthBytes(ImageInfo.nWidth) * ImageInfo.nHeight
else
nSize := ImageInfo.nWidth * ImageInfo.nHeight * (BitCount div 8);
GetMem(S, nSize);
m_FileStream.Read(S^, nSize);
SrcP := S;
//ImageInfo := IncPointer(m_FileStream.Memory, Position);
//if ImageInfo.nWidth * ImageInfo.nHeight <= 0 then Exit;
//if btVersion <> 0 then SrcP := IncPointer(ImageInfo, SizeOf(TWMImageInfo) - 4)
//else SrcP := IncPointer(ImageInfo, SizeOf(TWMImageInfo));
case BitCount of
8:
begin
try
Source := TDIB.Create;
Source.SetSize(WidthBytes(ImageInfo.nWidth), ImageInfo.nHeight, 8);
Source.ColorTable := MainPalette;
Source.UpdatePalette;
Source.Canvas.Brush.Color := clblack;
Source.Canvas.FillRect(Source.Canvas.ClipRect);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
Source.PixelFormat := MakeDIBPixelFormat(5, 6, 5);
DXImage.Bitmap := TBitmap.Create;
DXImage.Bitmap.Width := Source.Width;
DXImage.Bitmap.Height := Source.Height;
DXImage.Bitmap.PixelFormat := pf16bit;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Bitmap.Canvas.Draw(0, 0, Source);
{for I := DXImage.Bitmap.Height - 1 downto 0 do begin
DesP := DXImage.Bitmap.ScanLine[I];
SrcP := Source.ScanLine[I];
Move(SrcP^, DesP^, Source.WidthBytes);
Inc(SrcP, Source.WidthBytes);
end; }
{for I := 0 to DXImage.Bitmap.Height - 1 do begin //256色数据转换成16位数据
//DesP := PWord(Integer(DXImage.Texture.PBits) + DXImage.Texture.Pitch * (DXImage.Texture.Height - 1 - I));
//DesP := PWord(Integer(DXImage.Texture.PBits) + DXImage.Texture.Pitch * I);
//DesP := DXImage.Texture.ScanLine[I];
DesP := DXImage.Bitmap.ScanLine[I];
SrcP := Source.ScanLine[I];
for J := 0 to DXImage.Texture.Width - 1 do begin
RGB := MainPalette[SrcP^];
if Integer(RGB) = 0 then begin
PWord(DesP)^ := 0;
end else begin
PWord(DesP)^ := Word((_Max(RGB.rgbRed and $F8, 8) shl 8) or (_Max(RGB.rgbGreen and $FC, 8) shl 3) or (_Max(RGB.rgbBlue and $F8, 8) shr 3)); //565格式
end;
Inc(SrcP);
Inc(PWord(DesP));
end;
end;}
finally
Source.Free;
end;
{
DXImage.Bitmap := TBitmap.Create;
DXImage.Bitmap.Width := WidthBytes(ImageInfo.nWidth);
DXImage.Bitmap.Height := ImageInfo.nHeight;
DXImage.Bitmap.PixelFormat := pf16bit;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
for I := DXImage.Bitmap.Height - 1 downto 0 do begin //256色数据转换成16位数据
DesP := PWord(DXImage.Bitmap.ScanLine[I]);
for J := 0 to DXImage.Bitmap.Width - 1 do begin
RGB := MainPalette[SrcP^];
if Integer(RGB) = 0 then begin
PWord(DesP)^ := 0;
end else begin
PWord(DesP)^ := Word((_Max(RGB.rgbRed and $F8, 8) shl 8) or (_Max(RGB.rgbGreen and $FC, 8) shl 3) or (_Max(RGB.rgbBlue and $F8, 8) shr 3)); //565格式
end;
Inc(SrcP);
Inc(PWord(DesP));
end;
end;
}
end;
16:
begin
Source := TDIB.Create;
Source.PixelFormat := MakeDIBPixelFormat(5, 6, 5);
Source.SetSize(ImageInfo.nWidth, ImageInfo.nHeight, 16);
Source.Canvas.Brush.Color := clblack;
Source.Canvas.FillRect(Source.Canvas.ClipRect);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
DXImage.Bitmap := TBitmap.Create;
DXImage.Bitmap.Width := ImageInfo.nWidth;
DXImage.Bitmap.Height := ImageInfo.nHeight;
DXImage.Bitmap.PixelFormat := pf16bit;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Bitmap.Canvas.Draw(0, 0, Source);
Source.Free;
{ for I := DXImage.Bitmap.Height - 1 downto 0 do begin
DesP := DXImage.Bitmap.ScanLine[I];
Move(SrcP^, DesP^, ImageInfo.nWidth * 2);
Inc(SrcP, ImageInfo.nWidth * 2);
end;}
end;
24:
begin
Source := TDIB.Create;
Source.PixelFormat := MakeDIBPixelFormat(8, 8, 8);
Source.SetSize(ImageInfo.nWidth, ImageInfo.nHeight, 24);
Source.Canvas.Brush.Color := clblack;
Source.Canvas.FillRect(Source.Canvas.ClipRect);
DesP := Source.PBits;
Move(SrcP^, DesP^, nSize);
DXImage.Bitmap := TBitmap.Create;
DXImage.Bitmap.Width := ImageInfo.nWidth;
DXImage.Bitmap.Height := ImageInfo.nHeight;
DXImage.Bitmap.PixelFormat := pf24bit;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Bitmap.Canvas.Draw(0, 0, Source);
Source.Free;
{ for I := DXImage.Bitmap.Height - 1 downto 0 do begin
DesP := DXImage.Bitmap.ScanLine[I];
Move(SrcP^, DesP^, ImageInfo.nWidth * 3);
Inc(SrcP, ImageInfo.nWidth * 3);
end; }
end;
32:
begin
Source := TDIB.Create;
Source.PixelFormat := MakeDIBPixelFormat(8, 8, 8);
Source.SetSize(ImageInfo.nWidth, ImageInfo.nHeight, 32);
Source.Canvas.Brush.Color := clblack;
Source.Canvas.FillRect(Source.Canvas.ClipRect);
DXImage.Bitmap := TBitmap.Create;
DXImage.Bitmap.Width := ImageInfo.nWidth;
DXImage.Bitmap.Height := ImageInfo.nHeight;
DXImage.Bitmap.PixelFormat := pf32bit;
DXImage.nPx := ImageInfo.px;
DXImage.nPy := ImageInfo.py;
DXImage.Bitmap.Canvas.Draw(0, 0, Source);
Source.Free;
{for I := DXImage.Bitmap.Height - 1 downto 0 do begin
DesP := DXImage.Bitmap.ScanLine[I];
Move(SrcP^, DesP^, ImageInfo.nWidth * 4);
Inc(SrcP, ImageInfo.nWidth * 4);
end; }
end;
end;
FreeMem(S);
//except
//end;
end;
function TWilImages.GetCachedBitmap(Index: Integer): TBitmap;
var
nPosition: integer;
nErrCode: integer;
begin
Result := nil;
try
nErrCode := 0;
if (Index >= 0) and (Index < ImageCount) and (m_FileStream <> nil) and (Initialized) then
begin
if GetTickCount - m_dwMemChecktTick > 1000 * 5 then
begin
m_dwMemChecktTick := GetTickCount;
FreeOldMemorys(Index);
end;
nErrCode := 4;
if m_ImgArr[Index].Bitmap = nil then
begin
nErrCode := 5;
if Index < m_IndexList.Count then
begin
IndexList.Add(Pointer(Index));
nErrCode := 6;
nPosition := Integer(m_IndexList[Index]);
nErrCode := 7;
LoadDxBitmap(nPosition, @m_ImgArr[Index]);
nErrCode := 8;
m_ImgArr[Index].dwLatestTime := GetTickCount;
Result := m_ImgArr[Index].Bitmap;
end;
end
else
begin
m_ImgArr[Index].dwLatestTime := GetTickCount;
Result := m_ImgArr[Index].Bitmap;
end;
end;
except
Result := nil;
end;
end;
function TWilImages.GetCachedSurface(Index: Integer): TTexture;
var
nPosition: Integer;
nErrCode: Integer;
begin
Result := nil;
try
nErrCode := 0;
if (Index >= 0) and (Index < ImageCount) and (m_FileStream <> nil) and (Initialized) then
begin
if GetTickCount - m_dwMemChecktTick > 1000 * 5 then
begin
m_dwMemChecktTick := GetTickCount;
FreeOldMemorys(Index);
end;
nErrCode := 4;
if m_ImgArr[Index].Texture = nil then
begin
nErrCode := 5;
if Index < m_IndexList.Count then
begin
IndexList.Add(Pointer(Index));
nErrCode := 6;
nPosition := Integer(m_IndexList[Index]);
nErrCode := 7;
LoadDxImage(nPosition, @m_ImgArr[Index]);
nErrCode := 8;
m_ImgArr[Index].dwLatestTime := GetTickCount;
Result := m_ImgArr[Index].Texture;
end;
end
else
begin
m_ImgArr[Index].dwLatestTime := GetTickCount;
Result := m_ImgArr[Index].Texture;
end;
end;
except
Result := nil;
//DebugOutStr('TWilImages.GetCachedSurface Index: ' + IntToStr(Index) + ' Error Code: ' + IntToStr(nErrCode));
end;
end;
function TWilImages.GetCachedImage(Index: Integer; var PX, PY: Integer): TTexture;
var
nPosition: integer;
nErrCode: integer;
begin
Result := nil;
try
nErrCode := 0;
if (Index >= 0) and (Index < ImageCount) and (m_FileStream <> nil) and (Initialized) then
begin
nErrCode := 1;
if GetTickCount - m_dwMemChecktTick > 1000 * 5 then
begin
m_dwMemChecktTick := GetTickCount;
nErrCode := 2;
FreeOldMemorys(Index);
nErrCode := 3;
end;
nErrCode := 4;
if m_ImgArr[Index].Texture = nil then
begin
nErrCode := 5;
if Index < m_IndexList.Count then
begin
IndexList.Add(Pointer(Index));
nErrCode := 6;
nPosition := Integer(m_IndexList[Index]);
nErrCode := 7;
if LibType = ltUseCache then
begin
LoadDxImage(nPosition, @m_ImgArr[Index]);
end
else
begin
LoadDxBitmap(nPosition, @m_ImgArr[Index]);
end;
nErrCode := 8;
m_ImgArr[Index].dwLatestTime := GetTickCount;
PX := m_ImgArr[Index].nPx;
PY := m_ImgArr[Index].nPy;
Result := m_ImgArr[Index].Texture;
end;
end
else
begin
m_ImgArr[Index].dwLatestTime := GetTickCount;
PX := m_ImgArr[Index].nPx;
PY := m_ImgArr[Index].nPy;
Result := m_ImgArr[Index].Texture;
end;
end;
except
Result := nil;
end;
end;
function TWilImages.GetBitmap(Index: Integer; var PX, PY: Integer): TBitmap;
var
nPosition: integer;
nErrCode: integer;
begin
Result := nil;
try
nErrCode := 0;
if (Index >= 0) and (Index < ImageCount) and (m_FileStream <> nil) and (Initialized) then
begin
nErrCode := 1;
if GetTickCount - m_dwMemChecktTick > 1000 * 5 then
begin
m_dwMemChecktTick := GetTickCount;
nErrCode := 2;
FreeOldMemorys(Index);
nErrCode := 3;
end;
nErrCode := 4;
if m_ImgArr[Index].Bitmap = nil then
begin
nErrCode := 5;
if Index < m_IndexList.Count then
begin
IndexList.Add(Pointer(Index));
nErrCode := 6;
nPosition := Integer(m_IndexList[Index]);
nErrCode := 7;
LoadDxBitmap(nPosition, @m_ImgArr[Index]);
nErrCode := 8;
m_ImgArr[Index].dwLatestTime := GetTickCount;
PX := m_ImgArr[Index].nPx;
PY := m_ImgArr[Index].nPy;
Result := m_ImgArr[Index].Bitmap;
end;
end
else
begin
m_ImgArr[Index].dwLatestTime := GetTickCount;
PX := m_ImgArr[Index].nPx;
PY := m_ImgArr[Index].nPy;
Result := m_ImgArr[Index].Bitmap;
end;
end;
except
Result := nil;
end;
end;
end.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/johntao/mir4.git
git@gitee.com:johntao/mir4.git
johntao
mir4
mir4
master

搜索帮助