diff --git a/README.md b/README.md index 293dc86..5c67ab6 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ Available options are: -a, --attached Attach sprites, only valid for sprite. + -n, --piccon Use PicCon compatible color conversion for 4 bit palette, only valid with palette output file format. + Examples: amigeconv -f bitplanes -d 8 font.png font.raw diff --git a/src/amigeconv.c b/src/amigeconv.c index d469c71..07e0f63 100644 --- a/src/amigeconv.c +++ b/src/amigeconv.c @@ -12,8 +12,8 @@ #include "formats/sprite.h" #include "formats/palette.h" -#define AMIGECONV_VERSION "1.0.1" -#define AMIGECONV_VERSION_DATE "2019-09-01" +#define AMIGECONV_VERSION "1.0.2" +#define AMIGECONV_VERSION_DATE "2021-01-24" typedef enum { PALETTE_UNKNOWN = 0, @@ -93,14 +93,15 @@ static bool write_palette( image_t *const image, palette_t palette, const unsigned int colors, - bool copper + bool copper, + const bool piccon_compatibility ) { buffer_t *buffer; if (palette == PALETTE_PAL4) { if (copper) { - buffer = palette_convert_pal4_copper(image, colors); + buffer = palette_convert_pal4_copper(image, colors, piccon_compatibility); } else { - buffer = palette_convert_pal4(image, colors); + buffer = palette_convert_pal4(image, colors, piccon_compatibility); } } @@ -117,7 +118,7 @@ static bool write_palette( } if (palette == PALETTE_LOADRGB4) { - buffer = palette_convert_pal4(image, colors); + buffer = palette_convert_pal4(image, colors, piccon_compatibility); } if (palette == PALETTE_LOADRGB32) { @@ -146,11 +147,12 @@ static void usage() { printf(" -w, --width [16,32,64] Width, only valid with sprite output file format.\n"); printf(" -t, --controlword Write control word, only valid with sprite output file format.\n"); printf(" -a, --attached Attach mode sprite, only valid with sprite output file format.\n"); + printf(" -n, --piccon Use PicCon compatible color conversion for 4 bit palette, only valid with palette output file format.\n"); printf("\n"); } int main(int argc, char *argv[]) { - bool interleaved = false, copper = false, controlword = false, attached = false; + bool interleaved = false, copper = false, controlword = false, attached = false, piccon_compatibility = false; int depth = -1, colors = -1, width = -1; palette_t palette = PALETTE_UNKNOWN; format_t format = FORMAT_UNKNOWN; @@ -165,6 +167,7 @@ int main(int argc, char *argv[]) { {"width", required_argument, 0, 'w' }, {"controlword", no_argument, 0, 't' }, {"attached", no_argument, 0, 'a' }, + {"piccon", no_argument, 0, 'n' }, {0, 0, 0, 0} }; @@ -239,6 +242,9 @@ int main(int argc, char *argv[]) { case 'a': attached = true; break; + case 'n': + piccon_compatibility = true; + break; default: usage(); exit(EXIT_FAILURE); @@ -387,7 +393,7 @@ int main(int argc, char *argv[]) { goto error; } - if (!write_palette(outfile, &image, palette, colors, copper)) { + if (!write_palette(outfile, &image, palette, colors, copper, piccon_compatibility)) { error = true; printf("Error: Could not write output file \"%s\".\n\n", outfile); goto error; diff --git a/src/formats/palette.c b/src/formats/palette.c index e622f2d..8e55c39 100644 --- a/src/formats/palette.c +++ b/src/formats/palette.c @@ -1,11 +1,11 @@ #include -// #include +#include #include "../buffer.h" #include "../image.h" // PAL4 & LOADRGB4 is the same format -buffer_t *palette_convert_pal4(image_t *const image, const unsigned int colors) { +buffer_t *palette_convert_pal4(image_t *const image, const unsigned int colors, const bool piccon_compatibility) { if (colors < 1 || colors > 256) { return NULL; } unsigned int buffer_size = (((colors * 4) + (4 - 1)) >> 2) * 2; @@ -18,15 +18,18 @@ buffer_t *palette_convert_pal4(image_t *const image, const unsigned int colors) unsigned char g = buffer_get_byte(image->palette, i + 1); unsigned char b = buffer_get_byte(image->palette, i + 2); - // Correct conversion -// r = round((float)r / 17.0); -// g = round((float)g / 17.0); -// b = round((float)b / 17.0); + if (piccon_compatibility) { + // PicCon compatibility + r >>= 4; + g >>= 4; + b >>= 4; + } else { + // Correct conversion + r = round((float)r / 17.0); + g = round((float)g / 17.0); + b = round((float)b / 17.0); + } - // PicCon compatibility - r >>= 4; - g >>= 4; - b >>= 4; buffer_set_byte(buffer, j++, r); buffer_set_byte(buffer, j++, (g << 4) + b); @@ -35,7 +38,7 @@ buffer_t *palette_convert_pal4(image_t *const image, const unsigned int colors) return buffer; } -buffer_t *palette_convert_pal4_copper(image_t *const image, const unsigned int colors) { +buffer_t *palette_convert_pal4_copper(image_t *const image, const unsigned int colors, const bool piccon_compatibility) { if (colors < 1 || colors > 32) { return NULL; } unsigned int buffer_size = (((colors * 4) + (4 - 1)) >> 2) * 4; @@ -48,15 +51,17 @@ buffer_t *palette_convert_pal4_copper(image_t *const image, const unsigned int c unsigned char g = buffer_get_byte(image->palette, i + 1); unsigned char b = buffer_get_byte(image->palette, i + 2); - // Correct conversion -// r = round((float)r / 17.0); -// g = round((float)g / 17.0); -// b = round((float)b / 17.0); - - // PicCon compatibility - r >>= 4; - g >>= 4; - b >>= 4; + if (piccon_compatibility) { + // PicCon compatibility + r >>= 4; + g >>= 4; + b >>= 4; + } else { + // Correct conversion + r = round((float)r / 17.0); + g = round((float)g / 17.0); + b = round((float)b / 17.0); + } buffer_set_byte(buffer, j++, (reg >> 8) & 255); buffer_set_byte(buffer, j++, reg & 255); diff --git a/src/formats/palette.h b/src/formats/palette.h index 8462652..6163cf3 100644 --- a/src/formats/palette.h +++ b/src/formats/palette.h @@ -3,8 +3,8 @@ #include "../buffer.h" -buffer_t *palette_convert_pal4(image_t *const image, const unsigned int colors); -buffer_t *palette_convert_pal4_copper(image_t *const image, const unsigned int colors); +buffer_t *palette_convert_pal4(image_t *const image, const unsigned int colors, const bool piccon_compatibility); +buffer_t *palette_convert_pal4_copper(image_t *const image, const unsigned int colors, const bool piccon_compatibility); buffer_t *palette_convert_pal8(image_t *const image, const unsigned int colors); buffer_t *palette_convert_pal8_copper(image_t *const image, const unsigned int colors); buffer_t *palette_convert_pal32(image_t *const image, const unsigned int colors);