3 * Vertical Mirror alogorithm
5 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
8 #include "core/GP_Debug.h"
9 #include "core/GP_GetPutPixel.h"
10 #include "GP_Rotate.h"
12 @ for ps in pixelsizes:
13 static int GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Pixmap *src, GP_Pixmap *dst,
14 GP_ProgressCallback *callback)
18 GP_DEBUG(1, "Rotating image by 90 %ux%u", src->w, src->h);
20 for (x = 0; x < src->w; x++) {
21 for (y = 0; y < src->h; y++) {
22 uint32_t yr = src->h - y - 1;
23 GP_PutPixel_Raw_{{ ps.suffix }}(dst, yr, x, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
26 if (GP_ProgressCallbackReport(callback, x, src->w, src->h))
30 GP_ProgressCallbackDone(callback);
36 static int GP_FilterRotate90_Raw(const GP_Pixmap *src, GP_Pixmap *dst,
37 GP_ProgressCallback *callback)
39 GP_FN_RET_PER_BPP_PIXMAP(GP_FilterRotate90_Raw, src, src, dst, callback);
43 int GP_FilterRotate90(const GP_Pixmap *src, GP_Pixmap *dst,
44 GP_ProgressCallback *callback)
46 GP_ASSERT(src->pixel_type == dst->pixel_type,
47 "The src and dst pixel types must match");
48 GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
49 "Destination is not large enough");
51 if (GP_FilterRotate90_Raw(src, dst, callback)) {
52 GP_DEBUG(1, "Operation aborted");
59 GP_Pixmap *GP_FilterRotate90Alloc(const GP_Pixmap *src,
60 GP_ProgressCallback *callback)
64 res = GP_PixmapAlloc(src->h, src->w, src->pixel_type);
69 if (GP_FilterRotate90_Raw(src, res, callback)) {
70 GP_DEBUG(1, "Operation aborted");
78 @ def swap_pixels(ps, src, dst, x0, y0, x1, y1):
79 GP_Pixel pix0 = GP_GetPixel_Raw_{{ ps.suffix }}({{ src }}, {{ x0 }}, {{ y0 }});
80 GP_Pixel pix1 = GP_GetPixel_Raw_{{ ps.suffix }}({{ src }}, {{ x1 }}, {{ y1 }});
81 GP_PutPixel_Raw_{{ ps.suffix }}({{ dst }}, {{ x0 }}, {{ y0 }}, pix1);
82 GP_PutPixel_Raw_{{ ps.suffix }}({{ dst }}, {{ x1 }}, {{ y1 }}, pix0);
85 @ for ps in pixelsizes:
86 static int GP_FilterRotate180_Raw_{{ ps.suffix }}(const GP_Pixmap *src, GP_Pixmap *dst,
87 GP_ProgressCallback *callback)
91 GP_DEBUG(1, "Rotating image by 180 %ux%u", src->w, src->h);
93 for (x = 0; x < src->w; x++) {
94 for (y = 0; y < src->h; y++) {
95 uint32_t xr = src->w - x - 1;
96 uint32_t yr = src->h - y - 1;
98 {@ swap_pixels(ps, 'src', 'dst', 'x', 'y', 'xr', 'yr') @}
101 if (GP_ProgressCallbackReport(callback, x, src->w, src->h))
105 GP_ProgressCallbackDone(callback);
111 static int GP_FilterRotate180_Raw(const GP_Pixmap *src, GP_Pixmap *dst,
112 GP_ProgressCallback *callback)
114 GP_FN_RET_PER_BPP_PIXMAP(GP_FilterRotate180_Raw, src, src, dst, callback);
118 int GP_FilterRotate180(const GP_Pixmap *src, GP_Pixmap *dst,
119 GP_ProgressCallback *callback)
121 GP_ASSERT(src->pixel_type == dst->pixel_type,
122 "The src and dst pixel types must match");
123 GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
124 "Destination is not large enough");
126 if (GP_FilterRotate180_Raw(src, dst, callback)) {
127 GP_DEBUG(1, "Operation aborted");
134 GP_Pixmap *GP_FilterRotate180Alloc(const GP_Pixmap *src,
135 GP_ProgressCallback *callback)
139 res = GP_PixmapCopy(src, 0);
144 if (GP_FilterRotate180_Raw(src, res, callback)) {
145 GP_DEBUG(1, "Operation aborted");
153 @ for ps in pixelsizes:
154 static int GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Pixmap *src, GP_Pixmap *dst,
155 GP_ProgressCallback *callback)
159 GP_DEBUG(1, "Rotating image by 270 %ux%u", src->w, src->h);
161 for (x = 0; x < src->w; x++) {
162 for (y = 0; y < src->h; y++) {
163 uint32_t xr = src->w - x - 1;
164 GP_PutPixel_Raw_{{ ps.suffix }}(dst, y, xr, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
167 if (GP_ProgressCallbackReport(callback, x, src->w, src->h))
171 GP_ProgressCallbackDone(callback);
177 static int GP_FilterRotate270_Raw(const GP_Pixmap *src, GP_Pixmap *dst,
178 GP_ProgressCallback *callback)
180 GP_FN_RET_PER_BPP_PIXMAP(GP_FilterRotate270_Raw, src, src, dst, callback);
184 int GP_FilterRotate270(const GP_Pixmap *src, GP_Pixmap *dst,
185 GP_ProgressCallback *callback)
187 GP_ASSERT(src->pixel_type == dst->pixel_type,
188 "The src and dst pixel types must match");
189 GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
190 "Destination is not large enough");
192 if (GP_FilterRotate270_Raw(src, dst, callback)) {
193 GP_DEBUG(1, "Operation aborted");
200 GP_Pixmap *GP_FilterRotate270Alloc(const GP_Pixmap *src,
201 GP_ProgressCallback *callback)
205 res = GP_PixmapAlloc(src->h, src->w, src->pixel_type);
210 if (GP_FilterRotate270_Raw(src, res, callback)) {
211 GP_DEBUG(1, "Operation aborted");