diff options
Diffstat (limited to 'ffx-convert.cpp')
-rw-r--r-- | ffx-convert.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/ffx-convert.cpp b/ffx-convert.cpp new file mode 100644 index 0000000..0fa6818 --- /dev/null +++ b/ffx-convert.cpp @@ -0,0 +1,80 @@ +#include <unistd.h> +#include "generic.h" +#include "Main.h" +#include "Image.h" +#include "Input.h" +#include "Output.h" + +#define IMG_SX 256 +#define IMG_SY 256 + +#define BLOC_SX 16 +#define BLOC_SY 8 + +CODE_BEGINS + +Color LookUp(char i) { + return Color(i << 4, i << 4, i << 4, 255); +} + +int transform(int x, int y) { + int numero_bloc_x = x / BLOC_SX; + int numero_bloc_y = y / BLOC_SY; + + int numero_bloc = numero_bloc_y * (IMG_SX / BLOC_SX) + numero_bloc_x; + + int bx = x % BLOC_SX; + int by = y % BLOC_SY; + + return numero_bloc * BLOC_SX * BLOC_SY + by * BLOC_SX + bx; +} + +virtual int startup() throw (GeneralException) { + int c; + + while ((c = getopt(argc, argv, "")) != EOF) { + switch (c) { + default: + printm(M_ERROR, "Unknow option: %c\n", c); + throw Exit(-1); + } + } + + if ((argc - optind) != 2) { + printm(M_ERROR, "Need two arguments\n"); + throw Exit(-1); + } + + Input * map = new Input(argv[optind]); + Output * tga = new Output(argv[optind + 1]); + Image * img = new Image(IMG_SX, IMG_SY); + + map->seek(0x140); + + char buffer[65536]; + + Byte b; + + for (int i = 0; i < 32768; i++) { + int j = i << 1; + map->read(&b, 1); + buffer[j] = b & 0x0f; + buffer[j + 1] = (b & 0xf0) >> 4; + } + + img->Fill(); + + for (int y = 0; y < IMG_SX; y++) { + for (int x = 0; x < IMG_SY; x++) { + img->SetPixel(x, y, LookUp(buffer[transform(x, y)])); + } + } + + img->Prepare(FORMAT_TGA_BASIC); + + copy(img, tga); + + return 0; +} + +CODE_ENDS |