diff --git a/001.simple_image/Makefile b/001.simple_image/Makefile index a2675cc..bc7bf74 100644 --- a/001.simple_image/Makefile +++ b/001.simple_image/Makefile @@ -8,4 +8,4 @@ MODULE=image.s include ../base.mk $(EXTRA): $(IMAGECON) $(IMAGEFILE) - $(IMAGECON) $(IMAGEFILE) out/image + $(IMAGECON) --input $(IMAGEFILE) --output out/image --colors 32 diff --git a/001.simple_image/README.md b/001.simple_image/README.md index 62dfe53..28aa078 100644 --- a/001.simple_image/README.md +++ b/001.simple_image/README.md @@ -3,4 +3,8 @@ Display a simple image Building on [trackdisk.device](../000.trackdisk), we now display a simple color image. -Image display code and conversion tools adapted from https://github.com/vilcans/amiga-startup +I display a 5 bitplane (32 color) low res image. + +The image data is prepared using a new tool I wrote called [imagecon](../tools/imagecon/imagecon.c). This takes (almost) any 320x256 PNG and using [libimagequant](https://pngquant.org/lib/) it reduces the palette to 32 colors, then dumps out the copper list and interleaved bitplane data ready to be included into (image.s)[image.s]. + +The original version of this example used (vilcans amiga-startup)[https://github.com/vilcans/amiga-startup] as a starting point, however almost all of that code has been replaced as my understanding exanded. diff --git a/001.simple_image/image.s b/001.simple_image/image.s index 82a08d5..88de6c4 100644 --- a/001.simple_image/image.s +++ b/001.simple_image/image.s @@ -4,7 +4,7 @@ LVL3_INT_VECTOR equ $6c SCREEN_WIDTH_BYTES equ (320/8) -SCREEN_BIT_DEPTH equ 4 +SCREEN_BIT_DEPTH equ 5 entry: lea level3InterruptHandler(pc),a3 diff --git a/003.music/Makefile b/003.music/Makefile index 74c0484..7fbf6a1 100644 --- a/003.music/Makefile +++ b/003.music/Makefile @@ -1,11 +1,11 @@ MAKEADF=../tools/makeadf FLOPPY=bin/image.adf EXTRA=out/image-copper-list.s out/image.bin -IMAGEFILE=../assets/hello.png +IMAGEFILE=../assets/mission-beach.png MODULE=music.s include ../base.mk $(EXTRA): $(IMAGECON) $(IMAGEFILE) - $(IMAGECON) $(IMAGEFILE) out/image + $(IMAGECON) --input $(IMAGEFILE) --output out/image --colors 32 diff --git a/003.music/music.s b/003.music/music.s index 05861b7..4e1c7de 100644 --- a/003.music/music.s +++ b/003.music/music.s @@ -4,7 +4,7 @@ LVL3_INT_VECTOR equ $6c SCREEN_WIDTH_BYTES equ (320/8) -SCREEN_BIT_DEPTH equ 4 +SCREEN_BIT_DEPTH equ 5 include "P6112-Options.i" diff --git a/assets/hello.png b/assets/hello.png deleted file mode 100644 index 1048f49..0000000 Binary files a/assets/hello.png and /dev/null differ diff --git a/tools/imagecon/Makefile b/tools/imagecon/Makefile index 4c83129..12fb172 100644 --- a/tools/imagecon/Makefile +++ b/tools/imagecon/Makefile @@ -2,6 +2,9 @@ IMAGECON=./bin/imagecon SRCS=imagecon.c HOST_WARNINGS=-pedantic-errors -Wfatal-errors -Wall -Werror -Wextra -Wno-unused-parameter -Wshadow -limagequant HOST_CFLAGS=$(HOST_WARNINGS) +OUTPUT_BASE=out/mission-beach +REFERENCE_BASE=reference/mission-beach +TEST_IMAGE=../../assets/mission-beach.png $(IMAGECON): out bin $(SRCS) gcc $(HOST_CFLAGS) $(SRCS) -o $(IMAGECON) -lpng @@ -12,13 +15,13 @@ out: bin: mkdir bin -out/bitplane.bin: $(IMAGECON) - -rm -f out/bitplane.bin out/hello-copper-list.s - $(IMAGECON) ../../assets/hello.png out/hello +out/mission-beach.bin: $(IMAGECON) + -rm -f $(OUTPUT_BASE).bin $(OUTPUT_BASE)-copper-list.s + $(IMAGECON) --input $(TEST_IMAGE) --output $(OUTPUT_BASE) --colors 32 -test: $(IMAGECON) out/bitplane.bin - diff out/hello.bin reference/bitplane.bin - diff out/hello-copper-list.s reference/copper-list.s +test: $(IMAGECON) $(OUTPUT_BASE).bin + diff $(OUTPUT_BASE).bin $(REFERENCE_BASE).bin + diff $(OUTPUT_BASE)-copper-list.s $(REFERENCE_BASE)-copper-list.s @echo "Success!" clean: diff --git a/tools/imagecon/imagecon.c b/tools/imagecon/imagecon.c index 1fb6a40..581c63a 100644 --- a/tools/imagecon/imagecon.c +++ b/tools/imagecon/imagecon.c @@ -1,4 +1,6 @@ /* + * Orginal copyright from libpng example code + * * Copyright 2002-2011 Guillaume Cottenceau and contributors. * * This software may be freely redistributed under the terms @@ -6,12 +8,18 @@ * */ +/* + * Amiga bitplane creation inspired (copied) from https://github.com/vilcans/amiga-startup + */ + #include #include #include #include #include #include +#include +#include #define PNG_DEBUG 3 #include @@ -21,6 +29,13 @@ char** _argv; int verbose = 0; +void +usage() +{ + fprintf(stderr, "%s: --input [options]\nOptions:\n --colors \n --output \n", _argv[0]); + exit(1); +} + void abort_(const char * s, ...) { @@ -33,10 +48,10 @@ abort_(const char * s, ...) exit(1); } -int width, height; +#define MAX_PALETTE 32 +int width, height, maxColors = MAX_PALETTE; png_bytep* rowPointers; -#define MAX_PALETTE 16 typedef struct { unsigned char r; unsigned char g; @@ -157,7 +172,7 @@ processFile(char* outFilename) liq_attr *attr = liq_attr_create(); // liq_image *image = liq_image_create_rgba(attr, rowPointers, width, height, 0); liq_image *image = liq_image_create_rgba_rows(attr, (void**)rowPointers, width, height, 0); - liq_set_max_colors(attr, 16); + liq_set_max_colors(attr, maxColors); liq_set_speed(attr, 1); liq_result *res = liq_quantize_image(attr, image); liq_write_remapped_image(res, image, amigaImage, width*height); @@ -292,12 +307,79 @@ int main(int argc, char **argv) { _argv = argv; + char* inputFile = 0, *outputFile = 0; + int c; - if (argc != 3) - abort_("usage: %s: ", argv[0]); + while (1) + { + static struct option long_options[] = + { + /* These options set a flag. */ + {"verbose", no_argument, &verbose, 1}, + {"output", required_argument, 0, 'o'}, + {"colors", required_argument, 0, 'c'}, + {"input", required_argument, 0, 'i'}, + {0, 0, 0, 0} + }; + /* getopt_long stores the option index here. */ + int option_index = 0; + + c = getopt_long (argc, argv, "o:c:i:", + long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) + break; + + switch (c) + { + case 0: + break; + case 'i': + inputFile = optarg; + break; + + case 'o': + outputFile = optarg; + break; + + case 'c': + if (sscanf(optarg, "%d", &maxColors) != 1) { + abort_("invalid number of colors"); + } + break; + + case '?': + usage(); + break; + + default: + usage(); + break; + } + } + + if (outputFile == 0 && inputFile != 0) { + outputFile = basename(inputFile); + char* ptr = malloc(strlen(outputFile)+1); + strcpy(ptr, outputFile); + outputFile = ptr; + ptr = rindex(outputFile, '.'); + if (ptr) { + *ptr = 0; + } + } - readFile(argv[1]); - processFile(argv[2]); + if (inputFile == 0 || optind < argc) { + usage(); + } + + if (verbose) { + printf("Options:\nverbose = %d\ninputFile = %s\noutputFile = %s\nmaxColors = %d\n\n", verbose, inputFile, outputFile, maxColors); + } + + readFile(inputFile); + processFile(outputFile); return 0; } diff --git a/tools/imagecon/reference/bitplane.bin b/tools/imagecon/reference/bitplane.bin deleted file mode 100644 index d6fa56b..0000000 Binary files a/tools/imagecon/reference/bitplane.bin and /dev/null differ diff --git a/tools/imagecon/reference/copper-list.s b/tools/imagecon/reference/copper-list.s deleted file mode 100644 index 4776b8f..0000000 --- a/tools/imagecon/reference/copper-list.s +++ /dev/null @@ -1,16 +0,0 @@ - dc.w $180,$fff - dc.w $182,$1ae - dc.w $184,$e20 - dc.w $186,$d12 - dc.w $188,$fe0 - dc.w $18a,$b0 - dc.w $18c,$ddd - dc.w $18e,$6a - dc.w $190,$9dc - dc.w $192,$362 - dc.w $194,$2b5 - dc.w $196,$f92 - dc.w $198,$ee9 - dc.w $19a,$e9a - dc.w $19c,$fa7 - dc.w $19e,$744 diff --git a/tools/imagecon/reference/mission-beach-copper-list.s b/tools/imagecon/reference/mission-beach-copper-list.s new file mode 100644 index 0000000..d30c74e --- /dev/null +++ b/tools/imagecon/reference/mission-beach-copper-list.s @@ -0,0 +1,32 @@ + dc.w $180,$36b + dc.w $182,$48b + dc.w $184,$363 + dc.w $186,$ffd + dc.w $188,$111 + dc.w $18a,$443 + dc.w $18c,$fec + dc.w $18e,$37b + dc.w $190,$222 + dc.w $192,$332 + dc.w $194,$574 + dc.w $196,$eda + dc.w $198,$554 + dc.w $19a,$ca5 + dc.w $19c,$59c + dc.w $19e,$684 + dc.w $1a0,$a95 + dc.w $1a2,$bde + dc.w $1a4,$aba + dc.w $1a6,$dc9 + dc.w $1a8,$9bc + dc.w $1aa,$aa8 + dc.w $1ac,$8a9 + dc.w $1ae,$def + dc.w $1b0,$897 + dc.w $1b2,$bcc + dc.w $1b4,$fff + dc.w $1b6,$765 + dc.w $1b8,$db6 + dc.w $1ba,$486 + dc.w $1bc,$6ad + dc.w $1be,$8a4 diff --git a/tools/imagecon/reference/mission-beach.bin b/tools/imagecon/reference/mission-beach.bin new file mode 100644 index 0000000..d7f02fa Binary files /dev/null and b/tools/imagecon/reference/mission-beach.bin differ