Updated to last BGRABitmap. Fixed converter. Small fixes.

This commit is contained in:
meffi@lab313.ru
2014-04-27 23:00:00 +00:00
parent 8fe0f047c9
commit 911e5cb01a
10 changed files with 142 additions and 104 deletions

View File

@@ -23,11 +23,11 @@
<UseVersionInfo Value="True"/>
<AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="1"/>
<RevisionNr Value="74"/>
<BuildNr Value="2"/>
<RevisionNr Value="75"/>
<BuildNr Value="4"/>
<StringTable CompanyName="Lab 313" FileDescription="The best TIMs tool ever!:)" ProductVersion=""/>
</VersionInfo>
<BuildModes Count="5">
<BuildModes Count="6">
<Item1 Name="Debug" Default="True"/>
<Item2 Name="Win Release x86">
<CompilerOptions>
@@ -38,7 +38,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<OtherUnitFiles Value="lazpaint\bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
@@ -82,7 +82,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<OtherUnitFiles Value="lazpaint\bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
@@ -126,7 +126,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<OtherUnitFiles Value="lazpaint\bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
@@ -170,7 +170,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<OtherUnitFiles Value="lazpaint\bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
@@ -205,6 +205,50 @@
</Other>
</CompilerOptions>
</Item5>
<Item6 Name="Mac Release x86">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="output\tim2view_$(TargetOS)"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="lazpaint\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>
</Item6>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
@@ -307,7 +351,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir);bgrabitmap"/>
<OtherUnitFiles Value="bgrabitmap"/>
<OtherUnitFiles Value="lazpaint\bgrabitmap"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>

View File

@@ -6,9 +6,7 @@ uses
{$IFDEF UNIX}
cthreads, cmem,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, umain, edc, ucommon, ecc, ucdimage, utim, usettings, uscanresult,
uscanthread, ucpucount, udrawtim, BGRABitmap, uexportimport;
Forms, umain, Interfaces;
{$R *.res}

View File

@@ -3,16 +3,16 @@
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="9"/>
<BuildModes Active="Win Release x86"/>
<BuildModes Active="Debug"/>
<Units Count="15">
<Unit0>
<Filename Value="tim2view.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="tim2view"/>
<EditorIndex Value="11"/>
<EditorIndex Value="1"/>
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="46" Y="15"/>
<CursorPos X="46" Y="13"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
</Unit0>
@@ -25,8 +25,8 @@
<UnitName Value="umain"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/>
<TopLine Value="489"/>
<CursorPos X="63" Y="499"/>
<TopLine Value="890"/>
<CursorPos X="50" Y="901"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
@@ -41,20 +41,19 @@
<Filename Value="ecc.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ecc"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="13"/>
<CursorPos X="1" Y="1"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="ucommon.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ucommon"/>
<EditorIndex Value="4"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="14"/>
<TopLine Value="1"/>
<CursorPos X="35" Y="6"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
@@ -63,7 +62,7 @@
<Filename Value="utim.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="utim"/>
<EditorIndex Value="7"/>
<EditorIndex Value="10"/>
<WindowIndex Value="0"/>
<TopLine Value="185"/>
<CursorPos X="1" Y="204"/>
@@ -74,7 +73,7 @@
<Filename Value="ucdimage.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ucdimage"/>
<EditorIndex Value="1"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/>
<TopLine Value="112"/>
<CursorPos X="50" Y="117"/>
@@ -85,7 +84,7 @@
<Filename Value="usettings.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="usettings"/>
<EditorIndex Value="5"/>
<EditorIndex Value="9"/>
<WindowIndex Value="0"/>
<TopLine Value="81"/>
<CursorPos X="55" Y="92"/>
@@ -96,10 +95,10 @@
<Filename Value="uscanresult.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uscanresult"/>
<EditorIndex Value="12"/>
<EditorIndex Value="7"/>
<WindowIndex Value="0"/>
<TopLine Value="51"/>
<CursorPos X="1" Y="67"/>
<TopLine Value="1"/>
<CursorPos X="10" Y="5"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
</Unit8>
@@ -107,10 +106,10 @@
<Filename Value="uscanthread.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uscanthread"/>
<EditorIndex Value="6"/>
<EditorIndex Value="8"/>
<WindowIndex Value="0"/>
<TopLine Value="155"/>
<CursorPos X="36" Y="168"/>
<TopLine Value="1"/>
<CursorPos X="43" Y="6"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
</Unit9>
@@ -118,7 +117,7 @@
<Filename Value="ucpucount.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="ucpucount"/>
<EditorIndex Value="2"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/>
<TopLine Value="19"/>
<CursorPos X="87" Y="34"/>
@@ -129,11 +128,10 @@
<Filename Value="udrawtim.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="udrawtim"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="8"/>
<EditorIndex Value="5"/>
<WindowIndex Value="0"/>
<TopLine Value="234"/>
<CursorPos X="61" Y="245"/>
<TopLine Value="6"/>
<CursorPos X="49" Y="14"/>
<UsageCount Value="816"/>
<Loaded Value="True"/>
</Unit11>
@@ -149,22 +147,20 @@
<Unit13>
<Filename Value="todos.inc"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="10"/>
<WindowIndex Value="0"/>
<TopLine Value="1"/>
<CursorPos X="20" Y="1"/>
<CursorPos X="48" Y="2"/>
<UsageCount Value="802"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="uexportimport.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uexportimport"/>
<EditorIndex Value="9"/>
<EditorIndex Value="6"/>
<WindowIndex Value="0"/>
<TopLine Value="13"/>
<CursorPos X="52" Y="19"/>
<UsageCount Value="53"/>
<TopLine Value="7"/>
<CursorPos X="69" Y="16"/>
<UsageCount Value="56"/>
<Loaded Value="True"/>
</Unit14>
</Units>
@@ -173,7 +169,7 @@
</General>
</ProjectSession>
<Debugging>
<BreakPoints Count="4">
<BreakPoints Count="2">
<Item1>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
@@ -188,20 +184,6 @@
<Source Value="c:\Lazarus\fpc\2.6.2\source\packages\fcl-image\src\fppalette.inc"/>
<Line Value="159"/>
</Item2>
<Item3>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="umain.pas"/>
<Line Value="361"/>
</Item3>
<Item4>
<Kind Value="bpkSource"/>
<WatchScope Value="wpsLocal"/>
<WatchKind Value="wpkWrite"/>
<Source Value="umain.pas"/>
<Line Value="767"/>
</Item4>
</BreakPoints>
<Watches Count="3">
<Item1>

