summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-16bit-common.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-04-16 23:50:43 +0200
committerThomas Martitz <kugel@rockbox.org>2014-01-07 14:13:48 +0100
commitdeb6ac3693a6fb5c47abd0c32f966f5e38b6a68a (patch)
tree08cb6563035e9aca18618548c86b10a9d39a5cbe /firmware/drivers/lcd-16bit-common.c
parent36e469db8bb7789c89ff642b51c1471669b830f5 (diff)
downloadrockbox-deb6ac3693a6fb5c47abd0c32f966f5e38b6a68a.tar.gz
rockbox-deb6ac3693a6fb5c47abd0c32f966f5e38b6a68a.zip
lcd-16bit: Move lcd_gradient_fillrect/_part() to lcd-16bit-common.c.
Change-Id: I6b2d2ba73464610556cfd9ecec52fc62adb007c7
Diffstat (limited to 'firmware/drivers/lcd-16bit-common.c')
-rw-r--r--firmware/drivers/lcd-16bit-common.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/firmware/drivers/lcd-16bit-common.c b/firmware/drivers/lcd-16bit-common.c
index 99cbe489fc..9d36499418 100644
--- a/firmware/drivers/lcd-16bit-common.c
+++ b/firmware/drivers/lcd-16bit-common.c
@@ -1362,3 +1362,69 @@ void lcd_blit_yuv(unsigned char * const src[3],
1362 lcd_update_rect(LCD_WIDTH - y - height, x, height, width); 1362 lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
1363#endif 1363#endif
1364} 1364}
1365
1366/* Fill a rectangle with a gradient. This function draws only the partial
1367 * gradient. It assumes the original gradient is src_height high and skips
1368 * the first few rows. This is useful for drawing only the bottom half of
1369 * a full gradient.
1370 *
1371 * height == src_height and row_skip == 0 will draw the full gradient
1372 *
1373 * x, y, width, height - dimensions describing the rectangle
1374 * start_rgb - beginning color of the gradient
1375 * end_rgb - end color of the gradient
1376 * src_height - assumed original height (only height rows will be drawn)
1377 * row_skip - how many rows of the original gradient to skip
1378 */
1379void lcd_gradient_fillrect_part(int x, int y, int width, int height,
1380 unsigned start_rgb, unsigned end_rgb, int src_height, int row_skip)
1381{
1382 int old_pattern = current_vp->fg_pattern;
1383 int step_mul, i;
1384 int x1, x2;
1385 x1 = x;
1386 x2 = x + width;
1387
1388 if (height == 0) return;
1389
1390 step_mul = (1 << 16) / src_height;
1391 int h_r = RGB_UNPACK_RED(start_rgb);
1392 int h_g = RGB_UNPACK_GREEN(start_rgb);
1393 int h_b = RGB_UNPACK_BLUE(start_rgb);
1394 int rstep = (h_r - RGB_UNPACK_RED(end_rgb)) * step_mul;
1395 int gstep = (h_g - RGB_UNPACK_GREEN(end_rgb)) * step_mul;
1396 int bstep = (h_b - RGB_UNPACK_BLUE(end_rgb)) * step_mul;
1397 h_r = (h_r << 16) + (1 << 15);
1398 h_g = (h_g << 16) + (1 << 15);
1399 h_b = (h_b << 16) + (1 << 15);
1400
1401 if (row_skip > 0)
1402 {
1403 h_r -= rstep * row_skip;
1404 h_g -= gstep * row_skip;
1405 h_b -= bstep * row_skip;
1406 }
1407
1408 for(i = y; i < y + height; i++) {
1409 current_vp->fg_pattern = LCD_RGBPACK(h_r >> 16, h_g >> 16, h_b >> 16);
1410 lcd_hline(x1, x2, i);
1411 h_r -= rstep;
1412 h_g -= gstep;
1413 h_b -= bstep;
1414 }
1415
1416 current_vp->fg_pattern = old_pattern;
1417}
1418
1419/* Fill a rectangle with a gradient. The gradient's color will fade from
1420 * start_rgb to end_rgb over the height of the rectangle
1421 *
1422 * x, y, width, height - dimensions describing the rectangle
1423 * start_rgb - beginning color of the gradient
1424 * end_rgb - end color of the gradient
1425 */
1426void lcd_gradient_fillrect(int x, int y, int width, int height,
1427 unsigned start_rgb, unsigned end_rgb)
1428{
1429 lcd_gradient_fillrect_part(x, y, width, height, start_rgb, end_rgb, height, 0);
1430}