# HG changeset patch # User John Tsiombikas # Date 1403709592 -10800 # Node ID c359fcbd2422e4361a1d4063d26a7e50296fc9c7 initial commit diff -r 000000000000 -r c359fcbd2422 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Jun 25 18:19:52 2014 +0300 @@ -0,0 +1,8 @@ +\.o$ +\.d$ +\.swp$ +\.png$ +\.jpg$ +\.ppm$ +\.tga$ +img2gba$ diff -r 000000000000 -r c359fcbd2422 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Jun 25 18:19:52 2014 +0300 @@ -0,0 +1,20 @@ +PREFIX = /usr/local + +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +bin = img2gba + +CFLAGS = -pedantic -Wall -g +LDFLAGS = -limago + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + + +.PHONY: clean +clean: + rm $(obj) $(bin) + +.PHONY: install +install: + cp $(bin) $(DESTDIR)$(PREFIX)/bin/$(bin) diff -r 000000000000 -r c359fcbd2422 src/imgconv.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/imgconv.c Wed Jun 25 18:19:52 2014 +0300 @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +int save_image15(unsigned int *img, int x, int y, const char *fname, const char *array_name); + +int main(int argc, char **argv) +{ + int i; + + if(argc < 2) { + fprintf(stderr, "not enough arguments\n"); + return -1; + } + + for(i=1; i> 16) & 0xff) +#define GET_G(pixel) (((pixel) >> 8) & 0xff) +#define GET_B(pixel) (((pixel) >> 0) & 0xff) + +#define PACK_COLOR15(r, g, b) ((((r) & 0x1f) << 10) | (((g) & 0x1f) << 5) | ((b) & 0x1f)) + +int save_image15(unsigned int *img, int x, int y, const char *fname, const char *array_name) +{ + int i, j; + FILE *fp; + + if(!(fp = fopen(fname, "w"))) { + return -1; + } + + fprintf(fp, "\nconst unsigned short %s[] = {\n", array_name); + + for(j=0; j> 3; + unsigned short g = GET_G(*img) >> 3; + unsigned short b = GET_B(*img) >> 3; + unsigned short pixel15 = PACK_COLOR15(r, g, b); + fprintf(fp, "%u", pixel15); + if(i < x-1 || j < y-1) { + fprintf(fp, ", "); + } + img++; + } + fprintf(fp, "\n"); + } + + fprintf(fp, "};\n"); + + fclose(fp); + return 0; +}