summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2009-03-22 14:45:14 +0000
committerJens Arnold <amiconn@rockbox.org>2009-03-22 14:45:14 +0000
commit1d8679e7eca7a8f1eb3571d32d4992fb176a9a29 (patch)
tree54888de5704bc6969a24f37d943e4e27c2ac7c69
parent005caba3fb753de5448d7ead9d0bddad98802e7f (diff)
downloadrockbox-1d8679e7eca7a8f1eb3571d32d4992fb176a9a29.tar.gz
rockbox-1d8679e7eca7a8f1eb3571d32d4992fb176a9a29.zip
Pictureflow optimisations: (1) No need to restore the drawmode, the core takes care of that. (2) Making the angle positive before masking is redundant. (3) Slide rendering: * Precalculate a faded reflection table for alpha < 256, saving a multiply in the inner loop. * Group the inner loops so that less variables are precalculated, helping to keep stuff in registers. * Combine loop conditions so that a single check is sufficient.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20456 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/pictureflow.c114
1 files changed, 50 insertions, 64 deletions
diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c
index fd8079e21e..293be51985 100644
--- a/apps/plugins/pictureflow.c
+++ b/apps/plugins/pictureflow.c
@@ -294,8 +294,6 @@ void reset_track_list(void);
294void * buf; 294void * buf;
295size_t buf_size; 295size_t buf_size;
296 296
297static int old_drawmode;
298
299static bool thread_is_running; 297static bool thread_is_running;
300 298
301static int cover_animation_keyframe; 299static int cover_animation_keyframe;
@@ -502,8 +500,6 @@ static const short sin_tab[] = {
502 500
503static inline PFreal fsin(int iangle) 501static inline PFreal fsin(int iangle)
504{ 502{
505 while(iangle < 0)
506 iangle += IANGLE_MAX;
507 iangle &= IANGLE_MASK; 503 iangle &= IANGLE_MASK;
508 504
509 int i = (iangle >> 4); 505 int i = (iangle >> 4);
@@ -1460,10 +1456,19 @@ void render_slide(struct slide_data *slide, const int alpha)
1460 const int sw = bmp->width; 1456 const int sw = bmp->width;
1461 const int sh = bmp->height; 1457 const int sh = bmp->height;
1462 const PFreal slide_left = -sw * PFREAL_HALF + PFREAL_HALF; 1458 const PFreal slide_left = -sw * PFREAL_HALF + PFREAL_HALF;
1463
1464 const int h = LCD_HEIGHT;
1465 const int w = LCD_WIDTH; 1459 const int w = LCD_WIDTH;
1466 1460
1461 uint8_t reftab[REFLECT_HEIGHT]; /* on stack, which is in IRAM on several targets */
1462
1463 if (alpha == 256) { /* opaque -> copy table */
1464 rb->memcpy(reftab, reflect_table, sizeof(reftab));
1465 } else { /* precalculate faded table */
1466 int i, lalpha;
1467 for (i = 0; i < REFLECT_HEIGHT; i++) {
1468 lalpha = reflect_table[i];
1469 reftab[i] = (MULUQ(lalpha, alpha) + 129) >> 8;
1470 }
1471 }
1467 1472
1468 PFreal cosr = fcos(slide->angle); 1473 PFreal cosr = fcos(slide->angle);
1469 PFreal sinr = fsin(slide->angle); 1474 PFreal sinr = fsin(slide->angle);
@@ -1496,71 +1501,54 @@ void render_slide(struct slide_data *slide, const int alpha)
1496 break; 1501 break;
1497 if (zo || slide->angle) 1502 if (zo || slide->angle)
1498 dy = (CAM_DIST_R + zo + fmul(xs, sinr)) / CAM_DIST; 1503 dy = (CAM_DIST_R + zo + fmul(xs, sinr)) / CAM_DIST;
1499 int y1 = (LCD_HEIGHT / 2) - 1;
1500 int y2 = y1 + 1;
1501 pix_t *pixel1 = &buffer[y1 * BUFFER_WIDTH + x];
1502 pix_t *pixel2 = pixel1 + BUFFER_WIDTH;
1503 const int pixelstep = BUFFER_WIDTH;
1504 1504
1505 int p1 = (bmp->height - 1 - (DISPLAY_OFFS)) * PFREAL_ONE;
1506 int p2 = p1 + dy;
1507 const pix_t *ptr = &src[column * bmp->height]; 1505 const pix_t *ptr = &src[column * bmp->height];
1506 const int pixelstep = BUFFER_WIDTH;
1508 1507
1509 if (alpha == 256) 1508 int p = (bmp->height-1-DISPLAY_OFFS) * PFREAL_ONE;
1510 { 1509 int plim = MAX(0, p - (LCD_HEIGHT/2-1) * dy);
1511 while ((y1 >= 0) && (p1 >= 0)) 1510 pix_t *pixel = &buffer[((LCD_HEIGHT/2)-1)*BUFFER_WIDTH + x];
1512 { 1511
1513 *pixel1 = ptr[((unsigned)p1) >> PFREAL_SHIFT]; 1512 if (alpha == 256) {
1514 p1 -= dy; 1513 while (p >= plim) {
1515 y1--; 1514 *pixel = ptr[((unsigned)p) >> PFREAL_SHIFT];
1516 pixel1 -= pixelstep; 1515 p -= dy;
1517 } 1516 pixel -= pixelstep;
1518 while ((p2 < sh * PFREAL_ONE) && (y2 < h))
1519 {
1520 *pixel2 = ptr[((unsigned)p2) >> PFREAL_SHIFT];
1521 p2 += dy;
1522 y2++;
1523 pixel2 += pixelstep;
1524 } 1517 }
1525 while ((p2 < MIN(sh + REFLECT_HEIGHT, sh * 2) * PFREAL_ONE) && 1518 } else {
1526 (y2 < h)) 1519 while (p >= plim) {
1527 { 1520 *pixel = fade_color(ptr[((unsigned)p) >> PFREAL_SHIFT], alpha);
1528 int ty = (((unsigned)p2) >> PFREAL_SHIFT) - sh; 1521 p -= dy;
1529 int lalpha = reflect_table[ty]; 1522 pixel -= pixelstep;
1530 *pixel2 = fade_color(ptr[sh - 1 - ty],lalpha);
1531 p2 += dy;
1532 y2++;
1533 pixel2 += pixelstep;
1534 } 1523 }
1535 } 1524 }
1536 else 1525 p = (bmp->height-DISPLAY_OFFS) * PFREAL_ONE;
1537 { 1526 plim = MIN(sh * PFREAL_ONE, p + (LCD_HEIGHT/2) * dy);
1538 while ((y1 >= 0) && (p1 >= 0)) 1527 int plim2 = MIN(MIN(sh + REFLECT_HEIGHT, sh * 2) * PFREAL_ONE,
1539 { 1528 p + (LCD_HEIGHT/2) * dy);
1540 *pixel1 = fade_color(ptr[((unsigned)p1) >> PFREAL_SHIFT],alpha); 1529 pixel = &buffer[(LCD_HEIGHT/2)*BUFFER_WIDTH + x];
1541 p1 -= dy; 1530
1542 y1--; 1531 if (alpha == 256) {
1543 pixel1 -= pixelstep; 1532 while (p < plim) {
1533 *pixel = ptr[((unsigned)p) >> PFREAL_SHIFT];
1534 p += dy;
1535 pixel += pixelstep;
1544 } 1536 }
1545 while ((p2 < sh * PFREAL_ONE) && (y2 < h)) 1537 } else {
1546 { 1538 while (p < plim) {
1547 *pixel2 = fade_color(ptr[((unsigned)p2) >> PFREAL_SHIFT],alpha); 1539 *pixel = fade_color(ptr[((unsigned)p) >> PFREAL_SHIFT], alpha);
1548 p2 += dy; 1540 p += dy;
1549 y2++; 1541 pixel += pixelstep;
1550 pixel2 += pixelstep;
1551 }
1552 while ((p2 < MIN(sh + REFLECT_HEIGHT, sh * 2) * PFREAL_ONE) &&
1553 (y2 < h))
1554 {
1555 int ty = (((unsigned)p2) >> PFREAL_SHIFT) - sh;
1556 int lalpha = reflect_table[ty];
1557 lalpha = (MULUQ(lalpha, alpha) + 128) >> 8;
1558 *pixel2 = fade_color(ptr[sh - 1 - ty],lalpha);
1559 p2 += dy;
1560 y2++;
1561 pixel2 += pixelstep;
1562 } 1542 }
1563 } 1543 }
1544 while (p < plim2) {
1545 int ty = (((unsigned)p) >> PFREAL_SHIFT) - sh;
1546 int lalpha = reftab[ty];
1547 *pixel = fade_color(ptr[sh - 1 - ty], lalpha);
1548 p += dy;
1549 pixel += pixelstep;
1550 }
1551
1564 if (zo || slide->angle) 1552 if (zo || slide->angle)
1565 { 1553 {
1566 xsnum += xsnumi; 1554 xsnum += xsnumi;
@@ -1805,7 +1793,6 @@ void cleanup(void *parameter)
1805#ifdef USEGSLIB 1793#ifdef USEGSLIB
1806 grey_release(); 1794 grey_release();
1807#endif 1795#endif
1808 rb->lcd_set_drawmode(old_drawmode);
1809} 1796}
1810 1797
1811/** 1798/**
@@ -2300,7 +2287,6 @@ int main(void)
2300 int fpstxt_y; 2287 int fpstxt_y;
2301 2288
2302 bool instant_update; 2289 bool instant_update;
2303 old_drawmode = rb->lcd_get_drawmode();
2304#ifdef USEGSLIB 2290#ifdef USEGSLIB
2305 grey_show(true); 2291 grey_show(true);
2306 grey_set_drawmode(DRMODE_FG); 2292 grey_set_drawmode(DRMODE_FG);