wmaker: removed unused constant SCROLL_STEPS in the switchpanel code
[wmaker-crm.git] / wrlib / flip.c
blobf233238acd3a279a3b71763d7d4850c0f9636a42
1 /* flip.c - image flip
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,
20 * MA 02110-1301, USA.
23 #include "config.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include <X11/Xlib.h>
31 #include "wraster.h"
32 #include "rotate.h"
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)
41 /* Security */
42 if (source == NULL)
43 return NULL;
45 switch (mode & (RVerticalFlip | RHorizontalFlip)) {
46 case RHorizontalFlip:
47 return r_flip_horizontally(source);
49 case RVerticalFlip:
50 return r_flip_vertically(source);
52 case RHorizontalFlip | RVerticalFlip:
53 return wraster_rotate_image_180(source);
55 default:
56 return RRetainImage(source);
60 RImage *r_flip_vertically(RImage *source)
62 RImage *target;
63 int nwidth, nheight;
64 int x, y;
66 nwidth = source->width;
67 nheight = source->height;
69 target = RCreateImage(nwidth, nheight, (source->format != RRGBFormat));
70 if (!target)
71 return NULL;
73 if (source->format == RRGBFormat) {
74 unsigned char *optr, *nptr;
76 optr = source->data;
77 nptr = target->data + 3 * (nwidth * nheight - nwidth);
79 for (y = 0; y < nheight; y++) {
80 for (x = 0; x < nwidth; x++) {
81 nptr[0] = optr[0];
82 nptr[1] = optr[1];
83 nptr[2] = optr[2];
85 optr += 3;
86 nptr += 3;
88 nptr -= (nwidth * 3) * 2;
90 } else {
91 unsigned char *optr, *nptr;
93 optr = source->data;
94 nptr = target->data + 4 * (nwidth * nheight - nwidth);
96 for (y = 0; y < nheight; y++) {
97 for (x = 0; x < nwidth; x++) {
98 nptr[0] = optr[0];
99 nptr[1] = optr[1];
100 nptr[2] = optr[2];
101 nptr[3] = optr[3];
103 optr += 4;
104 nptr += 4;
106 nptr -= (nwidth * 4) * 2;
109 return target;
112 RImage *r_flip_horizontally(RImage *source)
114 RImage *target;
115 int nwidth, nheight;
116 int x, y;
118 nwidth = source->width;
119 nheight = source->height;
121 target = RCreateImage(nwidth, nheight, (source->format != RRGBFormat));
122 if (!target)
123 return NULL;
125 if (source->format == RRGBFormat) {
126 unsigned char *optr, *nptr;
128 optr = source->data;
129 nptr = target->data + 3 * (nwidth - 1);
131 for (y = nheight; y; y--) {
132 for (x = 0; x < nwidth; x++) {
133 nptr[0] = optr[0];
134 nptr[1] = optr[1];
135 nptr[2] = optr[2];
137 optr += 3;
138 nptr -= 3;
140 nptr += (nwidth * 3) * 2;
142 } else {
143 unsigned char *optr, *nptr;
145 optr = source->data;
146 nptr = target->data + 4 * (nwidth - 1);
148 for (y = nheight; y; y--) {
149 for (x = 0; x < nwidth; x++) {
150 nptr[0] = optr[0];
151 nptr[1] = optr[1];
152 nptr[2] = optr[2];
153 nptr[3] = optr[3];
155 optr += 4;
156 nptr -= 4;
158 nptr += (nwidth * 4) * 2;
161 return target;