3 * Raster graphics library
5 * Copyright (c) 2014-2021 Window Maker Team
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
36 static RImage
*r_flip_vertically(RImage
*source
);
37 static RImage
*r_flip_horizontally(RImage
*source
);
39 /* Flip an image in the direction(s) specified */
40 RImage
*RFlipImage(RImage
*source
, int mode
)
46 switch (mode
& (RVerticalFlip
| RHorizontalFlip
)) {
48 return r_flip_horizontally(source
);
51 return r_flip_vertically(source
);
53 case RHorizontalFlip
| RVerticalFlip
:
54 return wraster_rotate_image_180(source
);
57 return RRetainImage(source
);
61 RImage
*r_flip_vertically(RImage
*source
)
67 nwidth
= source
->width
;
68 nheight
= source
->height
;
70 target
= RCreateImage(nwidth
, nheight
, (source
->format
!= RRGBFormat
));
74 if (source
->format
== RRGBFormat
) {
75 unsigned char *optr
, *nptr
;
78 nptr
= target
->data
+ 3 * (nwidth
* nheight
- nwidth
);
80 for (y
= 0; y
< nheight
; y
++) {
81 for (x
= 0; x
< nwidth
; x
++) {
89 nptr
-= (nwidth
* 3) * 2;
92 unsigned char *optr
, *nptr
;
95 nptr
= target
->data
+ 4 * (nwidth
* nheight
- nwidth
);
97 for (y
= 0; y
< nheight
; y
++) {
98 for (x
= 0; x
< nwidth
; x
++) {
107 nptr
-= (nwidth
* 4) * 2;
113 RImage
*r_flip_horizontally(RImage
*source
)
119 nwidth
= source
->width
;
120 nheight
= source
->height
;
122 target
= RCreateImage(nwidth
, nheight
, (source
->format
!= RRGBFormat
));
126 if (source
->format
== RRGBFormat
) {
127 unsigned char *optr
, *nptr
;
130 nptr
= target
->data
+ 3 * (nwidth
- 1);
132 for (y
= nheight
; y
; y
--) {
133 for (x
= 0; x
< nwidth
; x
++) {
141 nptr
+= (nwidth
* 3) * 2;
144 unsigned char *optr
, *nptr
;
147 nptr
= target
->data
+ 4 * (nwidth
- 1);
149 for (y
= nheight
; y
; y
--) {
150 for (x
= 0; x
< nwidth
; x
++) {
159 nptr
+= (nwidth
* 4) * 2;