summaryrefslogtreecommitdiff
path: root/ffx-convert.cpp
diff options
context:
space:
mode:
authorPixel <Pixel>2002-10-06 18:40:21 +0000
committerPixel <Pixel>2002-10-06 18:40:21 +0000
commit63585e0a059b5f86417b36052b0180b8dae0faca (patch)
treecbf5f199d352e478b0e55d958f3138414293a14c /ffx-convert.cpp
parentac538a2d1e822d121a604800f9e3877c227e1af4 (diff)
Humf...
Diffstat (limited to 'ffx-convert.cpp')
-rw-r--r--ffx-convert.cpp80
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