From 465982b2af2fc524d954c01bf4fe9e6790c9a871 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Tue, 24 Jan 2006 08:12:36 +0000 Subject: Little optimization to the bmp loader loop (unfortunately almost no effect as the open() takes the longest time). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8436 a1c6a512-1295-4272-9138-f99709370657 --- apps/recorder/bmp.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'apps') diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index e55c2f9d1e..d2be8c9172 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c @@ -80,14 +80,6 @@ static long readlong(long *value) { #endif -/* Function to get a pixel from a line. (Tomas: maybe a better way?) */ -int getpix(int px, unsigned char *bmpbuf) { - int a = (px / 8); - int b = (7 - (px % 8)); - - return (bmpbuf[a] & (1 << b)) != 0; -} - /****************************************************************************** * read_bmp_file() @@ -172,6 +164,9 @@ int read_bmp_file(char* filename, /* loop to read rows and put them to buffer */ for (row = 0; row < bitmap_height; row++) { + int bitsel = 1 << ((bitmap_height - row - 1) % 8); + int bytesel = bitmap_width * ((bitmap_height - row - 1) / 8); + /* read one row */ ret = read(fd, bmpbuf, PaddedWidth); if (ret != PaddedWidth) { @@ -183,14 +178,11 @@ int read_bmp_file(char* filename, /* loop though the pixels in this line. */ for (col = 0; col < bitmap_width; col++) { - ret = getpix(col, bmpbuf); - if (ret == 1) { - bitmap[bitmap_width * ((bitmap_height - row - 1) / 8) + col] - &= ~ 1 << ((bitmap_height - row - 1) % 8); - } else { - bitmap[bitmap_width * ((bitmap_height - row - 1) / 8) + col] - |= 1 << ((bitmap_height - row - 1) % 8); - } + ret = (bmpbuf[col/8] & (1 << (7 - (col % 8)))) != 0; + if (ret == 1) + bitmap[bytesel + col] &= ~bitsel; + else + bitmap[bytesel + col] |= bitsel; } } @@ -201,5 +193,4 @@ int read_bmp_file(char* filename, *get_height = bitmap_height; return (PaddedHeight * bitmap_width); /* return the used buffer size. */ - } -- cgit v1.2.3