Added the screenshots for the Sansa Clip Zip manual.
[maemo-rb.git] / firmware / drivers / lcd-16bit-vert.c
blob1222c12455bab9a6de21d041d32bfaeeb740b8a9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Dave Chapman
11 * Copyright (C) 2009 by Karl Kurbjun
13 * Rockbox driver for 16-bit colour LCDs with vertical strides
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
25 #include "config.h"
27 #include "cpu.h"
28 #include "lcd.h"
29 #include "kernel.h"
30 #include "thread.h"
31 #include <stdlib.h>
32 #include "string-extra.h" /* mem*() */
33 #include "file.h"
34 #include "debug.h"
35 #include "system.h"
36 #include "font.h"
37 #include "rbunicode.h"
38 #include "bidi.h"
39 #include "scroll_engine.h"
41 #define ROW_INC 1
42 #define COL_INC LCD_HEIGHT
44 #include "lcd-16bit-common.c"
45 #include "lcd-bitmap-common.c"
47 /*** drawing functions ***/
49 /* Draw a horizontal line (optimised) */
50 void lcd_hline(int x1, int x2, int y)
52 int x;
53 fb_data *dst, *dst_end;
54 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[current_vp->drawmode];
56 /* direction flip */
57 if (x2 < x1)
59 x = x1;
60 x1 = x2;
61 x2 = x;
64 /******************** In viewport clipping **********************/
65 /* nothing to draw? */
66 if (((unsigned)y >= (unsigned)current_vp->height) ||
67 (x1 >= current_vp->width) ||
68 (x2 < 0))
69 return;
71 if (x1 < 0)
72 x1 = 0;
73 if (x2 >= current_vp->width)
74 x2 = current_vp->width-1;
76 /* Adjust x1 and y to viewport */
77 x1 += current_vp->x;
78 x2 += current_vp->x;
79 y += current_vp->y;
81 #if defined(HAVE_VIEWPORT_CLIP)
82 /********************* Viewport on screen clipping ********************/
83 /* nothing to draw? */
84 if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
85 || (x2 < 0))
86 return;
88 /* clipping */
89 if (x1 < 0)
90 x1 = 0;
91 if (x2 >= LCD_WIDTH)
92 x2 = LCD_WIDTH-1;
93 #endif
95 dst = FBADDR(x1 , y );
96 dst_end = dst + (x2 - x1) * LCD_HEIGHT;
100 pfunc(dst);
101 dst += LCD_HEIGHT;
103 while (dst <= dst_end);
106 /* Draw a vertical line (optimised) */
107 void lcd_vline(int x, int y1, int y2)
109 int y, height;
110 unsigned bits = 0;
111 enum fill_opt fillopt = OPT_NONE;
112 fb_data *dst, *dst_end;
114 /* direction flip */
115 if (y2 < y1)
117 y = y1;
118 y1 = y2;
119 y2 = y;
122 /******************** In viewport clipping **********************/
123 /* nothing to draw? */
124 if (((unsigned)x >= (unsigned)current_vp->width) ||
125 (y1 >= current_vp->height) ||
126 (y2 < 0))
127 return;
129 if (y1 < 0)
130 y1 = 0;
131 if (y2 >= current_vp->height)
132 y2 = current_vp->height-1;
134 /* adjust for viewport */
135 x += current_vp->x;
136 y1 += current_vp->y;
137 y2 += current_vp->y;
139 #if defined(HAVE_VIEWPORT_CLIP)
140 /********************* Viewport on screen clipping ********************/
141 /* nothing to draw? */
142 if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
143 || (y2 < 0))
144 return;
146 /* clipping */
147 if (y1 < 0)
148 y1 = 0;
149 if (y2 >= LCD_HEIGHT)
150 y2 = LCD_HEIGHT-1;
151 #endif
153 height = y2 - y1 + 1;
155 /* drawmode and optimisation */
156 if (current_vp->drawmode & DRMODE_INVERSEVID)
158 if (current_vp->drawmode & DRMODE_BG)
160 if (!lcd_backdrop)
162 fillopt = OPT_SET;
163 bits = current_vp->bg_pattern;
165 else
166 fillopt = OPT_COPY;
169 else
171 if (current_vp->drawmode & DRMODE_FG)
173 fillopt = OPT_SET;
174 bits = current_vp->fg_pattern;
177 if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
178 return;
180 dst = FBADDR(x, y1);
182 switch (fillopt)
184 case OPT_SET:
185 memset16(dst, bits, height);
186 break;
188 case OPT_COPY:
189 memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
190 height * sizeof(fb_data));
191 break;
193 case OPT_NONE: /* DRMODE_COMPLEMENT */
194 dst_end = dst + height;
196 *dst = ~(*dst);
197 while (++dst < dst_end);
198 break;
202 /* Draw a partial native bitmap */
203 void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
204 int stride, int x, int y, int width,
205 int height)
207 fb_data *dst;
209 /******************** Image in viewport clipping **********************/
210 /* nothing to draw? */
211 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
212 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
213 return;
215 if (x < 0)
217 width += x;
218 src_x -= x;
219 x = 0;
221 if (y < 0)
223 height += y;
224 src_y -= y;
225 y = 0;
228 if (x + width > current_vp->width)
229 width = current_vp->width - x;
230 if (y + height > current_vp->height)
231 height = current_vp->height - y;
233 /* adjust for viewport */
234 x += current_vp->x;
235 y += current_vp->y;
237 #if defined(HAVE_VIEWPORT_CLIP)
238 /********************* Viewport on screen clipping ********************/
239 /* nothing to draw? */
240 if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
241 || (x + width <= 0) || (y + height <= 0))
242 return;
244 /* clip image in viewport in screen */
245 if (x < 0)
247 width += x;
248 src_x -= x;
249 x = 0;
251 if (y < 0)
253 height += y;
254 src_y -= y;
255 y = 0;
257 if (x + width > LCD_WIDTH)
258 width = LCD_WIDTH - x;
259 if (y + height > LCD_HEIGHT)
260 height = LCD_HEIGHT - y;
261 #endif
263 src += stride * src_x + src_y; /* move starting point */
264 dst = FBADDR(x, y);
265 fb_data *dst_end = dst + width * LCD_HEIGHT;
269 memcpy(dst, src, height * sizeof(fb_data));
270 src += stride;
271 dst += LCD_HEIGHT;
273 while (dst < dst_end);
276 /* Draw a partial native bitmap */
277 void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
278 int src_y, int stride, int x,
279 int y, int width, int height)
281 fb_data *dst, *dst_end;
283 /******************** Image in viewport clipping **********************/
284 /* nothing to draw? */
285 if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
286 (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
287 return;
289 if (x < 0)
291 width += x;
292 src_x -= x;
293 x = 0;
295 if (y < 0)
297 height += y;
298 src_y -= y;
299 y = 0;
302 if (x + width > current_vp->width)
303 width = current_vp->width - x;
304 if (y + height > current_vp->height)
305 height = current_vp->height - y;
307 /* adjust for viewport */
308 x += current_vp->x;
309 y += current_vp->y;
311 #if defined(HAVE_VIEWPORT_CLIP)
312 /********************* Viewport on screen clipping ********************/
313 /* nothing to draw? */
314 if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
315 || (x + width <= 0) || (y + height <= 0))
316 return;
318 /* clip image in viewport in screen */
319 if (x < 0)
321 width += x;
322 src_x -= x;
323 x = 0;
325 if (y < 0)
327 height += y;
328 src_y -= y;
329 y = 0;
331 if (x + width > LCD_WIDTH)
332 width = LCD_WIDTH - x;
333 if (y + height > LCD_HEIGHT)
334 height = LCD_HEIGHT - y;
335 #endif
337 src += stride * src_x + src_y; /* move starting point */
338 dst = FBADDR(x, y);
339 dst_end = dst + width * LCD_HEIGHT;
343 int i;
344 for(i = 0;i < height;i++)
346 if (src[i] == REPLACEWITHFG_COLOR)
347 dst[i] = current_vp->fg_pattern;
348 else if(src[i] != TRANSPARENT_COLOR)
349 dst[i] = src[i];
351 src += stride;
352 dst += LCD_HEIGHT;
354 while (dst < dst_end);