Fully implemented TIM<->PNG converting. But it should be checked! Some other fixes.

This commit is contained in:
meffi@lab313.ru
2014-04-27 13:25:37 +00:00
parent 59bdb04762
commit 7ec4a64bc5
12 changed files with 421 additions and 314 deletions

View File

@@ -23,12 +23,188 @@
<UseVersionInfo Value="True"/> <UseVersionInfo Value="True"/>
<AutoIncrementBuild Value="True"/> <AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="1"/> <MajorVersionNr Value="1"/>
<RevisionNr Value="67"/> <RevisionNr Value="74"/>
<BuildNr Value="5"/> <BuildNr Value="2"/>
<StringTable CompanyName="Lab 313" FileDescription="The best TIMs tool ever!:)" ProductVersion=""/> <StringTable CompanyName="Lab 313" FileDescription="The best TIMs tool ever!:)" ProductVersion=""/>
</VersionInfo> </VersionInfo>
<BuildModes Count="1"> <BuildModes Count="5">
<Item1 Name="Default" Default="True"/> <Item1 Name="Debug" Default="True"/>
<Item2 Name="Win Release x86">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="output\tim2view_$(TargetOS)"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<TargetCPU Value="i386"/>
<TargetOS Value="win32"/>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item2>
<Item3 Name="Win Release x64">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="output\tim2view_$(TargetOS)"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<TargetCPU Value="x86_64"/>
<TargetOS Value="win64"/>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item3>
<Item4 Name="Linux Release x86">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="output\tim2view_$(TargetOS)"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<TargetCPU Value="i386"/>
<TargetOS Value="linux"/>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item4>
<Item5 Name="Linux Release x64">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="output\tim2view_$(TargetOS)"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<TargetCPU Value="x86_64"/>
<TargetOS Value="linux"/>
<Optimizations>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item5>
</BuildModes> </BuildModes>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
@@ -143,12 +319,14 @@
<Checks> <Checks>
<RangeChecks Value="True"/> <RangeChecks Value="True"/>
<OverflowChecks Value="True"/> <OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks> </Checks>
<VerifyObjMethodCallValidity Value="True"/>
</CodeGeneration> </CodeGeneration>
<Linking> <Linking>
<Debugging> <Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
<UseHeaptrc Value="True"/> <UseHeaptrc Value="True"/>
<UseExternalDbgSyms Value="True"/>
</Debugging> </Debugging>
<Options> <Options>
<Win32> <Win32>

View File

@@ -3,13 +3,13 @@
<ProjectSession> <ProjectSession>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="9"/> <Version Value="9"/>
<BuildModes Active="Default"/> <BuildModes Active="Win Release x86"/>
<Units Count="19"> <Units Count="15">
<Unit0> <Unit0>
<Filename Value="tim2view.lpr"/> <Filename Value="tim2view.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="tim2view"/> <UnitName Value="tim2view"/>
<EditorIndex Value="15"/> <EditorIndex Value="11"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<CursorPos X="46" Y="15"/> <CursorPos X="46" Y="15"/>
@@ -25,8 +25,8 @@
<UnitName Value="umain"/> <UnitName Value="umain"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="912"/> <TopLine Value="489"/>
<CursorPos X="48" Y="918"/> <CursorPos X="63" Y="499"/>
<UsageCount Value="816"/> <UsageCount Value="816"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
@@ -55,7 +55,7 @@
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="14"/> <TopLine Value="14"/>
<CursorPos X="15" Y="35"/> <CursorPos X="35" Y="6"/>
<UsageCount Value="816"/> <UsageCount Value="816"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit4> </Unit4>
@@ -65,8 +65,8 @@
<UnitName Value="utim"/> <UnitName Value="utim"/>
<EditorIndex Value="7"/> <EditorIndex Value="7"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="130"/> <TopLine Value="185"/>
<CursorPos X="1" Y="148"/> <CursorPos X="1" Y="204"/>
<UsageCount Value="816"/> <UsageCount Value="816"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit5> </Unit5>
@@ -76,8 +76,8 @@
<UnitName Value="ucdimage"/> <UnitName Value="ucdimage"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="189"/> <TopLine Value="112"/>
<CursorPos X="1" Y="204"/> <CursorPos X="50" Y="117"/>
<UsageCount Value="816"/> <UsageCount Value="816"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit6> </Unit6>
@@ -96,7 +96,7 @@
<Filename Value="uscanresult.pas"/> <Filename Value="uscanresult.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uscanresult"/> <UnitName Value="uscanresult"/>
<EditorIndex Value="16"/> <EditorIndex Value="12"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="51"/> <TopLine Value="51"/>
<CursorPos X="1" Y="67"/> <CursorPos X="1" Y="67"/>
@@ -109,8 +109,8 @@
<UnitName Value="uscanthread"/> <UnitName Value="uscanthread"/>
<EditorIndex Value="6"/> <EditorIndex Value="6"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="79"/> <TopLine Value="155"/>
<CursorPos X="76" Y="98"/> <CursorPos X="36" Y="168"/>
<UsageCount Value="816"/> <UsageCount Value="816"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit9> </Unit9>
@@ -132,8 +132,8 @@
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<EditorIndex Value="8"/> <EditorIndex Value="8"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="177"/> <TopLine Value="234"/>
<CursorPos X="51" Y="198"/> <CursorPos X="61" Y="245"/>
<UsageCount Value="816"/> <UsageCount Value="816"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit11> </Unit11>
@@ -149,10 +149,10 @@
<Unit13> <Unit13>
<Filename Value="todos.inc"/> <Filename Value="todos.inc"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="14"/> <EditorIndex Value="10"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<CursorPos X="31" Y="2"/> <CursorPos X="20" Y="1"/>
<UsageCount Value="802"/> <UsageCount Value="802"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit13> </Unit13>
@@ -160,53 +160,13 @@
<Filename Value="uexportimport.pas"/> <Filename Value="uexportimport.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uexportimport"/> <UnitName Value="uexportimport"/>
<EditorIndex Value="10"/>
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="76" Y="22"/>
<UsageCount Value="41"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
<Filename Value="bgrabitmap\bgrabitmaptypes.pas"/>
<UnitName Value="BGRABitmapTypes"/>
<EditorIndex Value="12"/>
<WindowIndex Value="0"/>
<TopLine Value="1336"/>
<CursorPos X="1" Y="1343"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit15>
<Unit16>
<Filename Value="bgrabitmap\bgradefaultbitmap.pas"/>
<UnitName Value="BGRADefaultBitmap"/>
<EditorIndex Value="9"/> <EditorIndex Value="9"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="548"/> <TopLine Value="13"/>
<CursorPos X="1" Y="570"/> <CursorPos X="52" Y="19"/>
<UsageCount Value="12"/> <UsageCount Value="53"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit16> </Unit14>
<Unit17>
<Filename Value="C:\Lazarus\fpc\2.6.4\source\packages\fcl-image\src\fpreadpng.pp"/>
<UnitName Value="FPReadPNG"/>
<EditorIndex Value="11"/>
<WindowIndex Value="0"/>
<TopLine Value="241"/>
<CursorPos X="46" Y="17"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="bgrabitmap\bgrareadpng.pas"/>
<UnitName Value="BGRAReadPng"/>
<EditorIndex Value="13"/>
<WindowIndex Value="0"/>
<TopLine Value="141"/>
<CursorPos X="1" Y="161"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit18>
</Units> </Units>
<General> <General>
<ActiveWindowIndexAtStart Value="0"/> <ActiveWindowIndexAtStart Value="0"/>
@@ -225,24 +185,38 @@
<Kind Value="bpkSource"/> <Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/> <WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/> <WatchKind Value="wpkWrite"/>
<Source Value="umain.pas"/> <Source Value="c:\Lazarus\fpc\2.6.2\source\packages\fcl-image\src\fppalette.inc"/>
<Line Value="503"/> <Line Value="159"/>
</Item2> </Item2>
<Item3> <Item3>
<Kind Value="bpkSource"/> <Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/> <WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/> <WatchKind Value="wpkWrite"/>
<Source Value="c:\Lazarus\fpc\2.6.2\source\packages\fcl-image\src\fppalette.inc"/> <Source Value="umain.pas"/>
<Line Value="159"/> <Line Value="361"/>
</Item3> </Item3>
<Item4> <Item4>
<Kind Value="bpkSource"/> <Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/> <WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/> <WatchKind Value="wpkWrite"/>
<Source Value="udrawtim.pas"/> <Source Value="umain.pas"/>
<Line Value="258"/> <Line Value="767"/>
</Item4> </Item4>
</BreakPoints> </BreakPoints>
<Watches Count="3">
<Item1>
<Expression Value="IDX"/>
<DisplayStyle Value="wdfHex"/>
</Item1>
<Item2>
<Expression Value="TData^[POS]"/>
<DisplayStyle Value="wdfHex"/>
</Item2>
<Item3>
<Expression Value="IDX_INT"/>
<DisplayStyle Value="wdfHex"/>
</Item3>
</Watches>
</Debugging> </Debugging>
<EditorMacros Count="0"/> <EditorMacros Count="0"/>
</CONFIG> </CONFIG>

