1 #include "kernel/geom.h"
7 void RrImageDraw(RrPixel32 *target, RrTextureRGBA *rgba, Rect *area)
9 RrPixel32 *draw = rgba->data;
10 gint c, i, e, t, sfw, sfh;
14 g_assert(rgba->data != NULL);
16 if ((rgba->width != sfw || rgba->height != sfh) &&
17 (rgba->width != rgba->cwidth || rgba->height != rgba->cheight)) {
18 double dx = rgba->width / (double)sfw;
19 double dy = rgba->height / (double)sfh;
24 /* scale it and cache it */
25 if (rgba->cache != NULL)
27 rgba->cache = g_new(RrPixel32, sfw * sfh);
30 for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) {
31 rgba->cache[i] = rgba->data[(int)px + iy];
36 iy = (int)py * rgba->width;
41 /* do we use the cache we may have just created, or the original? */
42 if (rgba->width != sfw || rgba->height != sfh)
45 /* apply the alpha channel */
46 for (i = 0, c = 0, t = area->x, e = sfw*sfh; i < e; ++i, ++t) {
47 guchar alpha, r, g, b, bgr, bgg, bgb;
49 alpha = draw[i] >> RrDefaultAlphaOffset;
50 r = draw[i] >> RrDefaultRedOffset;
51 g = draw[i] >> RrDefaultGreenOffset;
52 b = draw[i] >> RrDefaultBlueOffset;
56 t += area->width - sfw;
59 /* background color */
60 bgr = target[t] >> RrDefaultRedOffset;
61 bgg = target[t] >> RrDefaultGreenOffset;
62 bgb = target[t] >> RrDefaultBlueOffset;
64 r = bgr + (((r - bgr) * alpha) >> 8);
65 g = bgg + (((g - bgg) * alpha) >> 8);
66 b = bgb + (((b - bgb) * alpha) >> 8);
68 target[t] = (r << RrDefaultRedOffset)
69 | (g << RrDefaultGreenOffset)
70 | (b << RrDefaultBlueOffset);