Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/i386/boot2/graphic_utils.c

Source at commit 214 created 13 years 5 months ago.
By ifabio, update to chameleon trunk 630, and now the pakage folder is the same as blackosx branch, also add Icon "building" into buildpkg script, and add mint theme info into the English localizable.strings.
1
2 /* Graphic utility functions and data types
3 * Prashant Vaibhav (C) 12/12/2008
4 * Chameleon
5 */
6#include "boot.h"
7#include "graphic_utils.h"
8#include "gui.h"
9
10void blend( const pixmap_t *blendThis, // Source image
11 pixmap_t *blendInto, // Dest image
12 const position_t position) // Where to place the source image
13{
14 uint16_t sx, sy, dx, dy;
15 uint32_t dstrb, dstag, srcrb, srcag, drb, dag, rb, ag, alpha;
16
17uint16_t width = (blendThis->width + position.x < blendInto->width) ? blendThis->width: blendInto->width-position.x;
18uint16_t height = (blendThis->height + position.y < blendInto->height) ? blendThis->height: blendInto->height-position.y;
19
20 for (dy = position.y, sy = 0; sy < height; dy++, sy++) {
21 for (dx = position.x, sx = 0; sx < width; dx++, sx++) {
22 alpha = (pixel(blendThis, sx, sy).ch.a);
23
24 /* Skip blending for fully transparent pixel */
25 if (alpha == 0) continue;
26
27 /* For fully opaque pixel, there is no need to interpolate */
28 if (alpha == 255) {
29 pixel(blendInto, dx, dy).value = pixel(blendThis, sx, sy).value;
30 continue;
31 }
32
33 /* For semi-transparent pixels, do a full blend */
34 //alpha++
35 /* This is needed to spread the alpha over [0..256] instead of [0..255]
36Boundary conditions were handled above */
37 dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;
38 dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;
39 srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;
40 srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;
41 drb = srcrb - dstrb;
42 dag = srcag - dstag;
43 drb *= alpha; dag *= alpha;
44 drb >>= 8; dag >>= 8;
45 rb = (drb + dstrb) & 0x00FF00FF;
46 ag = ((dag + dstag) << 8) & 0xFF00FF00;
47 pixel(blendInto, dx, dy).value = (rb | ag);
48 }
49 }
50}
51
52position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter )
53{
54 position_t centered;
55 centered.x = ( background->width - toCenter->width ) / 2;
56 centered.y = ( background->height - toCenter->height ) / 2;
57 return centered;
58}
59
60position_t centeredAt( const pixmap_t *pixmap, const position_t center )
61{
62 position_t topleft;
63 topleft.x = center.x - (pixmap->width / 2);
64 topleft.y = center.y - (pixmap->height / 2);
65 return topleft;
66}
67
68position_t pos(const uint16_t x, const uint16_t y) { position_t p; p.x = x; p.y = y; return p; }
69
70void flipRB(pixmap_t *p)
71{
72//if(testForQemu()) return;
73
74uint32_t x;
75 register uint8_t tempB;
76for (x = 0; x < (p->height) * (p->width) ; x++) {
77tempB = (p->pixels[x]).ch.b;
78 (p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
79 (p->pixels[x]).ch.r = tempB;
80}
81}
82

Archive Download this file

Revision: 214