source: mainline/uspace/lib/softrend/pixconv.c@ a4e78743

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a4e78743 was 6d5e378, checked in by Martin Decky <martin@…>, 13 years ago

cherrypick GUI implementation (originally by Petr Koupy), with several major changes

  • for character-oriented devices a new output server and output protocol was created based on the original fb server
  • DDF visualizer drivers are pixel-oriented only
  • console and compositor can coexist in the same build
  • terminal widget is self-sufficient, no strange console nesting is needed
  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * Copyright (c) 2011 Petr Koupy
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup softrend
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <byteorder.h>
38#include "pixconv.h"
39
40/** Pixel conversion and mask functions
41 *
42 * These functions write an ARGB pixel value to a memory location
43 * in a predefined format. The naming convention corresponds to
44 * the names of the visuals and the format created by these functions.
45 * The functions use the so called network bit order (i.e. big endian)
46 * with respect to their names.
47 */
48
49void pixel2argb_8888(void *dst, pixel_t pix)
50{
51 *((uint32_t *) dst) = host2uint32_t_be(
52 (ALPHA(pix) << 24) | (RED(pix) << 16) | (GREEN(pix) << 8) | (BLUE(pix)));
53}
54
55void pixel2abgr_8888(void *dst, pixel_t pix)
56{
57 *((uint32_t *) dst) = host2uint32_t_be(
58 (ALPHA(pix) << 24) | (BLUE(pix) << 16) | (GREEN(pix) << 8) | (RED(pix)));
59}
60
61void pixel2rgba_8888(void *dst, pixel_t pix)
62{
63 *((uint32_t *) dst) = host2uint32_t_be(
64 (RED(pix) << 24) | (GREEN(pix) << 16) | (BLUE(pix) << 8) | (ALPHA(pix)));
65}
66
67void pixel2bgra_8888(void *dst, pixel_t pix)
68{
69 *((uint32_t *) dst) = host2uint32_t_be(
70 (BLUE(pix) << 24) | (GREEN(pix) << 16) | (RED(pix) << 8) | (ALPHA(pix)));
71}
72
73void pixel2rgb_0888(void *dst, pixel_t pix)
74{
75 *((uint32_t *) dst) = host2uint32_t_be(
76 (RED(pix) << 16) | (GREEN(pix) << 8) | (BLUE(pix)));
77}
78
79void pixel2bgr_0888(void *dst, pixel_t pix)
80{
81 *((uint32_t *) dst) = host2uint32_t_be(
82 (BLUE(pix) << 16) | (GREEN(pix) << 8) | (RED(pix)));
83}
84
85void pixel2rgb_8880(void *dst, pixel_t pix)
86{
87 *((uint32_t *) dst) = host2uint32_t_be(
88 (RED(pix) << 24) | (GREEN(pix) << 16) | (BLUE(pix) << 8));
89}
90
91void pixel2bgr_8880(void *dst, pixel_t pix)
92{
93 *((uint32_t *) dst) = host2uint32_t_be(
94 (BLUE(pix) << 24) | (GREEN(pix) << 16) | (RED(pix) << 8));
95}
96
97void pixel2rgb_888(void *dst, pixel_t pix)
98{
99 ((uint8_t *) dst)[0] = RED(pix);
100 ((uint8_t *) dst)[1] = GREEN(pix);
101 ((uint8_t *) dst)[2] = BLUE(pix);
102}
103
104void pixel2bgr_888(void *dst, pixel_t pix)
105{
106 ((uint8_t *) dst)[0] = BLUE(pix);
107 ((uint8_t *) dst)[1] = GREEN(pix);
108 ((uint8_t *) dst)[2] = RED(pix);
109}
110
111void pixel2rgb_555_be(void *dst, pixel_t pix)
112{
113 *((uint16_t *) dst) = host2uint16_t_be(
114 (NARROW(RED(pix), 5) << 10) | (NARROW(GREEN(pix), 5) << 5) | (NARROW(BLUE(pix), 5)));
115}
116
117void pixel2rgb_555_le(void *dst, pixel_t pix)
118{
119 *((uint16_t *) dst) = host2uint16_t_le(
120 (NARROW(RED(pix), 5) << 10) | (NARROW(GREEN(pix), 5) << 5) | (NARROW(BLUE(pix), 5)));
121}
122
123void pixel2rgb_565_be(void *dst, pixel_t pix)
124{
125 *((uint16_t *) dst) = host2uint16_t_be(
126 (NARROW(RED(pix), 5) << 11) | (NARROW(GREEN(pix), 6) << 5) | (NARROW(BLUE(pix), 5)));
127}
128
129void pixel2rgb_565_le(void *dst, pixel_t pix)
130{
131 *((uint16_t *) dst) = host2uint16_t_le(
132 (NARROW(RED(pix), 5) << 11) | (NARROW(GREEN(pix), 6) << 5) | (NARROW(BLUE(pix), 5)));
133}
134
135void pixel2bgr_323(void *dst, pixel_t pix)
136{
137 *((uint8_t *) dst) =
138 ~((NARROW(RED(pix), 3) << 5) | (NARROW(GREEN(pix), 2) << 3) | NARROW(BLUE(pix), 3));
139}
140
141void pixel2gray_8(void *dst, pixel_t pix)
142{
143 uint32_t red = RED(pix) * 5034375;
144 uint32_t green = GREEN(pix) * 9886846;
145 uint32_t blue = BLUE(pix) * 1920103;
146
147 *((uint8_t *) dst) = (red + green + blue) >> 24;
148}
149
150void visual_mask_8888(void *dst, bool mask)
151{
152 pixel2abgr_8888(dst, mask ? 0xffffffff : 0);
153}
154
155void visual_mask_0888(void *dst, bool mask)
156{
157 pixel2bgr_0888(dst, mask ? 0xffffffff : 0);
158}
159
160void visual_mask_8880(void *dst, bool mask)
161{
162 pixel2bgr_8880(dst, mask ? 0xffffffff : 0);
163}
164
165void visual_mask_888(void *dst, bool mask)
166{
167 pixel2bgr_888(dst, mask ? 0xffffffff : 0);
168}
169
170void visual_mask_555(void *dst, bool mask)
171{
172 pixel2rgb_555_be(dst, mask ? 0xffffffff : 0);
173}
174
175void visual_mask_565(void *dst, bool mask)
176{
177 pixel2rgb_565_be(dst, mask ? 0xffffffff : 0);
178}
179
180void visual_mask_323(void *dst, bool mask)
181{
182 pixel2bgr_323(dst, mask ? 0x0 : ~0x0);
183}
184
185void visual_mask_8(void *dst, bool mask)
186{
187 pixel2gray_8(dst, mask ? 0xffffffff : 0);
188}
189
190pixel_t argb_8888_2pixel(void *src)
191{
192 return (uint32_t_be2host(*((uint32_t *) src)));
193}
194
195pixel_t abgr_8888_2pixel(void *src)
196{
197 uint32_t val = uint32_t_be2host(*((uint32_t *) src));
198 return ((val & 0xff000000) | ((val & 0xff0000) >> 16) | (val & 0xff00) | ((val & 0xff) << 16));
199}
200
201pixel_t rgba_8888_2pixel(void *src)
202{
203 uint32_t val = uint32_t_be2host(*((uint32_t *) src));
204 return ((val << 24) | (val >> 8));
205}
206
207pixel_t bgra_8888_2pixel(void *src)
208{
209 uint32_t val = uint32_t_be2host(*((uint32_t *) src));
210 return ((val >> 24) | ((val & 0xff0000) >> 8) | ((val & 0xff00) << 8) | (val << 24));
211}
212
213pixel_t rgb_0888_2pixel(void *src)
214{
215 return (0xff000000 | (uint32_t_be2host(*((uint32_t *) src)) & 0xffffff));
216}
217
218pixel_t bgr_0888_2pixel(void *src)
219{
220 uint32_t val = uint32_t_be2host(*((uint32_t *) src));
221 return (0xff000000 | ((val & 0xff0000) >> 16) | (val & 0xff00) | ((val & 0xff) << 16));
222}
223
224pixel_t rgb_8880_2pixel(void *src)
225{
226 return (0xff000000 | (uint32_t_be2host(*((uint32_t *) src)) >> 8));
227}
228
229pixel_t bgr_8880_2pixel(void *src)
230{
231 uint32_t val = uint32_t_be2host(*((uint32_t *) src));
232 return (0xff000000 | (val >> 24) | ((val & 0xff0000) >> 8) | ((val & 0xff00) << 8));
233}
234
235pixel_t rgb_888_2pixel(void *src)
236{
237 uint8_t red = ((uint8_t *) src)[0];
238 uint8_t green = ((uint8_t *) src)[1];
239 uint8_t blue = ((uint8_t *) src)[2];
240
241 return (0xff000000 | (red << 16) | (green << 8) | (blue));
242}
243
244pixel_t bgr_888_2pixel(void *src)
245{
246 uint8_t blue = ((uint8_t *) src)[0];
247 uint8_t green = ((uint8_t *) src)[1];
248 uint8_t red = ((uint8_t *) src)[2];
249
250 return (0xff000000 | (red << 16) | (green << 8) | (blue));
251}
252
253pixel_t rgb_555_be_2pixel(void *src)
254{
255 uint16_t val = uint16_t_be2host(*((uint16_t *) src));
256 return (0xff000000 | ((val & 0x7c00) << 9) | ((val & 0x3e0) << 6) | ((val & 0x1f) << 3));
257}
258
259pixel_t rgb_555_le_2pixel(void *src)
260{
261 uint16_t val = uint16_t_le2host(*((uint16_t *) src));
262 return (0xff000000 | ((val & 0x7c00) << 9) | ((val & 0x3e0) << 6) | ((val & 0x1f) << 3));
263}
264
265pixel_t rgb_565_be_2pixel(void *src)
266{
267 uint16_t val = uint16_t_be2host(*((uint16_t *) src));
268 return (0xff000000 | ((val & 0xf800) << 8) | ((val & 0x7e0) << 5) | ((val & 0x1f) << 3));
269}
270
271pixel_t rgb_565_le_2pixel(void *src)
272{
273 uint16_t val = uint16_t_le2host(*((uint16_t *) src));
274 return (0xff000000 | ((val & 0xf800) << 8) | ((val & 0x7e0) << 5) | ((val & 0x1f) << 3));
275}
276
277pixel_t bgr_323_2pixel(void *src)
278{
279 uint8_t val = ~(*((uint8_t *) src));
280 return (0xff000000 | ((val & 0xe0) << 16) | ((val & 0x18) << 11) | ((val & 0x7) << 5));
281}
282
283pixel_t gray_8_2pixel(void *src)
284{
285 uint8_t val = *((uint8_t *) src);
286 return (0xff000000 | (val << 16) | (val << 8) | (val));
287}
288
289/** @}
290 */
Note: See TracBrowser for help on using the repository browser.