From e0c860b113a061822b0550f224e7ce90b60bda48 Mon Sep 17 00:00:00 2001 From: BoBo_Fett <93382571+JKBoBoFett@users.noreply.github.com> Date: Sun, 8 Jan 2023 08:07:04 -0500 Subject: [PATCH] -fixed error loading mats with cells that have different sizes and '..' in the filename (bad mats?) -added support for '01narsky.mat' in mots. This could be an early mat file as the version in the header reads 10 all other mats are 50 --- BMParrays.pas | 17 ++++++++++++----- MATImage.pas | 13 ++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/BMParrays.pas b/BMParrays.pas index 9bb47da..0a3aa0b 100644 --- a/BMParrays.pas +++ b/BMParrays.pas @@ -137,9 +137,9 @@ procedure TBMPARRAY.Assign(Source: TPersistent); if cel_count > 0 then begin - if (bmap.Height <> CellBitmaps[0].Height) or - (bmap.Width <> CellBitmaps[0].Width) then - raise Exception.Create('Bitmaps are not the same size!'); +// if (bmap.Height <> CellBitmaps[0].Height) or +// (bmap.Width <> CellBitmaps[0].Width) then +// raise Exception.Create('Bitmaps are not the same size!'); if bmap.PixelFormat <> CellBitmaps[0].PixelFormat then raise Exception.Create('Bitmaps are not the same pixel format!'); @@ -425,6 +425,11 @@ destructor TBMPARRAY.Destroy; WriteLn(OutFile, 'TEXTURES: '+inttostr(self.GetCellCount) ); + if ContainsText(filename,'..') then + begin + mpath := gpath + mname; + end; + for J := 0 to self.GetCellCount - 1 do begin //savebitmap:=Tbitmap.Create; @@ -432,20 +437,22 @@ destructor TBMPARRAY.Destroy; //savebitmap.Assign(self.GetCell(J)); mname := ExtractName(filename); mname := TPath.GetFileNameWithoutExtension(mname); + mname := ReplaceText(mname, '.', ''); //mots file name bug mname := mname+'_Cell'+inttostr(j); mname := ChangeFileExt(mname, '.bmp'); + // mname :=mname+'.bmp'; mpath := gpath + mname; Write(OutFile,mname); if (UpperCase(ExtractFileExt(mpath)) <> '.BMP') then begin - raise Exception.Create('Save MTS Cell wrong file type'); + raise Exception.Create('Save MTS Cell wrong file type '+mpath); end; if not ContainsText(mpath,'_Cell') then begin - raise Exception.Create('Save MTS Cell wrong file type'); + raise Exception.Create('Save MTS Cell wrong file type '+mpath); end; BMP_Save(saveBitmap, mpath); diff --git a/MATImage.pas b/MATImage.pas index ac3c39a..613a39d 100644 --- a/MATImage.pas +++ b/MATImage.pas @@ -704,6 +704,16 @@ function TMAT.LoadFromFile(filename: string;pos: longint=0): TBMPARRAY; if matFormatHeader.tag <> 'MAT ' then raise Exception.Create('Not a valid MAT file!'); + if (matFormatHeader.ver <> 10) and (matFormatHeader.ver <> 50) then + raise Exception.Create('Invalid Mat Version!'); + + if matFormatHeader.ver = 10 then // '01narsky.mat' in mots + begin + matFormatHeader.mat_Type := 2; + matFormatHeader.bits :=8; + end; + + //flat color mat if matFormatHeader.mat_Type = 0 then begin @@ -742,7 +752,6 @@ function TMAT.LoadFromFile(filename: string;pos: longint=0): TBMPARRAY; SetLength(matMipmapHeaderA, matFormatHeader.cel_count ); - //read internal cmp if matFormatHeader.mat_Type = 3 then begin @@ -759,6 +768,8 @@ function TMAT.LoadFromFile(filename: string;pos: longint=0): TBMPARRAY; if (matMipmapHeaderA[i].SizeX >8000) or (matMipmapHeaderA[i].SizeX <=0) then raise Exception.Create('Invalid Size in MipHeader!'); + if (matMipmapHeaderA[i].NumMipMaps >3) then matMipmapHeaderA[i].NumMipMaps:=1; // bug fix for 01narsky.mat in mots + toBMP(matMipmapHeaderA[i].SizeX,matMipmapHeaderA[i].SizeY); result.AddCellFromBMP(bmap);