From f3be7251a18155b1a4e2cfbbe845aab2ba6512ae Mon Sep 17 00:00:00 2001 From: alpine9000 Date: Sat, 5 Mar 2016 16:39:00 +1100 Subject: [PATCH] Added support for greyscale palette --- tools/imagecon/Makefile | 3 +- tools/imagecon/README.md | 5 ++ tools/imagecon/imagecon.c | 19 ++++++ tools/imagecon/imagecon.h | 1 + tools/imagecon/reference/mission-beach-grey.s | 67 +++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tools/imagecon/reference/mission-beach-grey.s diff --git a/tools/imagecon/Makefile b/tools/imagecon/Makefile index c7101bd..5a4e9d7 100644 --- a/tools/imagecon/Makefile +++ b/tools/imagecon/Makefile @@ -43,13 +43,14 @@ $(SHARED_PALETTE): $(IMAGECON) $(OUTPUT_BASE).bin: $(IMAGECON) -rm -f $(OUTPUT_BASE).bin $(OUTPUT_BASE)-copper-list.s $(OUTPUT_BASE)-palette.s - $(IMAGECON) --input $(TEST_IMAGE) --output $(OUTPUT_BASE) --output-copperlist --output-bitplanes --output-palette-asm --colors 32 --quantize + $(IMAGECON) --input $(TEST_IMAGE) --output $(OUTPUT_BASE) --output-copperlist --output-bitplanes --output-grey-palette --output-palette-asm --colors 32 --quantize $(IMAGECON) --input $(BOB_IMAGE) --output $(BOB_BASE) --output-mask --colors 32 --quantize test: $(IMAGECON) $(OUTPUT_BASE).bin $(SHARED_PALETTE) $(USED_PALETTE) diff $(OUTPUT_BASE).bin $(REFERENCE_BASE).bin diff $(OUTPUT_BASE)-copper-list.s $(REFERENCE_BASE)-copper-list.s diff $(OUTPUT_BASE)-palette.s $(REFERENCE_BASE)-palette.s + diff $(OUTPUT_BASE)-grey.s $(REFERENCE_BASE)-grey.s diff $(SHARED_PALETTE) $(REFERENCE_SHARED_PALETTE) diff $(SHARED_BASE).bin $(REFERENCE_SHARED_BASE).bin diff $(SHARED_BASE)-copper-list.s $(REFERENCE_SHARED_BASE)-copper-list.s diff --git a/tools/imagecon/README.md b/tools/imagecon/README.md index 325c4e0..cf5cfee 100644 --- a/tools/imagecon/README.md +++ b/tools/imagecon/README.md @@ -13,6 +13,7 @@ usage --quantize --output-palette --output-palette-asm + --output-grey-palette-asm --output-bitplanes --output-mask --output-copperlist @@ -66,6 +67,10 @@ Generate a palette file of the final palette used. Output will be the output fil Generate m68k assembler instructions to install the palette. No symbols are generated. Registers are preserved. +**--output-grey-palette-asm** + +Generate m68k assembler instructions to install a greyscale version of the palette. No symbols are generated. Registers are preserved. + **--use-palette** <palette file> Specify a palette file to use that will override the image or quantized palette. Overrides the --colors and --quantize options. diff --git a/tools/imagecon/imagecon.c b/tools/imagecon/imagecon.c index bfe9b97..0268d6d 100644 --- a/tools/imagecon/imagecon.c +++ b/tools/imagecon/imagecon.c @@ -20,6 +20,7 @@ imagecon_config_t config = { .outputPalette = 0, .outputMask = 0, .outputPaletteAsm = 0, + .outputPaletteGrey = 0, .outputBitplanes = 0, .outputCopperList = 0, .quantize = 0, @@ -40,6 +41,7 @@ usage() " --output-copperlist\n"\ " --output-mask\n"\ " --output-palette-asm\n"\ + " --output-grey-palette-asm\n"\ " --output-palette\n"\ " --use-palette \n"\ " --verbose\n", config.argv[0]); @@ -108,6 +110,7 @@ outputPalette(char* outFilename, imagecon_image_t* ic) FILE* fp = 0; FILE* paletteFP = 0; FILE* paletteAsmFP = 0; + FILE* paletteGreyFP = 0; if (config.outputCopperList) { fp = openFileWrite("%s-copper-list.s", outFilename); @@ -117,6 +120,11 @@ outputPalette(char* outFilename, imagecon_image_t* ic) paletteFP = openFileWrite("%s.pal", outFilename); } + if (config.outputPaletteGrey) { + paletteGreyFP = openFileWrite("%s-grey.s", outFilename); + fprintf(paletteGreyFP, "\tmovem.l d0-a6,-(sp)\n\tlea CUSTOM,a6\n"); + } + if (config.outputPaletteAsm) { paletteAsmFP = openFileWrite("%s-palette.s", outFilename); fprintf(paletteAsmFP, "\tmovem.l d0-a6,-(sp)\n\tlea CUSTOM,a6\n"); @@ -136,6 +144,11 @@ outputPalette(char* outFilename, imagecon_image_t* ic) if (paletteAsmFP) { fprintf(paletteAsmFP, "\tlea COLOR%02d(a6),a0\n\tmove.w #$%03x,(a0)\n", i, ic->palette[i].r << 8 | ic->palette[i].g << 4 | ic->palette[i].b); } + if (paletteGreyFP) { + unsigned grey = (ic->palette[i].r + ic->palette[i].g + ic->palette[i].b)/3; + fprintf(paletteGreyFP, "\tlea COLOR%02d(a6),a0\n\tmove.w #$%03x,(a0)\n", i, grey << 8 | grey << 4 | grey); + } + if (fp) { fprintf(fp, "\tdc.w $%x,$%x\n", 0x180+(i*2), ic->palette[i].r << 8 | ic->palette[i].g << 4 | ic->palette[i].b); } @@ -145,6 +158,11 @@ outputPalette(char* outFilename, imagecon_image_t* ic) fclose(paletteFP); } + if (paletteGreyFP) { + fprintf(paletteGreyFP, "\tmovem.l (sp)+,d0-a6\n"); + fclose(paletteGreyFP); + } + if (paletteAsmFP) { fprintf(paletteAsmFP, "\tmovem.l (sp)+,d0-a6\n"); fclose(paletteFP); @@ -478,6 +496,7 @@ main(int argc, char **argv) {"output-bitplanes", no_argument, &config.outputBitplanes, 1}, {"output-palette", no_argument, &config.outputPalette, 1}, {"output-palette-asm", no_argument, &config.outputPaletteAsm, 1}, + {"output-grey-palette-asm", no_argument, &config.outputPaletteGrey, 1}, {"output-mask", no_argument, &config.outputMask, 1}, {"use-palette", required_argument, 0, 'p'}, {"output", required_argument, 0, 'o'}, diff --git a/tools/imagecon/imagecon.h b/tools/imagecon/imagecon.h index 0a9a3c2..3ed4d8f 100644 --- a/tools/imagecon/imagecon.h +++ b/tools/imagecon/imagecon.h @@ -7,6 +7,7 @@ typedef struct { int maxColors; int outputPalette; int outputPaletteAsm; + int outputPaletteGrey; int outputMask; int outputBitplanes; int outputCopperList; diff --git a/tools/imagecon/reference/mission-beach-grey.s b/tools/imagecon/reference/mission-beach-grey.s new file mode 100644 index 0000000..7e55605 --- /dev/null +++ b/tools/imagecon/reference/mission-beach-grey.s @@ -0,0 +1,67 @@ + movem.l d0-a6,-(sp) + lea CUSTOM,a6 + lea COLOR00(a6),a0 + move.w #$666,(a0) + lea COLOR01(a6),a0 + move.w #$777,(a0) + lea COLOR02(a6),a0 + move.w #$444,(a0) + lea COLOR03(a6),a0 + move.w #$eee,(a0) + lea COLOR04(a6),a0 + move.w #$111,(a0) + lea COLOR05(a6),a0 + move.w #$333,(a0) + lea COLOR06(a6),a0 + move.w #$ddd,(a0) + lea COLOR07(a6),a0 + move.w #$777,(a0) + lea COLOR08(a6),a0 + move.w #$222,(a0) + lea COLOR09(a6),a0 + move.w #$222,(a0) + lea COLOR10(a6),a0 + move.w #$555,(a0) + lea COLOR11(a6),a0 + move.w #$ccc,(a0) + lea COLOR12(a6),a0 + move.w #$444,(a0) + lea COLOR13(a6),a0 + move.w #$999,(a0) + lea COLOR14(a6),a0 + move.w #$888,(a0) + lea COLOR15(a6),a0 + move.w #$666,(a0) + lea COLOR16(a6),a0 + move.w #$888,(a0) + lea COLOR17(a6),a0 + move.w #$ccc,(a0) + lea COLOR18(a6),a0 + move.w #$aaa,(a0) + lea COLOR19(a6),a0 + move.w #$bbb,(a0) + lea COLOR20(a6),a0 + move.w #$aaa,(a0) + lea COLOR21(a6),a0 + move.w #$999,(a0) + lea COLOR22(a6),a0 + move.w #$999,(a0) + lea COLOR23(a6),a0 + move.w #$eee,(a0) + lea COLOR24(a6),a0 + move.w #$888,(a0) + lea COLOR25(a6),a0 + move.w #$bbb,(a0) + lea COLOR26(a6),a0 + move.w #$fff,(a0) + lea COLOR27(a6),a0 + move.w #$666,(a0) + lea COLOR28(a6),a0 + move.w #$aaa,(a0) + lea COLOR29(a6),a0 + move.w #$666,(a0) + lea COLOR30(a6),a0 + move.w #$999,(a0) + lea COLOR31(a6),a0 + move.w #$777,(a0) + movem.l (sp)+,d0-a6