From 7ec4a64bc582cd08ce31d81b22d9c28a3404bcfd Mon Sep 17 00:00:00 2001 From: "meffi@lab313.ru" Date: Sun, 27 Apr 2014 13:25:37 +0000 Subject: [PATCH] Fully implemented TIM<->PNG converting. But it should be checked! Some other fixes. --- tim2view.lpi | 188 ++++++++++++++++++++++++++++++++++++++++++++-- tim2view.lps | 108 ++++++++++---------------- tim2view.res | Bin 16796 -> 16796 bytes todos.inc | 1 - ucdimage.pas | 22 +++--- ucommon.pas | 2 +- udrawtim.pas | 45 ++++++----- uexportimport.pas | 59 ++++++--------- umain.lfm | 75 +++++++++--------- umain.pas | 105 ++++++++++++-------------- uscanthread.pas | 34 ++++----- utim.pas | 96 +++++++++++------------ 12 files changed, 421 insertions(+), 314 deletions(-) diff --git a/tim2view.lpi b/tim2view.lpi index f877305..9f049ea 100644 --- a/tim2view.lpi +++ b/tim2view.lpi @@ -23,12 +23,188 @@ - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -143,12 +319,14 @@ + - + + diff --git a/tim2view.lps b/tim2view.lps index 6e6bb93..9046247 100644 --- a/tim2view.lps +++ b/tim2view.lps @@ -3,13 +3,13 @@ - - + + - + @@ -25,8 +25,8 @@ - - + + @@ -55,7 +55,7 @@ - + @@ -65,8 +65,8 @@ - - + + @@ -76,8 +76,8 @@ - - + + @@ -96,7 +96,7 @@ - + @@ -109,8 +109,8 @@ - - + + @@ -132,8 +132,8 @@ - - + + @@ -149,10 +149,10 @@ - + - + @@ -160,53 +160,13 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - + @@ -225,24 +185,38 @@ - - + + - - + + - - + + + + + + + + + + + + + + + + diff --git a/tim2view.res b/tim2view.res index cc4ac69c3172ec87f098addc0f8c73ddfc0177c6..3c0edffd52ecf81771ff07dd8186f3fd6130550d 100644 GIT binary patch delta 50 zcmV-20L}lLg8`g_0kEtC0|Ed_ldl6|lgI=dlMn=uljH;_2R8sT04@MBlM@Balb{4B Iv)~21JDNriA^-pY delta 50 zcmV-20L}lLg8`g_0kEtC0|fv>ldl6|lPm;~leh&alMn nil) and (lvList.Selected.Index <> -1); - actTim2Png.Enabled := (Surf^ <> nil) and actReplaceTim.Enabled; + actPngExport.Enabled := (Surf^ <> nil) and actReplaceTim.Enabled; actExtractTim.Enabled := actReplaceTim.Enabled; pnlImageOptions.Enabled := actReplaceTim.Enabled; @@ -871,7 +873,7 @@ var TIM: PTIM; I, CLUTS: Word; begin - TIM := SelectedTim; + TIM := SelectedTimInMode; if TIM = nil then Exit; CLUTS := GetTIMClutsCount(TIM); @@ -892,28 +894,13 @@ end; procedure TfrmMain.DrawSelTim; var TIM: PTIM; - Index: Integer; - mode: Byte; begin imgTim.Picture.Bitmap := nil; - case cbbBitMode.ItemIndex of - 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]; + TIM := SelectedTimInMode; if TIM = nil then Exit; - Index := cbbCLUT.ItemIndex; - - Tim2Png(TIM, Index, Surf, cbbTranspMode.ItemIndex); + Tim2Png(TIM, cbbCLUT.ItemIndex, Surf, cbbTranspMode.ItemIndex); imgTim.Picture.Bitmap := Surf^.Bitmap; FreeTIM(TIM); @@ -928,7 +915,7 @@ begin ClearGrid(@grdClut); - TIM := SelectedTim; + TIM := SelectedTimInMode; if TIM = nil then begin grdClut.ColCount := 1; @@ -995,7 +982,7 @@ begin if not ShowInfo then Exit; TimInfo := SelectedTimInfo; - TIM := SelectedTim; + TIM := SelectedTimInMode; I := 0; diff --git a/uscanthread.pas b/uscanthread.pas index 20864b9..db8f1be 100644 --- a/uscanthread.pas +++ b/uscanthread.pas @@ -89,11 +89,10 @@ var begin Synchronize(@StartScan); - try - if pScanResult.IsImage then - pSectorBufferSize := cSectorBufferSize - else - pSectorBufferSize := cClearBufferSize; + if pScanResult.IsImage then + pSectorBufferSize := cSectorBufferSize + else + pSectorBufferSize := cClearBufferSize; pClearBufferSize := cClearBufferSize; @@ -122,8 +121,8 @@ begin begin if pScanResult.IsImage then pTimPosition := pFilePos - pRealBufSize + - ((pClearBufferPosition - 1) div cSectorDataSize) * cSectorSize + - ((pClearBufferPosition - 1) mod cSectorDataSize) + cSectorInfoSize + ((pClearBufferPosition - 1) div cSectorDataSize) * cSectorSize + + ((pClearBufferPosition - 1) mod cSectorDataSize) + cSectorInfoSize else pTimPosition := pFilePos - pRealBufSize + (pClearBufferPosition - 1); @@ -147,7 +146,7 @@ begin begin if pRealBufSize >= (pSectorBufferSize div 2) then // Need to check file size - pRealBufSize := pRealBufSize - (pSectorBufferSize div 2); + pRealBufSize := pRealBufSize - (pSectorBufferSize div 2); end else begin @@ -161,18 +160,17 @@ begin ClearSectorBuffer(SectorBuffer, ClearBuffer); end; end; - finally - FreeTIM(TIM); - FreeMemory(SectorBuffer); - FreeMemory(ClearBuffer); - pSrcFileStream.Free; - pStopScan := True; - pFilePos := 0; - pStatusText := ''; + FreeTIM(TIM); + FreeMemory(SectorBuffer); + FreeMemory(ClearBuffer); - Synchronize(@FinishScan); - end; + pSrcFileStream.Free; + pStopScan := True; + pFilePos := 0; + pStatusText := ''; + + Synchronize(@FinishScan); end; procedure TScanThread.FinishScan; diff --git a/utim.pas b/utim.pas index 7173e80..92f3a13 100644 --- a/utim.pas +++ b/utim.pas @@ -149,7 +149,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 := 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; function GetCLUTColor(TIM: PTIM; CLUT_NUM, COLOR_NUM: Integer): TCLUT_COLOR; @@ -353,57 +353,55 @@ var Sector: TCDSector; P, TIM_FULL_SECTORS: Integer; begin - try - sImageStream := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); + sImageStream := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); - TimSectorNumber := Position div cSectorSize + 1; - TimOffsetInSector := Position mod cSectorSize - cSectorInfoSize; - TimStartSectorPos := (TimSectorNumber - 1) * cSectorSize; - FirstPartSize := cSectorDataSize - TimOffsetInSector; + TimSectorNumber := Position div cSectorSize + 1; + TimOffsetInSector := Position mod cSectorSize - cSectorInfoSize; + TimStartSectorPos := (TimSectorNumber - 1) * cSectorSize; + FirstPartSize := cSectorDataSize - TimOffsetInSector; - New(TIM_BUF); - P := 0; + New(TIM_BUF); + P := 0; - if SIZE < FirstPartSize then FirstPartSize := SIZE; + if SIZE < FirstPartSize then FirstPartSize := SIZE; - sImageStream.Seek(TimStartSectorPos, soBeginning); + sImageStream.Seek(TimStartSectorPos, soBeginning); + sImageStream.Read(Sector, cSectorSize); + + Move(Sector.dwData[TimOffsetInSector], TIM_BUF^[P], FirstPartSize); + Inc(P, FirstPartSize); + + Inc(TimStartSectorPos, cSectorSize); + sImageStream.Seek(TimStartSectorPos, soBeginning); + + TIM_FULL_SECTORS := (SIZE - P) div cSectorDataSize; + + while TIM_FULL_SECTORS > 0 do + begin sImageStream.Read(Sector, cSectorSize); - Move(Sector.dwData[TimOffsetInSector], TIM_BUF^[P], FirstPartSize); - Inc(P, FirstPartSize); + Move(Sector.dwData[0], TIM_BUF^[P], cSectorDataSize); + Inc(P, cSectorDataSize); Inc(TimStartSectorPos, cSectorSize); sImageStream.Seek(TimStartSectorPos, soBeginning); - TIM_FULL_SECTORS := (SIZE - P) div cSectorDataSize; - - while TIM_FULL_SECTORS > 0 do - begin - sImageStream.Read(Sector, cSectorSize); - - Move(Sector.dwData[0], TIM_BUF^[P], cSectorDataSize); - Inc(P, cSectorDataSize); - - Inc(TimStartSectorPos, cSectorSize); - sImageStream.Seek(TimStartSectorPos, soBeginning); - - Dec(TIM_FULL_SECTORS); - end; - - sImageStream.Read(Sector, cSectorSize); - - if SIZE > P then - begin - LastPartSize := SIZE - P; - Move(Sector.dwData[0], TIM_BUF^[P], LastPartSize); - end; - finally - P := 0; - Result := nil; - LoadTimFromBuf(TIM_BUF, Result, P); - sImageStream.Free; - Dispose(TIM_BUF); + Dec(TIM_FULL_SECTORS); end; + + sImageStream.Read(Sector, cSectorSize); + + if SIZE > P then + begin + LastPartSize := SIZE - P; + Move(Sector.dwData[0], TIM_BUF^[P], LastPartSize); + end; + + P := 0; + Result := nil; + LoadTimFromBuf(TIM_BUF, Result, P); + sImageStream.Free; + Dispose(TIM_BUF); end; function LoadTimFromStream(Stream: TStream; var Position: Integer; @@ -433,18 +431,14 @@ function LoadTimFromFile(const FileName: string; var Position: Integer; var sTIM: TFileStream; begin - if not ImageScan then + if ImageScan then + Result := LoadTimFromCDFile(FileName, Position, dwSize) + else begin - try - sTIM := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); - Result := LoadTimFromStream(sTIM, Position, dwSize); - finally - sTIM.Free; - end; - Exit; + sTIM := TFileStream.Create(UTF8ToSys(FileName), fmOpenRead or fmShareDenyWrite); + Result := LoadTimFromStream(sTIM, Position, dwSize); + sTIM.Free; end; - - Result := LoadTimFromCDFile(FileName, Position, dwSize); end; procedure SaveTimToFile(const FileName: string; TIM: PTIM);