Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/boot2/graphic_utils.c

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
11pixmap_t *blendInto,// Dest image
12const 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
20for (dy = position.y, sy = 0; sy < height; dy++, sy++)
21{
22for (dx = position.x, sx = 0; sx < width; dx++, sx++)
23{
24alpha = (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]
39Boundary conditions were handled above */
40dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;
41dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;
42srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;
43srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;
44drb = srcrb - dstrb;
45dag = srcag - dstag;
46drb *= alpha; dag *= alpha;
47drb >>= 8; dag >>= 8;
48rb = (drb + dstrb) & 0x00FF00FF;
49ag = ((dag + dstag) << 8) & 0xFF00FF00;
50pixel(blendInto, dx, dy).value = (rb | ag);
51}
52}
53}
54
55position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter )
56{
57position_t centered;
58centered.x = ( background->width - toCenter->width ) / 2;
59centered.y = ( background->height - toCenter->height ) / 2;
60return centered;
61}
62
63position_t centeredAt( const pixmap_t *pixmap, const position_t center )
64{
65position_t topleft;
66topleft.x = center.x - (pixmap->width / 2);
67topleft.y = center.y - (pixmap->height / 2);
68return 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;
78register uint8_t tempB;
79for (x = 0; x < (p->height) * (p->width) ; x++)
80{
81tempB = (p->pixels[x]).ch.b;
82(p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
83(p->pixels[x]).ch.r = tempB;
84}
85}
86

Archive Download this file

Revision: 1996