Initial commit
[pal.git] / pal.h
1 #ifndef __PAL_H
2 #define __PAL_H
3
4 #include <stdint.h>
5
6 #define PAL_READ_OK     0
7 #define PAL_READ_ERROR  1
8
9 #define PAL_READ_NOOPT -1
10
11 struct pal_rgb {
12         /** Red */
13         uint8_t r;
14         
15         /** Green */
16         uint8_t g;
17         
18         /** Blue */
19         uint8_t b;
20 };
21
22 struct pal {
23         /**
24          * Colors in the palette are in the range 0..63.
25          *
26          * The first element (index 0) is always considered transparent (actual
27          * color is ignored). If the value of one color component is not in the
28          * range 0..63, in a special table the index is marked as unused, and
29          * all components of the color are set to 0.
30          *
31          * Elements from 229 to 254 are used as 'animation colors' and Fallout
32          * sets their values itself. 229 to 232 are animated green (for
33          * radioactive waste), 238 to 247 are orange, red and yellow (for
34          * fires), and the rest are bright blue (computer screens).
35          */
36         struct pal_rgb colors[256];
37         
38         /** Table for converting RGB values => to index in the palette. */
39         uint8_t element[32768];
40
41         /* optional */
42         /*
43         char NEWC[4];
44         int8_t table1[65536];
45         int8_t table2[65536];
46         int8_t table3[65536];
47         */
48 };
49
50 struct pal_optional {
51         /** Tag for the availability of additional tables.?
52          *
53          * 'NEWC'
54          */
55         char newc[4];
56
57         /** Additional table */
58         int8_t table[3][65536];
59 };
60
61 /**
62  * Reads PAL informations about pallette
63  *
64  * @param in opened stream for reading
65  * @param _pal reference to structure where read informations will be stored
66  *
67  * @return when succesful function returns PAL_READ_OK, otherwise PAL_READ_ERROR
68  *         and errno should be checked for details.
69  */
70 int pal_read(FILE * in, struct pal * _pal);
71
72 /**
73  * Reads PAL optional informations about pallette
74  *
75  * @param in opened stream for reading
76  * @param _optional reference to structure where read informations will be stored
77  *
78  * @return when succesfully read optional informations, function returns
79  *         PAL_READ_OK and opt value contains read information. When there were
80  *         no informations in input stream, returns PAL_READ_NOOPT and opt is
81  *         unchanged, otherwise PAL_READ_ERROR is returned, opt is unchanged and
82  *         errno should be checked for details.
83  */
84 int pal_read_optional(FILE * in, struct pal_optional * opt);
85
86 #endif /* __PAL_H */