mirror of
https://github.com/gryf/wmaker.git
synced 2026-03-29 10:23:34 +02: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:
committed by
Carlos R. Mafra
parent
dda7f48407
commit
35a43c9430
22
wrlib/flip.c
22
wrlib/flip.c
@@ -46,7 +46,7 @@ RImage *RVerticalFlipImage(RImage *image)
|
|||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
optr = image->data;
|
optr = image->data;
|
||||||
nptr = img->data + 4 * (nwidth * nheight - nwidth - 1);
|
nptr = img->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++) {
|
||||||
@@ -64,7 +64,7 @@ RImage *RVerticalFlipImage(RImage *image)
|
|||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
optr = image->data;
|
optr = image->data;
|
||||||
nptr = img->data + 4 * (nwidth * nheight - nwidth - 1);
|
nptr = img->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,7 +76,7 @@ RImage *RVerticalFlipImage(RImage *image)
|
|||||||
optr += 4;
|
optr += 4;
|
||||||
nptr += 4;
|
nptr += 4;
|
||||||
}
|
}
|
||||||
nptr -= nwidth*8;
|
nptr -= nwidth * 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
@@ -99,34 +99,38 @@ RImage *RHorizontalFlipImage(RImage *image)
|
|||||||
if (bpp == 3) {
|
if (bpp == 3) {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
nptr = img->data + nwidth * nheight * 4 - 4;
|
optr = image->data;
|
||||||
|
nptr = img->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++) {
|
||||||
optr = image->data + (y*nwidth + x) * 3;
|
|
||||||
|
|
||||||
nptr[0] = optr[0];
|
nptr[0] = optr[0];
|
||||||
nptr[1] = optr[1];
|
nptr[1] = optr[1];
|
||||||
nptr[2] = optr[2];
|
nptr[2] = optr[2];
|
||||||
nptr[3] = 255;
|
nptr[3] = 255;
|
||||||
|
|
||||||
|
optr += 3;
|
||||||
nptr -= 4;
|
nptr -= 4;
|
||||||
}
|
}
|
||||||
|
nptr += 8 * nwidth;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
|
|
||||||
nptr = img->data + nwidth * nheight * 4 - 4;
|
optr = image->data;
|
||||||
|
nptr = img->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++) {
|
||||||
optr = image->data + (y*nwidth + x) * 4;
|
|
||||||
|
|
||||||
nptr[0] = optr[0];
|
nptr[0] = optr[0];
|
||||||
nptr[1] = optr[1];
|
nptr[1] = optr[1];
|
||||||
nptr[2] = optr[2];
|
nptr[2] = optr[2];
|
||||||
nptr[3] = optr[3];
|
nptr[3] = optr[3];
|
||||||
|
|
||||||
|
optr += 4;
|
||||||
nptr -= 4;
|
nptr -= 4;
|
||||||
}
|
}
|
||||||
|
nptr += 8 * nwidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return img;
|
return img;
|
||||||
|
|||||||
@@ -34,9 +34,9 @@
|
|||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
#endif
|
#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;
|
RImage *img;
|
||||||
int nwidth, nheight;
|
int nwidth, nheight;
|
||||||
@@ -66,40 +66,41 @@ RImage *RRotateImage(RImage * image, float angle)
|
|||||||
nheight = image->width;
|
nheight = image->width;
|
||||||
|
|
||||||
img = RCreateImage(nwidth, nheight, True);
|
img = RCreateImage(nwidth, nheight, True);
|
||||||
if (!img) {
|
if (!img)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (bpp == 3) {
|
if (bpp == 3) {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
unsigned offs;
|
|
||||||
|
|
||||||
offs = nwidth * 4;
|
|
||||||
|
|
||||||
optr = image->data;
|
optr = image->data;
|
||||||
|
nptr = img->data;
|
||||||
|
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = nwidth; x; x--) {
|
||||||
nptr = img->data + x * 4;
|
nptr = img->data + 4 * (x - 1);
|
||||||
for (y = nheight; y; y--) {
|
for (y = nheight; y; y--) {
|
||||||
nptr[0] = *optr++;
|
nptr[0] = *optr++;
|
||||||
nptr[1] = *optr++;
|
nptr[1] = *optr++;
|
||||||
nptr[2] = *optr++;
|
nptr[2] = *optr++;
|
||||||
nptr[3] = 255;
|
nptr[3] = 255;
|
||||||
|
|
||||||
nptr += offs;
|
nptr += 4 * nwidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
unsigned *p;
|
|
||||||
|
|
||||||
optr = (unsigned *)image->data;
|
optr = image->data;
|
||||||
p = (unsigned *)img->data;
|
nptr = img->data;
|
||||||
for (x = 0; x < nwidth; x++) {
|
|
||||||
nptr = p++;
|
for (x = nwidth; x; x--) {
|
||||||
|
nptr = img->data + 4 * (x - 1);
|
||||||
for (y = nheight; y; y--) {
|
for (y = nheight; y; y--) {
|
||||||
*nptr = *optr++;
|
nptr[0] = *optr++;
|
||||||
nptr += nwidth;
|
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;
|
nwidth = image->width;
|
||||||
nheight = image->height;
|
nheight = image->height;
|
||||||
img = RCreateImage(nwidth, nheight, True);
|
img = RCreateImage(nwidth, nheight, True);
|
||||||
if (!img) {
|
if (!img)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (bpp == 3) {
|
if (bpp == 3) {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
@@ -148,40 +148,39 @@ RImage *RRotateImage(RImage * image, float angle)
|
|||||||
nheight = image->width;
|
nheight = image->width;
|
||||||
|
|
||||||
img = RCreateImage(nwidth, nheight, True);
|
img = RCreateImage(nwidth, nheight, True);
|
||||||
if (!img) {
|
if (!img)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (bpp == 3) {
|
if (bpp == 3) {
|
||||||
unsigned char *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
unsigned offs;
|
|
||||||
|
|
||||||
offs = nwidth * 4;
|
|
||||||
|
|
||||||
optr = image->data;
|
optr = image->data;
|
||||||
|
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = nwidth; x; x--) {
|
||||||
nptr = img->data + x * 4;
|
nptr = img->data + 4 * nwidth * nheight - x * 4;
|
||||||
for (y = nheight; y; y--) {
|
for (y = nheight; y; y--) {
|
||||||
nptr[0] = *optr++;
|
nptr[0] = *optr++;
|
||||||
nptr[1] = *optr++;
|
nptr[1] = *optr++;
|
||||||
nptr[2] = *optr++;
|
nptr[2] = *optr++;
|
||||||
nptr[3] = 255;
|
nptr[3] = 255;
|
||||||
|
|
||||||
nptr += offs;
|
nptr -= 4 * nwidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned *optr, *nptr;
|
unsigned char *optr, *nptr;
|
||||||
unsigned *p;
|
|
||||||
|
|
||||||
optr = (unsigned *)image->data;
|
optr = image->data;
|
||||||
p = (unsigned *)img->data + nwidth * nheight;
|
|
||||||
for (x = 0; x < nwidth; x++) {
|
for (x = nwidth; x; x--) {
|
||||||
nptr = p--;
|
nptr = img->data + 4 * nwidth * nheight - x * 4;
|
||||||
for (y = nheight; y; y--) {
|
for (y = nheight; y; y--) {
|
||||||
*nptr = *optr++;
|
nptr[0] = *optr++;
|
||||||
nptr -= nwidth;
|
nptr[1] = *optr++;
|
||||||
|
nptr[2] = *optr++;
|
||||||
|
nptr[3] = *optr++;
|
||||||
|
|
||||||
|
nptr -= 4 * nwidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -295,7 +294,7 @@ copyLine(int x1, int y1, int x2, int y2, int nwidth, int format, unsigned char *
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static RImage *rotateImage(RImage * image, float angle)
|
static RImage *rotateImage(RImage *image, float angle)
|
||||||
{
|
{
|
||||||
(void) angle;
|
(void) angle;
|
||||||
puts("NOT FULLY IMPLEMENTED");
|
puts("NOT FULLY IMPLEMENTED");
|
||||||
|
|||||||
Reference in New Issue
Block a user