Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/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++) {
21for (dx = position.x, sx = 0; sx < width; dx++, sx++) {
22alpha = (pixel(blendThis, sx, sy).ch.a);
23
24/* Skip blending for fully transparent pixel */
25if (alpha == 0) {
26continue;
27}
28
29/* For fully opaque pixel, there is no need to interpolate */
30if (alpha == 255) {
31pixel(blendInto, dx, dy).value = pixel(blendThis, sx, sy).value;
32continue;
33}
34
35/* For semi-transparent pixels, do a full blend */
36//alpha++
37/* This is needed to spread the alpha over [0..256] instead of [0..255]
38Boundary conditions were handled above */
39dstrb = pixel(blendInto, dx, dy).value & 0xFF00FF;
40dstag = (pixel(blendInto, dx, dy).value >> 8) & 0xFF00FF;
41srcrb = pixel(blendThis, sx, sy).value & 0xFF00FF;
42srcag = (pixel(blendThis, sx, sy).value >> 8) & 0xFF00FF;
43drb = srcrb - dstrb;
44dag = srcag - dstag;
45drb *= alpha; dag *= alpha;
46drb >>= 8; dag >>= 8;
47rb = (drb + dstrb) & 0x00FF00FF;
48ag = ((dag + dstag) << 8) & 0xFF00FF00;
49pixel(blendInto, dx, dy).value = (rb | ag);
50}
51}
52}
53
54position_t centeredIn( const pixmap_t *background, const pixmap_t *toCenter ) {
55position_t centered;
56centered.x = ( background->width - toCenter->width ) / 2;
57centered.y = ( background->height - toCenter->height ) / 2;
58return centered;
59}
60
61position_t centeredAt( const pixmap_t *pixmap, const position_t center ) {
62position_t topleft;
63topleft.x = center.x - (pixmap->width / 2);
64topleft.y = center.y - (pixmap->height / 2);
65return 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;
75register 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: 2347