Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/GUI/graphic_utils.c

Source at commit 532 created 13 years 7 months ago.
By meklort, More module changes, temperary hack to disable static variables in modules until I get it fixed.
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{
22 for (dx = position.x, sx = 0; sx < width; dx++, sx++)
23{
24 alpha = (pixel(blendThis, sx, sy).ch.a);
25
26/* Skip blending for fully transparent pixel */
27if (alpha == 0) continue;
28
29/* For fully opaque pixel, there is no need to interpolate */
30if (alpha == 255)
31{
32pixel(blendInto, dx, dy).value = pixel(blendThis, sx, sy).value;
33continue;
34}
35
36/* For semi-transparent pixels, do a full blend */
37//alpha++
38/* This is needed to spread the alpha over [0..256] instead of [0..255]
39 Boundary conditions were handled above */
40 dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;
41 dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;
42 srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;
43 srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;
44 drb = srcrb - dstrb;
45 dag = srcag - dstag;
46 drb *= alpha; dag *= alpha;
47 drb >>= 8; dag >>= 8;
48 rb = (drb + dstrb) & 0x00FF00FF;
49 ag = ((dag + dstag) << 8) & 0xFF00FF00;
50 pixel(blendInto, dx, dy).value = (rb | ag);
51 }
52 }
53}
54
55position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter )
56{
57 position_t centered;
58 centered.x = ( background->width - toCenter->width ) / 2;
59 centered.y = ( background->height - toCenter->height ) / 2;
60 return centered;
61}
62
63position_t centeredAt( const pixmap_t *pixmap, const position_t center )
64{
65 position_t topleft;
66 topleft.x = center.x - (pixmap->width / 2);
67 topleft.y = center.y - (pixmap->height / 2);
68 return topleft;
69}
70
71position_t pos(const uint16_t x, const uint16_t y) { position_t p; p.x = x; p.y = y; return p; }
72
73void flipRB(pixmap_t *p)
74{
75//if(testForQemu()) return;
76
77uint32_t x;
78 register uint8_t tempB;
79for (x = 0; x < (p->height) * (p->width) ; x++) {
80tempB = (p->pixels[x]).ch.b;
81 (p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
82 (p->pixels[x]).ch.r = tempB;
83}
84}
85

Archive Download this file

Revision: 532