// NeL - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include
#include "nel/misc/file.h"
#include "nel/misc/bitmap.h"
#include "nel/misc/file.h"
#include "nel/misc/debug.h"
#include
using namespace NLMISC;
using namespace std;
#define TGA16 16
#define NOT_DEFINED 0xff
const int CutSize = 160;
const int SaveSize = 256;
void writeInstructions();
int main(int argc, char **argv);
// ***************************************************************************
bool getZoneNameFromXY (sint32 x, sint32 y, std::string &zoneName)
{
if ((y>0) || (y<-255) || (x<0) || (x>255))
return false;
zoneName = toString(-y) + "_";
zoneName += ('A' + (x/26));
zoneName += ('A' + (x%26));
return true;
}
void writeInstructions()
{
cout<"<>2;
}
}
}
// ***************************************************************************
int main(int argc, char **argv)
{
// Parse Command Line.
//====================
if(argc<2)
{
writeInstructions();
return 0;
}
if(!strcmp(argv[1],"/?"))
{
writeInstructions();
return 0;
}
if(!strcmp(argv[1],"-?"))
{
writeInstructions();
return 0;
}
if(argc != 2)
{
writeInstructions();
return 0;
}
// Reading TGA and converting to RGBA
//====================================
CBitmap picTga;
CBitmap picSrc;
std::string inputFileName(argv[1]);
NLMISC::CIFile input;
if(!input.open(inputFileName))
{
cerr<<"Can't open input file "< RGBASrc = picTga.getPixels();
CObjectVector RGBASrc2;
CObjectVector RGBADest;
RGBADest.resize(SaveSize*SaveSize*4);
uint dstRGBADestId= 0;
// Copy to the dest bitmap.
picSrc.resize(SaveSize, SaveSize, CBitmap::RGBA);
picSrc.getPixels(0) = RGBADest;
// Must be RGBA
nlassert (picSrc.getPixelFormat () == CBitmap::RGBA);
// Pointers
uint8 *pixelSrc = &(picTga.getPixels ()[0]);
uint8 *pixelDest = &(picSrc.getPixels ()[0]);
// clear the whole texture
for (sint y = 0;y < SaveSize;++y)
{
for (sint x = 0;x < SaveSize;++x)
{
pixelDest[(y*SaveSize+x)*4]=-1;
pixelDest[(y*SaveSize+x)*4+1]=-1;
pixelDest[(y*SaveSize+x)*4+2]=-1;
pixelDest[(y*SaveSize+x)*4+3]=-1;
}
}
// Resample
sint xzone, yzone;
for (yzone = int(yOrg/CutSize)*CutSize; yzone < yOrg+height; yzone += CutSize)
{
for (xzone = int(xOrg/CutSize)*CutSize; xzone < xOrg+width; xzone += CutSize)
{
sint x, y;
for (y=0; y= width || y+yzone-yOrg>=height || x+xzone-xOrg<0 || y+yzone-yOrg<0)
{
// black outside the bitmap
for (i=0; i<4; i++)
{
pixelDest[offsetDest+i] = 0;
}
}
else
{
const uint offsetSrc = ((y+yzone-yOrg)*width+x+xzone-xOrg)*4;
for (i=0; i<4; i++)
{
pixelDest[offsetDest+i] = pixelSrc[offsetSrc+i];
}
}
}
}
#if 0
// if we don't want to save the empty pictures (useless now)
int empty = 1;
for (y = 0;y < CutSize;++y)
{
for (x=0;x