removed clang-format and clang_complete files from the repo
[dosdemo] / src / rlebmap.h
1 #ifndef __RLE_BITMAP_H__
2 #define __RLE_BITMAP_H__
3
4 /* Limit streak count per scanline so we can directly jump to specific scanline
5  */
6 #define RLE_STREAKS_PER_SCANLINE 4
7
8 /* Streaks will not exceed this many pixels. This allows us to optimize with a
9  * padded framebuffer. If a streak start position happens to lie within
10  * framebuffer, we will blit it without checking for out of bounds */
11 #define RLE_MAX_STREAK_LENGTH 32
12
13 /* Using the following type for storing start and for storing length in (start,
14  * length) pairs. */
15 #define RLE_TYPE unsigned char
16
17 /* For now, keep a static fill color. We can change this. Not that much about
18  * speed, but let's keep function definitions more compact. */
19 #define RLE_FILL_COLOR 0
20
21 /* Two entries of RLE_FILL_COLOR (16 bits) packed one after the other. */
22 #define RLE_FILL_COLOR_32 ((RLE_FILL_COLOR << 16) | RLE_FILL_COLOR)
23
24 /* For fixed-point arithmetic. Used for scaling. */
25 #define RLE_FIXED_BITS 16
26
27 /* This is a bitmap (image in 1bpp), encoded as streaks of consecutive pixels.
28  */
29 typedef struct {
30         unsigned int w, h;
31
32         /* Each scan is RLE_BYTES_PER_SCANLINE long and contains pairs of
33          * (start, length). */
34         RLE_TYPE *scans;
35 } RleBitmap;
36
37 /* Constructor */
38 RleBitmap *rleCreate(unsigned int w, unsigned int h);
39
40 /* Destructor */
41 void rleDestroy(RleBitmap *rle);
42
43 /* Clears 'rle' to "all transparent" */
44 void rleClear(RleBitmap *rle);
45
46 /* Encode 'pixels' into 'rle' and also return it. Pixels are either 0 or 1. This
47  * will create an RleBitmap of 'h' scanlines. */
48 RleBitmap *rleEncode(RleBitmap *rle, unsigned char *pixels, unsigned int pixelsW,
49                      unsigned int pixelsH);
50
51 /* Rearranges the streaks to make it less frequent that they produce garbege when interpolated */
52 void rleDistributeStreaks(RleBitmap *rle);
53
54 /* Blits without scaling */
55 void rleBlit(RleBitmap *rle, unsigned short *dst, int dstW, int dstH, int dstStride, int blitX,
56              int blitY);
57
58 /* Scaled blit */
59 void rleBlitScale(RleBitmap *rle, unsigned short *dst, int dstW, int dstH, int dstStride, int blitX,
60                   int blitY, float scaleX, float scaleY);
61
62 /* Inverted blit (upside down) */
63 void rleBlitScaleInv(RleBitmap *rle, unsigned short *dst, int dstW, int dstH, int dstStride,
64                      int blitX, int blitY, float scaleX, float scaleY);
65
66 #endif // __RLE_BITMAP_H__