1 #ifndef MPLAYER_PACK_RECTANGLES_H
2 #define MPLAYER_PACK_RECTANGLES_H
3 
4 struct pos {
5     int x;
6     int y;
7 };
8 
9 struct bitmap_packer {
10     int w;
11     int h;
12     int w_max;
13     int h_max;
14     int padding;
15     int count;
16     struct pos *in;
17     struct pos *result;
18     int used_width;
19     int used_height;
20 
21     // internal
22     int *scratch;
23     int asize;
24 };
25 
26 struct sub_bitmaps;
27 
28 // Clear all internal state. Leave the following fields: w_max, h_max
29 void packer_reset(struct bitmap_packer *packer);
30 
31 // Get the bounding box used for bitmap data (including padding).
32 // The bounding box doesn't exceed (0,0)-(packer->w,packer->h).
33 void packer_get_bb(struct bitmap_packer *packer, struct pos out_bb[2]);
34 
35 /* Reallocate packer->in for at least to desired number of items.
36  * Also sets packer->count to the same value.
37  */
38 void packer_set_size(struct bitmap_packer *packer, int size);
39 
40 /* To use this, set packer->count to number of rectangles, w_max and h_max
41  * to maximum output rectangle size, and w and h to start size (may be 0).
42  * Write input sizes in packer->in.
43  * Resulting packing will be written in packer->result.
44  * w and h will be increased if necessary for successful packing.
45  * There is a strong guarantee that w and h will be powers of 2 (or set to 0).
46  * Return value is -1 if packing failed because w and h were set to max
47  * values but that wasn't enough, 1 if w or h was increased, and 0 otherwise.
48  */
49 int packer_pack(struct bitmap_packer *packer);
50 
51 #endif
52