From ca691233e4da10b605ee0556428329a1d2a87553 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 11 Mar 2012 11:25:38 +0000 Subject: [PATCH] New option --dump-palette. Fixed a double free in the cleanup code. git-svn-id: svn://svn.cc65.org/cc65/trunk@5604 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/sp65/bitmap.h | 10 ++++++++++ src/sp65/main.c | 23 ++++++++++++++++++++++- src/sp65/palette.c | 26 ++++++++++++++++++++++++++ src/sp65/palette.h | 5 +++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/sp65/bitmap.h b/src/sp65/bitmap.h index d4e09e84d..dc523f1a1 100644 --- a/src/sp65/bitmap.h +++ b/src/sp65/bitmap.h @@ -147,6 +147,16 @@ INLINE unsigned GetBitmapHeight (const Bitmap* B) # define GetBitmapHeight(B) ((B)->Height) #endif +#if defined(HAVE_INLINE) +INLINE const Palette* GetBitmapPalette (const Bitmap* B) +/* Get the palette of a bitmap */ +{ + return B->Pal; +} +#else +# define GetBitmapPalette(B) ((B)->Pal) +#endif + unsigned GetBitmapColors (const Bitmap* B); /* Get the number of colors in an image. The function will return the number * of palette entries for indexed bitmaps and 2^24 for non indexed bitmaps. diff --git a/src/sp65/main.c b/src/sp65/main.c index 1c0ca2701..313694ad7 100644 --- a/src/sp65/main.c +++ b/src/sp65/main.c @@ -161,6 +161,26 @@ static void OptConvertTo (const char* Opt attribute ((unused)), const char* Arg) +static void OptDumpPalette (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Dump the palette of the current work bitmap */ +{ + /* We must have a bitmap ... */ + if (C == 0) { + Error ("No bitmap"); + } + + /* ... which must be indexed */ + if (!BitmapIsIndexed (C)) { + Error ("Current bitmap is not indexed"); + } + + /* Dump the palette */ + DumpPalette (stdout, GetBitmapPalette (C)); +} + + + static void OptHelp (const char* Opt attribute ((unused)), const char* Arg attribute ((unused))) /* Print usage information and exit */ @@ -297,6 +317,7 @@ int main (int argc, char* argv []) /* Program long options */ static const LongOpt OptTab[] = { { "--convert-to", 1, OptConvertTo }, + { "--dump-palette", 0, OptDumpPalette }, { "--help", 0, OptHelp }, { "--list-conversions", 0, OptListConversions }, { "--pop", 0, OptPop }, @@ -374,8 +395,8 @@ int main (int argc, char* argv []) } /* Cleanup data */ + SetWorkBitmap (C); FreeBitmap (B); - FreeBitmap (C); FreeStrBuf (D); /* Success */ diff --git a/src/sp65/palette.c b/src/sp65/palette.c index afde3d7a2..01473e6dc 100644 --- a/src/sp65/palette.c +++ b/src/sp65/palette.c @@ -112,3 +112,29 @@ void FreePalette (Palette* P) +void DumpPalette (FILE* F, const Palette* P) +/* Dump the palette in readable form to the given file */ +{ + unsigned I; + + fputs ("Entry R G B A Combined\n", F); + fputs ("----------------------------------------------\n", F); + for (I = 0; I < P->Count; ++I) { + + /* Get the color entry */ + const Color* C = P->Entries + I; + + /* Output it */ + fprintf (F, + " %3u %3u %3u %3u %3u #%08lX\n", + I, + C->R, C->G, C->B, C->A, + (((unsigned long) C->A) << 24) | + (((unsigned long) C->B) << 16) | + (((unsigned long) C->G) << 8) | + (((unsigned long) C->R) << 0)); + } +} + + + diff --git a/src/sp65/palette.h b/src/sp65/palette.h index 925e606ee..d7180e0f0 100644 --- a/src/sp65/palette.h +++ b/src/sp65/palette.h @@ -38,6 +38,8 @@ +#include + /* sp65 */ #include "color.h" @@ -75,6 +77,9 @@ Palette* DupPalette (const Palette* P); void FreePalette (Palette* P); /* Free a dynamically allocated palette */ +void DumpPalette (FILE* F, const Palette* P); +/* Dump the palette in readable form to the given file */ + /* End of palette.h */ -- 2.39.5