1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
32 #include "string-extra.h" /* mem*() */
37 #include "rbunicode.h"
39 #include "scroll_engine.h"
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
)
53 fb_data
*dst
, *dst_end
;
54 lcd_fastpixelfunc_type
*pfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
];
64 /******************** In viewport clipping **********************/
65 /* nothing to draw? */
66 if (((unsigned)y
>= (unsigned)current_vp
->height
) ||
67 (x1
>= current_vp
->width
) ||
73 if (x2
>= current_vp
->width
)
74 x2
= current_vp
->width
-1;
76 /* Adjust x1 and y to viewport */
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
)
95 dst
= FBADDR(x1
, y
);
96 dst_end
= dst
+ (x2
- x1
) * LCD_HEIGHT
;
103 while (dst
<= dst_end
);
106 /* Draw a vertical line (optimised) */
107 void lcd_vline(int x
, int y1
, int y2
)
111 enum fill_opt fillopt
= OPT_NONE
;
112 fb_data
*dst
, *dst_end
;
122 /******************** In viewport clipping **********************/
123 /* nothing to draw? */
124 if (((unsigned)x
>= (unsigned)current_vp
->width
) ||
125 (y1
>= current_vp
->height
) ||
131 if (y2
>= current_vp
->height
)
132 y2
= current_vp
->height
-1;
134 /* adjust for viewport */
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
)
149 if (y2
>= LCD_HEIGHT
)
153 height
= y2
- y1
+ 1;
155 /* drawmode and optimisation */
156 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
158 if (current_vp
->drawmode
& DRMODE_BG
)
163 bits
= current_vp
->bg_pattern
;
171 if (current_vp
->drawmode
& DRMODE_FG
)
174 bits
= current_vp
->fg_pattern
;
177 if (fillopt
== OPT_NONE
&& current_vp
->drawmode
!= DRMODE_COMPLEMENT
)
185 memset16(dst
, bits
, height
);
189 memcpy(dst
, (void *)((long)dst
+ lcd_backdrop_offset
),
190 height
* sizeof(fb_data
));
193 case OPT_NONE
: /* DRMODE_COMPLEMENT */
194 dst_end
= dst
+ height
;
197 while (++dst
< dst_end
);
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
,
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))
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 */
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))
244 /* clip image in viewport in screen */
257 if (x
+ width
> LCD_WIDTH
)
258 width
= LCD_WIDTH
- x
;
259 if (y
+ height
> LCD_HEIGHT
)
260 height
= LCD_HEIGHT
- y
;
263 src
+= stride
* src_x
+ src_y
; /* move starting point */
265 fb_data
*dst_end
= dst
+ width
* LCD_HEIGHT
;
269 memcpy(dst
, src
, height
* sizeof(fb_data
));
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))
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 */
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))
318 /* clip image in viewport in screen */
331 if (x
+ width
> LCD_WIDTH
)
332 width
= LCD_WIDTH
- x
;
333 if (y
+ height
> LCD_HEIGHT
)
334 height
= LCD_HEIGHT
- y
;
337 src
+= stride
* src_x
+ src_y
; /* move starting point */
339 dst_end
= dst
+ width
* LCD_HEIGHT
;
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
)
354 while (dst
< dst_end
);