2 #include "../kernel/geom.h"
5 void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position,
8 unsigned long *draw = rgba->data;
11 sfw = position->width;
12 sfh = position->height;
14 /* it would be nice if this worked, but this function is well broken in these
16 g_assert(position->width == surarea->width &&
17 position->height == surarea->height);
19 g_assert(rgba->data != NULL);
21 if ((rgba->width != sfw || rgba->height != sfh) &&
22 (rgba->width != rgba->cwidth || rgba->height != rgba->cheight)) {
23 double dx = rgba->width / (double)sfw;
24 double dy = rgba->height / (double)sfh;
29 /* scale it and cache it */
30 if (rgba->cache != NULL)
32 rgba->cache = g_new(unsigned long, sfw * sfh);
35 for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) {
36 rgba->cache[i] = rgba->data[(int)px + iy];
41 iy = (int)py * rgba->width;
46 /* do we use the cache we may have just created, or the original? */
47 if (rgba->width != sfw || rgba->height != sfh)
50 /* apply the alpha channel */
51 for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) {
52 unsigned char alpha = draw[i] >> 24;
53 unsigned char r = draw[i] >> 16;
54 unsigned char g = draw[i] >> 8;
55 unsigned char b = draw[i];
57 /* background color */
58 unsigned char bgr = target[i] >> default_red_shift;
59 unsigned char bgg = target[i] >> default_green_shift;
60 unsigned char bgb = target[i] >> default_blue_shift;
62 r = bgr + (((r - bgr) * alpha) >> 8);
63 g = bgg + (((g - bgg) * alpha) >> 8);
64 b = bgb + (((b - bgb) * alpha) >> 8);
66 target[i] = (r << default_red_shift) | (g << default_green_shift) |
67 (b << default_blue_shift);