mirror of
https://github.com/cc65/cc65.git
synced 2025-02-03 22:32:24 +00:00
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
This commit is contained in:
parent
c9d65c56c2
commit
ca691233e4
@ -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.
|
||||
|
@ -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 */
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user