mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
wrlib: code refactoring in RFlipImage functions
Instead of calling all variables with variants of 'image', changed the name to reflect what image it is about for clarity. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
f85066a19e
commit
f2dea1b840
60
wrlib/flip.c
60
wrlib/flip.c
@@ -20,33 +20,35 @@
|
|||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#include "wraster.h"
|
#include "wraster.h"
|
||||||
|
|
||||||
RImage *RVerticalFlipImage(RImage *image)
|
RImage *RVerticalFlipImage(RImage *source)
|
||||||
{
|
{
|
||||||
RImage *img;
|
RImage *target;
|
||||||
int nwidth, nheight;
|
int nwidth, nheight;
|
||||||
int x, y;
|
int x, y;
|
||||||
int bpp = image->format == RRGBAFormat ? 4 : 3;
|
int bpp = source->format == RRGBAFormat ? 4 : 3;
|
||||||
|
|
||||||
nwidth = image->width;
|
nwidth = source->width;
|
||||||
nheight = image->height;
|
nheight = source->height;
|
||||||
|
|
||||||
img = RCreateImage(nwidth, nheight, True);
|
target = RCreateImage(nwidth, nheight, True);
|
||||||
if (!img)
|
if (!target)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (bpp == 3) {
|
if (bpp == 3) {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
optr = image->data;
|
optr = source->data;
|
||||||
nptr = img->data + 4 * (nwidth * nheight - nwidth);
|
nptr = target->data + 4 * (nwidth * nheight - nwidth);
|
||||||
|
|
||||||
for (y = 0; y < nheight; y++) {
|
for (y = 0; y < nheight; y++) {
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = 0; x < nwidth; x++) {
|
||||||
@@ -58,13 +60,13 @@ RImage *RVerticalFlipImage(RImage *image)
|
|||||||
optr += 3;
|
optr += 3;
|
||||||
nptr += 4;
|
nptr += 4;
|
||||||
}
|
}
|
||||||
nptr -= nwidth*8;
|
nptr -= (nwidth * 4) * 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
optr = image->data;
|
optr = source->data;
|
||||||
nptr = img->data + 4 * (nwidth * nheight - nwidth);
|
nptr = target->data + 4 * (nwidth * nheight - nwidth);
|
||||||
|
|
||||||
for (y = 0; y < nheight; y++) {
|
for (y = 0; y < nheight; y++) {
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = 0; x < nwidth; x++) {
|
||||||
@@ -76,31 +78,31 @@ RImage *RVerticalFlipImage(RImage *image)
|
|||||||
optr += 4;
|
optr += 4;
|
||||||
nptr += 4;
|
nptr += 4;
|
||||||
}
|
}
|
||||||
nptr -= nwidth * 8;
|
nptr -= (nwidth * 4) * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return img;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
RImage *RHorizontalFlipImage(RImage *image)
|
RImage *RHorizontalFlipImage(RImage *source)
|
||||||
{
|
{
|
||||||
RImage *img;
|
RImage *target;
|
||||||
int nwidth, nheight;
|
int nwidth, nheight;
|
||||||
int x, y;
|
int x, y;
|
||||||
int bpp = image->format == RRGBAFormat ? 4 : 3;
|
int bpp = source->format == RRGBAFormat ? 4 : 3;
|
||||||
|
|
||||||
nwidth = image->width;
|
nwidth = source->width;
|
||||||
nheight = image->height;
|
nheight = source->height;
|
||||||
|
|
||||||
img = RCreateImage(nwidth, nheight, True);
|
target = RCreateImage(nwidth, nheight, True);
|
||||||
if (!img)
|
if (!target)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (bpp == 3) {
|
if (bpp == 3) {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
optr = image->data;
|
optr = source->data;
|
||||||
nptr = img->data + 4 * (nwidth - 1);
|
nptr = target->data + 4 * (nwidth - 1);
|
||||||
|
|
||||||
for (y = nheight; y; y--) {
|
for (y = nheight; y; y--) {
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = 0; x < nwidth; x++) {
|
||||||
@@ -112,13 +114,13 @@ RImage *RHorizontalFlipImage(RImage *image)
|
|||||||
optr += 3;
|
optr += 3;
|
||||||
nptr -= 4;
|
nptr -= 4;
|
||||||
}
|
}
|
||||||
nptr += 8 * nwidth;
|
nptr += (nwidth * 4) * 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
optr = image->data;
|
optr = source->data;
|
||||||
nptr = img->data + 4 * (nwidth - 1);
|
nptr = target->data + 4 * (nwidth - 1);
|
||||||
|
|
||||||
for (y = nheight; y; y--) {
|
for (y = nheight; y; y--) {
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = 0; x < nwidth; x++) {
|
||||||
@@ -130,8 +132,8 @@ RImage *RHorizontalFlipImage(RImage *image)
|
|||||||
optr += 4;
|
optr += 4;
|
||||||
nptr -= 4;
|
nptr -= 4;
|
||||||
}
|
}
|
||||||
nptr += 8 * nwidth;
|
nptr += (nwidth * 4) * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return img;
|
return target;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user