From bd9c9c7836749fd0695c31393a7423fdc11c3245 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 30 Aug 2010 17:41:53 +0200 Subject: [PATCH] Fixed: tga2dds compilation under Linux --- .../3d/s3tc_compressor_lib/s3tc_compressor.h | 4 +- code/nel/tools/3d/tga_2_dds/tga2dds.cpp | 108 +++++++++--------- 2 files changed, 55 insertions(+), 57 deletions(-) diff --git a/code/nel/tools/3d/s3tc_compressor_lib/s3tc_compressor.h b/code/nel/tools/3d/s3tc_compressor_lib/s3tc_compressor.h index 33c819fcc..dde40428c 100644 --- a/code/nel/tools/3d/s3tc_compressor_lib/s3tc_compressor.h +++ b/code/nel/tools/3d/s3tc_compressor_lib/s3tc_compressor.h @@ -43,8 +43,8 @@ #define DDSCAPS_MIPMAP 0x00400000l #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ - ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ - ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 )) + ((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \ + ((uint32)(uint8)(ch2) << 16) | ((uint32)(uint8)(ch3) << 24 )) #endif diff --git a/code/nel/tools/3d/tga_2_dds/tga2dds.cpp b/code/nel/tools/3d/tga_2_dds/tga2dds.cpp index c36906f75..41a0ca9f6 100644 --- a/code/nel/tools/3d/tga_2_dds/tga2dds.cpp +++ b/code/nel/tools/3d/tga_2_dds/tga2dds.cpp @@ -54,8 +54,19 @@ uint8 getType(const char *sFileNameDest) return NOT_DEFINED; } CS3TCCompressor::DDS_HEADER h; - fread(&dds,1,4,f); - fread(&h,sizeof(CS3TCCompressor::DDS_HEADER),1,f); + + if (fread(&dds,1,4,f) != 4) + { + fclose(f); + return NOT_DEFINED; + } + + if (fread(&h,sizeof(CS3TCCompressor::DDS_HEADER),1,f) != 1) + { + fclose(f); + return NOT_DEFINED; + } + if(fclose(f)) { cerr<0) { return DXT1A; } - + if(h.ddpf.dwFourCC==MAKEFOURCC('D','X', 'T', '3')) { return DXT3; @@ -94,9 +105,21 @@ bool sameType(const char *sFileNameDest, uint8 &algo, bool wantMipMap) { return false; } + CS3TCCompressor::DDS_HEADER h; - fread(&dds,1,4,f); - fread(&h,sizeof(::DDS_HEADER),1,f); + + if (fread(&dds,1,4,f) != 4) + { + fclose(f); + return false; + } + + if (fread(&h,sizeof(::DDS_HEADER),1,f) != 1) + { + fclose(f); + return false; + } + if(fclose(f)) { cerr<0) algoOk=true; break; - + case DXT3: if(h.ddpf.dwFourCC==MAKEFOURCC('D','X', 'T', '3')) algoOk=true; @@ -129,7 +152,7 @@ bool sameType(const char *sFileNameDest, uint8 &algo, bool wantMipMap) } if(!algoOk) return false; - + // Test Mipmap. bool fileHasMipMap= (h.dwFlags&DDSD_MIPMAPCOUNT) && (h.dwMipMapCount>1); if(fileHasMipMap==wantMipMap) @@ -142,51 +165,35 @@ bool sameType(const char *sFileNameDest, uint8 &algo, bool wantMipMap) bool dataCheck(const char *sFileNameSrc, const char *sFileNameDest, uint8& algo, bool wantMipMap) { - HANDLE h1 = CreateFile( sFileNameSrc, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if(h1 == INVALID_HANDLE_VALUE) + uint32 lastWriteTime1 = CFile::getFileModificationDate(sFileNameSrc); + + if (!lastWriteTime1) { cerr<<"Can't open file "< lastWriteTime2) { return false; } - if(nComp==-1) + if (lastWriteTime1 < lastWriteTime2) { if(!sameType(sFileNameDest, algo, wantMipMap)) { return false; // file exists but a new compression type is required } - return true; } return true; } - void writeInstructions() { cout< [-o ] [-a ] [-m]"<>2; } } @@ -379,14 +386,12 @@ int main(int argc, char **argv) return 0; } - // Reading TGA or PNG and converting to RGBA //==================================== CBitmap picTga; CBitmap picTga2; CBitmap picSrc; - std::string inputFileName(argv[1]); if(inputFileName.find("_usercolor") RGBADest; RGBADest.resize(height*width*4); uint dstRGBADestId= 0; - - - // UserColor //=========== @@ -488,15 +490,14 @@ int main(int argc, char **argv) if (pos == std::string::npos) { // name whithout extension - userColorFileName = inputFileName + "_usercolor"; + userColorFileName = inputFileName + "_usercolor"; } else { // append input filename extension userColorFileName = inputFileName.substr(0,pos) + "_usercolor" + inputFileName.substr(pos); } - - + // Reading second Tga for user color, don't complain if _usercolor is missing NLMISC::CIFile input2; if (CPath::exists(userColorFileName) && input2.open(userColorFileName)) @@ -508,8 +509,6 @@ int main(int argc, char **argv) nlassert(height2==height); picTga2.convertToType (CBitmap::RGBA); - - RGBASrc2 = picTga2.getPixels(); NLMISC::CRGBA *pRGBASrc = (NLMISC::CRGBA*)&RGBASrc[0]; @@ -519,7 +518,7 @@ int main(int argc, char **argv) { // If no UserColor, must take same RGB, and keep same Alpha from src1 !!! So texture can have both alpha // userColor and other alpha usage. - if(pRGBASrc2[i].A==255) + if(pRGBASrc2[i].A==255) { RGBADest[dstRGBADestId++]= pRGBASrc[i].R; RGBADest[dstRGBADestId++]= pRGBASrc[i].G; @@ -610,12 +609,12 @@ int main(int argc, char **argv) cerr<<"Can't open output file "<