xref: /php-src/ext/gd/libgd/gd_transform.c (revision 246de922)
1 #include "gd.h"
2 
gdImageFlipVertical(gdImagePtr im)3 void gdImageFlipVertical(gdImagePtr im)
4 {
5 	register int x, y;
6 
7 	if (im->trueColor) {
8 		for (y = 0; y < im->sy / 2; y++) {
9 			int *row_dst = im->tpixels[y];
10 			int *row_src = im->tpixels[im->sy - 1 - y];
11 			for (x = 0; x < im->sx; x++) {
12 				register int p;
13 				p = row_dst[x];
14 				row_dst[x] = im->tpixels[im->sy - 1 - y][x];
15 				row_src[x] = p;
16 			}
17 		}
18 	} else {
19 		unsigned char p;
20 		for (y = 0; y < im->sy / 2; y++) {
21 			for (x = 0; x < im->sx; x++) {
22 				p = im->pixels[y][x];
23 				im->pixels[y][x] =	im->pixels[im->sy - 1 - y][x];
24 				im->pixels[im->sy - 1 - y][x] = p;
25 			}
26 		}
27 	}
28 	return;
29 }
30 
gdImageFlipHorizontal(gdImagePtr im)31 void gdImageFlipHorizontal(gdImagePtr im)
32 {
33 
34 	int x, y;
35 
36 	if (im->trueColor) {
37    		int *px1, *px2, tmp;
38 
39 		for (y = 0; y < im->sy; y++) {
40 			px1 = im->tpixels[y];
41 			px2 = im->tpixels[y] + im->sx - 1;
42 			for (x = 0; x < (im->sx >> 1); x++) {
43 				tmp = *px1;
44 				*px1 = *px2;
45 				*px2 = tmp;
46 				px1++;
47 				px2--;
48 			}
49 		}
50 	} else {
51 		unsigned char *px1, *px2, tmp;
52 
53 		for (y = 0; y < im->sy; y++) {
54 			px1 = im->pixels[y];
55 			px2 = im->pixels[y] + im->sx - 1;
56 			for (x = 0; x < (im->sx >> 1); x++) {
57 				tmp = *px1;
58 				*px1 = *px2;
59 				*px2 = tmp;
60 				px1++;
61 				px2--;
62 			}
63 		}
64 	}
65 }
66 
gdImageFlipBoth(gdImagePtr im)67 void gdImageFlipBoth(gdImagePtr im)
68 {
69 	gdImageFlipVertical(im);
70 	gdImageFlipHorizontal(im);
71 }
72 
73 
74