From 6f18e7250cccdf42e6d1a65cc3cbbb05aa8454b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Brammer?= Date: Sat, 9 May 2009 17:08:10 +0200 Subject: [PATCH] Load JPEG landscape textures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit committer: Günther Brammer --- engine/inc/C4Surface.h | 1 + engine/inc/C4SurfaceFile.h | 1 - engine/src/C4Def.cpp | 2 +- engine/src/C4Surface.cpp | 26 +++++++---- engine/src/C4SurfaceFile.cpp | 83 +----------------------------------- engine/src/C4Texture.cpp | 15 ++++--- standard/inc/StdSurface2.h | 3 +- standard/src/StdSurface2.cpp | 2 +- 8 files changed, 32 insertions(+), 101 deletions(-) diff --git a/engine/inc/C4Surface.h b/engine/inc/C4Surface.h index e064f5dee..b2d8f1202 100644 --- a/engine/inc/C4Surface.h +++ b/engine/inc/C4Surface.h @@ -44,6 +44,7 @@ class C4Surface: public CSurface BOOL Save(C4Group &hGroup, const char *szFilename); BOOL SavePNG(C4Group &hGroup, const char *szFilename, bool fSaveAlpha=true, bool fApplyGamma=false, bool fSaveOverlayOnly=false); BOOL Copy(C4Surface &fromSfc); + bool Read(CStdStream &hGroup, const char * extension, bool fOwnPal=false); BOOL ReadPNG(CStdStream &hGroup); bool ReadJPEG(CStdStream &hGroup); }; diff --git a/engine/inc/C4SurfaceFile.h b/engine/inc/C4SurfaceFile.h index c199fbadc..e3d7fb07c 100644 --- a/engine/inc/C4SurfaceFile.h +++ b/engine/inc/C4SurfaceFile.h @@ -25,7 +25,6 @@ class C4Surface; C4Surface *GroupReadSurface(CStdStream &hGroup, BYTE *bpPalette=NULL); CSurface8 *GroupReadSurface8(CStdStream &hGroup); -C4Surface *GroupReadSurfacePNG(CStdStream &hGroup); C4Surface *GroupReadSurfaceOwnPal(CStdStream &hGroup); CSurface8 *GroupReadSurfaceOwnPal8(CStdStream &hGroup); diff --git a/engine/src/C4Def.cpp b/engine/src/C4Def.cpp index 3a887cad7..09544afd9 100644 --- a/engine/src/C4Def.cpp +++ b/engine/src/C4Def.cpp @@ -765,7 +765,7 @@ BOOL C4Def::Load(C4Group &hGroup, if (hGroup.AccessEntry(C4CFN_RankFaces)) { pRankSymbols = new C4FacetSurface(); - if (!pRankSymbols->GetFace().Read(hGroup)) { delete pRankSymbols; pRankSymbols=NULL; } + if (!pRankSymbols->GetFace().ReadBMP(hGroup)) { delete pRankSymbols; pRankSymbols=NULL; } } // set size if (pRankSymbols) diff --git a/engine/src/C4Surface.cpp b/engine/src/C4Surface.cpp index bca09e57d..6ef72f7b1 100644 --- a/engine/src/C4Surface.cpp +++ b/engine/src/C4Surface.cpp @@ -80,6 +80,8 @@ BOOL C4Surface::LoadAny(C4GroupSet &hGroupset, const char *szName, bool fOwnPal, if (pGroup) break; } } + else + pGroup = hGroupset.FindEntry(szFilename); if (!pGroup) return false; // Load surface return Load(*pGroup,szFilename,fOwnPal,fNoErrIfNotFound); @@ -117,15 +119,7 @@ BOOL C4Surface::Load(C4Group &hGroup, const char *szFilename, bool fOwnPal, bool if (!fNoErrIfNotFound) LogF("%s: %s%c%s", LoadResStr("IDS_PRC_FILENOTFOUND"), hGroup.GetFullName().getData(), (char) DirectorySeparator, szFilename); return FALSE; } - // determine file type by file extension and load accordingly - bool fSuccess; - if (SEqualNoCase(GetExtension(szFilename), "png")) - fSuccess = !!ReadPNG(hGroup); - else if (SEqualNoCase(GetExtension(szFilename), "jpeg") - || SEqualNoCase(GetExtension(szFilename), "jpg")) - fSuccess = ReadJPEG(hGroup); - else - fSuccess = !!Read(hGroup, fOwnPal); + bool fSuccess = Read(hGroup, GetExtension(szFilename), fOwnPal); // loading error? log! if (!fSuccess) LogF("%s: %s%c%s", LoadResStr("IDS_ERR_NOFILE"), hGroup.GetFullName().getData(), (char) DirectorySeparator, szFilename); @@ -135,6 +129,20 @@ BOOL C4Surface::Load(C4Group &hGroup, const char *szFilename, bool fOwnPal, bool return fSuccess; } +bool C4Surface::Read(CStdStream &hGroup, const char * extension, bool fOwnPal) + { + // determine file type by file extension and load accordingly + if (SEqualNoCase(extension, "png")) + return ReadPNG(hGroup); + else if (SEqualNoCase(extension, "jpeg") + || SEqualNoCase(extension, "jpg")) + return ReadJPEG(hGroup); + else if (SEqualNoCase(extension, "bmp")) + return ReadBMP(hGroup, fOwnPal); + else + return false; + } + BOOL C4Surface::ReadPNG(CStdStream &hGroup) { // create mem block diff --git a/engine/src/C4SurfaceFile.cpp b/engine/src/C4SurfaceFile.cpp index 421f5712b..1a8efad54 100644 --- a/engine/src/C4SurfaceFile.cpp +++ b/engine/src/C4SurfaceFile.cpp @@ -29,7 +29,7 @@ C4Surface *GroupReadSurface(CStdStream &hGroup, BYTE *bpPalette) { // create surface C4Surface *pSfc=new C4Surface(); - if (!pSfc->Read(hGroup, !!bpPalette)) + if (!pSfc->ReadBMP(hGroup, !!bpPalette)) { delete pSfc; return NULL; } return pSfc; } @@ -47,7 +47,7 @@ C4Surface *GroupReadSurfaceOwnPal(CStdStream &hGroup) { // create surface C4Surface *pSfc=new C4Surface(); - if (!pSfc->Read(hGroup, true)) + if (!pSfc->ReadBMP(hGroup, true)) { delete pSfc; return NULL; } return pSfc; } @@ -60,82 +60,3 @@ CSurface8 *GroupReadSurfaceOwnPal8(CStdStream &hGroup) { delete pSfc; return NULL; } return pSfc; } - -C4Surface *GroupReadSurfacePNG(CStdStream &hGroup) - { - // create surface - C4Surface *pSfc=new C4Surface(); - pSfc->ReadPNG(hGroup); - return pSfc; - } - -/*BOOL SaveSurface(const char *szFilename, - SURFACE sfcSurface, - BYTE *bpPalette) - { - BITMAPINFOHEADER bmpinfo; - RGBQUAD rgbquad; - BITMAPFILEHEADER bmphead; - - int cnt,lcnt,ladd,pitch; - int imgwdt,imghgt; - BYTE fbuf[4]; - BYTE *timgbuf; - CStdFile hFile; - - // Lock the sfcSurface - if (!(timgbuf=lpDDraw->LockSurface(sfcSurface,pitch,&imgwdt,&imghgt))) - return FALSE; - - // Image line data in file is extended to be multiple of 4 - ladd=0; if (imgwdt%4!=0) ladd=4-imgwdt%4; - - // Set bitmap info - ZeroMem((BYTE*)&bmpinfo,sizeof(BITMAPINFOHEADER)); - bmpinfo.biSize=sizeof(BITMAPINFOHEADER); - bmpinfo.biWidth=imgwdt; - bmpinfo.biHeight=imghgt; - bmpinfo.biPlanes=1; - bmpinfo.biBitCount=8; - bmpinfo.biCompression=0; - bmpinfo.biSizeImage=imgwdt*imghgt; - bmpinfo.biClrUsed=bmpinfo.biClrImportant=256; - - // Set header - ZeroMem((BYTE*)&bmphead,sizeof(BITMAPFILEHEADER)); - bmphead.bfType=*((const WORD*)"BM"); - bmphead.bfSize=sizeof(BITMAPFILEHEADER) - +sizeof(BITMAPINFOHEADER) - +256*sizeof(RGBQUAD) - +(imgwdt+ladd)*imghgt; - bmphead.bfOffBits=sizeof(BITMAPFILEHEADER) - +sizeof(BITMAPINFOHEADER) - +256*sizeof(RGBQUAD); - - - if (!hFile.Create(szFilename,FALSE)) - { lpDDraw->UnLockSurface(sfcSurface); return FALSE; } - - - hFile.Write(&bmphead,sizeof(bmphead)); - hFile.Write(&bmpinfo,sizeof(bmpinfo)); - - for (cnt=0; cnt<256; cnt++) - { - rgbquad.rgbRed= bpPalette[cnt*3+0]; - rgbquad.rgbGreen=bpPalette[cnt*3+1]; - rgbquad.rgbBlue= bpPalette[cnt*3+2]; - hFile.Write(&rgbquad,sizeof(rgbquad)); - } - - for (lcnt=imghgt-1; lcnt>=0; lcnt--) - { - hFile.Write(timgbuf+(pitch*lcnt),imgwdt); - if (ladd>0) hFile.Write(fbuf,ladd); - } - - lpDDraw->UnLockSurface(sfcSurface); - hFile.Close(); - - return TRUE; - }*/ diff --git a/engine/src/C4Texture.cpp b/engine/src/C4Texture.cpp index baf52f423..570e222bc 100644 --- a/engine/src/C4Texture.cpp +++ b/engine/src/C4Texture.cpp @@ -283,19 +283,22 @@ int32_t C4TextureMap::LoadTextures(C4Group &hGroup, C4Group* OverloadFile) size_t binlen; // newgfx: load PNG-textures first hGroup.ResetSearch(); - while (hGroup.AccessNextEntry(C4CFN_PNGFiles,&binlen,texname)) + while (hGroup.AccessNextEntry("*",&binlen,texname)) { // check if it already exists in the map - SReplaceChar(texname,'.',0); - if (GetTexture(texname)) continue; - SAppend(".png", texname); - // load - if (ctex=GroupReadSurfacePNG(hGroup)) + if (GetTexture(GetFilenameOnly(texname))) continue; + // create surface + ctex = new C4Surface(); + if (ctex->Read(hGroup, GetExtension(texname))) { SReplaceChar(texname,'.',0); if (AddTexture(texname,ctex)) texnum++; else delete ctex; } + else + { + delete ctex; + } } #endif return texnum; diff --git a/standard/inc/StdSurface2.h b/standard/inc/StdSurface2.h index 475f0b94b..335bfe883 100644 --- a/standard/inc/StdSurface2.h +++ b/standard/inc/StdSurface2.h @@ -240,8 +240,7 @@ class CSurface void Default(); void Clip(int iX, int iY, int iX2, int iY2); void NoClip(); - bool Read(class CStdStream &hGroup, bool fOwnPal=false); - BOOL Save(const char *szFilename); + bool ReadBMP(class CStdStream &hGroup, bool fOwnPal=false); bool SavePNG(const char *szFilename, bool fSaveAlpha, bool fApplyGamma, bool fSaveOverlayOnly); BOOL AttachPalette(); BOOL Wipe(); // empty to transparent diff --git a/standard/src/StdSurface2.cpp b/standard/src/StdSurface2.cpp index cd19fb9b7..27e27e6c1 100644 --- a/standard/src/StdSurface2.cpp +++ b/standard/src/StdSurface2.cpp @@ -493,7 +493,7 @@ IDirect3DSurface9 *CSurface::GetSurface() } #endif //USE_DIRECTX -bool CSurface::Read(CStdStream &hGroup, bool fOwnPal) +bool CSurface::ReadBMP(CStdStream &hGroup, bool fOwnPal) { int lcnt,iLineRest; CBitmap256Info BitmapInfo;