1
0
mirror of https://frontier.innolan.net/github/AmigaExamples.git synced 2025-12-08 16:41:36 +00:00

Converted 001.simple_image to use imagecon

This commit is contained in:
alpine9000
2016-03-01 15:18:22 +11:00
parent 091aa147b4
commit 7677ed6951
8 changed files with 114 additions and 123 deletions

View File

@ -1,11 +1,11 @@
MAKEADF=../tools/makeadf
FLOPPY=bin/image.adf
EXTRA=out/image-copper.s out/image-data.bin
EXTRA=out/image-copper-list.s out/image.bin
IMAGEFILE=../assets/hello.png
MODULE=image.s
include ../base.mk
$(EXTRA): ../assets/hello.png ../tools/bitplanify.py
../tools/bitplanify.py ../assets/hello.png --copper $(EXTRA)
$(EXTRA): $(IMAGECON) $(IMAGEFILE)
$(IMAGECON) $(IMAGEFILE) out/image

View File

@ -61,9 +61,9 @@ copper:
dc.w BPL1MOD,SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH-SCREEN_WIDTH_BYTES
dc.w BPL2MOD,SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH-SCREEN_WIDTH_BYTES
include "out/image-copper.s"
include "out/image-copper-list.s"
dc.l $fffffffe
bitplanes:
incbin "out/image-data.bin"
incbin "out/image.bin"

View File

