# HG changeset patch # User John Tsiombikas # Date 1509276071 -7200 # Node ID 4c36d0f44aa6d99a0a50b429f03f6d48397db932 # Parent ae0ada629b037eec53ab948d4e21cbb69cb5c488 lbm loading diff -r ae0ada629b03 -r 4c36d0f44aa6 Makefile --- a/Makefile Fri Oct 27 15:42:58 2017 +0300 +++ b/Makefile Sun Oct 29 13:21:11 2017 +0200 @@ -1,5 +1,6 @@ src = $(wildcard src/*.c) obj = $(src:.c=.o) +dep = $(obj:.o=.d) bin = imgv CC = vc @@ -17,6 +18,17 @@ $(bin): $(obj) $(CC) -o $@ $(obj) $(LDFLAGS) +ifneq ($(CC), vc) +-include $(dep) +endif + +%.d: %.c + @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ + .PHONY: clean clean: rm -f $(obj) $(bin) + +.PHONY: cleandep +cleandep: + rm -f $(dep) diff -r ae0ada629b03 -r 4c36d0f44aa6 src/endian.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/endian.c Sun Oct 29 13:21:11 2017 +0200 @@ -0,0 +1,58 @@ +#include "endian.h" + +#ifdef NO_INET +static uint32_t init_once32(uint32_t x); +static uint16_t init_once16(uint16_t x); + +static uint16_t swap16(uint16_t x); +static uint32_t swap32(uint32_t x); +static uint16_t nop16(uint16_t x); +static uint32_t nop32(uint32_t x); + +uint16_t (*ntohs)(uint16_t) = init_once16; +uint16_t (*htons)(uint16_t) = init_once16; +uint32_t (*ntohl)(uint32_t) = init_once32; +uint32_t (*htonl)(uint32_t) = init_once32; + +static uint16_t init_once16(uint16_t x) +{ + int be = bigendian(); + ntohs = be ? nop16 : swap16; + htons = be ? nop16 : swap16; + return ntohs(x); +} + +static uint32_t init_once32(uint32_t x) +{ + int be = bigendian(); + ntohl = be ? nop32 : swap32; + htonl = be ? nop32 : swap32; + return ntohl(x); +} + +static uint16_t swap16(uint16_t x) +{ + return (x << 8) | (x >> 8); +} + +static uint32_t swap32(uint32_t x) +{ + return (x << 24) | (x >> 24) | ((x << 16) & 0xff0000) | ((x >> 16) & 0xff00); +} + +static uint16_t nop16(uint16_t x) +{ + return x; +} + +static uint32_t nop32(uint32_t x) +{ + return x; +} +#endif + +int bigendian(void) +{ + static const uint16_t x = 0xaabb; + return *(unsigned char*)&x == 0xaa; +} diff -r ae0ada629b03 -r 4c36d0f44aa6 src/endian.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/endian.h Sun Oct 29 13:21:11 2017 +0200 @@ -0,0 +1,20 @@ +#ifndef ENDIAN_H_ +#define ENDIAN_H_ + +#if defined(__unix__) || defined(__APPLE__) +#include +#elif defined(WIN32) +#include +#else +#define NO_INET +#include "inttypes.h" + +extern uint16_t (*ntohs)(uint16_t); +extern uint16_t (*htons)(uint16_t); +extern uint32_t (*ntohl)(uint32_t); +extern uint32_t (*htonl)(uint32_t); +#endif + +int bigendian(void); + +#endif /* ENDIAN_H_ */ diff -r ae0ada629b03 -r 4c36d0f44aa6 src/image.c --- a/src/image.c Fri Oct 27 15:42:58 2017 +0300 +++ b/src/image.c Sun Oct 29 13:21:11 2017 +0200 @@ -4,17 +4,7 @@ #include #include "image.h" #include "logger.h" - -#ifdef __unix__ -#include -#define HAVE_NTOHS -#else -static int bigendian(void); -static uint16_t swap16(uint16_t x); -static uint16_t nop16(uint16_t x); -static uint16_t (*ntohs)(uint16_t); -#endif - +#include "endian.h" #ifdef __GNUC__ #define PACKED __attribute__((packed)) @@ -39,10 +29,6 @@ struct palchange *tail = 0; FILE *fp; -#ifndef HAVE_NTOHS - ntohs = bigendian() ? nop16 : swap16; -#endif - logmsg("opening file: %s\n", fname); if(!(fp = fopen(fname, "rb"))) { logmsg("failed to open %s: %s\n", fname, strerror(errno)); @@ -65,6 +51,7 @@ img->width = ntohs(hdr.width); img->height = ntohs(hdr.height); img->nbitplanes = hdr.nbitplanes; + img->ham = 1; imgsz = img->width * img->height / 8 * img->nbitplanes; @@ -174,21 +161,3 @@ return img; } - -#ifndef HAVE_NTOHS -static int bigendian(void) -{ - static const uint16_t x = 0xaabb; - return *(unsigned char*)&x == 0xaa; -} - -static uint16_t swap16(uint16_t x) -{ - return (x << 8) | (x >> 8); -} - -static uint16_t nop16(uint16_t x) -{ - return x; -} -#endif diff -r ae0ada629b03 -r 4c36d0f44aa6 src/image.h --- a/src/image.h Fri Oct 27 15:42:58 2017 +0300 +++ b/src/image.h Sun Oct 29 13:21:11 2017 +0200 @@ -12,12 +12,13 @@ struct ham_image { int width, height; unsigned char *pixels; - uint16_t palette[16]; - int nbitplanes; + uint16_t palette[256]; + int nbitplanes, ham; struct palchange *chglist; }; struct ham_image *load_ham_image(const char *fname); struct ham_image *gen_ham_image(int w, int h, int nbpl); +struct ham_image *load_ilbm(const char *fname); #endif /* IMAGE_H_ */ diff -r ae0ada629b03 -r 4c36d0f44aa6 src/main.c --- a/src/main.c Fri Oct 27 15:42:58 2017 +0300 +++ b/src/main.c Sun Oct 29 13:21:11 2017 +0200 @@ -11,13 +11,37 @@ int main(int argc, char **argv) { + int i; + unsigned int flags = 0; + const char *fname = 0; struct ham_image *img; - if(argv[1]) { - if(!(img = load_ham_image(argv[1]))) { - fprintf(stderr, "failed to load image: %s\n", argv[1]); - return 1; + for(i=1; iwidth, img->height, + img->nbitplanes, img->ham ? " (HAM)" : ""); } else { printf("generating test image ...\n"); if(!(img = gen_ham_image(320, 256, 6))) { @@ -26,9 +50,13 @@ } } - if(gfx_init(6, GFX_HAM) == -1) { + if(img->nbitplanes >= 6) img->ham = 1; /* XXX */ + if(img->ham) flags |= GFX_HAM; + + if(gfx_init(img->nbitplanes, flags) == -1) { return 1; } + gfx_set_framebuffer(0, img->width, img->height); gfx_wait_vblank(); gfx_show_image(img); diff -r ae0ada629b03 -r 4c36d0f44aa6 src/sdl/gfx.c --- a/src/sdl/gfx.c Fri Oct 27 15:42:58 2017 +0300 +++ b/src/sdl/gfx.c Sun Oct 29 13:21:11 2017 +0200 @@ -7,10 +7,12 @@ static int scr_width, scr_height; static int fb_width, fb_height; static int num_bitplanes; +static int init_flags; int gfx_init(int nbpl, unsigned int flags) { + init_flags = flags; num_bitplanes = nbpl; scr_width = fb_width = (flags & GFX_HIRES) ? 640 : 320; scr_height = fb_height = (flags & GFX_ILACE) ? 512 : 256; @@ -161,14 +163,16 @@ for(j=0; jwidth; j++) { unsigned char idx = 0; - unsigned char ham; + unsigned char ham = 0; int bit = 7 - (j & 7); for(k=0; knbitplanes; k++) { idx |= (((*(src + k * img->width / 8) >> bit) & 1) << k); } - ham = (idx >> 4) & 3; + if(init_flags & GFX_HAM) { + ham = (idx >> 4) & 3; + } switch(ham) { case 0: