diff options
| author | Dana Jansens <danakj@orodu.net> | 2008-02-13 09:14:58 -0500 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2008-02-14 15:10:14 -0500 |
| commit | 38c96413b375516a25086cf169d2d3cb7c6075f7 (patch) | |
| tree | afb3d69d15db7b2212bd92565579b06c18ed3366 /render/image.c | |
| parent | a2e3026d8a398a4d08c05610c3f652dd14fcdf45 (diff) | |
pre-calc the sum of a picture added to an RrImage rather than calculating it every time
Diffstat (limited to 'render/image.c')
| -rw-r--r-- | render/image.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/render/image.c b/render/image.c index a618f782..a374ceb4 100644 --- a/render/image.c +++ b/render/image.c @@ -28,6 +28,18 @@ #define FLOOR(i) ((i) & (~0UL << FRACTION)) #define AVERAGE(a, b) (((((a) ^ (b)) & 0xfefefefeL) >> 1) + ((a) & (b))) +void RrImagePicInit(RrImagePic *pic, gint w, gint h, RrPixel32 *data) +{ + gint i; + + pic->width = w; + pic->height = h; + pic->data = data; + pic->sum = 0; + for (i = w*h; i > 0; --i) + pic->sum += *(data++); +} + /*! Add a picture to an Image, that is, add another copy of the image at another size. This may add it to the "originals" list or to the "resized" list. */ @@ -98,7 +110,7 @@ static RrImagePic* ResizeImage(RrPixel32 *src, gulong srcW, gulong srcH, gulong dstW, gulong dstH) { - RrPixel32 *dst; + RrPixel32 *dst, *dststart; RrImagePic *pic; gulong dstX, dstY, srcX, srcY; gulong srcX1, srcX2, srcY1, srcY2; @@ -118,11 +130,7 @@ static RrImagePic* ResizeImage(RrPixel32 *src, if (srcW == dstW && srcH == dstH) return NULL; /* no scaling needed ! */ - pic = g_new(RrImagePic, 1); - dst = g_new(RrPixel32, dstW * dstH); - pic->width = dstW; - pic->height = dstH; - pic->data = dst; + dststart = dst = g_new(RrPixel32, dstW * dstH); ratioX = (srcW << FRACTION) / dstW; ratioY = (srcH << FRACTION) / dstH; @@ -194,6 +202,9 @@ static RrImagePic* ResizeImage(RrPixel32 *src, } } + pic = g_new(RrImagePic, 1); + RrImagePicInit(pic, dstW, dstH, dststart); + return pic; } @@ -343,9 +354,7 @@ void RrImageAddPicture(RrImage *self, RrPixel32 *data, gint w, gint h) /* add the new picture */ pic = g_new(RrImagePic, 1); - pic->width = w; - pic->height = h; - pic->data = g_memdup(data, w*h*sizeof(RrPixel32)); + RrImagePicInit(pic, w, h, g_memdup(data, w*h*sizeof(RrPixel32))); AddPicture(self, &self->original, &self->n_original, pic); } |
