summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-01-24 08:12:36 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-01-24 08:12:36 +0000
commit465982b2af2fc524d954c01bf4fe9e6790c9a871 (patch)
treebd11b8267d16dd3dc1a055ac27f7ca6939096fb8
parentef4241a2ee20885ab6957ac842ca46096a8f96f5 (diff)
downloadrockbox-465982b2af2fc524d954c01bf4fe9e6790c9a871.tar.gz
rockbox-465982b2af2fc524d954c01bf4fe9e6790c9a871.zip
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
-rw-r--r--apps/recorder/bmp.c25
1 files changed, 8 insertions, 17 deletions
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. */
-
}