palpic2png.c: improve, make usable with ppic binary files
[rofl0r-openDOW.git] / palpic.h
bloba535997417d1427579cbc582965ce9235fd27038
1 #ifndef PALPIC_H
2 #define PALPIC_H
4 #include <stdint.h>
5 #include <netinet/in.h>
6 #include "../lib/include/endianness.h"
8 typedef union {
9 struct colors {
10 #if defined(IS_LITTLE_ENDIAN) && !defined(PALPIC_OPENGL)
11 uint8_t a,b,g,r;
12 #else
13 uint8_t r,g,b,a;
14 #endif
15 } colors;
16 uint32_t val;
17 } prgb;
19 typedef struct palpic {
20 char magic[4];
21 uint8_t version;
22 uint8_t palcount; /* 0 means 256 */
23 uint16_t spritecount;
24 uint16_t width;
25 uint16_t height;
26 uint16_t flags;
27 uint16_t padding;
28 //prgb palette[];
29 //uint8_t data[];
30 } palpic;
32 enum palpic_flags {
33 PPF_TRANSPARENT = 1,
36 #define palpic_empty { {'p', 'P', 'i', 'C', }, 1, 0, 0, 0, 0, 0, 0 }
38 #define PRGB(R,G,B) ((prgb) {.colors.r = R, .colors.g = G, .colors.b = B, .colors.a = 0xff,})
40 #if __GNUC__ + 0 > 3
41 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
42 #endif
44 static inline void palpic_hostformat(struct palpic *p) {
45 p->spritecount = ntohs(p->spritecount);
46 p->width = ntohs(p->width);
47 p->height = ntohs(p->height);
50 static inline void palpic_fileformat(struct palpic *p) {
51 p->spritecount = htons(p->spritecount);
52 p->width = htons(p->width);
53 p->height = htons(p->height);
56 static inline prgb* palpic_getpalette(const struct palpic* p) {
57 return (prgb*) (p+1);
60 #define palpic_getpalcount(P) (P->palcount ? P->palcount : 256)
62 static inline uint8_t* palpic_getdata(const struct palpic* p) {
63 return (uint8_t*)(p + 1) + (sizeof(prgb) * palpic_getpalcount(p));
66 static inline uint32_t palpic_getfilesize(const struct palpic* p) {
67 return sizeof(palpic) + (sizeof(prgb) * palpic_getpalcount(p)) + (p->width * p->height);
70 static inline unsigned palpic_getspriteheight(const struct palpic* p) {
71 return p->height / p->spritecount;
74 static inline unsigned palpic_getspritewidth(const struct palpic* p) {
75 return p->width;
78 static inline unsigned palpic_getspritecount(const struct palpic* p) {
79 return p->spritecount;
82 static inline uint8_t* palpic_getspritedata(const struct palpic* p, uint16_t spritenum) {
83 return palpic_getdata(p) + (spritenum * palpic_getspriteheight(p) * palpic_getspritewidth(p));
86 struct vo_desc {
87 void *mem;
88 unsigned pitch;
89 unsigned width;
90 unsigned height;
93 void blit_sprite(int x_pos, int y_pos, struct vo_desc *video,
94 unsigned scale, const struct palpic* pic, uint16_t spritenum, const prgb *palette);
96 #pragma RcB2 DEP "palpic.c"
98 #endif