diff --git a/tim2view.lpi b/tim2view.lpi index a8ef9cd..e287cbb 100644 --- a/tim2view.lpi +++ b/tim2view.lpi @@ -21,7 +21,9 @@ + + @@ -128,7 +130,15 @@ + + + + + + + + diff --git a/tim2view.lps b/tim2view.lps index 568542d..73147d7 100644 --- a/tim2view.lps +++ b/tim2view.lps @@ -1,134 +1,138 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tim2view.res b/tim2view.res index e92249d..6528d25 100644 Binary files a/tim2view.res and b/tim2view.res differ diff --git a/ucommon.pas b/ucommon.pas index a9089f5..cd495e0 100644 --- a/ucommon.pas +++ b/ucommon.pas @@ -3,7 +3,7 @@ unit ucommon; interface const - cProgramName = 'Tim2View SVN.r65 by [Lab 313] (for ' + + cProgramName = 'Tim2View SVN.r67 by [Lab 313] (for ' + {$IFDEF Linux}'Linux' + {$IFEND} {$IFDEF Darwin}'Mac OS X' + {$IFEND} {$IFDEF Windows}'Windows' + {$IFEND} @@ -14,7 +14,6 @@ const cAutoExtractionTimFormat = '%s_%.6d_%.2db' + '.tim'; cAutoExtractionPngFormat = '%s_%.6d_%.2db_%.2dc' + '.png'; - cCLUTGridColsCount = 32; sStatusBarScanningFile = 'Scanning File...'; sStatusBarTimsExtracting = 'TIMs Extracting...'; diff --git a/udrawtim.pas b/udrawtim.pas index 265e817..0ad5d6c 100644 --- a/udrawtim.pas +++ b/udrawtim.pas @@ -34,7 +34,7 @@ begin if (TIM^.HEAD^.bBPP in [cTIM4NC, cTIM8NC]) then begin Randomize; - for I := 1 to cRandomPaletteSize do + for I := 1 to $100 do Result^[I - 1] := GetCLUTColor(TIM, CLUT_NUM, I - 1); Exit; @@ -51,7 +51,7 @@ var P24: Integer; begin New(Result); - OFFSET := cTIMHeadSize + GetTIMCLUTSize(TIM) + cIMAGEHeadSize; + OFFSET := SizeOf(TTIMHeader) + GetTIMCLUTSize(TIM) + SizeOf(TIMAGEHeader); RW := GetTimRealWidth(TIM); case TIM^.HEAD^.bBPP of @@ -227,7 +227,7 @@ var COLS, Colors: Integer; begin Colors := GetTimColorsCount(TIM); - COLS := Min(Colors, cCLUTGridColsCount); + COLS := Min(Colors, 32); Rect := Grid^.CellRect(X, Y); if (Y * COLS + X) >= Colors then @@ -277,7 +277,7 @@ var X, Y, ROWS, COLS, COLORS: Integer; begin COLORS := GetTimColorsCount(TIM); - COLS := Min(COLORS, cCLUTGridColsCount); + COLS := Min(COLORS, 32); Grid^.ColCount := COLS; ROWS := Ceil(COLORS / COLS); diff --git a/umain.lfm b/umain.lfm index daa5f8a..2000cba 100644 --- a/umain.lfm +++ b/umain.lfm @@ -1,13 +1,14 @@ object frmMain: TfrmMain - Left = 1017 + Left = 561 Height = 590 - Top = 147 + Top = 213 Width = 780 HorzScrollBar.Page = 780 + HorzScrollBar.Range = 489 VertScrollBar.Page = 570 + VertScrollBar.Range = 344 ActiveControl = pnlList AllowDropFiles = True - AutoScroll = True ClientHeight = 570 ClientWidth = 780 Color = clBtnFace @@ -580,6 +581,7 @@ object frmMain: TfrmMain Top = 28 Width = 253 Align = alClient + AutoWidthLastColumn = True Columns = < item Caption = '# / 0' @@ -598,16 +600,16 @@ object frmMain: TfrmMain item Alignment = taCenter Caption = 'CLUTs' - Width = 57 + Width = 84 end> ColumnClick = False GridLines = True - HideSelection = False OwnerData = True PopupMenu = pmList ReadOnly = True RowSelect = True TabOrder = 0 + ToolTips = False ViewStyle = vsReport OnData = lvListData OnSelectItem = lvListSelectItem @@ -813,13 +815,11 @@ object frmMain: TfrmMain item Width = 50 end - item - Width = 50 - end item Width = 50 end> SimplePanel = False + SizeGrip = False end object dlgOpenFile: TOpenDialog Title = 'Please, select File...' diff --git a/umain.pas b/umain.pas index ee210ff..720e7f8 100644 --- a/umain.pas +++ b/umain.pas @@ -254,6 +254,7 @@ begin SetTimsListCount(SelectedScanResult.Count); actReturnFocus.Execute; + if lvList.Items.Count = 0 then Exit; lvList.ItemIndex := 0; lvList.Items[0].Focused := True; lvList.Items[0].Selected := True; @@ -261,7 +262,7 @@ end; procedure TfrmMain.actAboutExecute(Sender: TObject); begin - Application.MessageBox('Some "about strings" should be here!:)', 'About', MB_OK + MB_ICONINFORMATION); + Application.MessageBox(cProgramName + #13 + 'Some "about strings" should be here!:)', 'About', MB_OK + MB_ICONINFORMATION); end; procedure TfrmMain.actAssocTimsExecute(Sender: TObject); @@ -646,6 +647,7 @@ end; function TfrmMain.FGetSelectedScanResult: TScanResult; begin + if cbbFiles.ItemIndex = -1 then Exit; Result := ScanResults[cbbFiles.ItemIndex]; end; @@ -902,23 +904,9 @@ begin end; procedure TfrmMain.SetCLUTListToNoCLUT; -var - I: Integer; begin - if cbbCLUT.Items.Count > 0 then - begin - cbbCLUT.Items.BeginUpdate; - - for I := 0 to cbbCLUT.Items.Count - 2 do - cbbCLUT.Items.Delete(I); - - cbbCLUT.Items[0] := sThisTimHasNoClut; - - cbbCLUT.Items.EndUpdate; - end - else - cbbCLUT.Items.Add(sThisTimHasNoClut); - + cbbCLUT.Items.Clear; + cbbCLUT.Items.Add(sThisTimHasNoClut); cbbCLUT.ItemIndex := 0; end; @@ -954,7 +942,6 @@ procedure TfrmMain.ShowTimInfo(ShowInfo: Boolean); var I: Integer; TIM: PTIM; - ScanRes: TScanResult; TimInfo: TTimInfo; begin for I := 1 to sbMain.Panels.Count do @@ -962,15 +949,16 @@ begin if not ShowInfo then Exit; - ScanRes := SelectedScanResult; TimInfo := SelectedTimInfo; TIM := SelectedTim; I := 0; - sbMain.Panels[I].Text := Format('Position: 0x%x', [TimInfo.Position]); + sbMain.Panels[I].Text := Format('Pos: 0x%x', [TimInfo.Position]); sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); - sbMain.Panels[I].Text := Format('Version: %d', [GetTimVersion(TIM)]); + sbMain.Panels[I].Text := Format('Ver: %d', [GetTimVersion(TIM)]); + sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); + sbMain.Panels[I].Text := Format('Good: %s', [TIMIsGoodStr(TIM)]); sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); if TIMHasCLUT(TIM) then @@ -978,20 +966,16 @@ begin sbMain.Panels[I].Alignment := taRightJustify; sbMain.Panels[I].Text := 'CLUT:'; sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 20; Inc(I); - sbMain.Panels[I].Text := Format('VRAM.X: %d', [GetTimClutVRAMX(TIM)]); + sbMain.Panels[I].Text := Format('X/Y: %dx%d', [GetTimClutVRAMX(TIM), GetTimClutVRAMY(TIM)]); sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); - sbMain.Panels[I].Text := Format('VRAM.Y: %d', [GetTimClutVRAMY(TIM)]); - sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); - sbMain.Panels[I].Text := Format('Colors/CLUT: %d', [GetTimColorsCount(TIM)]); + sbMain.Panels[I].Text := Format('Colors: %d', [GetTimColorsCount(TIM)]); sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); end; sbMain.Panels[I].Alignment := taRightJustify; sbMain.Panels[I].Text := 'IMAGE:'; sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 20; Inc(I); - sbMain.Panels[I].Text := Format('VRAM.X: %d', [GetTimImageVRAMX(TIM)]); - sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); - sbMain.Panels[I].Text := Format('VRAM.Y: %d', [GetTimImageVRAMY(TIM)]); + sbMain.Panels[I].Text := Format('X/Y: %dx%d', [GetTimImageVRAMX(TIM), GetTimImageVRAMY(TIM)]); sbMain.Panels[I].Width := Canvas.GetTextWidth(sbMain.Panels[I].Text) + 8; Inc(I); FreeTIM(TIM); diff --git a/utim.pas b/utim.pas index 47b8a12..df83eeb 100644 --- a/utim.pas +++ b/utim.pas @@ -26,16 +26,6 @@ const cTIMNOCLUT = [cTIM4NC, cTIM8NC, cTIM16NC, cTIM24NC, cTIMMix]; cTIMBpp = [cTIM4C, cTIM8C, cTIM16C, cTIM24C, cTIM4NC, cTIM8NC, cTIM16NC, cTIM24NC, cTIMMix]; - cCLUTColorsMax = 1024; - cCLUTCountMax = 512; - cIMAGEWidthMax = 1024; - cIMAGEHeightMax = 1024; - cCLUTHeadSize = $0C; - cIMAGEHeadSize = $0C; - cTIMHeadSize = 8; - cRandomPaletteSize = $100; - cTIMMaxSize = cTIMHeadSize + cCLUTColorsMax * cCLUTCountMax * 2 + cCLUTHeadSize + cIMAGEWidthMax * cIMAGEHeightMax * 2 + cIMAGEHeadSize; - type TTIMHeader = packed record // TIM Header (8 bytes) bMagic: byte; // $10 (1 byte) @@ -46,7 +36,6 @@ type // variants: // [$08, $09, $0A, $0B, $02, $03, $00, $01] end; - PTIMHeader = ^TTIMHeader; type @@ -57,7 +46,6 @@ type wColorsCount: word; // Number of CLUT Colors (2 bytes) wClutsCount: word; // Count of Palettes (2 bytes) end; - PCLUTHeader = ^TCLUTHeader; type @@ -68,9 +56,17 @@ type wWidth: word; // Image Width (not Real) (2 bytes) wHeight: word; // Image Height (Real) (2 bytes) end; - PIMAGEHeader = ^TIMAGEHeader; + //Constants +const + cCLUTColorsMax = 1024; + cCLUTCountMax = 512; + cIMAGEWidthMax = 1024; + cIMAGEHeightMax = 1024; + cTIMMaxSize = SizeOf(TTIMHeader) + cCLUTColorsMax * cCLUTCountMax * 2 + SizeOf(TCLUTHeader) + cIMAGEWidthMax * cIMAGEHeightMax * 2 + SizeOf(TIMAGEHeader); + //Constants + type TTIMDataArray = array [0 .. cTIMMaxSize - 1] of byte; PTIMDataArray = ^TTIMDataArray; @@ -114,6 +110,7 @@ function GetTimWidth(TIM: PTIM): word; function GetTimRealWidth(TIM: PTIM): word; function GetTimHeight(TIM: PTIM): word; function TIMIsGood(TIM: PTIM): Boolean; +function TIMIsGoodStr(TIM: PTIM): string; function LoadTimFromBuf(BUFFER: pointer; var TIM: PTIM; var Position: Integer): Boolean; function LoadTimFromFile(const FileName: string; var Position: Integer; ImageScan: Boolean; dwSize: Integer): PTIM; procedure SaveTimToFile(const FileName: string; TIM: PTIM); @@ -170,7 +167,7 @@ begin CLUT_OFFSET := CLUT_NUM * GetTimColorsCount(TIM) * 2; - Move(TIM^.DATA^[cTIMHeadSize + cCLUTHeadSize + COLOR_NUM * 2 + CLUT_OFFSET], COLOR, 2); + Move(TIM^.DATA^[SizeOf(TTIMHeader) + SizeOf(TCLUTHeader) + COLOR_NUM * 2 + CLUT_OFFSET], COLOR, 2); Result := ConvertTIMColor(COLOR); end; @@ -184,7 +181,7 @@ begin CLUT_OFFSET := CLUT_NUM * GetTimColorsCount(TIM) * 2; COLOR_TO_WRITE := ConvertCLUTColor(COLOR); - Move(COLOR_TO_WRITE, TIM^.DATA^[cTIMHeadSize + cCLUTHeadSize + COLOR_NUM * 2 + CLUT_OFFSET], 2); + Move(COLOR_TO_WRITE, TIM^.DATA^[SizeOf(TTIMHeader) + SizeOf(TCLUTHeader) + COLOR_NUM * 2 + CLUT_OFFSET], 2); end; function GetTimHeight(TIM: PTIM): word; @@ -197,17 +194,17 @@ begin Result := 0; if not TIMHasCLUT(TIM) then Exit; - Result := TIM^.CLUT^.wColorsCount * TIM^.CLUT^.wClutsCount * 2 + cCLUTHeadSize; + Result := TIM^.CLUT^.wColorsCount * TIM^.CLUT^.wClutsCount * 2 + SizeOf(TCLUTHeader); end; function GetTIMIMAGESize(TIM: PTIM): Integer; begin - Result := TIM^.IMAGE^.wWidth * TIM^.IMAGE^.wHeight * 2 + cIMAGEHeadSize; + Result := TIM^.IMAGE^.wWidth * TIM^.IMAGE^.wHeight * 2 + SizeOf(TIMAGEHeader); end; function GetTIMSize(TIM: PTIM): Integer; begin - Result := GetTIMCLUTSize(TIM) + GetTIMIMAGESize(TIM) + cTIMHeadSize; + Result := GetTIMCLUTSize(TIM) + GetTIMIMAGESize(TIM) + SizeOf(TTIMHeader); end; function CheckVersion(TIM: PTIM): Boolean; @@ -292,12 +289,17 @@ end; procedure ClearTIM(TIM: PTIM); begin - FillChar(TIM^.HEAD^, cTIMHeadSize, 0); - FillChar(TIM^.CLUT^, cCLUTHeadSize, 0); - FillChar(TIM^.IMAGE^, cIMAGEHeadSize, 0); + FillChar(TIM^.HEAD^, SizeOf(TTIMHeader), 0); + FillChar(TIM^.CLUT^, SizeOf(TCLUTHeader), 0); + FillChar(TIM^.IMAGE^, SizeOf(TIMAGEHeader), 0); FillChar(TIM^.DATA^, cTIMMaxSize, 0); end; +function TIMIsGoodStr(TIM: PTIM): string; +begin + if TIMIsGood(TIM) then Result := 'Yes' else Result := 'No'; +end; + function LoadTimFromBuf(BUFFER: pointer; var TIM: PTIM; var Position: Integer): Boolean; var P: Integer; @@ -311,18 +313,18 @@ begin if TIM = nil then TIM := CreateTIM; - Move(PBytesArray(BUFFER)^[P], TIM^.HEAD^, cTIMHeadSize); + Move(PBytesArray(BUFFER)^[P], TIM^.HEAD^, SizeOf(TTIMHeader)); if not CheckHEAD(TIM) then Exit; - Inc(P, cTIMHeadSize); + Inc(P, SizeOf(TTIMHeader)); if TIMHasCLUT(TIM) then begin - Move(PBytesArray(BUFFER)^[P], TIM^.CLUT^, cCLUTHeadSize); + Move(PBytesArray(BUFFER)^[P], TIM^.CLUT^, SizeOf(TCLUTHeader)); if not CheckCLUT(TIM) then Exit; Inc(P, GetTIMCLUTSize(TIM)); end; - Move(PBytesArray(BUFFER)^[P], TIM^.IMAGE^, cIMAGEHeadSize); + Move(PBytesArray(BUFFER)^[P], TIM^.IMAGE^, SizeOf(TIMAGEHeader)); if not CheckIMAGE(TIM) then Exit; if not CheckTIMSize(TIM) then Exit;