summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/gray_drawgraymap.c
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-07-25 20:50:34 +0000
committerJens Arnold <amiconn@rockbox.org>2005-07-25 20:50:34 +0000
commitc20a00ef3e35b15acf422a2e7f6716abde840c24 (patch)
tree903cf122a1203360022dad4a06cc24b7ea805463 /apps/plugins/lib/gray_drawgraymap.c
parent12a4ed383f21b65a5a244f47fe1bc9f13d4f63bb (diff)
downloadrockbox-c20a00ef3e35b15acf422a2e7f6716abde840c24.tar.gz
rockbox-c20a00ef3e35b15acf422a2e7f6716abde840c24.zip
Complete rework of the grayscale library: (1) Implemented the new rockbox graphics api. (2) Added buffered mode, and implemented most drawing functions for buffered mode only. Buffered mode will ease implementation of animated graphics. Some functions are additionally provided as unbuffered versions (drawing grayscale bitmaps, scrolling) since unbuffered mode is better suited for non-animated graphics (JPEG viewer, mandelbrot) and saves some RAM, which is important on Archos. (3) Put all functions in a couple of source files, no more one-function-per-files. This became possible since sectioned compilation for the plugin library and appropriate linking for the pluginswas introduced, otherwise the binaries would be bloated by unused functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7241 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib/gray_drawgraymap.c')
-rw-r--r--apps/plugins/lib/gray_drawgraymap.c275
1 files changed, 0 insertions, 275 deletions
diff --git a/apps/plugins/lib/gray_drawgraymap.c b/apps/plugins/lib/gray_drawgraymap.c
deleted file mode 100644
index 2760d5a96c..0000000000
--- a/apps/plugins/lib/gray_drawgraymap.c
+++ /dev/null
@@ -1,275 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Grayscale framework
11* gray_drawgraymap() function
12*
13* This is a generic framework to use grayscale display within Rockbox
14* plugins. It obviously does not work for the player.
15*
16* Copyright (C) 2004 Jens Arnold
17*
18* All files in this archive are subject to the GNU General Public License.
19* See the file COPYING in the source tree root for full license agreement.
20*
21* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22* KIND, either express or implied.
23*
24****************************************************************************/
25
26#ifndef SIMULATOR /* not for simulator by now */
27#include "plugin.h"
28
29#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
30#include "gray.h"
31
32/* Prototypes */
33static void _writearray(unsigned char *address, const unsigned char *src,
34 int stride, unsigned mask);
35
36/* Write an 8-pixel block, defined by their brightnesses in a graymap.
37 * Address is the byte in the first bitplane, src is the graymap start address,
38 * stride is the increment for the graymap to get to the next pixel, mask
39 * determines which pixels of the destination block are changed. For "0" bits,
40 * the src address is not incremented! */
41static void _writearray(unsigned char *address, const unsigned char *src,
42 int stride, unsigned mask)
43{
44 unsigned long pat_stack[8];
45 register unsigned char *end_addr;
46 register unsigned long *pat_ptr = &pat_stack[8];
47
48 /* precalculate the bit patterns with random shifts (same RNG as
49 * _writepixel, see there for an explanation) for all 8 pixels and put them
50 * on an extra "stack" */
51 asm (
52 "mov #8,r3 \n" /* loop count in r3: 8 pixels */
53 "mov %7,r2 \n" /* copy mask */
54
55 ".wa_loop: \n" /** load pattern for pixel **/
56 "mov #0,r0 \n" /* pattern for skipped pixel must be 0 */
57 "shlr r2 \n" /* shift out lsb of mask */
58 "bf .wa_skip \n" /* skip this pixel */
59
60 "mov.b @%2,r0 \n" /* load src byte */
61 "extu.b r0,r0 \n" /* extend unsigned */
62 "mulu %4,r0 \n" /* macl = byte * depth; */
63 "add %3,%2 \n" /* src += stride; */
64 "sts macl,r4 \n" /* r4 = macl; */
65 "add r4,r0 \n" /* byte += r4; */
66 "shlr8 r0 \n" /* byte >>= 8; */
67 "shll2 r0 \n"
68 "mov.l @(r0,%5),r4 \n" /* r4 = bitpattern[byte]; */
69
70 "mov #75,r0 \n"
71 "mulu r0,%0 \n" /* multiply by 75 */
72 "sts macl,%0 \n"
73 "add #74,%0 \n" /* add another 74 */
74 /* Since the lower bits are not very random: */
75 "swap.b %0,r1 \n" /* get bits 8..15 (need max. 5) */
76 "and %6,r1 \n" /* mask out unneeded bits */
77
78 "cmp/hs %4,r1 \n" /* random >= depth ? */
79 "bf .wa_ntrim \n"
80 "sub %4,r1 \n" /* yes: random -= depth; */
81 ".wa_ntrim: \n"
82
83 "mov.l .ashlsi3,r0 \n" /** rotate pattern **/
84 "jsr @r0 \n" /* r4 -> r0, shift left by r5 */
85 "mov r1,r5 \n"
86
87 "mov %4,r5 \n"
88 "sub r1,r5 \n" /* r5 = depth - r1 */
89 "mov.l .lshrsi3,r1 \n"
90 "jsr @r1 \n" /* r4 -> r0, shift right by r5 */
91 "mov r0,r1 \n" /* store previous result in r1 */
92
93 "or r1,r0 \n" /* rotated_pattern = r0 | r1 */
94
95 ".wa_skip: \n"
96 "mov.l r0,@-%1 \n" /* push on pattern stack */
97
98 "add #-1,r3 \n" /* decrease loop count */
99 "cmp/pl r3 \n" /* loop count > 0? */
100 "bt .wa_loop \n" /* yes: loop */
101 : /* outputs */
102 /* %0, in & out */ "+r"(_gray_random_buffer),
103 /* %1, in & out */ "+r"(pat_ptr)
104 : /* inputs */
105 /* %2 */ "r"(src),
106 /* %3 */ "r"(stride),
107 /* %4 */ "r"(_graybuf->depth),
108 /* %5 */ "r"(_graybuf->bitpattern),
109 /* %6 */ "r"(_graybuf->randmask),
110 /* %7 */ "r"(mask)
111 : /* clobbers */
112 "r0", "r1", "r2", "r3", "r4", "r5", "macl", "pr"
113 );
114
115 end_addr = address + MULU16(_graybuf->depth, _graybuf->plane_size);
116
117 /* set the bits for all 8 pixels in all bytes according to the
118 * precalculated patterns on the pattern stack */
119 asm volatile (
120 "mov.l @%3+,r1 \n" /* pop all 8 patterns */
121 "mov.l @%3+,r2 \n"
122 "mov.l @%3+,r3 \n"
123 "mov.l @%3+,r8 \n"
124 "mov.l @%3+,r9 \n"
125 "mov.l @%3+,r10 \n"
126 "mov.l @%3+,r11 \n"
127 "mov.l @%3+,r12 \n"
128
129 "not %4,%4 \n" /* "set" mask -> "keep" mask */
130 "extu.b %4,%4 \n" /* mask out high bits */
131 "tst %4,%4 \n" /* nothing to keep? */
132 "bt .wa_sloop \n" /* yes: jump to short loop */
133
134 ".wa_floop: \n" /** full loop (there are bits to keep)**/
135 "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
136 "rotcl r0 \n" /* rotate t bit into r0 */
137 "shlr r2 \n"
138 "rotcl r0 \n"
139 "shlr r3 \n"
140 "rotcl r0 \n"
141 "shlr r8 \n"
142 "rotcl r0 \n"
143 "shlr r9 \n"
144 "rotcl r0 \n"
145 "shlr r10 \n"
146 "rotcl r0 \n"
147 "shlr r11 \n"
148 "rotcl r0 \n"
149 "shlr r12 \n"
150 "mov.b @%0,%3 \n" /* read old value */
151 "rotcl r0 \n"
152 "and %4,%3 \n" /* mask out unneeded bits */
153 "or r0,%3 \n" /* set new bits */
154 "mov.b %3,@%0 \n" /* store value to bitplane */
155 "add %2,%0 \n" /* advance to next bitplane */
156 "cmp/hi %0,%1 \n" /* last bitplane done? */
157 "bt .wa_floop \n" /* no: loop */
158
159 "bra .wa_end \n"
160 "nop \n"
161
162 ".wa_sloop: \n" /** short loop (nothing to keep) **/
163 "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
164 "rotcl r0 \n" /* rotate t bit into r0 */
165 "shlr r2 \n"
166 "rotcl r0 \n"
167 "shlr r3 \n"
168 "rotcl r0 \n"
169 "shlr r8 \n"
170 "rotcl r0 \n"
171 "shlr r9 \n"
172 "rotcl r0 \n"
173 "shlr r10 \n"
174 "rotcl r0 \n"
175 "shlr r11 \n"
176 "rotcl r0 \n"
177 "shlr r12 \n"
178 "rotcl r0 \n"
179 "mov.b r0,@%0 \n" /* store byte to bitplane */
180 "add %2,%0 \n" /* advance to next bitplane */
181 "cmp/hi %0,%1 \n" /* last bitplane done? */
182 "bt .wa_sloop \n" /* no: loop */
183
184 ".wa_end: \n"
185 : /* outputs */
186 : /* inputs */
187 /* %0 */ "r"(address),
188 /* %1 */ "r"(end_addr),
189 /* %2 */ "r"(_graybuf->plane_size),
190 /* %3 */ "r"(pat_ptr),
191 /* %4 */ "r"(mask)
192 : /* clobbers */
193 "r0", "r1", "r2", "r3", "r8", "r9", "r10", "r11", "r12"
194 );
195}
196
197/* References to C library routines used in _writearray */
198asm (
199 ".align 2 \n"
200".ashlsi3: \n" /* C library routine: */
201 ".long ___ashlsi3 \n" /* shift r4 left by r5, return in r0 */
202".lshrsi3: \n" /* C library routine: */
203 ".long ___lshrsi3 \n" /* shift r4 right by r5, return in r0 */
204 /* both routines preserve r4, destroy r5 and take ~16 cycles */
205);
206
207/*---------------------------------------------------------------------------
208 Copy a grayscale bitmap into the display
209 ----------------------------------------------------------------------------
210 A grayscale bitmap contains one byte for every pixel that defines the
211 brightness of the pixel (0..255). Bytes are read in row-major order.
212 The <stride> parameter is useful if you want to show only a part of a
213 bitmap. It should always be set to the "row length" of the bitmap, so
214 for displaying the whole bitmap, nx == stride.
215
216 This is the only drawing function NOT using the drawinfo.
217 */
218void gray_drawgraymap(const unsigned char *src, int x, int y, int nx, int ny,
219 int stride)
220{
221 int shift;
222 unsigned mask_top, mask_bottom;
223 const unsigned char *src_row;
224 unsigned char *dst, *dst_row;
225
226 if ((unsigned) x >= (unsigned) _graybuf->width
227 || (unsigned) y >= (unsigned) _graybuf->height)
228 return;
229
230 if ((unsigned) (y + ny) >= (unsigned) _graybuf->height) /* clip bottom */
231 ny = _graybuf->height - y;
232
233 if ((unsigned) (x + nx) >= (unsigned) _graybuf->width) /* clip right */
234 nx = _graybuf->width - x;
235
236 dst = _graybuf->data + x + MULU16(_graybuf->width, y >> 3);
237 shift = y & 7;
238 ny += shift;
239
240 mask_top = 0xFFu << (y & 7);
241 mask_bottom = ~(0xFEu << ((ny - 1) & 7));
242 if (ny <= 8)
243 mask_bottom &= mask_top;
244
245 if (ny > 8)
246 {
247 src_row = src;
248 dst_row = dst;
249
250 for (x = 0; x < nx; x++)
251 _writearray(dst_row++, src_row++, stride, mask_top);
252
253 src += MULU16(stride, 8 - shift);
254 dst += _graybuf->width;
255
256 for (y = 8; y < ny - 8; y += 8)
257 {
258 src_row = src;
259 dst_row = dst;
260
261 for (x = 0; x < nx; x++)
262 _writearray(dst_row++, src_row++, stride, 0xFFu);
263
264 src += stride << 3;
265 dst += _graybuf->width;
266 }
267 }
268
269 for (x = 0; x < nx; x++)
270 _writearray(dst++, src++, stride, mask_bottom);
271}
272
273#endif // #ifdef HAVE_LCD_BITMAP
274#endif // #ifndef SIMULATOR
275