]> git.sur5r.net Git - cc65/commitdiff
New option --dump-palette. Fixed a double free in the cleanup code.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Mar 2012 11:25:38 +0000 (11:25 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 11 Mar 2012 11:25:38 +0000 (11:25 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5604 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/bitmap.h
src/sp65/main.c
src/sp65/palette.c
src/sp65/palette.h

index d4e09e84d135e8c401c910e229e68216e31569c2..dc523f1a1a0b3243587a8a9cf6d0165253bfecf0 100644 (file)
@@ -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.
index 1c0ca27017ad10204537c3f1281f6327ec43ca27..313694ad7409d64da69c2a418418e2810429167a 100644 (file)
@@ -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 */
index afde3d7a24a1171c4a289ff843b689e291262954..01473e6dcaacf821ca9ef82c70e568adf3a44283 100644 (file)
@@ -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));
+    }
+}
+
+
+
index 925e606eeb760f59935f917f7573f938f2b22aba..d7180e0f03379bb7c0a4f5e5cd36db8ec27f9d6d 100644 (file)
@@ -38,6 +38,8 @@
 
 
 
+#include <stdio.h>
+
 /* 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 */