X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=render%2Fimage.c;h=2ec710438cd32632cb8f09aabd97c7404373b1f9;hb=615cbd96075905d75533f9b615c4ee6a75f4f9a4;hp=5bd3285b19b8cc67cf1a05771911f84b77d40127;hpb=c0568cd7ef9542540b11068c002bb6a8d35f3d84;p=chaz%2Fopenbox diff --git a/render/image.c b/render/image.c index 5bd3285b..2ec71043 100644 --- a/render/image.c +++ b/render/image.c @@ -1,64 +1,73 @@ -#include -#include "../kernel/geom.h" +#include "geom.h" #include "image.h" +#include "color.h" + +#include -void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position) +void RrImageDraw(RrPixel32 *target, RrTextureRGBA *rgba, RrRect *area) { - unsigned long *draw = rgba->data; - int c, sfw, sfh; - unsigned int i, e, bgi; - sfw = position->width; - sfh = position->height; + RrPixel32 *draw = rgba->data; + gint c, i, e, t, sfw, sfh; + sfw = area->width; + sfh = area->height; - g_assert(rgba->data != NULL); + g_assert(rgba->data != NULL); - if ((rgba->width != sfw || rgba->height != sfh) && - (rgba->width != rgba->cwidth || rgba->height != rgba->cheight)) { - double dx = rgba->width / (double)sfw; - double dy = rgba->height / (double)sfh; - double px = 0.0; - double py = 0.0; - int iy = 0; + if ((rgba->width != sfw || rgba->height != sfh) && + (rgba->width != rgba->cwidth || rgba->height != rgba->cheight)) { + double dx = rgba->width / (double)sfw; + double dy = rgba->height / (double)sfh; + double px = 0.0; + double py = 0.0; + int iy = 0; - /* scale it and cache it */ - if (rgba->cache != NULL) - g_free(rgba->cache); - rgba->cache = g_new(unsigned long, sfw * sfh); - rgba->cwidth = sfw; - rgba->cheight = sfh; - for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) { - rgba->cache[i] = rgba->data[(int)px + iy]; - if (++c >= sfw) { - c = 0; - px = 0; - py += dy; - iy = (int)py * rgba->width; - } else - px += dx; - } + /* scale it and cache it */ + if (rgba->cache != NULL) + g_free(rgba->cache); + rgba->cache = g_new(RrPixel32, sfw * sfh); + rgba->cwidth = sfw; + rgba->cheight = sfh; + for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) { + rgba->cache[i] = rgba->data[(int)px + iy]; + if (++c >= sfw) { + c = 0; + px = 0; + py += dy; + iy = (int)py * rgba->width; + } else + px += dx; + } + + /* do we use the cache we may have just created, or the original? */ + if (rgba->width != sfw || rgba->height != sfh) + draw = rgba->cache; + + /* apply the alpha channel */ + for (i = 0, c = 0, t = area->x, e = sfw*sfh; i < e; ++i, ++t) { + guchar alpha, r, g, b, bgr, bgg, bgb; -/* do we use the cache we may have just created, or the original? */ - if (rgba->width != sfw || rgba->height != sfh) - draw = rgba->cache; + alpha = draw[i] >> RrDefaultAlphaOffset; + r = draw[i] >> RrDefaultRedOffset; + g = draw[i] >> RrDefaultGreenOffset; + b = draw[i] >> RrDefaultBlueOffset; - /* apply the alpha channel */ - for (i = 0, c = 0, e = sfw*sfh; i < e; ++i, ++bgi) { - unsigned char alpha = draw[i] >> 24; - unsigned char r = draw[i] >> 16; - unsigned char g = draw[i] >> 8; - unsigned char b = draw[i]; + if (c >= sfw) { + c = 0; + t += area->width - sfw; + } - /* background color */ - unsigned char bgr = target[i] >> default_red_shift; - unsigned char bgg = target[i] >> default_green_shift; - unsigned char bgb = target[i] >> default_blue_shift; + /* background color */ + bgr = target[t] >> RrDefaultRedOffset; + bgg = target[t] >> RrDefaultGreenOffset; + bgb = target[t] >> RrDefaultBlueOffset; - r = bgr + (((r - bgr) * alpha) >> 8); - g = bgg + (((g - bgg) * alpha) >> 8); - b = bgb + (((b - bgb) * alpha) >> 8); + r = bgr + (((r - bgr) * alpha) >> 8); + g = bgg + (((g - bgg) * alpha) >> 8); + b = bgb + (((b - bgb) * alpha) >> 8); - target[i] = (r << default_red_shift) | (g << default_green_shift) | - (b << default_blue_shift); + target[t] = (r << RrDefaultRedOffset) + | (g << RrDefaultGreenOffset) + | (b << RrDefaultBlueOffset); + } } - } }