Changed: Minor changes

This commit is contained in:
kervala 2016-09-23 13:29:50 +02:00
parent 263bf36347
commit 1fe1079f2e

View file

@ -46,7 +46,7 @@ const uint32 posStep= 4;
// *************************************************************************** // ***************************************************************************
// Try all position to put pSrc in pDst // Try all position to put pSrc in pDst
bool tryAllPos (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 &x, sint32 &y) bool tryAllPos(NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 &x, sint32 &y)
{ {
uint32 i, j; uint32 i, j;
CObjectVector<uint8> &rSrcPix = pSrc->getPixels(); CObjectVector<uint8> &rSrcPix = pSrc->getPixels();
@ -86,7 +86,7 @@ bool tryAllPos (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 &x, sint32
} }
// *************************************************************************** // ***************************************************************************
void putPixel(uint8 *dst, uint8 *src, bool alphaTransfert) void putPixel(uint8 *dst, uint8 *src, bool alphaTransfert)
{ {
dst[0] = src[0]; dst[0] = src[0];
dst[1] = src[1]; dst[1] = src[1];
@ -98,7 +98,7 @@ void putPixel(uint8 *dst, uint8 *src, bool alphaTransfert)
} }
// *************************************************************************** // ***************************************************************************
bool putIn (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 x, sint32 y, bool alphaTransfert=true) bool putIn(NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 x, sint32 y, bool alphaTransfert=true)
{ {
uint8 *rSrcPix = &pSrc->getPixels()[0]; uint8 *rSrcPix = &pSrc->getPixels()[0];
uint8 *rDstPix = &pDst->getPixels()[0]; uint8 *rDstPix = &pDst->getPixels()[0];
@ -145,18 +145,17 @@ bool putIn (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 x, sint32 y, bo
} }
// *************************************************************************** // ***************************************************************************
string getBaseName (const string &fullname) string getBaseName(const string &fullname)
{ {
string sTmp2; string basename;
string::size_type pos = fullname.rfind('_'); string::size_type pos = fullname.rfind('_');
if (pos != string::npos) if (pos != string::npos) basename = fullname.substr(0, pos+1);
sTmp2 = fullname.substr(0, pos+1); return basename;
return sTmp2;
} }
// *************************************************************************** // ***************************************************************************
// resize the bitmap to the next power of 2 and preserve content // resize the bitmap to the next power of 2 and preserve content
void enlargeCanvas (NLMISC::CBitmap &b) void enlargeCanvas(NLMISC::CBitmap &b)
{ {
sint32 nNewWidth = b.getWidth(), nNewHeight = b.getHeight(); sint32 nNewWidth = b.getWidth(), nNewHeight = b.getHeight();
if (nNewWidth > nNewHeight) if (nNewWidth > nNewHeight)
@ -221,6 +220,7 @@ int main(int argc, char **argv)
outString(toString("ERROR: directory %s does not exist", sDir.c_str())); outString(toString("ERROR: directory %s does not exist", sDir.c_str()));
return -1; return -1;
} }
CPath::getPathContent(sDir, false, false, true, AllMapNames); CPath::getPathContent(sDir, false, false, true, AllMapNames);
} }
@ -238,7 +238,8 @@ int main(int argc, char **argv)
{ {
pBtmp = new NLMISC::CBitmap; pBtmp = new NLMISC::CBitmap;
NLMISC::CIFile inFile; NLMISC::CIFile inFile;
if (!inFile.open( AllMapNames[i] )) throw NLMISC::Exception("Unable to open " + AllMapNames[i]);
if (!inFile.open(AllMapNames[i])) throw NLMISC::Exception("Unable to open " + AllMapNames[i]);
uint8 colors = pBtmp->load(inFile); uint8 colors = pBtmp->load(inFile);
@ -288,6 +289,7 @@ int main(int argc, char **argv)
vector<NLMISC::CUV> UVMin, UVMax; vector<NLMISC::CUV> UVMin, UVMax;
UVMin.resize (mapSize, NLMISC::CUV(0.0f, 0.0f)); UVMin.resize (mapSize, NLMISC::CUV(0.0f, 0.0f));
UVMax.resize (mapSize, NLMISC::CUV(0.0f, 0.0f)); UVMax.resize (mapSize, NLMISC::CUV(0.0f, 0.0f));
for (sint i = 0; i < mapSize; ++i) for (sint i = 0; i < mapSize; ++i)
{ {
sint32 x, y; sint32 x, y;
@ -297,40 +299,20 @@ int main(int argc, char **argv)
enlargeCanvas (GlobalTexture); enlargeCanvas (GlobalTexture);
enlargeCanvas (GlobalMask); enlargeCanvas (GlobalMask);
} }
putIn (AllMaps[i], &GlobalTexture, x, y); putIn (AllMaps[i], &GlobalTexture, x, y);
putIn (AllMaps[i], &GlobalMask, x, y, false); putIn (AllMaps[i], &GlobalMask, x, y, false);
UVMin[i].U = (float)x; UVMin[i].U = (float)x;
UVMin[i].V = (float)y; UVMin[i].V = (float)y;
UVMax[i].U = (float)x+AllMaps[i]->getWidth(); UVMax[i].U = (float)x+AllMaps[i]->getWidth();
UVMax[i].V = (float)y+AllMaps[i]->getHeight(); UVMax[i].V = (float)y+AllMaps[i]->getHeight();
/* // Do not remove this is useful for debugging #if 0
{ // Do not remove this is useful for debugging
NLMISC::COFile outTga; writeFileDependingOnFilename(fmtName.substr(0, fmtName.rfind('.')) + "_txt.png", GlobalTexture);
string fmtName = ppArgs[1]; writeFileDependingOnFilename(fmtName.substr(0, fmtName.rfind('.')) + "_msk.png", GlobalMask);
if (fmtName.rfind('.') == string::npos) #endif
fmtName += ".tga";
if (outTga.open(fmtName))
{
GlobalTexture.writeTGA (outTga, 32);
outTga.close();
}
}
{
NLMISC::COFile outTga;
string fmtName = ppArgs[1];
if (fmtName.rfind('.') == string::npos)
fmtName += "_msk.tga";
else
fmtName = fmtName.substr(0,fmtName.rfind('.')) + "_msk.tga";
if (outTga.open(fmtName))
{
GlobalMask.writeTGA (outTga, 32);
outTga.close();
}
}*/
} }
// Convert UV from pixel to ratio // Convert UV from pixel to ratio
@ -369,10 +351,10 @@ int main(int argc, char **argv)
for (sint i = 0; i < mapSize; ++i) for (sint i = 0; i < mapSize; ++i)
{ {
// get the string whitout path // get the string whitout path
string fileName= CFile::getFilename(AllMapNames[i]); string fileName = CFile::getFilename(AllMapNames[i]);
fprintf (f, "%s %.12f %.12f %.12f %.12f\n", fileName.c_str(), UVMin[i].U, UVMin[i].V, fprintf (f, "%s %.12f %.12f %.12f %.12f\n", fileName.c_str(), UVMin[i].U, UVMin[i].V, UVMax[i].U, UVMax[i].V);
UVMax[i].U, UVMax[i].V);
} }
fclose (f); fclose (f);
outString(toString("Writing UV file %s", fmtName.c_str())); outString(toString("Writing UV file %s", fmtName.c_str()));
@ -387,7 +369,8 @@ int main(int argc, char **argv)
// Load existing uv file // Load existing uv file
CIFile iFile; CIFile iFile;
string filename = CPath::lookup (existingUVfilename, false); string filename = CPath::lookup (existingUVfilename, false);
if( (filename == "") || (!iFile.open(filename)) )
if( filename.empty() || !iFile.open(filename) )
{ {
outString(toString("ERROR: Unable to open %s", existingUVfilename.c_str())); outString(toString("ERROR: Unable to open %s", existingUVfilename.c_str()));
return -1; return -1;
@ -440,7 +423,6 @@ int main(int argc, char **argv)
UVMax[i].U, UVMax[i].V); UVMax[i].U, UVMax[i].V);
} }
} }
// fclose (iFile);
fclose (f); fclose (f);
outString(toString("Writing UV file: %s", fmtName.c_str())); outString(toString("Writing UV file: %s", fmtName.c_str()));
} }