Fixed: tga2dds compilation under Linux

This commit is contained in:
kervala 2010-08-30 17:41:53 +02:00
parent 47b3d5ce60
commit 06ec6effa8
2 changed files with 55 additions and 57 deletions

View file

@ -43,8 +43,8 @@
#define DDSCAPS_MIPMAP 0x00400000l #define DDSCAPS_MIPMAP 0x00400000l
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \ #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \ ((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \
((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 )) ((uint32)(uint8)(ch2) << 16) | ((uint32)(uint8)(ch3) << 24 ))
#endif #endif

View file

@ -54,8 +54,19 @@ uint8 getType(const char *sFileNameDest)
return NOT_DEFINED; return NOT_DEFINED;
} }
CS3TCCompressor::DDS_HEADER h; 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)) if(fclose(f))
{ {
cerr<<sFileNameDest<< "is not closed"<<endl; cerr<<sFileNameDest<< "is not closed"<<endl;
@ -94,9 +105,21 @@ bool sameType(const char *sFileNameDest, uint8 &algo, bool wantMipMap)
{ {
return false; return false;
} }
CS3TCCompressor::DDS_HEADER h; 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)) if(fclose(f))
{ {
cerr<<sFileNameDest<< "is not closed"<<endl; cerr<<sFileNameDest<< "is not closed"<<endl;
@ -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) 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); uint32 lastWriteTime1 = CFile::getFileModificationDate(sFileNameSrc);
if(h1 == INVALID_HANDLE_VALUE)
if (!lastWriteTime1)
{ {
cerr<<"Can't open file "<<sFileNameSrc<<endl; cerr<<"Can't open file "<<sFileNameSrc<<endl;
return 1; return false;
} }
HANDLE h2 = CreateFile( sFileNameDest, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); uint32 lastWriteTime2 = CFile::getFileModificationDate(sFileNameDest);
if (h2==INVALID_HANDLE_VALUE)
if (!lastWriteTime2)
{ {
return false; // destination file doesn't exist yet return false; // destination file doesn't exist yet
} }
uint8 res; if(lastWriteTime1 > lastWriteTime2)
FILETIME Tmp;
FILETIME lpLastWriteTime1;
FILETIME lpLastWriteTime2;
res = GetFileTime(h1, &Tmp, &Tmp, &lpLastWriteTime1);
nlassert(res);
res = GetFileTime(h2, &Tmp, &Tmp, &lpLastWriteTime2);
nlassert(res);
uint32 nComp = CompareFileTime(&lpLastWriteTime1, &lpLastWriteTime2);
CloseHandle(h1);
CloseHandle(h2);
if(nComp==+1)
{ {
return false; return false;
} }
if(nComp==-1) if (lastWriteTime1 < lastWriteTime2)
{ {
if(!sameType(sFileNameDest, algo, wantMipMap)) if(!sameType(sFileNameDest, algo, wantMipMap))
{ {
return false; // file exists but a new compression type is required return false; // file exists but a new compression type is required
} }
return true;
} }
return true; return true;
} }
void writeInstructions() void writeInstructions()
{ {
cout<<endl; cout<<endl;
@ -379,14 +386,12 @@ int main(int argc, char **argv)
return 0; return 0;
} }
// Reading TGA or PNG and converting to RGBA // Reading TGA or PNG and converting to RGBA
//==================================== //====================================
CBitmap picTga; CBitmap picTga;
CBitmap picTga2; CBitmap picTga2;
CBitmap picSrc; CBitmap picSrc;
std::string inputFileName(argv[1]); std::string inputFileName(argv[1]);
if(inputFileName.find("_usercolor")<inputFileName.length()) if(inputFileName.find("_usercolor")<inputFileName.length())
{ {
@ -456,9 +461,6 @@ int main(int argc, char **argv)
RGBADest.resize(height*width*4); RGBADest.resize(height*width*4);
uint dstRGBADestId= 0; uint dstRGBADestId= 0;
// UserColor // UserColor
//=========== //===========
/* /*
@ -496,7 +498,6 @@ int main(int argc, char **argv)
userColorFileName = inputFileName.substr(0,pos) + "_usercolor" + inputFileName.substr(pos); userColorFileName = inputFileName.substr(0,pos) + "_usercolor" + inputFileName.substr(pos);
} }
// Reading second Tga for user color, don't complain if _usercolor is missing // Reading second Tga for user color, don't complain if _usercolor is missing
NLMISC::CIFile input2; NLMISC::CIFile input2;
if (CPath::exists(userColorFileName) && input2.open(userColorFileName)) if (CPath::exists(userColorFileName) && input2.open(userColorFileName))
@ -508,8 +509,6 @@ int main(int argc, char **argv)
nlassert(height2==height); nlassert(height2==height);
picTga2.convertToType (CBitmap::RGBA); picTga2.convertToType (CBitmap::RGBA);
RGBASrc2 = picTga2.getPixels(); RGBASrc2 = picTga2.getPixels();
NLMISC::CRGBA *pRGBASrc = (NLMISC::CRGBA*)&RGBASrc[0]; NLMISC::CRGBA *pRGBASrc = (NLMISC::CRGBA*)&RGBASrc[0];
@ -638,7 +637,6 @@ int main(int argc, char **argv)
} }
output.close(); output.close();
} }
else else
{ {