1 | /* Graphic utility functions and data types␊ |
2 | * Prashant Vaibhav (C) 12/12/2008␊ |
3 | * Chameleon␊ |
4 | */␊ |
5 | ␊ |
6 | // Everything here is 32 bits per pixel non-premultiplied ARGB format␊ |
7 | //␊ |
8 | ␊ |
9 | #ifndef GRAPHIC_UTILS_H␊ |
10 | #define GRAPHIC_UTILS_H␊ |
11 | ␊ |
12 | //Azi:include***␊ |
13 | //#include "boot.h" - "graphic_utils.h" included only on graphics.h atm, that already includes boot.h.␊ |
14 | ␊ |
15 | ␊ |
16 | typedef union {␊ |
17 | struct {␊ |
18 | uint8_t b;␊ |
19 | uint8_t g;␊ |
20 | uint8_t r;␊ |
21 | uint8_t a;␊ |
22 | } ch;␊ |
23 | uint8_t channel[4];␊ |
24 | uint32_t value;␊ |
25 | } pixel_t;␊ |
26 | ␊ |
27 | typedef struct {␊ |
28 | uint16_t␉height;␊ |
29 | uint16_t␉width;␊ |
30 | pixel_t*␉pixels;␊ |
31 | } pixmap_t;␊ |
32 | ␊ |
33 | typedef struct {␊ |
34 | uint32_t x;␊ |
35 | uint32_t y;␊ |
36 | } position_t;␊ |
37 | ␊ |
38 | // Blends the given pixmap into the given background at the given position␊ |
39 | // Uses the alpha channels to blend, and preserves the final alpha (so the␊ |
40 | // resultant pixmap can be blended again with another background).␊ |
41 | // ported from www.stereopsis.com/doubleblend.html␊ |
42 | void blend( const pixmap_t *blendThis, // Source image␊ |
43 | pixmap_t *blendInto, // Dest image␊ |
44 | const position_t position); // Where to place the source image␊ |
45 | // Returns the topleft co-ordinate where if you put the 'toCenter' pixmap,␊ |
46 | // it is centered in the background.␊ |
47 | position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter );␊ |
48 | ␊ |
49 | // Returns the topleft co-ordinate where if you put the given pixmap, its␊ |
50 | // center will coincide with the th given center.␊ |
51 | position_t centeredAt( const pixmap_t *pixmap, const position_t center );␊ |
52 | ␊ |
53 | // Utility function returns a position_t struct given the x and y coords as uint16␊ |
54 | position_t pos(const uint16_t x, const uint16_t y);␊ |
55 | ␊ |
56 | // Flips the R and B components of all pixels in the given pixmap␊ |
57 | void flipRB(pixmap_t *p);␊ |
58 | ␊ |
59 | // Utility function to get pixel at (x,y) in a pixmap␊ |
60 | #define pixel(p,x,y) ((p)->pixels[(x) + (y) * (p)->width])␊ |
61 | ␊ |
62 | #endif//GRAPHIC_UTILS_H␊ |
63 | |