3 * Raster graphics library
5 * Copyright (c) 2014 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,
35 static RImage
*r_flip_vertically(RImage
*source
);
36 static RImage
*r_flip_horizontally(RImage
*source
);
38 /* Flip an image in the direction(s) specified */
39 RImage
*RFlipImage(RImage
*source
, int mode
)
45 switch (mode
& (RVerticalFlip
| RHorizontalFlip
)) {
47 return r_flip_horizontally(source
);
50 return r_flip_vertically(source
);
52 case RHorizontalFlip
| RVerticalFlip
:
53 return wraster_rotate_image_180(source
);
56 return RRetainImage(source
);
60 RImage
*r_flip_vertically(RImage
*source
)
66 nwidth
= source
->width
;
67 nheight
= source
->height
;
69 target
= RCreateImage(nwidth
, nheight
, (source
->format
!= RRGBFormat
));
73 if (source
->format
== RRGBFormat
) {
74 unsigned char *optr
, *nptr
;
77 nptr
= target
->data
+ 3 * (nwidth
* nheight
- nwidth
);
79 for (y
= 0; y
< nheight
; y
++) {
80 for (x
= 0; x
< nwidth
; x
++) {
88 nptr
-= (nwidth
* 3) * 2;
91 unsigned char *optr
, *nptr
;
94 nptr
= target
->data
+ 4 * (nwidth
* nheight
- nwidth
);
96 for (y
= 0; y
< nheight
; y
++) {
97 for (x
= 0; x
< nwidth
; x
++) {
106 nptr
-= (nwidth
* 4) * 2;
112 RImage
*r_flip_horizontally(RImage
*source
)
118 nwidth
= source
->width
;
119 nheight
= source
->height
;
121 target
= RCreateImage(nwidth
, nheight
, (source
->format
!= RRGBFormat
));
125 if (source
->format
== RRGBFormat
) {
126 unsigned char *optr
, *nptr
;
129 nptr
= target
->data
+ 3 * (nwidth
- 1);
131 for (y
= nheight
; y
; y
--) {
132 for (x
= 0; x
< nwidth
; x
++) {
140 nptr
+= (nwidth
* 3) * 2;
143 unsigned char *optr
, *nptr
;
146 nptr
= target
->data
+ 4 * (nwidth
- 1);
148 for (y
= nheight
; y
; y
--) {
149 for (x
= 0; x
< nwidth
; x
++) {
158 nptr
+= (nwidth
* 4) * 2;