1 /* Palette-manipulation functions functions for xcftools 2 * 3 * This file was written by Henning Makholm <henning@makholm.net> 4 * It is hereby in the public domain. 5 * 6 * In jurisdictions that do not recognise grants of copyright to the 7 * public domain: I, the author and (presumably, in those jurisdictions) 8 * copyright holder, hereby permit anyone to distribute and use this code, 9 * in source code or binary form, with or without modifications. This 10 * permission is world-wide and irrevocable. 11 * 12 * Of course, I will not be liable for any errors or shortcomings in the 13 * code, since I give it away without asking any compenstations. 14 * 15 * If you use or distribute this code, I would appreciate receiving 16 * credit for writing it, in whichever way you find proper and customary. 17 */ 18 19 #ifndef PALETTE_H 20 #define PALETTE_H 21 22 #include "xcftools.h" 23 #include "pixels.h" 24 25 #define MAX_PALETTE 256 26 extern rgba palette[MAX_PALETTE] ; 27 extern unsigned paletteSize ; 28 29 typedef uint8_t index_t ; 30 31 void init_palette_hash(void); 32 33 /* lookup_or_intern() returns a negative number if there is no room 34 * for the color in the palette. 35 */ 36 int lookup_or_intern(rgba color); 37 38 /* palettify_row will convert a row of 'rgba' values into a packed row 39 * of 'uint8_t' indces. If it succeeds without running out of colormap 40 * entries, it returns nonzero. On the other hand if it does run out 41 * of colormap entries it returns zero _and_ undoes the conversions 42 * already done, so that the row is still a full row of 'rgba' values 43 * afterwards. 44 */ 45 int palettify_row(rgba *row,unsigned ncols); 46 47 /* palettify_rows is like palettify_rows, but works on several 48 * rows at a time. 49 */ 50 int palettify_rows(rgba *rows[],unsigned ncols,unsigned nlines); 51 52 #endif /* PALETTE_H */ 53