X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fsp65%2Fpalette.c;h=b407b365c906226abe2db3513e3a3cc155b260e5;hb=35e1184901ca38bdb2e56d154ed3b71f6096eacc;hp=3ada051baac29459172cdc2baa5db8d3dda335d8;hpb=364eb07a59e9622e1438860c7c8ffebdb896454c;p=cc65 diff --git a/src/sp65/palette.c b/src/sp65/palette.c index 3ada051ba..b407b365c 100644 --- a/src/sp65/palette.c +++ b/src/sp65/palette.c @@ -33,6 +33,8 @@ +#include + /* common */ #include "check.h" #include "xmalloc.h" @@ -66,6 +68,45 @@ Palette* NewPalette (unsigned Entries) +Palette* NewMonochromePalette (void) +/* Create and return a palette with two entries (black and white) */ +{ + /* Create a new palette */ + Palette* P = NewPalette (2); + + /* Set the two colors */ + P->Entries[0] = RGBA (0x00, 0x00, 0x00, 0x00); + P->Entries[1] = RGBA (0xFF, 0xFF, 0xFF, 0x00); + + /* Return the new palette */ + return P; +} + + + +Palette* DupPalette (const Palette* P) +/* Create a copy of a palette */ +{ + Palette* N; + + + /* Allow to pass a NULL palette */ + if (P == 0) { + return 0; + } + + /* Create a new palette */ + N = NewPalette (P->Count); + + /* Copy the palette data */ + memcpy (N->Entries, P->Entries, P->Count * sizeof (P->Entries[0])); + + /* Return the copy */ + return N; +} + + + void FreePalette (Palette* P) /* Free a dynamically allocated palette */ { @@ -74,3 +115,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)); + } +} + + +