1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-04 21:04:18 +01:00

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 <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-07-04 23:28:36 +02:00
committed by Carlos R. Mafra
parent f2dea1b840
commit cd29983e03

View File

@@ -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;