summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-src/src/gd_transform.c
blob: 1a96daaf43840b6126d6f44cf1ef6afde327ebbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
 * File: Transformations
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#include "gd.h"

/**
 * Function: gdImageFlipVertical
 *
 * Flip an image vertically
 *
 * The image is mirrored upside-down.
 *
 * Parameters:
 *   im - The image.
 *
 * See also:
 *   - <gdImageFlipHorizontal>
 *   - <gdImageFlipBoth>
 */
BGD_DECLARE(void) gdImageFlipVertical(gdImagePtr im)
{
	register int x, y;

	if (im->trueColor) {
		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++) {
				register int p;
				p = row_dst[x];
				row_dst[x] = im->tpixels[im->sy - 1 - y][x];
				row_src[x] = p;
			}
		}
	} else {
		unsigned char p;
		for (y = 0; y < im->sy / 2; y++) {
			for (x = 0; x < im->sx; x++) {
				p = im->pixels[y][x];
				im->pixels[y][x] =	im->pixels[im->sy - 1 - y][x];
				im->pixels[im->sy - 1 - y][x] = p;
			}
		}
	}
	return;
}

/**
 * Function: gdImageFlipHorizontal
 *
 * Flip an image horizontally
 *
 * The image is mirrored left-right.
 *
 * Parameters:
 *   im - The image.
 *
 * See also:
 *   - <gdImageFlipVertical>
 *   - <gdImageFlipBoth>
 */
BGD_DECLARE(void) gdImageFlipHorizontal(gdImagePtr im)
{

	int x, y;

	if (im->trueColor) {
		int *px1, *px2, tmp;

		for (y = 0; y < im->sy; y++) {
			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 *px1, *px2, tmp;

		for (y = 0; y < im->sy; y++) {
			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--;
			}
		}
	}
}

/**
 * Function: gdImageFlipBoth
 *
 * Flip an image vertically and horizontally
 *
 * The image is mirrored upside-down and left-right.
 *
 * Parameters:
 *   im - The image.
 *
 * See also:
 *   - <gdImageFlipVertical>
 *   - <gdImageFlipHorizontal>
 */
BGD_DECLARE(void) gdImageFlipBoth(gdImagePtr im)
{
	gdImageFlipVertical(im);
	gdImageFlipHorizontal(im);
}