mirror of
https://frontier.innolan.net/github/AmigaExamples.git
synced 2026-01-12 05:37:18 +00:00
Improvements to imagecon and related changes
This commit is contained in:
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
BIN
assets/hello.png
BIN
assets/hello.png
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
@ -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:
|
||||
|
||||
@ -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 <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#define PNG_DEBUG 3
|
||||
#include <png.h>
|
||||
@ -21,6 +29,13 @@
|
||||
char** _argv;
|
||||
int verbose = 0;
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "%s: --input <input.png> [options]\nOptions:\n --colors <max colors>\n --output <output prefix>\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: <file_in> <file_out>", 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;
|
||||
}
|
||||
|
||||
Binary file not shown.
@ -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
|
||||
32
tools/imagecon/reference/mission-beach-copper-list.s
Normal file
32
tools/imagecon/reference/mission-beach-copper-list.s
Normal file
@ -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
|
||||
BIN
tools/imagecon/reference/mission-beach.bin
Normal file
BIN
tools/imagecon/reference/mission-beach.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user