From cd29983e03b696252d91cd5264bca0417a1768b0 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Fri, 4 Jul 2014 23:28:36 +0200 Subject: [PATCH] wrlib: do not create an alpha channel if the original image did not have it in RFlipImage As it does not cost anything in the current code to not add this channel, it is then probably a good idea to keep the output image with the same format as the input image, this avoid wasting +33% of memory for something that may be at best unused and at worst will induce extra cost when manipulating the image. Signed-off-by: Christophe CURIS --- wrlib/flip.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/wrlib/flip.c b/wrlib/flip.c index 03d6166a..ea5aeeef 100644 --- a/wrlib/flip.c +++ b/wrlib/flip.c @@ -35,32 +35,30 @@ RImage *RVerticalFlipImage(RImage *source) RImage *target; int nwidth, nheight; int x, y; - int bpp = source->format == RRGBAFormat ? 4 : 3; nwidth = source->width; nheight = source->height; - target = RCreateImage(nwidth, nheight, True); + target = RCreateImage(nwidth, nheight, (source->format != RRGBFormat)); if (!target) return NULL; - if (bpp == 3) { + if (source->format == RRGBFormat) { unsigned char *optr, *nptr; optr = source->data; - nptr = target->data + 4 * (nwidth * nheight - nwidth); + nptr = target->data + 3 * (nwidth * nheight - nwidth); for (y = 0; y < nheight; y++) { for (x = 0; x < nwidth; x++) { nptr[0] = optr[0]; nptr[1] = optr[1]; nptr[2] = optr[2]; - nptr[3] = 255; optr += 3; - nptr += 4; + nptr += 3; } - nptr -= (nwidth * 4) * 2; + nptr -= (nwidth * 3) * 2; } } else { unsigned char *optr, *nptr; @@ -89,32 +87,30 @@ RImage *RHorizontalFlipImage(RImage *source) RImage *target; int nwidth, nheight; int x, y; - int bpp = source->format == RRGBAFormat ? 4 : 3; nwidth = source->width; nheight = source->height; - target = RCreateImage(nwidth, nheight, True); + target = RCreateImage(nwidth, nheight, (source->format != RRGBFormat)); if (!target) return NULL; - if (bpp == 3) { + if (source->format == RRGBFormat) { unsigned char *optr, *nptr; optr = source->data; - nptr = target->data + 4 * (nwidth - 1); + nptr = target->data + 3 * (nwidth - 1); for (y = nheight; y; y--) { for (x = 0; x < nwidth; x++) { nptr[0] = optr[0]; nptr[1] = optr[1]; nptr[2] = optr[2]; - nptr[3] = 255; optr += 3; - nptr -= 4; + nptr -= 3; } - nptr += (nwidth * 4) * 2; + nptr += (nwidth * 3) * 2; } } else { unsigned char *optr, *nptr;