From c0d859fb883a96df121b71dbf61b01bb8811de8d Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Wed, 21 Sep 2016 16:26:03 -0700 Subject: [PATCH] improved playfield1 and png2image fixed issue when number of colors is less than 2^n, output and use colors from png2image --- hardware/playfield1.c | 19 ++++++++++--------- hardware/{test-320x200.h => test320x200.h} | 7 ++++++- hardware/{test-320x256.h => test320x256.h} | 6 +++++- .../{test-320x256x2.h => test320x256x2.h} | 7 ++++++- utils/png2image.py | 7 ++++--- 5 files changed, 31 insertions(+), 15 deletions(-) rename hardware/{test-320x200.h => test320x200.h} (99%) rename hardware/{test-320x256.h => test320x256.h} (99%) rename hardware/{test-320x256x2.h => test320x256x2.h} (99%) diff --git a/hardware/playfield1.c b/hardware/playfield1.c index 3404c08..9e99d3e 100644 --- a/hardware/playfield1.c +++ b/hardware/playfield1.c @@ -15,12 +15,14 @@ #ifdef USE_PAL #if NUM_BITPLANES == 1 -#include "test-320x256.h" +#include "test320x256.h" +#define NUM_COLORS 2 #else -#include "test-320x256x2.h" +#include "test320x256x2.h" +#define NUM_COLORS 4 #endif #else -#include "test-320x200.h" +#include "test320x200.h" #endif /* @@ -123,8 +125,8 @@ int main(int argc, char **argv) UWORD lib_version = ((struct Library *) GfxBase)->lib_Version; BOOL is_pal = init_display(lib_version); - ULONG pl1data = (ULONG) imdata; - ULONG pl2data = ((ULONG) &imdata[20 * NUM_RASTER_LINES]); + ULONG pl1data = (ULONG) image_data; + ULONG pl2data = ((ULONG) &image_data[20 * NUM_RASTER_LINES]); // hardcoded for UAE, since it seems that the mode returned is always NTSC is_pal = USE_PAL; @@ -141,10 +143,9 @@ int main(int argc, char **argv) custom.diwstrt = DIWSTRT_VALUE; custom.diwstop = DIWSTOP_VALUE; - custom.color[0] = COLOR0; // background red - custom.color[1] = COLOR1; // color 1 is yellow - custom.color[2] = COLOR2; - custom.color[3] = COLOR3; + for (int i = 0; i < NUM_COLORS; i++) { + custom.color[i] = image_colors[i]; + } // Initialize copper list with image data address coplist[1] = (pl1data >> 16) & 0xffff; diff --git a/hardware/test-320x200.h b/hardware/test320x200.h similarity index 99% rename from hardware/test-320x200.h rename to hardware/test320x200.h index 555d369..677749c 100644 --- a/hardware/test-320x200.h +++ b/hardware/test320x200.h @@ -1,5 +1,5 @@ /* Ensure that this data is within chip memory or you'll see nothing !!! */ -UWORD __chip imdata[] = { +UWORD __chip image_data[] = { // plane 0 0xe000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x007f,0xffff, 0xf800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00ff,0xffff, @@ -202,3 +202,8 @@ UWORD __chip imdata[] = { 0xffff,0xff80,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000f,0xfe00,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xffff, 0xffff,0xff00,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0003,0xfc00,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xffff }; + +UWORD image_colors[2] = { + 0xfff,0x000 +}; + diff --git a/hardware/test-320x256.h b/hardware/test320x256.h similarity index 99% rename from hardware/test-320x256.h rename to hardware/test320x256.h index 9b24539..036588a 100644 --- a/hardware/test-320x256.h +++ b/hardware/test320x256.h @@ -1,5 +1,5 @@ /* Ensure that this data is within chip memory or you'll see nothing !!! */ -UWORD __chip imdata[] = { +UWORD __chip image_data[] = { // plane 0 0xe000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x007f,0xffff, 0xf800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00ff,0xffff, @@ -259,3 +259,7 @@ UWORD __chip imdata[] = { 0xffff,0xff00,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0003,0xfc00,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xffff }; +UWORD image_colors[2] = { + 0xfff,0x000 +}; + diff --git a/hardware/test-320x256x2.h b/hardware/test320x256x2.h similarity index 99% rename from hardware/test-320x256x2.h rename to hardware/test320x256x2.h index 05b40a6..32b8d94 100644 --- a/hardware/test-320x256x2.h +++ b/hardware/test320x256x2.h @@ -1,5 +1,5 @@ /* Ensure that this data is within chip memory or you'll see nothing !!! */ -UWORD __chip imdata[] = { +UWORD __chip image_data[] = { // plane 0 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xe000,0x03fe, 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xc000,0x01f8, @@ -515,3 +515,8 @@ UWORD __chip imdata[] = { 0x0000,0x0000,0x01ff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xff80,0x0000,0x0000,0x0000, 0x0018,0x0000,0x03ff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xff80,0x0000,0x0000,0x0000 }; + +UWORD image_colors[4] = { + 0x000,0x40b,0x2f1,0xfff +}; + diff --git a/utils/png2image.py b/utils/png2image.py index 363974b..4210a64 100755 --- a/utils/png2image.py +++ b/utils/png2image.py @@ -27,7 +27,7 @@ def write_amiga_image(image, outfile, img_name, use_intuition): # colors is a list of 3-integer lists ([[r1, g1, b1], ...]) colors = [i for i in chunks([b for b in im.palette.tobytes()], 3)] - depth = int(math.log(len(colors), 2)) + depth = round(math.log(len(colors), 2)) map_words_per_row = int(width / 16) if width % 16 > 0: @@ -58,12 +58,13 @@ def write_amiga_image(image, outfile, img_name, use_intuition): outfile.write('UWORD __chip %s[] = {\n' % imgdata_varname) indent = 4 for i, plane in enumerate(planes): + if i > 0: + outfile.write(',\n') outfile.write(' ' * indent + '// plane %d\n' % i) lines = [(' ' * indent) + ','.join(['0x%04x' % i for i in chunk]) for chunk in chunks(plane, map_words_per_row)] outfile.write(',\n'.join(lines)) - outfile.write('\n') - outfile.write('};\n\n') + outfile.write('\n};\n\n') planepick = 2 ** depth - 1 # currently we always use all of the planes