Binary file not shown.

View File

@@ -1,2 +1 @@
{ TODO : Zooming? } { TODO : Zooming? }
{ TODO 1 : Export: save as paletted PNG. Import: find matched colors in CLUT when importing }

View File

@@ -78,14 +78,12 @@ begin
pFile := GetMemory(cSectorHeaderSize); pFile := GetMemory(cSectorHeaderSize);
try
tmp := TFileStream.Create(Utf8ToSys(FileName), fmOpenRead or fmShareDenyWrite); tmp := TFileStream.Create(Utf8ToSys(FileName), fmOpenRead or fmShareDenyWrite);
tmp.Read(pFile^[0], cSectorHeaderSize); tmp.Read(pFile^[0], cSectorHeaderSize);
Result := ((Sz mod cSectorSize) = 0) and (CompareMem(@cSectorHeader, pFile, cSectorHeaderSize)); Result := ((Sz mod cSectorSize) = 0) and (CompareMem(@cSectorHeader, pFile, cSectorHeaderSize));
finally
tmp.free; tmp.free;
FreeMemory(pFile); FreeMemory(pFile);
end;
end; end;
procedure ReplaceTimInFileFromMemory(const FileName: string; TIM: PTIM; procedure ReplaceTimInFileFromMemory(const FileName: string; TIM: PTIM;
@@ -124,7 +122,7 @@ begin
FillChar(Sector, cSectorSize, 0); FillChar(Sector, cSectorSize, 0);
sImageStream.Read(Sector, cSectorSize); sImageStream.Read(Sector, cSectorSize);
sImageStream.Seek(TimStartSectorPos + cSectorHeaderSize, soBeginning); sImageStream.Seek(Int64(TimStartSectorPos) + Int64(cSectorHeaderSize), soBeginning);
Move(Sector.dwAddress[0], SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize); Move(Sector.dwAddress[0], SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize);
FillChar(Sector.dwAddress[0], cSectorAddressSize + cSectorModeSize, 0); FillChar(Sector.dwAddress[0], cSectorAddressSize + cSectorModeSize, 0);
@@ -140,7 +138,7 @@ begin
sImageStream.Seek(TimStartSectorPos, soBeginning); sImageStream.Seek(TimStartSectorPos, soBeginning);
sImageStream.Write(Sector, cSectorSize); sImageStream.Write(Sector, cSectorSize);
sImageStream.Seek(TimStartSectorPos + cSectorHeaderSize, soBeginning); sImageStream.Seek(Int64(TimStartSectorPos) + Int64(cSectorHeaderSize), soBeginning);
sImageStream.Write(SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize); sImageStream.Write(SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize);
Inc(TimStartSectorPos, cSectorSize); Inc(TimStartSectorPos, cSectorSize);
@@ -167,7 +165,7 @@ begin
sImageStream.Seek(TimStartSectorPos, soBeginning); sImageStream.Seek(TimStartSectorPos, soBeginning);
sImageStream.Write(Sector, cSectorSize); sImageStream.Write(Sector, cSectorSize);
sImageStream.Seek(TimStartSectorPos + cSectorHeaderSize, soBeginning); sImageStream.Seek(Int64(TimStartSectorPos) + Int64(cSectorHeaderSize), soBeginning);
sImageStream.Write(SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize); sImageStream.Write(SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize);
Inc(TimStartSectorPos, cSectorSize); Inc(TimStartSectorPos, cSectorSize);
@@ -195,7 +193,7 @@ begin
sImageStream.Seek(TimStartSectorPos, soBeginning); sImageStream.Seek(TimStartSectorPos, soBeginning);
sImageStream.Write(Sector, cSectorSize); sImageStream.Write(Sector, cSectorSize);
sImageStream.Seek(TimStartSectorPos + cSectorHeaderSize, soBeginning); sImageStream.Seek(Int64(TimStartSectorPos) + Int64(cSectorHeaderSize), soBeginning);
sImageStream.Write(SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize); sImageStream.Write(SecAddrAndMode[0], cSectorAddressSize + cSectorModeSize);
end; end;
end; end;

View File

@@ -3,7 +3,7 @@ unit ucommon;
interface interface
const const
cProgramName = 'Tim2View SVN.r70 by [Lab 313] (for ' + cProgramName = 'Tim2View SVN.r74 by [Lab 313] (for ' +
{$IFDEF Linux}'Linux' + {$IFEND} {$IFDEF Linux}'Linux' + {$IFEND}
{$IFDEF Darwin}'Mac OS X' + {$IFEND} {$IFDEF Darwin}'Mac OS X' + {$IFEND}
{$IFDEF Windows}'Windows' + {$IFEND} {$IFDEF Windows}'Windows' + {$IFEND}

View File

@@ -92,17 +92,17 @@ begin
CC := GetCLUTColor(TIM, CLUT_NUM, I - 1); CC := GetCLUTColor(TIM, CLUT_NUM, I - 1);
if I <= COUNT then if I <= COUNT then
begin begin
R := CC.R; R := CC.R + ((I - 1) and %00000011) shl 1 + CC.STP;
G := CC.G; G := CC.G + ((I - 1) and %00011100) shr 2;
B := CC.B; B := CC.B + ((I - 1) and %11100000) shr 5;
A := CC.STP; A := CC.STP;
end end
else else
begin begin
R := 0; R := ((I - 1) and %00000011) shl 1 + CC.STP;
G := 0; G := ((I - 1) and %00011100) shr 2;
B := 0; B := ((I - 1) and %11100000) shr 5;
A := 1; A := 0;
end; end;
FC := BGRAToFPColor(BGRA(R, G, B, A)); FC := BGRAToFPColor(BGRA(R, G, B, A));
@@ -209,7 +209,8 @@ begin
for X := 1 to RW do for X := 1 to RW do
begin begin
case TIM^.HEAD^.bBPP of case TIM^.HEAD^.bBPP of
cTIM4C, cTIM4NC, cTIM8C, cTIM8NC: Surf^.Pixels[X - 1, Y - 1] := INDEXES^[IDX] mod COLORS; cTIM4C, cTIM4NC, cTIM8C, cTIM8NC:
Surf^.Pixels[X - 1, Y - 1] := INDEXES^[IDX] mod COLORS;
cTIM16C, cTIM16NC, cTIMMix: cTIM16C, cTIM16NC, cTIMMix:
begin begin
CW := 0; CW := 0;
@@ -243,7 +244,7 @@ procedure Png2Tim(Image: PDrawSurf; Dest: PTIM);
var var
IW, IH, X, Y, CW: Word; IW, IH, X, Y, CW: Word;
TData: PTIMDataArray; TData: PTIMDataArray;
IDX, POS, C: Integer; POS: Integer;
CC: TCLUT_COLOR; CC: TCLUT_COLOR;
PC: TBGRAPixel; PC: TBGRAPixel;
FC: TFPColor; FC: TFPColor;
@@ -253,33 +254,29 @@ begin
IH := Image^.Height; IH := Image^.Height;
TData := @Dest^.DATA^[SizeOf(TTIMHeader) + GetTIMCLUTSize(Dest) + SizeOf(TIMAGEHeader)]; TData := @Dest^.DATA^[SizeOf(TTIMHeader) + GetTIMCLUTSize(Dest) + SizeOf(TIMAGEHeader)];
{ TODO : Fix colors finding. }
POS := 0; POS := 0;
for Y := 1 to IH do for Y := 0 to IH-1 do
case Dest^.HEAD^.bBPP of case Dest^.HEAD^.bBPP of
cTIM4C, cTIM4NC: cTIM4C, cTIM4NC:
for X := 1 to (IW div 2) do for X := 0 to (IW div 2)-1 do
begin begin
IDX := Image^.Pixels[X - 1, Y - 1]; TData^[POS] := Byte(Image^.Pixels[X * 2, Y]);
TData^[POS] := (IDX and $F); TData^[POS] := (Byte(Image^.Pixels[X * 2 + 1, Y]) shl 4) and $F0 + TData^[POS];
IDX := Image^.Pixels[X, Y - 1];
TData^[POS] := TData^[0] + (IDX and $F0);
Inc(POS); Inc(POS);
end; end;
cTIM8C, cTIM8NC: cTIM8C, cTIM8NC:
for X := 1 to IW do for X := 0 to IW-1 do
begin begin
C := Image^.Pixels[X - 1, Y - 1]; TData^[POS] := Byte(Image^.Pixels[X, Y]);
TData^[POS] := Byte(C);
Inc(POS); Inc(POS);
end; end;
cTIM16C, cTIM16NC: cTIM16C, cTIM16NC:
for X := 1 to IW do for X := 0 to IW-1 do
begin begin
FC := Image^.Colors[X - 1, Y - 1]; FC := Image^.Colors[X, Y];
CC.STP := StpFromAlpha(@FC); CC.STP := StpFromAlpha(@FC);
PC := FPColorToBGRA(FC); PC := FPColorToBGRA(FC);
CC.R := PC.red; CC.R := PC.red;
@@ -293,16 +290,16 @@ begin
end; end;
cTIM24C, cTIM24NC: cTIM24C, cTIM24NC:
for X := 1 to IW do for X := 0 to IW-1 do
begin begin
FC := Image^.Colors[X - 1, Y - 1]; FC := Image^.Colors[X, Y];
PC := FPColorToBGRA(FC); PC := FPColorToBGRA(FC);
CD := (PC.blue shl 16) + (PC.green shl 8) + PC.red; CD := (PC.blue shl 16) + (PC.green shl 8) + PC.red;
Move(CD, TData^[POS], 3); Move(CD, TData^[POS], 3);
Inc(POS, 3); Inc(POS, 3);
if Odd(IW) and ((IW - X) = 0) then if Odd(IW) and ((IW - X + 1) = 0) then
begin begin
TData^[POS] := 0; TData^[POS] := 0;
Inc(POS); Inc(POS);

View File

@@ -3,55 +3,44 @@ unit uexportimport;
interface interface
uses uses
FPWritePNG, zstream, udrawtim; udrawtim;
procedure SaveImage(Surf: PDrawSurf; Indexed: Boolean; const FileName: string; PngWriter: TFPWriterPNG); procedure SaveImage(const FileName: string; Surf: PDrawSurf; Indexed: Boolean);
function LoadImage(const FileName: string; var Surf: PDrawSurf): Boolean; function LoadImage(const FileName: string): PDrawSurf;
function CreatePngWriter(ForExport: Boolean): TFPWriterPNG;
implementation implementation
uses uses
FPReadPNG, Classes, BGRABitmap, FileUtil, sysutils; FPReadPNG, Classes, BGRABitmap, FileUtil, sysutils, zstream, FPWritePNG;
function CreatePngWriter(ForExport: Boolean): TFPWriterPNG; procedure SaveImage(const FileName: string; Surf: PDrawSurf; Indexed: Boolean);
var
Writer: TFPWriterPNG;
begin begin
Result := TFPWriterPNG.Create; Writer := TFPWriterPNG.Create;
Result.CompressionLevel := clnone; Writer.CompressionLevel := clnone;
Result.WordSized := False; Writer.UseAlpha := True;
Result.UseAlpha := (not ForExport);
Writer.Indexed := Indexed;
Surf^.SaveToFileUTF8(FileName, Writer);
Writer.Free;
end; end;
procedure SaveImage(Surf: PDrawSurf; Indexed: Boolean; const FileName: string; PngWriter: TFPWriterPNG); function LoadImage(const FileName: string): PDrawSurf;
begin
PngWriter.Indexed := Indexed;
Surf^.SaveToFileUTF8(FileName, PngWriter);
end;
function LoadImage(const FileName: string; var Surf: PDrawSurf): Boolean;
var var
Reader: TFPReaderPNG; Reader: TFPReaderPNG;
Image: TFileStream; Stream: TFileStream;
begin begin
Result := False;
try
Reader := TFPReaderPNG.Create; Reader := TFPReaderPNG.Create;
Image := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); Stream := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite);
Result := Reader.CheckContents(Image); Stream.Position := 0;
if Result then New(Result);
begin Result^ := TBGRABitmap.Create;
New(Surf); Result^.UsePalette := True;
Surf^ := TBGRABitmap.Create; Reader.ImageRead(Stream, Result^);
Image.Position := 0; Stream.Free;
Surf^.LoadFromStream(Image);
end;
finally
Image.Free;
Reader.Free; Reader.Free;
end;
end; end;
end. end.

