1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-30 18:32:34 +01:00

wrlib: fixed transformation functions

With a set of images i was able to detect that
the flip functions was shifting the image by 1px.

The 90 and 270 degrees rotation were not working as
the functions were also mirroring the img.

The patch is also fixing the C style based on checkpatch.
This commit is contained in:
David Maciejak
2014-05-26 22:42:44 +08:00
committed by Carlos R. Mafra
parent dda7f48407
commit 35a43c9430
2 changed files with 99 additions and 96 deletions

View File

@@ -34,9 +34,9 @@
#define PI 3.14159265358979323846
#endif
static RImage *rotateImage(RImage * image, float angle);
static RImage *rotateImage(RImage *image, float angle);
RImage *RRotateImage(RImage * image, float angle)
RImage *RRotateImage(RImage *image, float angle)
{
RImage *img;
int nwidth, nheight;
@@ -66,40 +66,41 @@ RImage *RRotateImage(RImage * image, float angle)
nheight = image->width;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
if (!img)
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
unsigned offs;
offs = nwidth * 4;
optr = image->data;
nptr = img->data;
for (x = 0; x < nwidth; x++) {
nptr = img->data + x * 4;
for (x = nwidth; x; x--) {
nptr = img->data + 4 * (x - 1);
for (y = nheight; y; y--) {
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = 255;
nptr += offs;
nptr += 4 * nwidth;
}
}
} else {
unsigned *optr, *nptr;
unsigned *p;
unsigned char *optr, *nptr;
optr = (unsigned *)image->data;
p = (unsigned *)img->data;
for (x = 0; x < nwidth; x++) {
nptr = p++;
optr = image->data;
nptr = img->data;
for (x = nwidth; x; x--) {
nptr = img->data + 4 * (x - 1);
for (y = nheight; y; y--) {
*nptr = *optr++;
nptr += nwidth;
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = *optr++;
nptr += 4 * nwidth;
}
}
}
@@ -109,9 +110,8 @@ RImage *RRotateImage(RImage * image, float angle)
nwidth = image->width;
nheight = image->height;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
if (!img)
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
@@ -148,40 +148,39 @@ RImage *RRotateImage(RImage * image, float angle)
nheight = image->width;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
if (!img)
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
unsigned offs;
offs = nwidth * 4;
optr = image->data;
for (x = 0; x < nwidth; x++) {
nptr = img->data + x * 4;
for (x = nwidth; x; x--) {
nptr = img->data + 4 * nwidth * nheight - x * 4;
for (y = nheight; y; y--) {
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = 255;
nptr += offs;
nptr -= 4 * nwidth;
}
}
} else {
unsigned *optr, *nptr;
unsigned *p;
unsigned char *optr, *nptr;
optr = (unsigned *)image->data;
p = (unsigned *)img->data + nwidth * nheight;
for (x = 0; x < nwidth; x++) {
nptr = p--;
optr = image->data;
for (x = nwidth; x; x--) {
nptr = img->data + 4 * nwidth * nheight - x * 4;
for (y = nheight; y; y--) {
*nptr = *optr++;
nptr -= nwidth;
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = *optr++;
nptr -= 4 * nwidth;
}
}
}
@@ -209,7 +208,7 @@ RImage *RRotateImage(RImage * image, float angle)
* for each point P1 in the line from C to A
* for each point P2 in the perpendicular line starting at P1
* get pixel from the source and plot at P2
* increment pixel location from source
* increment pixel location from source
*
*/
@@ -295,7 +294,7 @@ copyLine(int x1, int y1, int x2, int y2, int nwidth, int format, unsigned char *
}
#endif
static RImage *rotateImage(RImage * image, float angle)
static RImage *rotateImage(RImage *image, float angle)
{
(void) angle;
puts("NOT FULLY IMPLEMENTED");