1 #ifndef RL_IMAGE_H
2 #define RL_IMAGE_H
3 
4 #include <rl_userdata.h>
5 
6 #include <stdint.h>
7 #include <stddef.h>
8 
9 /*
10 An image with RLE-encoded pixels and per-pixel alpha of 0, 25, 50, 75 and 100%.
11 Images save the background in the bg pointer when blit, and restore the
12 background with that information when unblit.
13 */
14 
15 typedef struct
16 {
17   rl_userdata_t ud;
18 
19   int width;     /* the image width */
20   int height;    /* the image height */
21   int used;      /* number of overwritten pixels on the background */
22 
23   const uint32_t* rows; /* offsets to rle data for each row */
24 
25   uint8_t   data[ 0 ]; /* stored row offsets and rle data */
26 }
27 rl_image_t;
28 
29 typedef struct
30 {
31   int num_images;
32 
33   const rl_image_t* images[ 0 ];
34 }
35 rl_imageset_t;
36 
37 /* Creates an image given the RLE-encoded data produced by rlrle. */
38 rl_image_t* rl_image_create( const void* data, size_t size );
39 /* Destroys an image. */
40 #define rl_image_destroy( image ) do { rl_free( (void*)image ); } while ( 0 )
41 
42 /* Creates an image set. */
43 rl_imageset_t* rl_imageset_create( const void* data, size_t size );
44 /* Destroyes an image set. */
45 void rl_imageset_destroy( const rl_imageset_t* imageset );
46 
47 /* Blits an image to the given background. */
48 void rl_image_blit_nobg( const rl_image_t* image, int x, int y );
49 /* Blits an image to the given background, saving overwritten pixels in bg. */
50 uint16_t* rl_image_blit( const rl_image_t* image, int x, int y, uint16_t* bg );
51 /* Erases an image from the given background, restoring overwritten pixels from bg. */
52 void rl_image_unblit( const rl_image_t* image, int x, int y, const uint16_t* bg );
53 
54 #endif /* RL_IMAGE_H */
55