View File

@@ -828,12 +828,12 @@ object frmMain: TfrmMain
DefaultExt = '.bin' DefaultExt = '.bin'
Filter = 'All Files (*.*)|*.*' Filter = 'All Files (*.*)|*.*'
Options = [ofHideReadOnly, ofNoChangeDir, ofAllowMultiSelect, ofNoNetworkButton, ofEnableSizing, ofForceShowHidden] Options = [ofHideReadOnly, ofNoChangeDir, ofAllowMultiSelect, ofNoNetworkButton, ofEnableSizing, ofForceShowHidden]
left = 576 left = 560
top = 448 top = 112
end end
object mmMain: TMainMenu object mmMain: TMainMenu
left = 352 left = 336
top = 448 top = 112
object mnFile: TMenuItem object mnFile: TMenuItem
Caption = '&File' Caption = '&File'
object mnScanFile: TMenuItem object mnScanFile: TMenuItem
@@ -863,16 +863,13 @@ object frmMain: TfrmMain
object mnReplaceIn: TMenuItem object mnReplaceIn: TMenuItem
Action = actReplaceTim Action = actReplaceTim
end end
object MenuItem1: TMenuItem
Caption = '-'
end
object mnSaveToPNG: TMenuItem object mnSaveToPNG: TMenuItem
Action = actTim2Png
end
end
object mnEdit: TMenuItem
Caption = '&Edit'
object mnExportTim: TMenuItem
Action = actPngExport Action = actPngExport
end end
object mnImport: TMenuItem object mnImportPng: TMenuItem
Action = actPngImport Action = actPngImport
end end
end end
@@ -912,17 +909,17 @@ object frmMain: TfrmMain
Title = 'Please, select filename for PNG...' Title = 'Please, select filename for PNG...'
DefaultExt = '.png' DefaultExt = '.png'
Filter = 'Portable Network Graphics (*.png)|*.png' Filter = 'Portable Network Graphics (*.png)|*.png'
Options = [ofHideReadOnly, ofNoChangeDir, ofNoNetworkButton, ofEnableSizing] Options = [ofOverwritePrompt, ofHideReadOnly, ofNoChangeDir, ofNoNetworkButton, ofEnableSizing]
left = 688 left = 672
top = 448 top = 112
end end
object dlgSaveTIM: TSaveDialog object dlgSaveTIM: TSaveDialog
Title = 'Please, select where to save TIM file...' Title = 'Please, select where to save TIM file...'
DefaultExt = '.tim' DefaultExt = '.tim'
Filter = 'PSX TIM Files (*.tim)|*.tim|All Files (*.*)|*.*' Filter = 'PSX TIM Files (*.tim)|*.tim|All Files (*.*)|*.*'
Options = [ofOverwritePrompt, ofHideReadOnly, ofNoChangeDir, ofNoNetworkButton, ofEnableSizing] Options = [ofOverwritePrompt, ofHideReadOnly, ofNoChangeDir, ofNoNetworkButton, ofEnableSizing]
left = 608 left = 592
top = 448 top = 112
end end
object dlgColor: TColorDialog object dlgColor: TColorDialog
Color = clBlack Color = clBlack
@@ -948,12 +945,12 @@ object frmMain: TfrmMain
'ColorS=F0FBFF' 'ColorS=F0FBFF'
'ColorT=A4A0A0' 'ColorT=A4A0A0'
) )
left = 496 left = 480
top = 448 top = 112
end end
object actList: TActionList object actList: TActionList
left = 416 left = 400
top = 448 top = 112
object actScanFile: TAction object actScanFile: TAction
Caption = 'Scan &File...' Caption = 'Scan &File...'
OnExecute = actScanFileExecute OnExecute = actScanFileExecute
@@ -984,14 +981,18 @@ object frmMain: TfrmMain
OnExecute = actExtractTimExecute OnExecute = actExtractTimExecute
ShortCut = 113 ShortCut = 113
end end
object actPngImport: TAction
Caption = '&Import PNG...'
OnExecute = actPngImportExecute
end
object actReplaceTim: TAction object actReplaceTim: TAction
Caption = '&Replace TIM...' Caption = '&Replace TIM...'
OnExecute = actReplaceTimExecute OnExecute = actReplaceTimExecute
ShortCut = 114 ShortCut = 114
end end
object actTim2Png: TAction object actPngExport: TAction
Caption = 'Save as &PNG...' Caption = 'Export &PNG...'
OnExecute = actTim2PngExecute OnExecute = actPngExportExecute
ShortCut = 115 ShortCut = 115
end end
object actOpenRepo: TAction object actOpenRepo: TAction
@@ -1043,18 +1044,10 @@ object frmMain: TfrmMain
Caption = '&Background Color' Caption = '&Background Color'
OnExecute = actChangeBackColorExecute OnExecute = actChangeBackColorExecute
end end
object actPngImport: TAction
Caption = '&Import PNG to TIM...'
OnExecute = actPngImportExecute
end
object actPngExport: TAction
Caption = '&Export TIM to PNG...'
OnExecute = actTim2PngExecute
end
end end
object pmList: TPopupMenu object pmList: TPopupMenu
left = 448 left = 432
top = 448 top = 112
object ExtractTIM1: TMenuItem object ExtractTIM1: TMenuItem
Action = actExtractTim Action = actExtractTim
end end
@@ -1062,7 +1055,7 @@ object frmMain: TfrmMain
Action = actReplaceTim Action = actReplaceTim
end end
object SaveasPNG1: TMenuItem object SaveasPNG1: TMenuItem
Action = actTim2Png Action = actPngExport
end end
object N7: TMenuItem object N7: TMenuItem
Caption = '-' Caption = '-'
@@ -1075,10 +1068,10 @@ object frmMain: TfrmMain
end end
end end
object pmImage: TPopupMenu object pmImage: TPopupMenu
left = 384 left = 368
top = 448 top = 112
object mnSaveAsPng: TMenuItem object mnSaveAsPng: TMenuItem
Action = actTim2Png Action = actPngExport
end end
object mnSaveAsTim: TMenuItem object mnSaveAsTim: TMenuItem
Action = actExtractTim Action = actExtractTim
@@ -1096,15 +1089,15 @@ object frmMain: TfrmMain
end end
object dlgSelectDir: TSelectDirectoryDialog object dlgSelectDir: TSelectDirectoryDialog
Options = [ofNoChangeDir, ofNoNetworkButton, ofEnableSizing, ofViewDetail] Options = [ofNoChangeDir, ofNoNetworkButton, ofEnableSizing, ofViewDetail]
left = 528 left = 512
top = 448 top = 112
end end
object dlgOpenPNG: TOpenPictureDialog object dlgOpenPNG: TOpenPictureDialog
Title = 'Please, select PNG...' Title = 'Please, select PNG...'
DefaultExt = '.png' DefaultExt = '.png'
Filter = 'Portable Network Graphics (*.png)|*.png' Filter = 'Portable Network Graphics (*.png)|*.png'
Options = [ofHideReadOnly, ofNoChangeDir, ofNoNetworkButton, ofEnableSizing] Options = [ofHideReadOnly, ofNoChangeDir, ofNoNetworkButton, ofEnableSizing]
left = 656 left = 640
top = 448 top = 112
end end
end end

