Commits

pajoye  committed 19840b9

- #129:
- revert horizontal/vertical, was too confusing, it acts now like any
application (ie. gimp/ps) instead of talking about h/v axis
- optimize both
- add simple example

  • Participants
  • Parent commits 5b793ad
  • Branches GD-2.0

Comments (0)

Files changed (2)

File src/gd_tga.c

 	if (tga->flipv && tga->fliph) {
 		gdImageFlipBoth(image);
 	} else if (tga->flipv) {
-		gdImageFlipHorizontal(image);
-	} else if (tga->fliph) {
 		gdImageFlipVertical(image);
+	} else if (tga->fliph) {
+		gdImageFlipHorizontal(image);
 	}
  
 	free_tga(tga);

File src/gd_transform.c

 #include "gd.h"
 
-BGD_DECLARE(void)
-gdImageFlipHorizontal(gdImagePtr im)
+BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im)
 {
 	register int x, y;
 
-
 	if (im->trueColor) {
-		int p;
 		for (y = 0; y < im->sy / 2; y++) {
+			int *row_dst = im->tpixels[y];
+			int *row_src = im->tpixels[im->sy - 1 - y];
 			for (x = 0; x < im->sx; x++) {
-				p = im->tpixels[y][x];
-				im->tpixels[y][x] =	im->tpixels[im->sy - 1 - y][x];
-				im->tpixels[im->sy - 1 - y][x] = p;
+				register int p;
+				p = row_dst[x];
+				row_dst[x] = im->tpixels[im->sy - 1 - y][x];
+				row_src[x] = p;
 			}
 		}
 	} else {
 				im->tpixels[im->sy - 1 - y][x] = p;
 			}
 		}
-
 	}
 	return;
 }
 
-BGD_DECLARE(void)
-gdImageFlipVertical(gdImagePtr im)
+BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im)
 {
 
 	int x, y;
 
 	if (im->trueColor) {
-		int p;
+   		int *px1, *px2, tmp;
 
 		for (y = 0; y < im->sy; y++) {
-			for (x = 0; x < im->sx / 2; x++) {
-				p = im->tpixels[y][x];
-				im->tpixels[y][x] =	im->tpixels[y][im->sx - 1 - x];
-				im->tpixels[y][im->sx - 1 - x] = p;
+			px1 = im->tpixels[y];
+			px2 = im->tpixels[y] + im->sx - 1;
+			for (x = 0; x < (im->sx >> 1); x++) {
+				tmp = *px1;
+				*px1 = *px2;
+				*px2 = tmp;
+				px1++;
+				px2--;
 			}
 		}
 	} else {
-		unsigned char p;
+		unsigned char *px1, *px2, tmp;
 
 		for (y = 0; y < im->sy; y++) {
-			for (x = 0; x < im->sx / 2; x++) {
-				p = im->pixels[y][x];
-				im->pixels[y][x] =	im->pixels[y][im->sx - 1 - x];
-				im->pixels[y][im->sx - 1 - x] = p;
+			px1 = im->pixels[y];
+			px2 = im->pixels[y] + im->sx - 1;
+			for (x = 0; x < (im->sx >> 1); x++) {
+				tmp = *px1;
+				*px1 = *px2;
+				*px2 = tmp;
+				px1++;
+				px2--;
 			}
 		}
 	}
 }
 
-BGD_DECLARE(void)
-gdImageFlipBoth(gdImagePtr im)
+BGD_DECLARE(void) gdImageFlipBoth(gdImagePtr im)
 {
 	gdImageFlipVertical(im);
 	gdImageFlipHorizontal(im);
 }
 
+