diff --git a/tim2view.lpi b/tim2view.lpi index 9f049ea..6f0379a 100644 --- a/tim2view.lpi +++ b/tim2view.lpi @@ -23,11 +23,11 @@ - - + + - + @@ -38,7 +38,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -170,7 +170,7 @@ - + @@ -205,6 +205,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -307,7 +351,7 @@ - + diff --git a/tim2view.lpr b/tim2view.lpr index ec6401b..9363cb8 100644 --- a/tim2view.lpr +++ b/tim2view.lpr @@ -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} diff --git a/tim2view.lps b/tim2view.lps index 9046247..8450797 100644 --- a/tim2view.lps +++ b/tim2view.lps @@ -3,16 +3,16 @@ - + - + - + @@ -25,8 +25,8 @@ - - + + @@ -41,20 +41,19 @@ - - - + + - + @@ -63,7 +62,7 @@ - + @@ -74,7 +73,7 @@ - + @@ -85,7 +84,7 @@ - + @@ -96,10 +95,10 @@ - + - - + + @@ -107,10 +106,10 @@ - + - - + + @@ -118,7 +117,7 @@ - + @@ -129,11 +128,10 @@ - - + - - + + @@ -149,22 +147,20 @@ - - + - - + - - - + + + @@ -173,7 +169,7 @@ - + @@ -188,20 +184,6 @@ - - - - - - - - - - - - - - diff --git a/tim2view.res b/tim2view.res index 3c0edff..46491ec 100644 Binary files a/tim2view.res and b/tim2view.res differ diff --git a/todos.inc b/todos.inc index 45a6f01..cac4430 100644 --- a/todos.inc +++ b/todos.inc @@ -1 +1,2 @@ { TODO : Zooming? } +{ TODO : Add different PNG output for Export. } diff --git a/ucommon.pas b/ucommon.pas index 6ab8156..c1dc54b 100644 --- a/ucommon.pas +++ b/ucommon.pas @@ -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} diff --git a/udrawtim.pas b/udrawtim.pas index 1f1e7c0..792545b 100644 --- a/udrawtim.pas +++ b/udrawtim.pas @@ -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; diff --git a/umain.lfm b/umain.lfm index dd7606a..8c0c82e 100644 --- a/umain.lfm +++ b/umain.lfm @@ -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 diff --git a/umain.pas b/umain.pas index 9588975..17e6863 100644 --- a/umain.pas +++ b/umain.pas @@ -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; diff --git a/usettings.pas b/usettings.pas index 6f03c8b..93cc2f1 100644 --- a/usettings.pas +++ b/usettings.pas @@ -5,7 +5,7 @@ unit usettings; interface uses - Classes, SysUtils, IniFiles, Graphics; + SysUtils, IniFiles, Graphics; type