105
umain.pas
View File

@@ -28,7 +28,6 @@ type
actExtractTIMs: TAction; actExtractTIMs: TAction;
actChangeFile: TAction; actChangeFile: TAction;
actChangeBackColor: TAction; actChangeBackColor: TAction;
actPngExport: TAction;
actPngImport: TAction; actPngImport: TAction;
actStopScan: TAction; actStopScan: TAction;
actOpenLab: TAction; actOpenLab: TAction;
@@ -39,7 +38,7 @@ type
actScanFile: TAction; actScanFile: TAction;
actList: TActionList; actList: TActionList;
actStretch: TAction; actStretch: TAction;
actTim2Png: TAction; actPngExport: TAction;
btnExtractAllTims: TButton; btnExtractAllTims: TButton;
btnExtractPNGs: TButton; btnExtractPNGs: TButton;
btnShowClut: TButton; btnShowClut: TButton;
@@ -57,9 +56,8 @@ type
imgTim: TImage; imgTim: TImage;
lblStatus: TLabel; lblStatus: TLabel;
lvList: TListView; lvList: TListView;
mnImport: TMenuItem; MenuItem1: TMenuItem;
mnExportTim: TMenuItem; mnImportPng: TMenuItem;
mnEdit: TMenuItem;
mnChangeBackColor2: TMenuItem; mnChangeBackColor2: TMenuItem;
N8: TMenuItem; N8: TMenuItem;
mnChangeBackColor: TMenuItem; mnChangeBackColor: TMenuItem;
@@ -126,7 +124,7 @@ type
procedure actScanFileExecute(Sender: TObject); procedure actScanFileExecute(Sender: TObject);
procedure actStopScanExecute(Sender: TObject); procedure actStopScanExecute(Sender: TObject);
procedure actStretchExecute(Sender: TObject); procedure actStretchExecute(Sender: TObject);
procedure actTim2PngExecute(Sender: TObject); procedure actPngExportExecute(Sender: TObject);
procedure btnShowClutClick(Sender: TObject); procedure btnShowClutClick(Sender: TObject);
procedure cbbBitModeChange(Sender: TObject); procedure cbbBitModeChange(Sender: TObject);
procedure cbbTranspModeChange(Sender: TObject); procedure cbbTranspModeChange(Sender: TObject);
@@ -156,9 +154,8 @@ type
function FGetTimInfoByIdx(Index: Integer): TTimInfo; function FGetTimInfoByIdx(Index: Integer): TTimInfo;
property TimInfoByIdx[Index: Integer]: TTimInfo read FGetTimInfoByIdx; //Info about tim by index property TimInfoByIdx[Index: Integer]: TTimInfo read FGetTimInfoByIdx; //Info about tim by index
function FGetSelectedTim(NewBitMode: Integer): PTIM; function FGetSelectedTim: PTIM;
property SelectedTim: PTIM Index $FF read FGetSelectedTim; //Tim, selected in list property SelectedTimInMode: PTIM read FGetSelectedTim; //Tim, selected in list
property SelectedTimInMode[NewBitMode: Integer]: PTIM read FGetSelectedTim; //Tim, selected in list
procedure ScanPath(const Path: string); procedure ScanPath(const Path: string);
procedure ScanFile(const FileName: string); procedure ScanFile(const FileName: string);
@@ -188,7 +185,7 @@ var
implementation implementation
uses ucdimage, ucpucount, lcltype, ucommon, LCLIntf, uexportimport, FPWritePNG uses ucdimage, ucpucount, lcltype, ucommon, LCLIntf, uexportimport
{$IFDEF windows} {$IFDEF windows}
,registry ,registry
@@ -237,21 +234,18 @@ begin
UpdateTim(True, False, False); UpdateTim(True, False, False);
end; end;
procedure TfrmMain.actTim2PngExecute(Sender: TObject); procedure TfrmMain.actPngExportExecute(Sender: TObject);
var var
TIM: PTIM; TIM: PTIM;
Writer: TFPWriterPNG;
begin begin
TIM := SelectedTim; TIM := SelectedTimInMode;
if TIM = nil then Exit; if TIM = nil then Exit;
dlgSavePNG.FileName := FormatPngName(SelectedScanResult.ScanFile, TIM^.dwTimNumber, SelectedTimInfo.BitMode, cbbCLUT.ItemIndex); dlgSavePNG.FileName := FormatPngName(SelectedScanResult.ScanFile, TIM^.dwTimNumber, SelectedTimInfo.BitMode, cbbCLUT.ItemIndex);
if not dlgSavePNG.Execute then Exit; if not dlgSavePNG.Execute then Exit;
Writer := CreatePngWriter((Sender as TAction) = actPngExport); SaveImage(dlgSavePNG.FileName, Surf, TIMisIndexed(TIM));
SaveImage(Surf, TIMisIndexed(TIM), dlgSavePNG.FileName, Writer);
Writer.Free;
FreeTIM(TIM); FreeTIM(TIM);
{$IFDEF Linux}FpChmod(dlgSavePNG.FileName, &777){$IFEND} {$IFDEF Linux}FpChmod(dlgSavePNG.FileName, &777){$IFEND}
end; end;
@@ -265,6 +259,17 @@ end;
procedure TfrmMain.cbbBitModeChange(Sender: TObject); procedure TfrmMain.cbbBitModeChange(Sender: TObject);
begin begin
case cbbBitMode.ItemIndex of
1: cbbBitMode.Tag := NativeInt(cTIM4C);
2: cbbBitMode.Tag := NativeInt(cTIM4NC);
3: cbbBitMode.Tag := NativeInt(cTIM8C);
4: cbbBitMode.Tag := NativeInt(cTIM8NC);
5: cbbBitMode.Tag := NativeInt(cTIM16NC);
6: cbbBitMode.Tag := NativeInt(cTIM24NC);
else
cbbBitMode.Tag := NativeInt($FF);
end;
UpdateTim(True, False, False); UpdateTim(True, False, False);
end; end;
@@ -284,7 +289,7 @@ begin
lvList.Items[0].Focused := True; lvList.Items[0].Focused := True;
lvList.Items[0].Selected := True; lvList.Items[0].Selected := True;
ShowTim; //ShowTim;
end; end;
procedure TfrmMain.actAboutExecute(Sender: TObject); procedure TfrmMain.actAboutExecute(Sender: TObject);
@@ -377,18 +382,15 @@ var
IsImage: Boolean; IsImage: Boolean;
ScanTim: TTimInfo; ScanTim: TTimInfo;
TIM: PTIM; TIM: PTIM;
Surf_: PDrawSurf; PNG: PDrawSurf;
Writer: TFPWriterPNG;
begin begin
lblStatus.Caption := sStatusBarPngsExtracting; lblStatus.Caption := sStatusBarPngsExtracting;
FName := SelectedScanResult.ScanFile; FName := SelectedScanResult.ScanFile;
IsImage := SelectedScanResult.IsImage; IsImage := SelectedScanResult.IsImage;
New(Surf_); New(PNG);
Surf_^ := nil; PNG^ := nil;
Writer := CreatePngWriter(False);
pbProgress.Position := 0; pbProgress.Position := 0;
pbProgress.Max := SelectedScanResult.Count; pbProgress.Max := SelectedScanResult.Count;
@@ -405,21 +407,20 @@ begin
CreateDirUTF8(Path); CreateDirUTF8(Path);
TIM := LoadTimFromFile(FName, OFFSET, IsImage, SIZE); TIM := LoadTimFromFile(FName, OFFSET, IsImage, SIZE);
Tim2Png(TIM, cbbCLUT.ItemIndex, Surf_, cbbTranspMode.ItemIndex); Tim2Png(TIM, cbbCLUT.ItemIndex, PNG, cbbTranspMode.ItemIndex);
Path := Path + FormatPngName(FName, I - 1, BIT_MODE, 0); Path := Path + FormatPngName(FName, I - 1, BIT_MODE, 0);
SaveImage(Surf_, TIMisIndexed(TIM), Path, Writer); SaveImage(Path, PNG, TIMisIndexed(TIM));
{$IFDEF Linux}FpChmod(Path, &777){$IFEND} {$IFDEF Linux}FpChmod(Path, &777){$IFEND}
Surf_^.Free; PNG^.Free;
Surf_^ := nil; PNG^ := nil;
FreeTIM(TIM); FreeTIM(TIM);
pbProgress.Position := I; pbProgress.Position := I;
Application.ProcessMessages; Application.ProcessMessages;
end; end;
Dispose(Surf_); Dispose(PNG);
Writer.Free;
lblStatus.Caption := sStatusBarExtracted; lblStatus.Caption := sStatusBarExtracted;
pbProgress.Position := 0; pbProgress.Position := 0;
end; end;
@@ -432,7 +433,7 @@ begin
if not dlgSaveTIM.Execute then Exit; if not dlgSaveTIM.Execute then Exit;
TIM := SelectedTim; TIM := SelectedTimInMode;
SaveTimToFile(dlgSaveTIM.FileName, TIM); SaveTimToFile(dlgSaveTIM.FileName, TIM);
{$IFDEF Linux}FpChmod(dlgSaveTIM.FileName, &777){$IFEND} {$IFDEF Linux}FpChmod(dlgSaveTIM.FileName, &777){$IFEND}
FreeTIM(TIM); FreeTIM(TIM);
@@ -495,13 +496,12 @@ var
ScanRes: TScanResult; ScanRes: TScanResult;
begin begin
if not dlgOpenPNG.Execute then Exit; if not dlgOpenPNG.Execute then Exit;
if not LoadImage(dlgOpenPNG.FileName, Image) then Exit;
TIM := SelectedTim; TIM := SelectedTimInMode;
if TIM = nil then Exit; if TIM = nil then Exit;
Image := LoadImage(dlgOpenPNG.FileName);
Png2Tim(Image, TIM); Png2Tim(Image, TIM);
SaveTimToFile('test.tim', TIM);
ScanRes := SelectedScanResult; ScanRes := SelectedScanResult;
ReplaceTimInFileFromMemory(ScanRes.ScanFile, TIM, SelectedTimInfo.Position, ScanRes.IsImage); ReplaceTimInFileFromMemory(ScanRes.ScanFile, TIM, SelectedTimInfo.Position, ScanRes.IsImage);
ShowTim; ShowTim;
@@ -561,6 +561,8 @@ procedure TfrmMain.FormCreate(Sender: TObject);
begin begin
Settings := TSettings.Create(ExtractFilePath(ParamStrUTF8(0))); Settings := TSettings.Create(ExtractFilePath(ParamStrUTF8(0)));
cbbBitMode.Tag := NativeInt($FF);
actStretch.Checked := Settings.StretchMode; actStretch.Checked := Settings.StretchMode;
cbbTranspMode.ItemIndex := Settings.TranspMode; cbbTranspMode.ItemIndex := Settings.TranspMode;
LastDir := Settings.LastDir; LastDir := Settings.LastDir;
@@ -598,7 +600,7 @@ var
R, G, B: Byte; R, G, B: Byte;
CLUT_COLOR: TCLUT_COLOR; CLUT_COLOR: TCLUT_COLOR;
begin begin
TIM := SelectedTim; TIM := SelectedTimInMode;
if TIM = nil then Exit; if TIM = nil then Exit;
SELECTED_CELL := grdClut.Row * grdClut.ColCount + grdClut.Col; SELECTED_CELL := grdClut.Row * grdClut.ColCount + grdClut.Col;
@@ -654,7 +656,7 @@ procedure TfrmMain.grdClutDrawCell(Sender: TObject; aCol, aRow: Integer;
var var
TIM: PTIM; TIM: PTIM;
begin begin
TIM := SelectedTim; TIM := SelectedTimInMode;
if TIM = nil then Exit; if TIM = nil then Exit;
if not TIMHasCLUT(TIM) then if not TIMHasCLUT(TIM) then
@@ -712,7 +714,7 @@ begin
Result := SelectedScanResult.ScanTim[Index]; Result := SelectedScanResult.ScanTim[Index];
end; end;
function TfrmMain.FGetSelectedTim(NewBitMode: Integer): PTIM; function TfrmMain.FGetSelectedTim: PTIM;
var var
P: Integer; P: Integer;
begin begin
@@ -723,8 +725,8 @@ begin
P := SelectedTimInfo.Position; P := SelectedTimInfo.Position;
Result := LoadTimFromFile(SelectedScanResult.ScanFile, P, SelectedScanResult.IsImage, SelectedTimInfo.Size); Result := LoadTimFromFile(SelectedScanResult.ScanFile, P, SelectedScanResult.IsImage, SelectedTimInfo.Size);
if NewBitMode = $FF then Exit; if Integer(cbbBitMode.Tag) = $FF then Exit;
Result^.HEAD^.bBPP := NewBitMode; Result^.HEAD^.bBPP := Integer(cbbBitMode.Tag);
end; end;
function TfrmMain.CheckForFileOpened(const FileName: string): boolean; function TfrmMain.CheckForFileOpened(const FileName: string): boolean;
@@ -818,7 +820,7 @@ begin
actCloseFiles.Enabled := cbbFiles.Enabled; actCloseFiles.Enabled := cbbFiles.Enabled;
actReplaceTim.Enabled := (lvList.Selected <> nil) and (lvList.Selected.Index <> -1); actReplaceTim.Enabled := (lvList.Selected <> nil) and (lvList.Selected.Index <> -1);
actTim2Png.Enabled := (Surf^ <> nil) and actReplaceTim.Enabled; actPngExport.Enabled := (Surf^ <> nil) and actReplaceTim.Enabled;
actExtractTim.Enabled := actReplaceTim.Enabled; actExtractTim.Enabled := actReplaceTim.Enabled;
pnlImageOptions.Enabled := actReplaceTim.Enabled; pnlImageOptions.Enabled := actReplaceTim.Enabled;
@@ -871,7 +873,7 @@ var
TIM: PTIM; TIM: PTIM;
I, CLUTS: Word; I, CLUTS: Word;
begin begin
TIM := SelectedTim; TIM := SelectedTimInMode;
if TIM = nil then Exit; if TIM = nil then Exit;
CLUTS := GetTIMClutsCount(TIM); CLUTS := GetTIMClutsCount(TIM);
@@ -892,28 +894,13 @@ end;
procedure TfrmMain.DrawSelTim; procedure TfrmMain.DrawSelTim;
var var
TIM: PTIM; TIM: PTIM;
Index: Integer;
mode: Byte;
begin begin
imgTim.Picture.Bitmap := nil; imgTim.Picture.Bitmap := nil;
case cbbBitMode.ItemIndex of TIM := SelectedTimInMode;
1: mode := cTIM4C;
2: mode := cTIM4NC;
3: mode := cTIM8C;
4: mode := cTIM8NC;
5: mode := cTIM16NC;
6: mode := cTIM24NC;
else
mode := $FF;
end;
TIM := SelectedTimInMode[mode];
if TIM = nil then Exit; if TIM = nil then Exit;
Index := cbbCLUT.ItemIndex; Tim2Png(TIM, cbbCLUT.ItemIndex, Surf, cbbTranspMode.ItemIndex);
Tim2Png(TIM, Index, Surf, cbbTranspMode.ItemIndex);
imgTim.Picture.Bitmap := Surf^.Bitmap; imgTim.Picture.Bitmap := Surf^.Bitmap;
FreeTIM(TIM); FreeTIM(TIM);
@@ -928,7 +915,7 @@ begin
ClearGrid(@grdClut); ClearGrid(@grdClut);
TIM := SelectedTim; TIM := SelectedTimInMode;
if TIM = nil then if TIM = nil then
begin begin
grdClut.ColCount := 1; grdClut.ColCount := 1;
@@ -995,7 +982,7 @@ begin
if not ShowInfo then Exit; if not ShowInfo then Exit;
TimInfo := SelectedTimInfo; TimInfo := SelectedTimInfo;
TIM := SelectedTim; TIM := SelectedTimInMode;
I := 0; I := 0;

View File

@@ -89,7 +89,6 @@ var
begin begin
Synchronize(@StartScan); Synchronize(@StartScan);
try
if pScanResult.IsImage then if pScanResult.IsImage then
pSectorBufferSize := cSectorBufferSize pSectorBufferSize := cSectorBufferSize
else else
@@ -161,7 +160,7 @@ begin
ClearSectorBuffer(SectorBuffer, ClearBuffer); ClearSectorBuffer(SectorBuffer, ClearBuffer);
end; end;
end; end;
finally
FreeTIM(TIM); FreeTIM(TIM);
FreeMemory(SectorBuffer); FreeMemory(SectorBuffer);
FreeMemory(ClearBuffer); FreeMemory(ClearBuffer);
@@ -172,7 +171,6 @@ begin
pStatusText := ''; pStatusText := '';
Synchronize(@FinishScan); Synchronize(@FinishScan);
end;
end; end;
procedure TScanThread.FinishScan; procedure TScanThread.FinishScan;

View File

@@ -149,7 +149,7 @@ end;
function ConvertCLUTColor(COLOR: TCLUT_COLOR): word; function ConvertCLUTColor(COLOR: TCLUT_COLOR): word;
begin 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 := Word(COLOR.STP shl 15) or Word((COLOR.B div 8) shl 10) or Word((COLOR.G div 8) shl 5) or Word(COLOR.R div 8);
end; end;
function GetCLUTColor(TIM: PTIM; CLUT_NUM, COLOR_NUM: Integer): TCLUT_COLOR; function GetCLUTColor(TIM: PTIM; CLUT_NUM, COLOR_NUM: Integer): TCLUT_COLOR;
@@ -353,7 +353,6 @@ var
Sector: TCDSector; Sector: TCDSector;
P, TIM_FULL_SECTORS: Integer; P, TIM_FULL_SECTORS: Integer;
begin begin
try
sImageStream := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); sImageStream := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite);
TimSectorNumber := Position div cSectorSize + 1; TimSectorNumber := Position div cSectorSize + 1;
@@ -397,13 +396,12 @@ begin
LastPartSize := SIZE - P; LastPartSize := SIZE - P;
Move(Sector.dwData[0], TIM_BUF^[P], LastPartSize); Move(Sector.dwData[0], TIM_BUF^[P], LastPartSize);
end; end;
finally
P := 0; P := 0;
Result := nil; Result := nil;
LoadTimFromBuf(TIM_BUF, Result, P); LoadTimFromBuf(TIM_BUF, Result, P);
sImageStream.Free; sImageStream.Free;
Dispose(TIM_BUF); Dispose(TIM_BUF);
end;
end; end;
function LoadTimFromStream(Stream: TStream; var Position: Integer; function LoadTimFromStream(Stream: TStream; var Position: Integer;
@@ -433,18 +431,14 @@ function LoadTimFromFile(const FileName: string; var Position: Integer;
var var
sTIM: TFileStream; sTIM: TFileStream;
begin begin
if not ImageScan then if ImageScan then
Result := LoadTimFromCDFile(FileName, Position, dwSize)
else
begin begin
try
sTIM := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); sTIM := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite);
Result := LoadTimFromStream(sTIM, Position, dwSize); Result := LoadTimFromStream(sTIM, Position, dwSize);
finally
sTIM.Free; sTIM.Free;
end; end;
Exit;
end;
Result := LoadTimFromCDFile(FileName, Position, dwSize);
end; end;
procedure SaveTimToFile(const FileName: string; TIM: PTIM); procedure SaveTimToFile(const FileName: string; TIM: PTIM);