More compact screendump routines for core and greylib. The core routine might be a little slower for vertically packed mono and greyscale displays, the greylib one should be faster in all cases. * Reduce stack usage of greyscale screendump on the Clip* Rename a macro in the bitmap LCD simulation.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19959 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2009-02-09 23:34:44 +00:00
parent a12c2d59ad
commit 309a3c4590
3 changed files with 177 additions and 199 deletions

View file

@ -425,21 +425,23 @@ static void (*screen_dump_hook)(int fh) = NULL;
void screen_dump(void)
{
int fh;
int fd, y;
char filename[MAX_PATH];
int bx, by;
fb_data *src;
#if LCD_DEPTH == 1
static unsigned char line_block[8][BMP_LINESIZE];
#elif LCD_DEPTH == 2
#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
static unsigned char line_block[BMP_LINESIZE];
#elif LCD_PIXELFORMAT == VERTICAL_PACKING
static unsigned char line_block[4][BMP_LINESIZE];
#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
static unsigned char line_block[8][BMP_LINESIZE];
unsigned mask;
unsigned val;
#elif (LCD_DEPTH == 2) && (LCD_PIXELFORMAT != HORIZONTAL_PACKING)
int shift;
unsigned val;
#endif
#elif LCD_DEPTH == 16
static unsigned short line_block[BMP_LINESIZE/2];
#if LCD_DEPTH <= 8
unsigned char *dst, *dst_end;
unsigned char linebuf[BMP_LINESIZE];
#elif LCD_DEPTH <= 16
unsigned short *dst, *dst_end;
unsigned short linebuf[BMP_LINESIZE/2];
#endif
#if CONFIG_RTC
@ -449,132 +451,97 @@ void screen_dump(void)
IF_CNFN_NUM_(, NULL));
#endif
fh = creat(filename);
if (fh < 0)
fd = creat(filename);
if (fd < 0)
return;
if (screen_dump_hook)
{
screen_dump_hook(fh);
screen_dump_hook(fd);
}
else
{
write(fh, bmpheader, sizeof(bmpheader));
write(fd, bmpheader, sizeof(bmpheader));
/* BMP image goes bottom up */
for (y = LCD_HEIGHT - 1; y >= 0; y--)
{
memset(linebuf, 0, BMP_LINESIZE);
#if defined(HAVE_LCD_SPLIT) && (LCD_SPLIT_LINES == 2)
if (y == LCD_SPLIT_POS - 1)
{
write(fd, linebuf, BMP_LINESIZE);
write(fd, linebuf, BMP_LINESIZE);
}
#endif
dst = linebuf;
#if LCD_DEPTH == 1
for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
{
unsigned char *src = &lcd_framebuffer[by][0];
unsigned char *dst = &line_block[7][0];
dst_end = dst + LCD_WIDTH/2;
src = lcd_framebuffer[y >> 3];
mask = 1 << (y & 7);
memset(line_block, 0, sizeof(line_block));
#ifdef HAVE_LCD_SPLIT
if (by == (LCD_SPLIT_POS/8 - 1))
write(fh, line_block, LCD_SPLIT_LINES * sizeof(line_block[0]));
#endif
for (bx = LCD_WIDTH/2; bx > 0; bx--)
do
{
unsigned char *dst_blk = dst++;
unsigned src_byte0 = *src++ << 4;
unsigned src_byte1 = *src++;
int iy;
for (iy = 8; iy > 0; iy--)
{
*dst_blk = (src_byte0 & 0x10)
| (src_byte1 & 0x01)
val = (*src++ & mask) ? 0x10 : 0;
val |= (*src++ & mask) ? 0x01 : 0;
#ifdef HAVE_LCD_SPLIT
| (by < (LCD_SPLIT_POS/8) ? 0x22 : 0)
if (y < LCD_SPLIT_POS)
val |= 0x22;
#endif
;
src_byte0 >>= 1;
src_byte1 >>= 1;
dst_blk -= BMP_LINESIZE;
}
*dst++ = val;
}
while (dst < dst_end);
write(fh, line_block, sizeof(line_block));
}
#elif LCD_DEPTH == 2
dst_end = dst + LCD_WIDTH/2;
#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
{
unsigned char *src = &lcd_framebuffer[by][0];
unsigned char *dst = line_block;
src = lcd_framebuffer[y];
memset(line_block, 0, sizeof(line_block));
for (bx = LCD_FBWIDTH; bx > 0; bx--)
do
{
unsigned src_byte = *src++;
unsigned data = *src++;
*dst++ = ((src_byte >> 2) & 0x30) | ((src_byte >> 4) & 0x03);
*dst++ = ((src_byte << 2) & 0x30) | (src_byte & 0x03);
*dst++ = (data >> 2) & 0x30 | (data >> 4) & 0x03;
*dst++ = (data << 2) & 0x30 | data & 0x03;
}
while (dst < dst_end);
write(fh, line_block, sizeof(line_block));
}
#elif LCD_PIXELFORMAT == VERTICAL_PACKING
for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
{
unsigned char *src = &lcd_framebuffer[by][0];
unsigned char *dst = &line_block[3][0];
src = lcd_framebuffer[y >> 2];
shift = 2 * (y & 3);
memset(line_block, 0, sizeof(line_block));
for (bx = LCD_WIDTH/2; bx > 0; bx--)
do
{
unsigned char *dst_blk = dst++;
unsigned src_byte0 = *src++ << 4;
unsigned src_byte1 = *src++;
int iy;
for (iy = 4; iy > 0; iy--)
{
*dst_blk = (src_byte0 & 0x30) | (src_byte1 & 0x03);
src_byte0 >>= 2;
src_byte1 >>= 2;
dst_blk -= BMP_LINESIZE;
}
val = ((*src++ >> shift) & 3) << 4;
val |= ((*src++ >> shift) & 3);
*dst++ = val;
}
while (dst < dst_end);
write(fh, line_block, sizeof(line_block));
}
#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
{
const fb_data *src = &lcd_framebuffer[by][0];
unsigned char *dst = &line_block[7][0];
src = lcd_framebuffer[y >> 3];
shift = y & 7;
memset(line_block, 0, sizeof(line_block));
for (bx = LCD_WIDTH/2; bx > 0; bx--)
do
{
unsigned char *dst_blk = dst++;
unsigned src_data0 = *src++ << 4;
unsigned src_data1 = *src++;
int iy;
unsigned data = (*src++ >> shift) & 0x0101;
for (iy = 8; iy > 0; iy--)
{
*dst_blk = (src_data0 & 0x10) | (src_data1 & 0x01)
| ((src_data0 & 0x1000) | (src_data1 & 0x0100)) >> 7;
src_data0 >>= 1;
src_data1 >>= 1;
dst_blk -= BMP_LINESIZE;
}
val = (((data >> 7) | data) & 3) << 4;
data = (*src++ >> shift) & 0x0101;
val |= ((data >> 7) | data) & 3;
*dst++ = val;
}
while (dst < dst_end);
write(fh, line_block, sizeof(line_block));
}
#endif
#elif LCD_DEPTH == 16
for (by = LCD_HEIGHT - 1; by >= 0; by--)
{
unsigned short *src = &lcd_framebuffer[by][0];
unsigned short *dst = line_block;
memset(line_block, 0, sizeof(line_block));
for (bx = LCD_WIDTH; bx > 0; bx--)
dst_end = dst + LCD_WIDTH;
src = lcd_framebuffer[y];
do
{
#if (LCD_PIXELFORMAT == RGB565SWAPPED)
/* iPod LCD data is big endian although the CPU is not */
@ -583,13 +550,13 @@ void screen_dump(void)
*dst++ = htole16(*src++);
#endif
}
while (dst < dst_end);
write(fh, line_block, sizeof(line_block));
}
#endif /* LCD_DEPTH */
write(fd, linebuf, BMP_LINESIZE);
}
}
close(fh);
close(fd);
}
void screen_dump_set_hook(void (*hook)(int fh))

