this here is the part where i run out of skills really...
i have no idea how the pixel tiles are structured and whatnot,
graphics editing im decent at, but graphics formats, i really have no clue about, hence i believe i can no longer be of any further assistance myself.
(which is why i asked for help to begin with.)
in any case, here's a tiny bit of code that allows taking the raw data out of the example file, and aligning it so that it works.
a freind of mine, Paulguy wrote this for me as an attempt to get closer to how these files are built, but i never actually tested it as i dont have a compiler handy.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#define TILE_WIDTH (16)
#define TILE_HEIGHT (8)
int main(int argc, char **argv) {
int offset, width, height, paloffset;
long filesize;
FILE *infile;
char buffer[TILE_WIDTH];
char palbuffer[1024];
int i, j, k;
if(argc < 6) {
fprintf(stderr, "USAGE: %s <filename> <offset> <width> <height> <paloffset>\n"\
"\tOutput goes to standard output.\n", argv[0]);
exit(EXIT_FAILURE);
}
offset = atoi(argv[2]);
width = atoi(argv[3]);
height = atoi(argv[4]);
paloffset = atoi(argv[5]);
if(offset < 0) {
fprintf(stderr, "Offset must be positive.\n");
exit(EXIT_FAILURE);
}
if(width < TILE_WIDTH || width % TILE_WIDTH != 0) {
fprintf(stderr, "Width must be greater than 0 and a multiple of %i.", TILE_WIDTH);
exit(EXIT_FAILURE);
}
if(height < TILE_HEIGHT || height % TILE_HEIGHT != 0) {
fprintf(stderr, "Height must be greater than 0 and a multiple of %i.", TILE_HEIGHT);
exit(EXIT_FAILURE);
}
infile = fopen(argv[1], "r");
if(infile == NULL) {
fprintf(stderr, "Failed to open %s.", argv[1]);
exit(EXIT_FAILURE);
}
fseek(infile, 0, SEEK_END);
filesize = ftell(infile);
fseek(infile, 0, SEEK_SET);
if(width * height + offset > filesize) {
fprintf(stderr, "Read with set width(%i), height(%i) and offset(%i) would go past the end of the file.\n", width, height, offset);
fclose(infile);
exit(EXIT_FAILURE);
}
if(paloffset < 0 || paloffset + 1024 > filesize) {
fprintf(stderr, "Palette offset must be a positive value and within 1024 bytes from the end of the file.\n");
fclose(infile);
exit(EXIT_FAILURE);
}
for(i = 0; i < height; i += TILE_HEIGHT) {
for(j = 0; j < TILE_HEIGHT; j++) {
for(k = 0; k < width; k += TILE_WIDTH) {
fseek(infile, offset + (i * width) + (j * TILE_WIDTH) + (k * TILE_HEIGHT), SEEK_SET);
fread(buffer, TILE_WIDTH, 1, infile);
fwrite(buffer, TILE_WIDTH, 1, stdout);
}
}
}
fseek(infile, paloffset, SEEK_SET);
fread(palbuffer, 1024, 1, infile);
fwrite(palbuffer, 1024, 1, stdout);
fprintf(stderr, "Palette written to %i.\n", width * height);
fclose(infile);
exit(EXIT_SUCCESS);
}
this bit of code realigns the data so that it can be displayed correctly with conventional means.
another piece of code below, encodes back to tiled format. Again, not tested by me as i still dont have a compiler set up.
i dont see the guy much who writes these so i never had the chance to ask how exactly they do their job, but as far as i understood, they take the raw pixel data and just realign it.
here's what he wrote:
- I wrote the program that can encode back in to the tiled format.
- but it still doesn't work with any image format.
- it'll work on the output of the original decoder.
- if you know the palette and data offsets of a TGA it should just work as-is though.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#define TILE_WIDTH (16)
#define TILE_HEIGHT (8)
int main(int argc, char **argv) {
int offset, width, height, paloffset;
long filesize;
FILE *infile;
char buffer[TILE_WIDTH];
char palbuffer[1024];
int i, j, k;
if(argc < 6) {
fprintf(stderr, "USAGE: %s <filename> <offset> <width> <height> <paloffset>\n"\
"\tOutput goes to standard output.\n", argv[0]);
exit(EXIT_FAILURE);
}
offset = atoi(argv[2]);
width = atoi(argv[3]);
height = atoi(argv[4]);
paloffset = atoi(argv[5]);
if(offset < 0) {
fprintf(stderr, "Offset must be positive.\n");
exit(EXIT_FAILURE);
}
if(width < TILE_WIDTH || width % TILE_WIDTH != 0) {
fprintf(stderr, "Width must be greater than 0 and a multiple of %i.", TILE_WIDTH);
exit(EXIT_FAILURE);
}
if(height < TILE_HEIGHT || height % TILE_HEIGHT != 0) {
fprintf(stderr, "Height must be greater than 0 and a multiple of %i.", TILE_HEIGHT);
exit(EXIT_FAILURE);
}
infile = fopen(argv[1], "r");
if(infile == NULL) {
fprintf(stderr, "Failed to open %s.", argv[1]);
exit(EXIT_FAILURE);
}
fseek(infile, 0, SEEK_END);
filesize = ftell(infile);
fseek(infile, 0, SEEK_SET);
if(width * height + offset > filesize) {
fprintf(stderr, "Read with set width(%i), height(%i) and offset(%i) would go past the end of the file.\n", width, height, offset);
fclose(infile);
exit(EXIT_FAILURE);
}
if(paloffset < 0 || paloffset + 1024 > filesize) {
fprintf(stderr, "Palette offset must be a positive value and within 1024 bytes from the end of the file.\n");
fclose(infile);
exit(EXIT_FAILURE);
}
for(i = 0; i < height; i += TILE_HEIGHT) {
for(j = 0; j < width; j += TILE_WIDTH) {
for(k = 0; k < TILE_HEIGHT; k++) {
fseek(infile, offset + (i * width) + j + (k * width), SEEK_SET);
fread(buffer, TILE_WIDTH, 1, infile);
fwrite(buffer, TILE_WIDTH, 1, stdout);
}
}
}
fseek(infile, paloffset, SEEK_SET);
fread(palbuffer, 1024, 1, infile);
fwrite(palbuffer, 1024, 1, stdout);
fprintf(stderr, "Palette written to %i.\n", width * height);
fclose(infile);
exit(EXIT_SUCCESS);
}
hopefully it'll be of assistance.
i am currently examining wiht him the possibility to convert to a 256-color TGA with an RGBA palette (ps2 graphics artists tool supports this format, even though i failed to get it to display right on paint shop pro and photoshop)
we chose the TGA as target format due to it's significant similarity to the "corrected" TPL file.