Binary file not shown.

View File

@@ -1 +1,2 @@
{ TODO : Zooming? }
{ TODO : Add different PNG output for Export. }

View File

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

View File

@@ -11,7 +11,7 @@ type
PDrawGrid = ^TDrawGrid;
procedure Tim2Png(TIM: PTIM; CLUT_NUM: Integer; Surf: PDrawSurf; TranspMode: Byte);
procedure Tim2Png(TIM: PTIM; CLUT_NUM: Integer; Image: PDrawSurf; TranspMode: Byte; ForExport: Boolean);
procedure Png2Tim(Image: PDrawSurf; Dest: PTIM);
procedure DrawClutCell(TIM: PTIM; CLUT_NUM: Integer; Grid: PDrawGrid; X, Y: Integer);
procedure DrawClut(TIM: PTIM; CLUT_NUM: Integer; Grid: PDrawGrid);
@@ -69,7 +69,7 @@ begin
end
end;
procedure PrepareClut(TIM: PTIM; CLUT_NUM: Integer; Pal: PFPPalette; TranspMode: Integer);
procedure PrepareClut(TIM: PTIM; CLUT_NUM: Integer; Pal: PFPPalette; TranspMode: Integer; ForExport: Boolean);
var
I, COUNT: Integer;
CC: TCLUT_COLOR;
@@ -92,19 +92,26 @@ begin
CC := GetCLUTColor(TIM, CLUT_NUM, I - 1);
if I <= COUNT then
begin
R := CC.R + ((I - 1) and %00000011) shl 1 + CC.STP;
G := CC.G + ((I - 1) and %00011100) shr 2;
B := CC.B + ((I - 1) and %11100000) shr 5;
R := CC.R;
G := CC.G;
B := CC.B;
A := CC.STP;
end
else
begin
R := ((I - 1) and %00000011) shl 1 + CC.STP;
G := ((I - 1) and %00011100) shr 2;
B := ((I - 1) and %11100000) shr 5;
R := 0;
G := 0;
B := 0;
A := 0;
end;
if ForExport then
begin
R := R + ((I - 1) and %00000011);
G := G + ((I - 1) and %00011100) shr 2;
B := B + ((I - 1) and %11100000) shr 5;
end;
FC := BGRAToFPColor(BGRA(R, G, B, A));
AlphaForMode(@FC, TranspMode);
Pal^.Add(FC);
@@ -175,7 +182,7 @@ begin
ClearCanvas(@Grid^.Canvas, Grid^.CellRect(X - 1, Y - 1));
end;
procedure Tim2Png(TIM: PTIM; CLUT_NUM: Integer; Surf: PDrawSurf; TranspMode: Byte);
procedure Tim2Png(TIM: PTIM; CLUT_NUM: Integer; Image: PDrawSurf; TranspMode: Byte; ForExport: Boolean);
var
RW, RH, CW: Word;
INDEXES: PIMAGE_INDEXES;
@@ -188,14 +195,14 @@ begin
RW := GetTimRealWidth(TIM);
RH := GetTimHeight(TIM);
if (Surf^ <> nil) then Surf^.Free;
if (Image^ <> nil) then Image^.Free;
Surf^ := TBGRABitmap.Create(RW, RH);
Surf^.UsePalette := not(TIM^.HEAD^.bBPP in [cTIM16NC, cTIM24NC]);
Image^ := TBGRABitmap.Create(RW, RH);
Image^.UsePalette := not(TIM^.HEAD^.bBPP in [cTIM16NC, cTIM24NC]);
PAL := @(Surf^.Palette);
PAL := @(Image^.Palette);
PrepareClut(TIM, CLUT_NUM, PAL, TranspMode);
PrepareClut(TIM, CLUT_NUM, PAL, TranspMode, ForExport);
INDEXES := PrepareIMAGE(TIM);
COLORS := GetTimColorsCount(TIM);
@@ -210,7 +217,7 @@ begin
begin
case TIM^.HEAD^.bBPP of
cTIM4C, cTIM4NC, cTIM8C, cTIM8NC:
Surf^.Pixels[X - 1, Y - 1] := INDEXES^[IDX] mod COLORS;
Image^.Pixels[X - 1, Y - 1] := INDEXES^[IDX] mod COLORS;
cTIM16C, cTIM16NC, cTIMMix:
begin
CW := 0;
@@ -220,7 +227,7 @@ begin
FC := BGRAToFPColor(BGRA(CC.R, CC.G, CC.B, CC.STP));
AlphaForMode(@FC, TranspMode);
Surf^.Colors[X - 1, Y - 1] := FC;
Image^.Colors[X - 1, Y - 1] := FC;
end;
cTIM24C, cTIM24NC:
begin
@@ -229,7 +236,7 @@ begin
R := (INDEX and $FF);
G := ((INDEX and $FF00) shr 8);
B := ((INDEX and $FF0000) shr 16);
Surf^.Colors[X - 1, Y - 1] := BGRAToFPColor(BGRA(R, G, B, 255));
Image^.Colors[X - 1, Y - 1] := BGRAToFPColor(BGRA(R, G, B, 255));
end;
else
Break;

