Index: libs/ui/dither.c |
— | — | @@ -1,164 +0,0 @@ |
2 | | -//
|
3 | | -//
|
4 | | -// Copyright 2011 TheSeven
|
5 | | -//
|
6 | | -//
|
7 | | -// This file is part of emCORE.
|
8 | | -//
|
9 | | -// emCORE is free software: you can redistribute it and/or
|
10 | | -// modify it under the terms of the GNU General Public License as
|
11 | | -// published by the Free Software Foundation, either version 2 of the
|
12 | | -// License, or (at your option) any later version.
|
13 | | -//
|
14 | | -// emCORE is distributed in the hope that it will be useful,
|
15 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
17 | | -// See the GNU General Public License for more details.
|
18 | | -//
|
19 | | -// You should have received a copy of the GNU General Public License along
|
20 | | -// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
21 | | -//
|
22 | | -//
|
23 | | -
|
24 | | -
|
25 | | -#include "emcorelib.h"
|
26 | | -#include "dither.h"
|
27 | | -
|
28 | | -
|
29 | | -static void dither_slow(int width, int height, void* inbuf, int inx, int iny, int instride,
|
30 | | - void* outbuf, int outx, int outy, int outstride)
|
31 | | -{
|
32 | | - int bpp = lcd_get_bytes_per_pixel();
|
33 | | - int bits = lcd_get_format();
|
34 | | - int swap = bits & BIT(30);
|
35 | | - int rwidth = MAX(7, bits & BITRANGE(0, 3));
|
36 | | - int gwidth = MAX(7, bits & BITRANGE(10, 13));
|
37 | | - int bwidth = MAX(7, bits & BITRANGE(20, 23));
|
38 | | - int rshift = bits & BITRANGE(4, 9);
|
39 | | - int gshift = bits & BITRANGE(14, 19);
|
40 | | - int bshift = bits & BITRANGE(24, 29);
|
41 | | - int roffs = 1 << (6 - rwidth);
|
42 | | - int goffs = 1 << (6 - gwidth);
|
43 | | - int boffs = 1 << (6 - bwidth);
|
44 | | - int rmask = BITRANGE(7 - rwidth, 7);
|
45 | | - int gmask = BITRANGE(7 - gwidth, 7);
|
46 | | - int bmask = BITRANGE(7 - bwidth, 7);
|
47 | | - int rclip = 7 - rshift;
|
48 | | - int gclip = 7 - gshift;
|
49 | | - int bclip = 7 - bshift;
|
50 | | - char* in = ((char*)inbuf) + (instride * iny + inx) * 3;
|
51 | | - char* out = ((char*)outbuf) + (instride * iny + inx) * bpp;
|
52 | | - int x, y;
|
53 | | - for (y = 0; y < height; y++)
|
54 | | - {
|
55 | | - for (x = 0; x < width; x++)
|
56 | | - {
|
57 | | - int origb = *in++;
|
58 | | - int origg = *in++;
|
59 | | - int origr = *in++;
|
60 | | - int realr = origr >> rclip;
|
61 | | - int realg = origg >> gclip;
|
62 | | - int realb = origb >> bclip;
|
63 | | - int errr = origr - (realr << rclip) - roffs;
|
64 | | - int errg = origg - (realg << gclip) - goffs;
|
65 | | - int errb = origb - (realb << bclip) - boffs;
|
66 | | - if (x + 1 < width)
|
67 | | - {
|
68 | | - *(in + 0) = MAX(0, MIN(255, *(in + 0) + errb / 2));
|
69 | | - *(in + 1) = MAX(0, MIN(255, *(in + 1) + errg / 2));
|
70 | | - *(in + 2) = MAX(0, MIN(255, *(in + 2) + errr / 2));
|
71 | | - }
|
72 | | - if (y + 1 < height)
|
73 | | - {
|
74 | | - *(in + 3 * instride - 1) = MAX(0, MIN(255, *(in + 3 * instride - 1) + errr / 4));
|
75 | | - *(in + 3 * instride - 2) = MAX(0, MIN(255, *(in + 3 * instride - 2) + errg / 4));
|
76 | | - *(in + 3 * instride - 3) = MAX(0, MIN(255, *(in + 3 * instride - 3) + errb / 4));
|
77 | | - *(in + 3 * instride - 4) = MAX(0, MIN(255, *(in + 3 * instride - 4) + errr / 4));
|
78 | | - *(in + 3 * instride - 5) = MAX(0, MIN(255, *(in + 3 * instride - 5) + errg / 4));
|
79 | | - *(in + 3 * instride - 6) = MAX(0, MIN(255, *(in + 3 * instride - 6) + errb / 4));
|
80 | | - }
|
81 | | - int pixel = (realr << rshift) | (realg << gshift) | (realb << bshift);
|
82 | | - if (bpp == 1) *out = pixel;
|
83 | | - else if (bpp == 2)
|
84 | | - {
|
85 | | - if (swap) *((short*)out) = (pixel >> 8) | ((pixel << 8) & 0xff00);
|
86 | | - else *((short*)out) = pixel;
|
87 | | - }
|
88 | | - else if (bpp == 3)
|
89 | | - {
|
90 | | - if (swap)
|
91 | | - {
|
92 | | - *(out + 0) = pixel & 0xff;
|
93 | | - *(out + 1) = (pixel >> 8) & 0xff;
|
94 | | - *(out + 2) = (pixel >> 16) & 0xff;
|
95 | | - }
|
96 | | - else
|
97 | | - {
|
98 | | - *(out + 0) = (pixel >> 16) & 0xff;
|
99 | | - *(out + 1) = (pixel >> 8) & 0xff;
|
100 | | - *(out + 2) = pixel & 0xff;
|
101 | | - }
|
102 | | - }
|
103 | | - else if (bpp == 4)
|
104 | | - {
|
105 | | - if (swap) *((int*)out) = (pixel >> 24) | ((pixel >> 8) & 0xff00)
|
106 | | - | ((pixel << 8) & 0xff0000) | ((pixel << 24) & 0xff000000);
|
107 | | - else *((int*)out) = pixel;
|
108 | | - }
|
109 | | - out += bpp;
|
110 | | - }
|
111 | | - in += (instride - width) * 3;
|
112 | | - out += (outstride - width) * bpp;
|
113 | | - }
|
114 | | -}
|
115 | | -
|
116 | | -static void dither_rgb565(int width, int height, void* inbuf, int inx, int iny, int instride,
|
117 | | - void* outbuf, int outx, int outy, int outstride)
|
118 | | -{
|
119 | | - char* in = ((char*)inbuf) + (instride * iny + inx) * 3;
|
120 | | - short* out = ((short*)outbuf) + instride * iny + inx;
|
121 | | - int x, y;
|
122 | | - for (y = 0; y < height; y++)
|
123 | | - {
|
124 | | - for (x = 0; x < width; x++)
|
125 | | - {
|
126 | | - int origb = *in++;
|
127 | | - int origg = *in++;
|
128 | | - int origr = *in++;
|
129 | | - int realr = origr >> 3;
|
130 | | - int realg = origg >> 2;
|
131 | | - int realb = origb >> 3;
|
132 | | - int errr = origr - (realr << 3) - 4;
|
133 | | - int errg = origg - (realg << 2) - 2;
|
134 | | - int errb = origb - (realb << 3) - 4;
|
135 | | - if (x + 1 < width)
|
136 | | - {
|
137 | | - *(in + 0) = MAX(0, MIN(255, *(in + 0) + errb / 2));
|
138 | | - *(in + 1) = MAX(0, MIN(255, *(in + 1) + errg / 2));
|
139 | | - *(in + 2) = MAX(0, MIN(255, *(in + 2) + errr / 2));
|
140 | | - }
|
141 | | - if (y + 1 < height)
|
142 | | - {
|
143 | | - *(in + 3 * instride - 1) = MAX(0, MIN(255, *(in + 3 * instride - 1) + errr / 4));
|
144 | | - *(in + 3 * instride - 2) = MAX(0, MIN(255, *(in + 3 * instride - 2) + errg / 4));
|
145 | | - *(in + 3 * instride - 3) = MAX(0, MIN(255, *(in + 3 * instride - 3) + errb / 4));
|
146 | | - *(in + 3 * instride - 4) = MAX(0, MIN(255, *(in + 3 * instride - 4) + errr / 4));
|
147 | | - *(in + 3 * instride - 5) = MAX(0, MIN(255, *(in + 3 * instride - 5) + errg / 4));
|
148 | | - *(in + 3 * instride - 6) = MAX(0, MIN(255, *(in + 3 * instride - 6) + errb / 4));
|
149 | | - }
|
150 | | - *out++ = (realr << 11) | (realg << 5) | realb;
|
151 | | - }
|
152 | | - in += (instride - width) * 3;
|
153 | | - out += outstride - width;
|
154 | | - }
|
155 | | -}
|
156 | | -
|
157 | | -
|
158 | | -void dither(int width, int height, void* inbuf, int inx, int iny, int instride,
|
159 | | - void* outbuf, int outx, int outy, int outstride)
|
160 | | -{
|
161 | | - int bits = lcd_get_format();
|
162 | | - if (bits == 0x004154b1)
|
163 | | - dither_rgb565(width, height, inbuf, inx, iny, instride, outbuf, outx, outy, outstride);
|
164 | | - else dither_slow(width, height, inbuf, inx, iny, instride, outbuf, outx, outy, outstride);
|
165 | | -}
|
Index: libs/ui/dither.h |
— | — | @@ -1,34 +0,0 @@ |
2 | | -//
|
3 | | -//
|
4 | | -// Copyright 2011 TheSeven
|
5 | | -//
|
6 | | -//
|
7 | | -// This file is part of emCORE.
|
8 | | -//
|
9 | | -// emCORE is free software: you can redistribute it and/or
|
10 | | -// modify it under the terms of the GNU General Public License as
|
11 | | -// published by the Free Software Foundation, either version 2 of the
|
12 | | -// License, or (at your option) any later version.
|
13 | | -//
|
14 | | -// emCORE is distributed in the hope that it will be useful,
|
15 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
17 | | -// See the GNU General Public License for more details.
|
18 | | -//
|
19 | | -// You should have received a copy of the GNU General Public License along
|
20 | | -// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
21 | | -//
|
22 | | -//
|
23 | | -
|
24 | | -
|
25 | | -#ifndef __DITHER_H__
|
26 | | -#define __DITHER_H__
|
27 | | -
|
28 | | -#include "emcorelib.h"
|
29 | | -
|
30 | | -
|
31 | | -void dither(int width, int height, void* inbuf, int inx, int iny, int instride,
|
32 | | - void* outbuf, int outx, int outy, int outstride);
|
33 | | -
|
34 | | -
|
35 | | -#endif
|
Index: libs/ui/export/libui.h |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | #include "emcorelib.h"
|
29 | 29 |
|
30 | 30 |
|
31 | | -#include "../dither.h"
|
| 31 | +#include "../blend.h"
|
32 | 32 |
|
33 | 33 |
|
34 | 34 | /* increase this every time the api struct changes */
|
— | — | @@ -45,7 +45,7 @@ |
46 | 46 |
|
47 | 47 | struct libui_api
|
48 | 48 | {
|
49 | | - typeof(dither)* dither;
|
| 49 | + typeof(blend)* blend;
|
50 | 50 | };
|
51 | 51 |
|
52 | 52 | #endif
|
Index: libs/ui/SOURCES |
— | — | @@ -1,2 +1,2 @@ |
2 | 2 | main.c
|
3 | | -dither.c
|
| 3 | +blend.c
|
Index: libs/ui/main.c |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 |
|
29 | 29 | struct libui_api apitable =
|
30 | 30 | {
|
31 | | - .dither = dither
|
| 31 | + .blend = blend
|
32 | 32 | };
|
33 | 33 |
|
34 | 34 | EMCORE_LIB_HEADER(0x49554365, LIBUI_API_VERSION, LIBUI_MIN_API_VERSION, NULL, NULL, apitable)
|
Index: libs/ui/blend.c |
— | — | @@ -0,0 +1,56 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2011 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emCORE.
|
| 8 | +//
|
| 9 | +// emCORE is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emCORE is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#include "emcorelib.h"
|
| 26 | +#include "blend.h"
|
| 27 | +
|
| 28 | +
|
| 29 | +void blend(int width, int height, int opacity,
|
| 30 | + void* outbuf, int outx, int outy, int outstride,
|
| 31 | + void* in1buf, int in1x, int in1y, int in1stride,
|
| 32 | + void* in2buf, int in2x, int in2y, int in2stride)
|
| 33 | +{
|
| 34 | + char* in1 = (char*)in1buf + (in1x + in1y * in1stride) * 3;
|
| 35 | + char* in2 = (char*)in2buf + (in2x + in2y * in2stride) * 4;
|
| 36 | + char* out = (char*)outbuf + (outx + outy * outstride) * 3;
|
| 37 | + int x, y;
|
| 38 | + for (y = 0; y < height; y++)
|
| 39 | + {
|
| 40 | + for (x = 0; x < width; x++)
|
| 41 | + {
|
| 42 | + int r1 = *in1++;
|
| 43 | + int g1 = *in1++;
|
| 44 | + int b1 = *in1++;
|
| 45 | + int r2 = *in2++;
|
| 46 | + int g2 = *in2++;
|
| 47 | + int b2 = *in2++;
|
| 48 | + int a = *in2++ * opacity;
|
| 49 | + *out++ = (a * r2 + (65535 - a) * r1) >> 16;
|
| 50 | + *out++ = (a * g2 + (65535 - a) * g1) >> 16;
|
| 51 | + *out++ = (a * b2 + (65535 - a) * b1) >> 16;
|
| 52 | + }
|
| 53 | + in1 += (in1stride - width) * 3;
|
| 54 | + in2 += (in2stride - width) * 4;
|
| 55 | + out += (outstride - width) * 3;
|
| 56 | + }
|
| 57 | +}
|
Index: libs/ui/blend.h |
— | — | @@ -0,0 +1,36 @@ |
| 2 | +//
|
| 3 | +//
|
| 4 | +// Copyright 2011 TheSeven
|
| 5 | +//
|
| 6 | +//
|
| 7 | +// This file is part of emCORE.
|
| 8 | +//
|
| 9 | +// emCORE is free software: you can redistribute it and/or
|
| 10 | +// modify it under the terms of the GNU General Public License as
|
| 11 | +// published by the Free Software Foundation, either version 2 of the
|
| 12 | +// License, or (at your option) any later version.
|
| 13 | +//
|
| 14 | +// emCORE is distributed in the hope that it will be useful,
|
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 17 | +// See the GNU General Public License for more details.
|
| 18 | +//
|
| 19 | +// You should have received a copy of the GNU General Public License along
|
| 20 | +// with emCORE. If not, see <http://www.gnu.org/licenses/>.
|
| 21 | +//
|
| 22 | +//
|
| 23 | +
|
| 24 | +
|
| 25 | +#ifndef __BLEND_H__
|
| 26 | +#define __BLEND_H__
|
| 27 | +
|
| 28 | +#include "emcorelib.h"
|
| 29 | +
|
| 30 | +
|
| 31 | +void blend(int width, int height, int opacity,
|
| 32 | + void* outbuf, int outx, int outy, int outstride,
|
| 33 | + void* in1buf, int in1x, int in1y, int in1stride,
|
| 34 | + void* in2buf, int in2x, int in2y, int in2stride);
|
| 35 | +
|
| 36 | +
|
| 37 | +#endif
|