Skip to content

Commit

Permalink
-fixed error loading mats with cells that have different sizes and '.…
Browse files Browse the repository at this point in the history
….' 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
  • Loading branch information
JKBoBoFett committed Jan 8, 2023
1 parent 7011774 commit e0c860b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
17 changes: 12 additions & 5 deletions BMParrays.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down Expand Up @@ -425,27 +425,34 @@ 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;
savebitmap:=(self.GetCell(J));
//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);
Expand Down
13 changes: 12 additions & 1 deletion MATImage.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down

0 comments on commit e0c860b

Please sign in to comment.