@ -1,5 +1,8 @@
(re)Learning how to program an Amiga after a 20 year break
==========================================================
Introduction
------------
This repo is not meant to be an amiga programming guide.
Documentation
-------------
@ -71,3 +74,23 @@ Notes:
# make
# make install
```
5. libtool
```
# wget http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz
# tar zxfv libtool-2.4.6.tar.gz
# cd libtool-2.4.6
# ./configure --prefix=/usr/local
# make
# make install
```
6. libpng
```
# wget ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.21.tar.gz
# tar zxfv libpng-1.6.21.tar.gz
# cd libpng-1.6.21
# ./configure --prefix=/usr/local
# make
# make install
```

View File

@ -1,5 +1,7 @@
HOST_WARNINGS=-pedantic-errors -Wfatal-errors -Wall -Werror -Wextra -Wno-unused-parameter -Wshadow
HOST_CFLAGS=-g $(HOST_WARNINGS)
IMAGECONDIR=../tools/imagecon
IMAGECON=$(IMAGECONDIR)/bin/imagecon
all: bin out $(MAKEADF) $(FLOPPY)
@ -21,6 +23,9 @@ bin:
out:
mkdir out
$(IMAGECON):
make -C $(IMAGECONDIR)
$(MAKEADF): ../tools/makeadf.c
gcc ../tools/makeadf.c -o $(MAKEADF)

View File

@ -1,6 +1,23 @@
IMAGECON=./bin/imagecon
SRCS=imagecon.c
HOST_WARNINGS=-pedantic-errors -Wfatal-errors -Wall -Werror -Wextra -Wno-unused-parameter -Wshadow
HOST_CFLAGS=$(HOST_WARNINGS)
imagecon: $(SRCS)
gcc $(HOST_CFLAGS) $(SRCS) -o imagecon -lpng
imagecon: out bin $(SRCS)
gcc $(HOST_CFLAGS) $(SRCS) -o $(IMAGECON) -lpng
out:
mkdir out
bin:
mkdir bin
bitplane.bin copper-list.s: bin/imagecon
$(IMAGECON) ../../assets/hello.png out/hello
test: bitplane.bin copper-list.s
diff out/hello.bin reference/bitplane.bin
diff out/hello-copper-list.s reference/copper-list.s
clean:
rm -r out bin

View File

@ -16,88 +16,73 @@
#define PNG_DEBUG 3
#include <png.h>
char** _argv;
void
abort_(const char * s, ...)
{
fprintf(stderr, "%s: ", _argv[0]);
va_list args;
va_start(args, s);
vfprintf(stderr, s, args);
fprintf(stderr, "\n");
va_end(args);
abort();
exit(1);
}
//int x, y;
int width, height, rowbytes;
png_byte color_type;
png_byte bit_depth;
png_structp png_ptr;
png_infop info_ptr;
int number_of_passes;
png_bytep * row_pointers;
int width, height;
png_bytep* rowPointers;
#define MAX_PALETTE 16
typedef struct {
unsigned char r;
unsigned char g;
unsigned char b;
} amiga_color_t;
#define MAX_PALETTE 16
int blah[MAX_PALETTE] = {0xfff, 0xd12, 0x744, 0xe20, 0x362, 0x06a, 0x0b0, 0x1ae, 0x2b5, 0xf92, 0xe9a, 0xfa7, 0x9dc, 0xddd , 0xfe0 , 0xee9};
amiga_color_t palette[MAX_PALETTE];
int paletteIndex = 0;
unsigned* amigaImage = 0;
void read_png_file(char* file_name)
void readFile(char* file_name)
{
/* for (int i = 0; i < MAX_PALETTE; i++) {
palette[i].r = blah[i] >> 8 & 0xf;
palette[i].g = blah[i] >> 4 & 0xf;
palette[i].b = blah[i] & 0xf;
}
paletteIndex = 16;
*/
png_structp png_ptr;
png_byte color_type;
png_byte bit_depth;
png_infop info_ptr;
int number_of_passes, rowbytes;
unsigned char header[8]; // 8 is the maximum size that can be checked
/* open file and test for it being a png */
FILE *fp = fopen(file_name, "rb");
if (!fp)
abort_("[read_png_file] File %s could not be opened for reading", file_name);
abort_("Failed to open %s", file_name);
fread(header, 1, 8, fp);
if (png_sig_cmp(header, 0, 8))
abort_("[read_png_file] File %s is not recognized as a PNG file", file_name);
abort_("File %s is not recognized as a PNG file", file_name);
/* initialize stuff */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
abort_("[read_png_file] png_create_read_struct failed");
abort_("png_create_read_struct failed");
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
abort_("[read_png_file] png_create_info_struct failed");
abort_("png_create_info_struct failed");
if (setjmp(png_jmpbuf(png_ptr)))
abort_("[read_png_file] Error during init_io");
abort_("Error during init_io");
png_init_io(png_ptr, fp);
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
width = png_get_image_width(png_ptr, info_ptr);
height = png_get_image_height(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
printf("width = %d\n", width);
printf("height = %d\n", height);
printf("color_type = %d (palette = %s)\n", color_type, color_type == PNG_COLOR_TYPE_PALETTE ? "yes" : "no");
@ -129,12 +114,10 @@ void read_png_file(char* file_name)
color_type = png_get_color_type(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
/* read file */
if (setjmp(png_jmpbuf(png_ptr)))
abort_("[read_png_file] Error during read_image");
abort_("Error during read_image");
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
rowPointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
if (bit_depth == 16)
rowbytes = width*8;
@ -142,9 +125,9 @@ void read_png_file(char* file_name)
rowbytes = width*4;
for (int y=0; y<height; y++)
row_pointers[y] = (png_byte*) malloc(rowbytes);
rowPointers[y] = (png_byte*) malloc(rowbytes);
png_read_image(png_ptr, row_pointers);
png_read_image(png_ptr, rowPointers);
fclose(fp);
@ -156,71 +139,14 @@ void read_png_file(char* file_name)
}
void
write_png_file(char* file_name)
{
/* create file */
FILE *fp = fopen(file_name, "wb");
if (!fp)
abort_("[write_png_file] File %s could not be opened for writing", file_name);
/* initialize stuff */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
abort_("[write_png_file] png_create_write_struct failed");
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
abort_("[write_png_file] png_create_info_struct failed");
if (setjmp(png_jmpbuf(png_ptr)))
abort_("[write_png_file] Error during init_io");
png_init_io(png_ptr, fp);
/* write header */
if (setjmp(png_jmpbuf(png_ptr)))
abort_("[write_png_file] Error during writing header");
png_set_IHDR(png_ptr, info_ptr, width, height,
8, 6, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
/* write bytes */
if (setjmp(png_jmpbuf(png_ptr)))
abort_("[write_png_file] Error during writing bytes");
png_write_image(png_ptr, row_pointers);
/* end write */
if (setjmp(png_jmpbuf(png_ptr)))
abort_("[write_png_file] Error during end of write");
png_write_end(png_ptr, NULL);
/* cleanup heap allocation */
for (int y=0; y<height; y++)
free(row_pointers[y]);
free(row_pointers);
fclose(fp);
}
void
process_file(void)
processFile(char* outFilename)
{
amigaImage = calloc(width*height, 4);
for (int y=0; y<height; y++) {
png_byte* row = row_pointers[y];
png_byte* row = rowPointers[y];
for (int x=0; x<width; x++) {
png_byte* ptr = &(row[x*4]);
@ -247,13 +173,6 @@ process_file(void)
palette[index] = color ;
amigaImage[(width*y)+x] = index;
// printf("Pixel at position [ %d - %d ] has pindex = %d\n", x, y, index);
/* perform whatever modifications needed, for example to set red value to 0 and green value to the blue one:
ptr[0] = 0;
ptr[1] = ptr[2]; */
}
}
@ -264,7 +183,12 @@ process_file(void)
printf("number of colors = %d\n", numColors);
printf("number of bitplanes = %d\n", numBitPlanes);
FILE* fp = fopen("copper-list.s", "w+");
char filenameBuffer[2048];
snprintf(filenameBuffer, 2048, "%s-copper-list.s", outFilename);
FILE* fp = fopen(filenameBuffer, "w+");
if (!fp) {
abort_("failed to open %s for writing", filenameBuffer);
}
for (int i = 0; i < paletteIndex; i++) {
printf("%d: %x %d %d %d\n", i , palette[i].r << 8 | palette[i].g << 4 | palette[i].b, palette[i].r, palette[i].g, palette[i].b);
@ -307,7 +231,12 @@ process_file(void)
#endif
fp = fopen("bitplane.bin", "w+");
snprintf(filenameBuffer, 2048, "%s.bin", outFilename);
fp = fopen(filenameBuffer, "w+");
if (!fp) {
abort_("failed to open %s for writing", filenameBuffer);
}
for (int y = 0; y < height; y++) {
for (int plane_index = 0; plane_index < numBitPlanes; plane_index++) {
char* plane = bitplanes[plane_index];
@ -322,12 +251,13 @@ process_file(void)
int
main(int argc, char **argv)
{
if (argc != 2)
abort_("Usage: program_name <file_in> <file_out>");
_argv = argv;
read_png_file(argv[1]);
process_file();
// write_png_file(argv[2]);
if (argc != 3)
abort_("usage: %s: <file_in> <file_out>", argv[0]);
readFile(argv[1]);
processFile(argv[2]);
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,16 @@
dc.w $180,$fff
dc.w $182,$ee9
dc.w $184,$ddd
dc.w $186,$fe0
dc.w $188,$fa7
dc.w $18a,$9dc
dc.w $18c,$f92
dc.w $18e,$2b5
dc.w $190,$e20
dc.w $192,$e9a
dc.w $194,$b0
dc.w $196,$d12
dc.w $198,$1ae
dc.w $19a,$6a
dc.w $19c,$744
dc.w $19e,$362