From: Christophe CURIS <[email protected]>

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 <[email protected]>
---
 wrlib/flip.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/wrlib/flip.c b/wrlib/flip.c
index 03d6166..ea5aeee 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;
-- 
2.0.0


-- 
To unsubscribe, send mail to [email protected].

Reply via email to