View File

@@ -1,7 +1,7 @@
object frmMain: TfrmMain
Left = 807
Left = 919
Height = 590
Top = 193
Top = 209
Width = 780
HorzScrollBar.Page = 780
HorzScrollBar.Range = 489
@@ -954,12 +954,12 @@ object frmMain: TfrmMain
object actScanFile: TAction
Caption = 'Scan &File...'
OnExecute = actScanFileExecute
ShortCut = 116
ShortCut = 117
end
object actScanDir: TAction
Caption = 'Scan &Directory...'
OnExecute = actScanDirExecute
ShortCut = 117
ShortCut = 118
end
object actCloseFile: TAction
Caption = 'Close &this File'
@@ -981,20 +981,21 @@ object frmMain: TfrmMain
OnExecute = actExtractTimExecute
ShortCut = 113
end
object actPngExport: TAction
Caption = 'Export &PNG...'
OnExecute = actPngExportExecute
ShortCut = 115
end
object actPngImport: TAction
Caption = '&Import PNG...'
OnExecute = actPngImportExecute
ShortCut = 116
end
object actReplaceTim: TAction
Caption = '&Replace TIM...'
OnExecute = actReplaceTimExecute
ShortCut = 114
end
object actPngExport: TAction
Caption = 'Export &PNG...'
OnExecute = actPngExportExecute
ShortCut = 115
end
object actOpenRepo: TAction
Caption = 'Tim2Vew &SVN Repo'
OnExecute = actOpenRepoExecute

View File

