Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / 3d / tga_resize / main.cpp
blob17cd16d616653ecd5711e19e2fd46319f1f248dc
3 #include "nel/misc/bitmap.h"
4 #include "nel/misc/file.h"
5 #include <vector>
8 using namespace NLMISC;
9 using namespace std;
12 void usage()
14 printf("Usage: tga_resize tgaFileIn tgaFileOut divideRatio.\n \
15 eg: tga_resize pipo.tga pipo.tga 2\n \
16 => pipo.tga widht and height are divided by 2 \n\n");
21 int main(int argc, char *argv[])
23 if(argc != 4)
25 usage();
26 return -1;
28 else
30 CBitmap btmp;
31 CIFile inFile;
32 COFile outFile;
34 uint divideRatio;
35 NLMISC::fromString(argv[3], divideRatio);
36 if(divideRatio==0 || !isPowerOf2(divideRatio))
38 printf("divideRatio must be a powerOf2 (1, 2, 4, 8 ...) \n");
39 return 0;
42 try
44 // read.
45 if (!inFile.open(argv[1]))
47 printf("Can't open input file %s \n", argv[1]);
48 return -1;
50 uint8 depth= btmp.load(inFile);
51 if(depth==0)
52 throw Exception("Bad File Format");
53 inFile.close();
55 // resize.
56 btmp.resample(btmp.getWidth() / divideRatio, btmp.getHeight() / divideRatio);
58 // output.
59 if (!outFile.open(argv[2]))
61 printf("Can't open output file %s \n", argv[2]);
62 return -1;
64 btmp.writeTGA(outFile, depth);
66 catch (const Exception &e)
68 printf("Error: %s\n", e.what());
69 return -1;
72 return 0;