~ndiddy/satconv

df959258cf3e4caac694f83e507817e8820be4e8 — Nathan Misner 2 years ago bdfec82 master
added support for 1 word tiles
5 files changed, 39 insertions(+), 11 deletions(-)

M readme.txt
M satconv
M satconv.c
M tile.c
M tile.h
M readme.txt => readme.txt +8 -4
@@ 15,9 15,12 @@ m42 map.tmx: Converts map.tmx (Tiled XML) to a .map file (4bpp graphics and 2 wo
m81 map.tmx: Converts map.tmx (Tiled XML) to a .map file (8bpp graphics and SCL_PN_10BIT format)
m82 map.tmx: Converts map.tmx (Tiled XML) to a .map file (8bpp graphics and 2 word format)

t0 file.bmp: Converts file.bmp to a framebuffer graphics file
t1 file.bmp: Converts file.bmp to a .tle file (8x8 tile size)
t2 file.bmp: Converts file.bmp to a .tle file (16x16 tile size)
t01 file.bmp: Converts file.bmp to a framebuffer graphics file (1 word palette)
t02 file.bmp: Converts file.bmp to a framebuffer graphics file (2 word palette)
t11 file.bmp: Converts file.bmp to a .tle file (8x8 tile size) (1 word palette)
t12 file.bmp: Converts file.bmp to a .tle file (8x8 tile size) (2 word palette)
t21 file.bmp: Converts file.bmp to a .tle file (16x16 tile size) (1 word palette)
t22 file.bmp: Converts file.bmp to a .tle file (16x16 tile size) (2 word palette)

---palette spr file format---
4 bytes: 0x0000


@@ 45,6 48,7 @@ n bytes: map data

---tle file format---
4 bytes: palette length
4 bytes: palette data type (1 or 2)
n bytes: palette
4 bytes: image size
n bytes: image data 


@@ 92,4 96,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
\ No newline at end of file
THE SOFTWARE.

M satconv => satconv +0 -0
M satconv.c => satconv.c +3 -3
@@ 81,12 81,12 @@ int main(int argc, char **argv) {
			// tile graphics
			case 't':
			case 'T':
				infile = &line[3];
				infile = &line[4];
				ext = strchr(infile, '.');
				ext_index = MIN(8, ext - infile);
				memcpy(outfile, infile, ext_index);
				strcpy(outfile + ext_index, ".tle");
				tile_process(infile, outfile, line[1] - ASCII_NUMBER_BASE);
				tile_process(infile, outfile, line[1] - ASCII_NUMBER_BASE, line[2] - ASCII_NUMBER_BASE);
				break;
			
			// tilemap


@@ 108,4 108,4 @@ int main(int argc, char **argv) {
	
	fclose(asset_list);
	return 0;
}
\ No newline at end of file
}

M tile.c => tile.c +27 -3
@@ 45,7 45,29 @@ int tile_read(BMP *image, uint8_t *buffer, int width, int height, int start_x, i
	return 1;
}

int tile_process(char *filename, char *outname, int type) {
void tile_writepalette(FILE *file, uint32_t *palette, int words, int len) {
    if (words == 2) {
        fwrite(palette, sizeof(uint32_t), len, file);
    }
    else {
        uint16_t *tempPalette = malloc(len * sizeof(uint16_t));
        uint32_t color;
        uint8_t r, g, b;
        for (int i = 0; i < len; i++) {
            color = ntohl(palette[i]);
            r = (color & 0xff) >> 3;
            g = ((color >> 8) & 0xff) >> 3;
            b = ((color >> 16) & 0xff) >> 3;
            tempPalette[i] = r | (g << 5) | (b << 10) | 0x8000;
            tempPalette[i] = htons(tempPalette[i]);
        }
        fwrite(tempPalette, sizeof(uint16_t), len, file);
        free(tempPalette);
    }

}

int tile_process(char *filename, char *outname, int type, int palwords) {
	BMP *infile = BMP_ReadFile(filename);
	BMP_CHECK_ERROR(stdout, 0);
	int width = BMP_GetWidth(infile);


@@ 197,7 219,9 @@ int tile_process(char *filename, char *outname, int type) {
	}
	uint32_t out_palsize = htonl(palsize);
	fwrite(&out_palsize, sizeof(uint32_t), 1, outfile);
	fwrite(palette, sizeof(uint32_t), palsize, outfile);
    uint32_t out_palwords = htonl(palwords);
    fwrite(&out_palwords, sizeof(uint32_t), 1, outfile);
    tile_writepalette(outfile, palette, palwords, palsize);
	uint32_t out_image_data_size = htonl(image_data_size);
	fwrite(&out_image_data_size, sizeof(uint32_t), 1, outfile);
	fwrite(image_data, sizeof(uint8_t), image_data_size, outfile);


@@ 213,4 237,4 @@ ERR_EXIT:
	free(image_data);
	BMP_Free(infile);
	return 0;
}
\ No newline at end of file
}

M tile.h => tile.h +1 -1
@@ 26,6 26,6 @@ typedef enum {
	TILE_16x16,
} TILE_TYPE;

int tile_process(char *filename, char *outname, int type);
int tile_process(char *filename, char *outname, int type, int palwords);

#endif