/* bmp.h */
#pragma once
#include <gui.h>
#include <shapes.h>

#define showbitmap(x)           showbitmap_($1 # x, (x))
#define showrecord(f,args...)   do { \
    zero(tmp, BufSz); \
    n = (int8)snprintf(tmp, (BufSz-1), $1 (f), args); \
    if (!n) \
        return $1 0; \
    bytes += n; \
    if (bytes > (BufSz-1)) \
        return $1 0; \
    stringcopy(p, tmp, $2 n); \
    p += n; \
} while(false)
#define BmpHdrSz    118

struct s_bitmapheader {
    int16 signature;
    int16 size;
    int16 _;
    int16 __, ___;
    int16 offset;
    int16 ____;
} packed;
typedef struct s_bitmapheader bitmapheader;

struct s_infoheader {
    int16 _;
    int16 ________________;
    int16 width;
    int16 __;
    int16 height;
    int16 ___;
    int16 _____;
    int16 ______;
    int16 _______, ________;
    int16 _________, __________;
    int16 ___________, ____________;
    int16 numcolors;
    int16 _____________;
    int16 _______________, _________________;
} packed;
typedef struct s_infoheader infoheader;

typedef rgb colortable[16];

struct s_bitmap {
    int8 *filename;
    int16 x;
    int16 y;
    bitmapheader *hdr;
    infoheader *info;
    colortable *colors;
} packed;
typedef struct s_bitmap bitmap;

bitmap *parsebmp(int8*,int16,int16);
boolean drawbmp(bitmap*);
int8 *addbmp(int8*);
int8 *showbitmap_(int8*,bitmap*);
int8 getclr(colortable*,int8);
