+#include <string.h>
+
/* common */
#include "check.h"
#include "xmalloc.h"
Palette* NewMonochromePalette (void)
/* Create and return a palette with two entries (black and white) */
-{
+{
/* Create a new palette */
Palette* P = NewPalette (2);
+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 */
{
+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));
+ }
+}