Reviewed, simplified code.

This commit is contained in:
meffi@lab313.ru
2014-04-14 23:48:39 +00:00
parent 90c0e78a66
commit 519a7f2e86
15 changed files with 1058 additions and 2346 deletions

View File

@@ -1,9 +1,9 @@
unit uTIM;
unit utim;
interface
uses
Windows, uCommon, System.Classes;
ucommon;
const
cTIMMagic = $10;
@@ -145,7 +145,7 @@ function ConvertCLUTColor(COLOR: TCLUT_COLOR): word;
implementation
uses
System.SysUtils, uCDIMAGE;
ucdimage, classes, sysutils;
function ConvertTIMColor(COLOR: word): TCLUT_COLOR;
begin
@@ -157,8 +157,7 @@ end;
function ConvertCLUTColor(COLOR: TCLUT_COLOR): word;
begin
Result := (COLOR.STP shl 15) or ((COLOR.B div 8) shl 10) or
((COLOR.G div 8) shl 5) or (COLOR.R div 8);
Result := (COLOR.STP shl 15) or ((COLOR.B div 8) shl 10) or ((COLOR.G div 8) shl 5) or (COLOR.R div 8);
end;
function GetCLUTColor(TIM: PTIM; CLUT_NUM, COLOR_NUM: Integer): TCLUT_COLOR;
@@ -177,8 +176,7 @@ begin
CLUT_OFFSET := CLUT_NUM * GetTimColorsCount(TIM) * 2;
Move(TIM^.DATA^[cTIMHeadSize + cCLUTHeadSize + COLOR_NUM * 2 + CLUT_OFFSET],
COLOR, 2);
Move(TIM^.DATA^[cTIMHeadSize + cCLUTHeadSize + COLOR_NUM * 2 + CLUT_OFFSET], COLOR, 2);
Result := ConvertTIMColor(COLOR);
end;
@@ -331,12 +329,10 @@ begin
Inc(Position);
TIM_POS := P;
if TIM = nil then
TIM := CreateTIM;
if TIM = nil then TIM := CreateTIM;
Move(PBytesArray(BUFFER)^[P], TIM^.HEAD^, cTIMHeadSize);
if not CheckHEAD(TIM) then
Exit;
if not CheckHEAD(TIM) then Exit;
Inc(P, cTIMHeadSize);
if TIMHasCLUT(TIM) then
@@ -349,10 +345,8 @@ begin
Move(PBytesArray(BUFFER)^[P], TIM^.IMAGE^, cIMAGEHeadSize);
if not CheckIMAGE(TIM) then
Exit;
if not CheckTIMSize(TIM) then
Exit;
if not CheckIMAGE(TIM) then Exit;
if not CheckTIMSize(TIM) then Exit;
TIM^.dwSize := GetTIMSize(TIM);
TIM^.bGOOD := TIMIsGood(TIM);
@@ -372,6 +366,9 @@ var
Sector: TCDSector;
P, TIM_FULL_SECTORS: Integer;
begin
sImageStream := nil;
TIM_BUF := nil;
try
sImageStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
@@ -383,8 +380,7 @@ begin
New(TIM_BUF);
P := 0;
if SIZE < FirstPartSize then
FirstPartSize := SIZE;
if SIZE < FirstPartSize then FirstPartSize := SIZE;
sImageStream.Seek(TimStartSectorPos, soBeginning);
sImageStream.Read(Sector, cSectorSize);
@@ -434,8 +430,7 @@ var
begin
Result := nil;
if dwSize > cTIMMaxSize then
Exit;
if dwSize > cTIMMaxSize then Exit;
New(BUF);
Result := CreateTIM;
@@ -444,8 +439,7 @@ begin
Stream.Read(BUF^[0], dwSize);
P := 0;
if not LoadTimFromBuf(BUF, Result, P) then
FreeTIM(Result);
if not LoadTimFromBuf(BUF, Result, P) then FreeTIM(Result);
Dispose(BUF);
end;
@@ -455,6 +449,7 @@ function LoadTimFromFile(const FileName: string; var Position: Integer;
var
sTIM: TFileStream;
begin
sTIM := nil;
if not ImageScan then
begin
try