#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; */ return y * IMG_SX + x; } 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; } */ for (int i = 0; i < 65536; i++) { map->read(&b, 1); buffer[i] = b; } 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