View file

@ -708,10 +708,10 @@ void grey_deferred_lcd_update(void)
/*** Screenshot ***/
#ifdef HAVE_LCD_SPLIT
#define GRADIENT_MAX 127
#define NUM_SHADES 128
#define BMP_NUMCOLORS 256
#else
#define GRADIENT_MAX 128
#define NUM_SHADES 129
#define BMP_NUMCOLORS 129
#endif
@ -754,7 +754,7 @@ static const unsigned char colorindex[4] = {128, 85, 43, 0};
static void grey_screendump_hook(int fd)
{
int i;
int x, y, gx, gy;
int y, gx, gy;
#if LCD_PIXELFORMAT == VERTICAL_PACKING
#if LCD_DEPTH == 1
unsigned val;
@ -766,45 +766,50 @@ static void grey_screendump_hook(int fd)
unsigned data;
int shift;
#endif /* LCD_PIXELFORMAT */
fb_data *lcdptr;
unsigned char *clut_entry;
unsigned char linebuf[MAX(4*BMP_NUMCOLORS,BMP_LINESIZE)];
fb_data *src;
unsigned char *gsrc;
unsigned char *dst, *dst_end;
unsigned char linebuf[MAX(4*NUM_SHADES,BMP_LINESIZE)];
rb->write(fd, bmpheader, sizeof(bmpheader)); /* write header */
/* build clut */
rb->memset(linebuf, 0, 4*BMP_NUMCOLORS);
clut_entry = linebuf;
rb->memset(linebuf, 0, 4*NUM_SHADES);
dst = linebuf;
for (i = 0; i <= GRADIENT_MAX; i++)
for (i = 0; i < NUM_SHADES; i++)
{
*clut_entry++ = (_GREY_MULUQ(BLUE_CMP(LCD_BL_BRIGHTCOLOR)
-BLUE_CMP(LCD_BL_DARKCOLOR), i) >> 7)
+ BLUE_CMP(LCD_BL_DARKCOLOR);
*clut_entry++ = (_GREY_MULUQ(GREEN_CMP(LCD_BL_BRIGHTCOLOR)
-GREEN_CMP(LCD_BL_DARKCOLOR), i) >> 7)
+ GREEN_CMP(LCD_BL_DARKCOLOR);
*clut_entry++ = (_GREY_MULUQ(RED_CMP(LCD_BL_BRIGHTCOLOR)
-RED_CMP(LCD_BL_DARKCOLOR), i) >> 7)
+ RED_CMP(LCD_BL_DARKCOLOR);
clut_entry++;
*dst++ = (_GREY_MULUQ(BLUE_CMP(LCD_BL_BRIGHTCOLOR)
-BLUE_CMP(LCD_BL_DARKCOLOR), i) >> 7)
+ BLUE_CMP(LCD_BL_DARKCOLOR);
*dst++ = (_GREY_MULUQ(GREEN_CMP(LCD_BL_BRIGHTCOLOR)
-GREEN_CMP(LCD_BL_DARKCOLOR), i) >> 7)
+ GREEN_CMP(LCD_BL_DARKCOLOR);
*dst++ = (_GREY_MULUQ(RED_CMP(LCD_BL_BRIGHTCOLOR)
-RED_CMP(LCD_BL_DARKCOLOR), i) >> 7)
+ RED_CMP(LCD_BL_DARKCOLOR);
dst++;
}
rb->write(fd, linebuf, 4*NUM_SHADES);
#ifdef HAVE_LCD_SPLIT
for (i = 0; i <= GRADIENT_MAX; i++)
dst = linebuf;
for (i = 0; i <= NUM_SHADES; i++)
{
*clut_entry++ = (_GREY_MULUQ(BLUE_CMP(LCD_BL_BRIGHTCOLOR_2)
-BLUE_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
+ BLUE_CMP(LCD_BL_DARKCOLOR_2);
*clut_entry++ = (_GREY_MULUQ(GREEN_CMP(LCD_BL_BRIGHTCOLOR_2)
-GREEN_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
+ GREEN_CMP(LCD_BL_DARKCOLOR_2);
*clut_entry++ = (_GREY_MULUQ(RED_CMP(LCD_BL_BRIGHTCOLOR_2)
-RED_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
+ RED_CMP(LCD_BL_DARKCOLOR_2);
clut_entry++;
*dst++ = (_GREY_MULUQ(BLUE_CMP(LCD_BL_BRIGHTCOLOR_2)
-BLUE_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
+ BLUE_CMP(LCD_BL_DARKCOLOR_2);
*dst++ = (_GREY_MULUQ(GREEN_CMP(LCD_BL_BRIGHTCOLOR_2)
-GREEN_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
+ GREEN_CMP(LCD_BL_DARKCOLOR_2);
*dst++ = (_GREY_MULUQ(RED_CMP(LCD_BL_BRIGHTCOLOR_2)
-RED_CMP(LCD_BL_DARKCOLOR_2), i) >> 7)
+ RED_CMP(LCD_BL_DARKCOLOR_2);
dst++;
}
rb->write(fd, linebuf, 4*NUM_SHADES);
#endif
rb->write(fd, linebuf, 4*BMP_NUMCOLORS);
/* BMP image goes bottom -> top */
for (y = LCD_HEIGHT - 1; y >= 0; y--)
@ -819,116 +824,122 @@ static void grey_screendump_hook(int fd)
}
#endif
dst = linebuf;
dst_end = dst + LCD_WIDTH;
gy = y - _grey_info.y;
gx = -_grey_info.x;
#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
gsrc = _grey_info.values + _GREY_MULUQ(_grey_info.width, gy);
#if LCD_DEPTH == 2
lcdptr = rb->lcd_framebuffer + _GREY_MULUQ(LCD_FBWIDTH, y);
for (x = 0; x < LCD_WIDTH; x += 4)
src = rb->lcd_framebuffer + _GREY_MULUQ(LCD_FBWIDTH, y);
do
{
gx = x - _grey_info.x;
if (((unsigned)gy < (unsigned)_grey_info.height)
&& ((unsigned)gx < (unsigned)_grey_info.width))
{
unsigned char *src = _grey_info.values
+ _GREY_MULUQ(_grey_info.width, gy) + gx;
for (i = 0; i < 4; i++)
linebuf[x + i] = *src++;
*dst++ = *gsrc++;
*dst++ = *gsrc++;
*dst++ = *gsrc++;
*dst++ = *gsrc++;
}
else
{
unsigned data = *lcdptr;
linebuf[x] = colorindex[(data >> 6) & 3];
linebuf[x + 1] = colorindex[(data >> 4) & 3];
linebuf[x + 2] = colorindex[(data >> 2) & 3];
linebuf[x + 3] = colorindex[data & 3];
unsigned data = *src;
*dst++ = colorindex[(data >> 6) & 3];
*dst++ = colorindex[(data >> 4) & 3];
*dst++ = colorindex[(data >> 2) & 3];
*dst++ = colorindex[data & 3];
}
lcdptr++;
gx++, src++;
}
while (dst < dst_end);
#endif /* LCD_DEPTH */
#elif LCD_PIXELFORMAT == VERTICAL_PACKING
gsrc = _grey_info.values + (~gy & _GREY_BMASK)
+ _GREY_MULUQ(_grey_info.width, gy & ~_GREY_BMASK);
#if LCD_DEPTH == 1
mask = 1 << (y & 7);
lcdptr = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3);
src = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3);
for (x = 0; x < LCD_WIDTH; x++)
do
{
gx = x - _grey_info.x;
if (((unsigned)gy < (unsigned)_grey_info.height)
&& ((unsigned)gx < (unsigned)_grey_info.width))
{
val = _grey_info.values[_GREY_MULUQ(_grey_info.width,
gy & ~_GREY_BMASK)
+ (gx << _GREY_BSHIFT)
+ (~gy & _GREY_BMASK)];
val = *gsrc;
#ifdef HAVE_LCD_SPLIT
val -= val >> 7;
#endif
gsrc += _GREY_BSIZE;
}
else
{
#ifdef HAVE_NEGATIVE_LCD
val = (*lcdptr & mask) ? GRADIENT_MAX : 0;
val = (*src & mask) ? (NUM_SHADES-1) : 0;
#else
val = (*lcdptr & mask) ? 0 : GRADIENT_MAX;
val = (*src & mask) ? 0 : (NUM_SHADES-1);
#endif
}
#ifdef HAVE_LCD_SPLIT
if (y < LCD_SPLIT_POS)
val |= 0x80;
#endif
linebuf[x] = val;
lcdptr++;
*dst++ = val;
gx++, src++;
}
while (dst < dst_end);
#elif LCD_DEPTH == 2
shift = 2 * (y & 3);
lcdptr = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 2);
for (x = 0; x < LCD_WIDTH; x++)
src = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 2);
do
{
gx = x - _grey_info.x;
if (((unsigned)gy < (unsigned)_grey_info.height)
&& ((unsigned)gx < (unsigned)_grey_info.width))
{
linebuf[x] = _grey_info.values[_GREY_MULUQ(_grey_info.width,
gy & ~_GREY_BMASK)
+ (gx << _GREY_BSHIFT)
+ (~gy & _GREY_BMASK)];
*dst++ = *gsrc;
gsrc += _GREY_BSIZE;
}
else
{
linebuf[x] = colorindex[(*lcdptr >> shift) & 3];
*dst++ = colorindex[(*src >> shift) & 3];
}
lcdptr++;
gx++, src++;
}
while (dst < dst_end);
#endif /* LCD_DEPTH */
#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
gsrc = _grey_info.values + (~gy & _GREY_BMASK)
+ _GREY_MULUQ(_grey_info.width, gy & ~_GREY_BMASK);
#if LCD_DEPTH == 2
shift = y & 7;
lcdptr = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3);
for (x = 0; x < LCD_WIDTH; x++)
src = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3);
do
{
gx = x - _grey_info.x;
if (((unsigned)gy < (unsigned)_grey_info.height)
&& ((unsigned)gx < (unsigned)_grey_info.width))
{
linebuf[x] = _grey_info.values[_GREY_MULUQ(_grey_info.width,
gy & ~_GREY_BMASK)
+ (gx << _GREY_BSHIFT)
+ (~gy & _GREY_BMASK)];
*dst++ = *gsrc;
gsrc += _GREY_BSIZE;
}
else
{
data = (*lcdptr >> shift) & 0x0101;
linebuf[x] = colorindex[((data >> 7) | data) & 3];
data = (*src >> shift) & 0x0101;
*dst++ = colorindex[((data >> 7) | data) & 3];
}
lcdptr++;
gx++, src++;
}
while (dst < dst_end);
#endif /* LCD_DEPTH */
#endif /* LCD_PIXELFORMAT */

View file

@ -59,9 +59,9 @@ SDL_Color lcd_color2_bright = {RED_CMP(LCD_BRIGHTCOLOR_2),
#endif
#ifdef HAVE_LCD_SPLIT
#define GRADIENT_MAX 127
#define NUM_SHADES 128
#else
#define GRADIENT_MAX 128
#define NUM_SHADES 129
#endif
#endif /* LCD_DEPTH <= 8 */
@ -78,9 +78,9 @@ static unsigned long get_lcd_pixel(int x, int y)
{
#if LCD_DEPTH == 1
#ifdef HAVE_NEGATIVE_LCD
return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? GRADIENT_MAX : 0;
return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? (NUM_SHADES-1) : 0;
#else
return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? 0 : GRADIENT_MAX;
return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? 0 : (NUM_SHADES-1);
#endif
#elif LCD_DEPTH == 2
#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
@ -122,17 +122,17 @@ void sim_backlight(int value)
#if LCD_DEPTH <= 8
if (value > 0) {
sdl_set_gradient(lcd_surface, &lcd_bl_color_dark,
&lcd_bl_color_bright, 0, GRADIENT_MAX+1);
&lcd_bl_color_bright, 0, NUM_SHADES);
#ifdef HAVE_LCD_SPLIT
sdl_set_gradient(lcd_surface, &lcd_bl_color2_dark,
&lcd_bl_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
&lcd_bl_color2_bright, NUM_SHADES, NUM_SHADES);
#endif
} else {
sdl_set_gradient(lcd_surface, &lcd_color_dark,
&lcd_color_bright, 0, GRADIENT_MAX+1);
&lcd_color_bright, 0, NUM_SHADES);
#ifdef HAVE_LCD_SPLIT
sdl_set_gradient(lcd_surface, &lcd_color2_dark,
&lcd_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
&lcd_color2_bright, NUM_SHADES, NUM_SHADES);
#endif
}
sdl_gui_update(lcd_surface, 0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
@ -162,17 +162,17 @@ void sim_lcd_init(void)
#if LCD_DEPTH <= 8
#ifdef HAVE_BACKLIGHT
sdl_set_gradient(lcd_surface, &lcd_bl_color_dark,
&lcd_bl_color_bright, 0, GRADIENT_MAX+1);
&lcd_bl_color_bright, 0, NUM_SHADES);
#ifdef HAVE_LCD_SPLIT
sdl_set_gradient(lcd_surface, &lcd_bl_color2_dark,
&lcd_bl_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
&lcd_bl_color2_bright, NUM_SHADES, NUM_SHADES);
#endif
#else /* !HAVE_BACKLIGHT */
sdl_set_gradient(lcd_surface, &lcd_color_dark,
&lcd_color_bright, 0, GRADIENT_MAX+1);
&lcd_color_bright, 0, NUM_SHADES);
#ifdef HAVE_LCD_SPLIT
sdl_set_gradient(lcd_surface, &lcd_color2_dark,
&lcd_color2_bright, GRADIENT_MAX+1, GRADIENT_MAX+1);
&lcd_color2_bright, NUM_SHADES, NUM_SHADES);
#endif
#endif /* !HAVE_BACKLIGHT */
#endif /* LCD_DEPTH < 8 */