From 63585e0a059b5f86417b36052b0180b8dae0faca Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 6 Oct 2002 18:40:21 +0000 Subject: Humf... --- ffx-convert.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 ffx-convert.cpp (limited to 'ffx-convert.cpp') 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 +#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 -- cgit v1.2.3