@@ -5,10 +5,10 @@ unit umain;
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ActnList,
Classes, SysUtils, FileUtil, Forms, Dialogs, ActnList,
Menus, StdCtrls, ExtCtrls, ComCtrls, Grids, ExtDlgs,
uscanresult, uscanthread, usettings, utim, udrawtim;
uscanresult, uscanthread, usettings, utim, udrawtim, types;
{$INCLUDE todos.inc}
@@ -185,7 +185,8 @@ var
implementation
uses ucdimage, ucpucount, lcltype, ucommon, LCLIntf, uexportimport
uses ucdimage, ucpucount, lcltype, ucommon, LCLIntf, uexportimport,
FPimage
{$IFDEF windows}
,registry
@@ -237,17 +238,20 @@ end;
procedure TfrmMain.actPngExportExecute(Sender: TObject);
var
TIM: PTIM;
Image: PDrawSurf;
begin
TIM := SelectedTimInMode;
if TIM = nil then Exit;
dlgSavePNG.FileName := FormatPngName(SelectedScanResult.ScanFile, TIM^.dwTimNumber, SelectedTimInfo.BitMode, cbbCLUT.ItemIndex);
if not dlgSavePNG.Execute then Exit;
SaveImage(dlgSavePNG.FileName, Surf, TIMisIndexed(TIM));
Tim2Png(TIM, cbbCLUT.ItemIndex, Image, cbbTranspMode.ItemIndex, True);
SaveImage(dlgSavePNG.FileName, Image, TIMisIndexed(TIM));
FreeTIM(TIM);
{$IFDEF Linux}FpChmod(dlgSavePNG.FileName, &777){$IFEND}
Image^.Free;
Dispose(Image);
{$IFDEF Linux}FpChmod(dlgSavePNG.FileName, &777);{$IFEND}
end;
procedure TfrmMain.btnShowClutClick(Sender: TObject);
@@ -382,15 +386,15 @@ var
IsImage: Boolean;
ScanTim: TTimInfo;
TIM: PTIM;
PNG: PDrawSurf;
Image: PDrawSurf;
begin
lblStatus.Caption := sStatusBarPngsExtracting;
FName := SelectedScanResult.ScanFile;
IsImage := SelectedScanResult.IsImage;
New(PNG);
PNG^ := nil;
New(Image);
Image^ := nil;
pbProgress.Position := 0;
pbProgress.Max := SelectedScanResult.Count;
@@ -407,20 +411,20 @@ begin
CreateDirUTF8(Path);
TIM := LoadTimFromFile(FName, OFFSET, IsImage, SIZE);
Tim2Png(TIM, cbbCLUT.ItemIndex, PNG, cbbTranspMode.ItemIndex);
Tim2Png(TIM, cbbCLUT.ItemIndex, Image, cbbTranspMode.ItemIndex, False);
Path := Path + FormatPngName(FName, I - 1, BIT_MODE, 0);
SaveImage(Path, PNG, TIMisIndexed(TIM));
{$IFDEF Linux}FpChmod(Path, &777){$IFEND}
PNG^.Free;
PNG^ := nil;
SaveImage(Path, Image, TIMisIndexed(TIM));
{$IFDEF Linux}FpChmod(Path, &777);{$IFEND}
Image^.Free;
Image^ := nil;
FreeTIM(TIM);
pbProgress.Position := I;
Application.ProcessMessages;
end;
Dispose(PNG);
Dispose(Image);
lblStatus.Caption := sStatusBarExtracted;
pbProgress.Position := 0;
end;
@@ -435,7 +439,7 @@ begin
TIM := SelectedTimInMode;
SaveTimToFile(dlgSaveTIM.FileName, TIM);
{$IFDEF Linux}FpChmod(dlgSaveTIM.FileName, &777){$IFEND}
{$IFDEF Linux}FpChmod(dlgSaveTIM.FileName, &777);{$IFEND}
FreeTIM(TIM);
end;
@@ -469,7 +473,7 @@ begin
TIM := LoadTimFromFile(FName, OFFSET, IsImage, SIZE);
Path := Path + FormatTimName(FName, I - 1, BIT_MODE);
SaveTimToFile(Path, TIM);
{$IFDEF Linux}FpChmod(Path, &777){$IFEND}
{$IFDEF Linux}FpChmod(Path, &777);{$IFEND}
FreeTIM(TIM);
pbProgress.Position := I;
@@ -553,7 +557,6 @@ begin
Surf^.Free;
Dispose(Surf);
Settings.Free;
end;
@@ -821,6 +824,7 @@ begin
actReplaceTim.Enabled := (lvList.Selected <> nil) and (lvList.Selected.Index <> -1);
actPngExport.Enabled := (Surf^ <> nil) and actReplaceTim.Enabled;
actPngImport.Enabled := actReplaceTim.Enabled;
actExtractTim.Enabled := actReplaceTim.Enabled;
pnlImageOptions.Enabled := actReplaceTim.Enabled;
@@ -895,13 +899,14 @@ procedure TfrmMain.DrawSelTim;
var
TIM: PTIM;
begin
imgTim.Picture.Bitmap.FreeImage;
imgTim.Picture.Bitmap := nil;
TIM := SelectedTimInMode;
if TIM = nil then Exit;
Tim2Png(TIM, cbbCLUT.ItemIndex, Surf, cbbTranspMode.ItemIndex);
imgTim.Picture.Bitmap := Surf^.Bitmap;
Tim2Png(TIM, cbbCLUT.ItemIndex, Surf, cbbTranspMode.ItemIndex, False);
imgTim.Picture.Bitmap.Assign(Surf^.Bitmap);
FreeTIM(TIM);
imgTim.Stretch := actStretch.Checked;

View File

@@ -5,7 +5,7 @@ unit usettings;
interface
uses
Classes, SysUtils, IniFiles, Graphics;
SysUtils, IniFiles, Graphics;
type