From af94a88e5de76c4b00df102f82643b4b64cb529a Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 26 Jul 2018 19:35:16 +0300 Subject: [PATCH] conv_sprite tool --- tools/conv_sprite | 13 ++++++++ tools/conv_sprite.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100755 tools/conv_sprite create mode 100644 tools/conv_sprite.c diff --git a/tools/conv_sprite b/tools/conv_sprite new file mode 100755 index 0000000..c05deb7 --- /dev/null +++ b/tools/conv_sprite @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "pass the sprite header file as argument" + exit 1 +fi + +cc -pedantic -Wall -DHDRFILE=\"$1\" -o /tmp/conv_sprite.bin conv_sprite.c +if [ $? != 0 ]; then + exit 1 +fi + +/tmp/conv_sprite.bin diff --git a/tools/conv_sprite.c b/tools/conv_sprite.c new file mode 100644 index 0000000..ff50a6a --- /dev/null +++ b/tools/conv_sprite.c @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include HDRFILE + +#define MAX_SPRITE_WIDTH 16 + +static void conv_sprite(int slice, unsigned char *img, int width, int height, int pitch); +static void conv_img_data(int sub, uint16_t *out, unsigned char *img, int width, + int height, int pitch); + +int main(int argc, char **argv) +{ + int i, nslices; + + nslices = (width + MAX_SPRITE_WIDTH - 1) / MAX_SPRITE_WIDTH; + fprintf(stderr, "source image: %dx%d. splitting into %d slices\n", + width, height, nslices); + + printf("\t.data\n\n"); + + for(i=0; i MAX_SPRITE_WIDTH) spr_w = MAX_SPRITE_WIDTH; + + conv_sprite(i, header_data + xstart, spr_w, height, width); + } + + printf("\n\t.global sprpal\n"); + printf("sprpal:\n"); + for(i=0; i<16; i++) { + int r = header_data_cmap[i][0] >> 4; + int g = header_data_cmap[i][1] >> 4; + int b = header_data_cmap[i][2] >> 4; + unsigned int col = ((r & 0xf) << 8) | ((g & 0xf) << 4) | (b & 0xf); + printf("\t.short 0x%03x\n", col); + } +} + +static void conv_sprite(int slice, unsigned char *img, int width, int height, int pitch) +{ + int i, j; + uint16_t *sprdata; + + for(i=0; i<2; i++) { + printf("\n\t.global spr%d%c\n", slice, i == 0 ? 'a' : 'b'); + printf("spr%d%c:\n", slice, i == 0 ? 'a' : 'b'); + printf("\t.short 0\n"); /* position x/y */ + printf("\t.short 0\n"); /* vstop */ + + sprdata = malloc(height * 2 * sizeof *sprdata); + conv_img_data(i, sprdata, img, width, height, pitch); + + for(j=0; j> inshift) & 1); + bit1 = (bit1 << 1) | ((img[j] >> (inshift + 1)) & 1); + } + if(width < MAX_SPRITE_WIDTH) { + bit0 <<= MAX_SPRITE_WIDTH - width; + bit1 <<= MAX_SPRITE_WIDTH - width; + } + *out++ = bit0; + *out++ = bit1; + img += pitch; + } +} + -- 1.7.10.4