diff --git a/apps/plugin.h b/apps/plugin.h index 464614d..3a6239f 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -711,7 +711,7 @@ struct plugin_api { #endif #ifdef HAVE_LCD_BITMAP int (*read_bmp_file)(const char* filename, struct bitmap *bm, int maxsize, - int format); + unsigned int format); void (*screen_dump_set_hook)(void (*hook)(int fh)); #endif int (*show_logo)(void); diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index 9327ac5..7d33a26 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c @@ -88,16 +88,31 @@ union rgb_union { uint32_t raw; }; -/* masks for supported BI_BITFIELDS encodings (16/32 bit), little endian */ -static const unsigned char bitfields[3][12] = { - { 0x00,0x7c,0x00,0, 0xe0,0x03,0x00,0, 0x1f,0x00,0x00,0 }, /* 15 bit */ - { 0x00,0xf8,0x00,0, 0xe0,0x07,0x00,0, 0x1f,0x00,0x00,0 }, /* 16 bit */ - { 0x00,0x00,0xff,0, 0x00,0xff,0x00,0, 0xff,0x00,0x00,0 }, /* 32 bit */ +/* masks for supported BI_BITFIELDS encodings (16/32 bit) */ +static const struct uint8_rgb bitfields[3][3] = { + /* 15bit */ + { + { .blue = 0x00, .green = 0x7c, .red = 0x00 }, + { .blue = 0xe0, .green = 0x03, .red = 0x00 }, + { .blue = 0x1f, .green = 0x00, .red = 0x00 }, + }, + /* 16bit */ + { + { .blue = 0x00, .green = 0xf8, .red = 0x00 }, + { .blue = 0xe0, .green = 0x07, .red = 0x00 }, + { .blue = 0x1f, .green = 0x00, .red = 0x00 }, + }, + /* 32bit */ + { + { .blue = 0x00, .green = 0x00, .red = 0xff }, + { .blue = 0x00, .green = 0xff, .red = 0x00 }, + { .blue = 0xff, .green = 0x00, .red = 0x00 }, + }, }; #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) /* canonical ordered dither matrix */ -static const unsigned char dither_matrix[16][16] = { +const unsigned char dither_matrix[16][16] = { { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, @@ -120,7 +135,7 @@ static const unsigned char dither_matrix[16][16] = { #if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \ || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \ && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED)) -static const unsigned short vi_pattern[4] = { +const unsigned short vi_pattern[4] = { 0x0101, 0x0100, 0x0001, 0x0000 }; #endif @@ -139,12 +154,6 @@ static inline uint32_t readlong(uint32_t *value) ((uint32_t)bytes[2] << 16) | ((uint32_t)bytes[3] << 24); } -static inline unsigned brightness(union rgb_union color) -{ - return (3 * (unsigned)color.red + 6 * (unsigned)color.green - + (unsigned)color.blue) / 10; -} - /****************************************************************************** * read_bmp_file() * @@ -154,7 +163,7 @@ static inline unsigned brightness(union rgb_union color) int read_bmp_file(const char* filename, struct bitmap *bm, int maxsize, - int format) + unsigned int format) { int fd, ret; fd = open(filename, O_RDONLY); @@ -170,6 +179,188 @@ int read_bmp_file(const char* filename, return ret; } +static inline void set_rgb_union(struct uint8_rgb *dst, union rgb_union src) +{ + dst->red = src.red; + dst->green = src.green; + dst->blue = src.blue; +} + +static int read_one_line(int fd, struct uint8_rgb *bmpb, int padded_width, + int width, int depth, struct uint8_rgb *palette) +{ + uint32_t data = 0, mask, mask_end; + int ret; + struct uint8_rgb q0, q1; + int i, end; + uint8_t data1; + uint16_t data2; + uint32_t data4; + + switch (depth) { + case 1: + q0 = palette[0]; + q1 = palette[1]; + end = (width + 7) >> 3; + for (i = 0; i < end; i++) { + ret = read(fd, &data1, sizeof(data1)); + if (ret != sizeof(data1)) { + DEBUGF("read_one_line: error reading image, read returned: %d " + "expected: %d\n", ret, sizeof(data1)); + return -9; + } + + if (i != (end - 1)) + mask_end = 0x00; + else + mask_end = 0x80 >> (width & 7); + + for (mask = 0x80; mask != mask_end; mask >>= 1) + *bmpb++ = (data1 & mask) ? q1 : q0; + } + break; + + case 4: + end = (width + 1) >> 1; + for (i = 0; i < end; i++) { + ret = read(fd, &data1, sizeof(data1)); + if (ret != sizeof(data1)) { + DEBUGF("read_one_line: error reading image, read returned: %d " + "expected: %d\n", ret, sizeof(data1)); + return -9; + } + + *bmpb++ = palette[data1 >> 4]; + if (!((i == (end - 1)) && (width & 1))) + *bmpb++ = palette[data1 & 0x0f]; + } + break; + + case 8: + end = width; + for (i = 0; i < end; i++) { + ret = read(fd, &data1, sizeof(data1)); + if (ret != sizeof(data1)) { + DEBUGF("read_one_line: error reading image, read returned: %d " + "expected: %d\n", ret, sizeof(data1)); + return -9; + } + + *bmpb++ = palette[data1]; + } + break; + + case 15: + case 16: + end = width; + for (i = 0; i < end; i++) { + uint32_t component, rgb; + + ret = read(fd, &data2, sizeof(data2)); + if (ret != sizeof(data2)) { + DEBUGF("read_one_line: error reading image, read returned: %d " + "expected: %d\n", ret, sizeof(data2)); + return -9; + } + + data = letoh16(data2); + /* blue */ + component = (data << 3) & 0xf8; +#ifdef ROCKBOX_BIG_ENDIAN + rgb = (component | (component >> 5)) << 8; + /* green */ + data >>= 2; + if (depth == 15) { + component = data & 0xf8; + rgb |= component | (component >> 5); + } else { + data >>= 1; + component = data & 0xfc; + rgb |= component | (component >> 6); + } + /* red */ + data >>= 5; + component = data & 0xf8; + rgb = (rgb << 8) | component | (component >> 5); + set_rgb_union(bmpb, (union rgb_union)(rgb << 8)); + bmpb++; +#else /* little endian */ + rgb = component | (component >> 5); + /* green */ + data >>= 2; + if (depth == 15) { + component = data & 0xf8; + rgb |= (component | (component >> 5)) << 8; + } else { + data >>= 1; + component = data & 0xfc; + rgb |= (component | (component >> 6)) << 8; + } + /* red */ + data >>= 5; + component = data & 0xf8; + rgb |= (component | (component >> 5)) << 16; + set_rgb_union(bmpb, (union rgb_union)rgb); + bmpb++; +#endif + } + break; + + case 24: + end = width; + for (i = 0; i < end; i++) { + int j; + for (j = 0; j < 3; j++) { + ret = read(fd, &data1, sizeof(data1)); + if (ret != sizeof(data1)) { + DEBUGF("read_one_line: error reading image, read returned:" + " %d expected: %d\n", ret, sizeof(data1)); + return -9; + } + if (j == 0) + bmpb->blue = data1; + else if (j == 1) + bmpb->green = data1; + else if (j == 2) + bmpb->red = data1; + + } + bmpb++; + } + break; + + case 32: + end = width; + for (i = 0; i < end; i++) { + ret = read(fd, &data4, sizeof(data4)); + if (ret != sizeof(data4)) { + DEBUGF("read_one_line: error reading image, read returned: %d " + "expected: %d\n", ret, sizeof(data4)); + return -9; + } + + set_rgb_union(bmpb, (union rgb_union)(data4)); + bmpb++; + } + break; + } + + int pad = padded_width - ((width * depth + 7) >> 3); + if (pad > 0) + lseek(fd, pad, SEEK_CUR); + + return 0; +} + +static inline int rgbcmp(struct uint8_rgb rgb1, struct uint8_rgb rgb2) +{ + if ((rgb1.red == rgb2.red) && (rgb1.green == rgb2.green) && + (rgb1.blue == rgb2.blue)) + return 0; + else + return 1; +} + /****************************************************************************** * read_bmp_fd() * @@ -180,24 +371,24 @@ int read_bmp_file(const char* filename, int read_bmp_fd(int fd, struct bitmap *bm, int maxsize, - int format) + unsigned int format) { struct bmp_header bmph; - int width, height, padded_width; - int dst_height, dst_width; + int padded_width; + struct dim src_dim; int depth, numcolors, compression, totalsize; int row, col, ret; - int rowstart, rowstop, rowstep; unsigned char *bitmap = bm->data; - uint32_t bmpbuf[LCD_WIDTH]; /* Buffer for one line */ - uint32_t palette[256]; + struct uint8_rgb bmpbuf[LCD_WIDTH]; /* Buffer for one line */ + struct uint8_rgb palette[256]; + bool remote = false; + struct rowset rset; #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) bool transparent = false; bool dither = false; -#ifdef HAVE_REMOTE_LCD - bool remote = false; +#ifdef HAVE_REMOTE_LCD if (format & FORMAT_REMOTE) { remote = true; #if LCD_REMOTE_DEPTH == 1 @@ -231,27 +422,28 @@ int read_bmp_fd(int fd, return -3; } - width = readlong(&bmph.width); - if (width > LCD_WIDTH) { + src_dim.width = readlong(&bmph.width); + if (src_dim.width > LCD_WIDTH) { DEBUGF("read_bmp_fd: Bitmap too wide (%d pixels, max is %d)\n", - width, LCD_WIDTH); + src_dim.width, LCD_WIDTH); return -4; } - height = readlong(&bmph.height); - if (height < 0) { /* Top-down BMP file */ - height = -height; - rowstart = 0; - rowstop = height; - rowstep = 1; + src_dim.height = readlong(&bmph.height); + if (src_dim.height < 0) { /* Top-down BMP file */ + src_dim.height = -src_dim.height; + rset.rowstart = 0; + rset.rowstop = src_dim.height; + rset.rowstep = 1; } else { /* normal BMP */ - rowstart = height - 1; - rowstop = -1; - rowstep = -1; + rset.rowstart = src_dim.height - 1; + rset.rowstop = -1; + rset.rowstep = -1; } depth = readshort(&bmph.bit_count); - padded_width = ((width * depth + 31) >> 3) & ~3; /* 4-byte boundary aligned */ + /* 4-byte boundary aligned */ + padded_width = ((src_dim.width * depth + 31) >> 3) & ~3; #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) if (format == FORMAT_ANY) { @@ -263,45 +455,10 @@ int read_bmp_fd(int fd, bm->format = format; #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ /* returning image size */ - bm->width = width; - bm->height = height; + bm->width = src_dim.width; + bm->height = src_dim.height; -#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) - if (format == FORMAT_NATIVE) { -#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 - if (remote) { -#if (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) - dst_width = width; - dst_height = (height + 7) >> 3; -#endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ - totalsize = dst_width * dst_height * sizeof(fb_remote_data); - } else -#endif /* defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 */ - { -#if LCD_DEPTH == 2 -#if LCD_PIXELFORMAT == HORIZONTAL_PACKING - dst_width = (width + 3) >> 2; - dst_height = height; -#elif LCD_PIXELFORMAT == VERTICAL_PACKING - dst_width = width; - dst_height = (height + 3) >> 2; -#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED - dst_width = width; - dst_height = (height + 7) >> 3; -#endif /* LCD_PIXELFORMAT */ -#elif LCD_DEPTH == 16 - dst_width = width; - dst_height = height; -#endif /* LCD_DEPTH */ - totalsize = dst_width * dst_height * sizeof(fb_data); - } - } else -#endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ - { - dst_width = width; - dst_height = (height + 7) >> 3; - totalsize = dst_width * dst_height; - } + totalsize = get_totalsize(bm, remote); /* Check if this fits the buffer */ if (totalsize > maxsize) { @@ -319,11 +476,15 @@ int read_bmp_fd(int fd, numcolors = (compression == 3) ? 3 : 0; if (numcolors > 0 && numcolors <= 256) { - if (read(fd, palette, numcolors * sizeof(uint32_t)) - != numcolors * (int)sizeof(uint32_t)) - { - DEBUGF("read_bmp_fd: Can't read color palette\n"); - return -7; + int i; + union rgb_union pal; + for (i = 0; i < numcolors; i++) { + if (read(fd, &pal, sizeof(pal)) != (int)sizeof(pal)) + { + DEBUGF("read_bmp_fd: Can't read color palette\n"); + return -7; + } + set_rgb_union(&palette[i], pal); } } @@ -343,15 +504,27 @@ int read_bmp_fd(int fd, case 32: if (compression == 3) { /* BI_BITFIELDS */ - if (!memcmp(palette, bitfields[0], 12)) { /* 15 bit */ - depth = 15; - break; + bool found; + int i, j; + + /* (i == 0) is 15bit, (i == 1) is 16bit, (i == 2) is 32bit */ + for (i = 0; i < ARRAY_SIZE(bitfields); i++) { + for (j = 0; j < ARRAY_SIZE(bitfields[0]); j++) { + if (!rgbcmp(palette[j], bitfields[i][j])) { + found = true; + } else { + found = false; + break; + } + } + if (found) { + if (i == 0) /* 15bit */ + depth = 15; + break; + } } - if (!memcmp(palette, bitfields[1], 12) /* 16 bit */ - || !memcmp(palette, bitfields[2], 12)) /* 32 bit */ - { + if (found) break; - } } /* else fall through */ default: @@ -367,120 +540,20 @@ int read_bmp_fd(int fd, lseek(fd, (off_t)readlong(&bmph.off_bits), SEEK_SET); memset(bitmap, 0, totalsize); + int fb_width = get_fb_width(bm, remote); /* loop to read rows and put them to buffer */ - for (row = rowstart; row != rowstop; row += rowstep) { - unsigned data, mask; + for (row = rset.rowstart; row != rset.rowstop; row += rset.rowstep) { + unsigned mask; unsigned char *p; - uint16_t *p2; - uint32_t *rp; - union rgb_union *qp; - union rgb_union q0, q1; - - /* read one row */ - ret = read(fd, bmpbuf, padded_width); - if (ret != padded_width) { - DEBUGF("read_bmp_fd: error reading image, read returned: %d " - "expected: %d\n", ret, padded_width); - return -9; - } - - /* convert whole line in-place to XRGB8888 (little endian) */ - rp = bmpbuf + width; - switch (depth) { - case 1: - q0.raw = palette[0]; - q1.raw = palette[1]; - p = (unsigned char*)bmpbuf + ((width + 7) >> 3); - mask = 0x80 >> ((width + 7) & 7); - while (p > (unsigned char*)bmpbuf) { - data = *(--p); - for (; mask <= 0x80; mask <<= 1) - *(--rp) = (data & mask) ? q1.raw : q0.raw; - mask = 0x01; - } - break; + struct uint8_rgb *qp; - case 4: - if (width & 1) - rp++; - p = (unsigned char*)bmpbuf + ((width + 1) >> 1); - while (p > (unsigned char*)bmpbuf) { - data = *(--p); - *(--rp) = palette[data & 0x0f]; - *(--rp) = palette[data >> 4]; - } - break; - - case 8: - p = (unsigned char*)bmpbuf + width; - while (p > (unsigned char*)bmpbuf) - *(--rp) = palette[*(--p)]; - break; - - case 15: - case 16: - p2 = (uint16_t *)bmpbuf + width; - while (p2 > (uint16_t *)bmpbuf) { - unsigned component, rgb; - - data = letoh16(*(--p2)); - /* blue */ - component = (data << 3) & 0xf8; -#ifdef ROCKBOX_BIG_ENDIAN - rgb = (component | (component >> 5)) << 8; - /* green */ - data >>= 2; - if (depth == 15) { - component = data & 0xf8; - rgb |= component | (component >> 5); - } else { - data >>= 1; - component = data & 0xfc; - rgb |= component | (component >> 6); - } - /* red */ - data >>= 5; - component = data & 0xf8; - rgb = (rgb << 8) | component | (component >> 5); - *(--rp) = rgb << 8; -#else /* little endian */ - rgb = component | (component >> 5); - /* green */ - data >>= 2; - if (depth == 15) { - component = data & 0xf8; - rgb |= (component | (component >> 5)) << 8; - } else { - data >>= 1; - component = data & 0xfc; - rgb |= (component | (component >> 6)) << 8; - } - /* red */ - data >>= 5; - component = data & 0xf8; - rgb |= (component | (component >> 5)) << 16; - *(--rp) = rgb; -#endif - } - break; - - case 24: - p = (unsigned char*)bmpbuf + 3 * width; - while (p > (unsigned char*)bmpbuf) { - data = *(--p); - data = (data << 8) | *(--p); - data = (data << 8) | *(--p); - *(--rp) = htole32(data); - } - break; + if (0 != read_one_line(fd, bmpbuf, padded_width, src_dim.width, + depth, palette)) + return -9; - case 32: /* already in desired format */ - break; - } - /* Convert to destination format */ - qp = (union rgb_union *)bmpbuf; + qp = bmpbuf; #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) if (format == FORMAT_NATIVE) { #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 @@ -488,17 +561,17 @@ int read_bmp_fd(int fd, #if (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) /* iAudio X5/M5 remote */ fb_remote_data *dest = (fb_remote_data *)bitmap - + dst_width * (row >> 3); + + fb_width * (row >> 3); int shift = row & 7; int delta = 127; unsigned bright; - for (col = 0; col < width; col++) { + for (col = 0; col < src_dim.width; col++) { if (dither) - delta = dither_matrix[row & 0xf][col & 0xf]; + delta = dither_mat(row & 0xf, col & 0xf); bright = brightness(*qp++); bright = (3 * bright + (bright >> 6) + delta) >> 8; - *dest++ |= vi_pattern[bright] << shift; + *dest++ |= vi_pat(bright) << shift; } #endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ } else @@ -507,15 +580,15 @@ int read_bmp_fd(int fd, #if LCD_DEPTH == 2 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING /* greyscale iPods */ - fb_data *dest = (fb_data *)bitmap + dst_width * row; + fb_data *dest = (fb_data *)bitmap + fb_width * row; int shift = 6; int delta = 127; unsigned bright; unsigned data = 0; - for (col = 0; col < width; col++) { + for (col = 0; col < src_dim.width; col++) { if (dither) - delta = dither_matrix[row & 0xf][col & 0xf]; + delta = dither_mat(row & 0xf, col & 0xf); bright = brightness(*qp++); bright = (3 * bright + (bright >> 6) + delta) >> 8; data |= (~bright & 3) << shift; @@ -530,42 +603,43 @@ int read_bmp_fd(int fd, *dest++ = data; #elif LCD_PIXELFORMAT == VERTICAL_PACKING /* iriver H1x0 */ - fb_data *dest = (fb_data *)bitmap + dst_width * (row >> 2); + fb_data *dest = (fb_data *)bitmap + fb_width * (row >> 2); int shift = 2 * (row & 3); int delta = 127; unsigned bright; - for (col = 0; col < width; col++) { + for (col = 0; col < src_dim.width; col++) { if (dither) - delta = dither_matrix[row & 0xf][col & 0xf]; + delta = dither_mat(row & 0xf, col & 0xf); bright = brightness(*qp++); bright = (3 * bright + (bright >> 6) + delta) >> 8; *dest++ |= (~bright & 3) << shift; } #elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED /* iAudio M3 */ - fb_data *dest = (fb_data *)bitmap + dst_width * (row >> 3); + fb_data *dest = (fb_data *)bitmap + fb_width * (row >> 3); int shift = row & 7; int delta = 127; unsigned bright; - for (col = 0; col < width; col++) { + for (col = 0; col < src_dim.width; col++) { if (dither) - delta = dither_matrix[row & 0xf][col & 0xf]; + delta = dither_mat(row & 0xf, col & 0xf); bright = brightness(*qp++); bright = (3 * bright + (bright >> 6) + delta) >> 8; - *dest++ |= vi_pattern[bright] << shift; + *dest++ |= vi_pat(bright) << shift; } #endif /* LCD_PIXELFORMAT */ #elif LCD_DEPTH == 16 /* iriver h300, colour iPods, X5 */ - fb_data *dest = (fb_data *)bitmap + dst_width * row; + fb_data *dest = (fb_data *)bitmap + fb_width * row; int delta = 127; unsigned r, g, b; + struct uint8_rgb q0; - for (col = 0; col < width; col++) { + for (col = 0; col < src_dim.width; col++) { if (dither) - delta = dither_matrix[row & 0xf][col & 0xf]; + delta = dither_mat(row & 0xf, col & 0xf); q0 = *qp++; r = (31 * q0.red + (q0.red >> 3) + delta) >> 8; g = (63 * q0.green + (q0.green >> 2) + delta) >> 8; @@ -577,10 +651,10 @@ int read_bmp_fd(int fd, } else #endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ { - p = bitmap + dst_width * (row >> 3); + p = bitmap + fb_width * (row >> 3); mask = 1 << (row & 7); - for (col = 0; col < width; col++, p++) + for (col = 0; col < src_dim.width; col++, p++) if (brightness(*qp++) < 128) *p |= mask; } diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h index 3ac73de..73ed4cb 100644 --- a/apps/recorder/bmp.h +++ b/apps/recorder/bmp.h @@ -23,6 +23,155 @@ #include "config.h" #include "lcd.h" +#include "inttypes.h" +#ifdef HAVE_REMOTE_LCD +#include "lcd-remote.h" +#endif + +#define ARRAY_SIZE(array) (int)(sizeof(array)/(sizeof(array[0]))) + +struct uint8_rgb { + uint8_t blue; + uint8_t green; + uint8_t red; +}; + +struct dim { + short width; + short height; +}; + +struct rowset { + short rowstep; + short rowstart; + short rowstop; +}; + +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) +extern const unsigned char dither_matrix[16][16]; +static inline unsigned char dither_mat(unsigned int x, unsigned int y) +{ + return dither_matrix[y][x]; +} +#endif + +static inline unsigned brightness(struct uint8_rgb color) +{ + return (3 * (unsigned)color.red + 6 * (unsigned)color.green + + (unsigned)color.blue) / 10; +} + +#if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \ + || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \ + && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED)) +extern const unsigned short vi_pattern[4]; +static inline unsigned short vi_pat(unsigned int bright) +{ + return vi_pattern[bright]; +} +#endif + +static inline int get_fb_height(struct bitmap *bm, bool remote) +{ + const int height = bm->height; +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) + const unsigned int format = bm->format; +#endif + int dst_height; + +#if !defined(HAVE_REMOTE_LCD) || \ + (defined(HAVE_REMOTE_LCD) &&(LCD_REMOTE_DEPTH == 1)) + (void) remote; +#endif + +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) + if (format == FORMAT_NATIVE) { +#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 + if (remote) { +#if (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) + dst_height = (height + 7) >> 3; +#endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ + } else +#endif /* defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 */ + { +#if LCD_DEPTH == 2 +#if LCD_PIXELFORMAT == HORIZONTAL_PACKING + dst_height = height; +#elif LCD_PIXELFORMAT == VERTICAL_PACKING + dst_height = (height + 3) >> 2; +#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED + dst_height = (height + 7) >> 3; +#endif /* LCD_PIXELFORMAT */ +#elif LCD_DEPTH == 16 + dst_height = height; +#endif /* LCD_DEPTH */ + } + } else +#endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ + { + dst_height = (height + 7) >> 3; + } + + return dst_height; +} + +static inline int get_fb_width(struct bitmap *bm, bool remote) +{ + const int width = bm->width; +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) + const unsigned int format = bm->format; +#endif + int dst_width; + +#if !defined(HAVE_REMOTE_LCD) || \ + (defined(HAVE_REMOTE_LCD) &&(LCD_REMOTE_DEPTH == 1)) + (void) remote; +#endif + +#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) + if (format == FORMAT_NATIVE) { +#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 + if (remote) { +#if (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) + dst_width = width; +#endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ + } else +#endif /* defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 */ + { +#if LCD_DEPTH == 2 +#if LCD_PIXELFORMAT == HORIZONTAL_PACKING + dst_width = (width + 3) >> 2; +#elif LCD_PIXELFORMAT == VERTICAL_PACKING + dst_width = width; +#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED + dst_width = width; +#endif /* LCD_PIXELFORMAT */ +#elif LCD_DEPTH == 16 + dst_width = width; +#endif /* LCD_DEPTH */ + } + } else +#endif /* (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1) */ + { + dst_width = width; + } + + return dst_width; +} + +static inline int get_totalsize(struct bitmap *bm, bool remote) +{ + int sz; +#if defined(HAVE_REMOTE_LCD) && \ + (LCD_REMOTE_DEPTH == 2) && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) + if (remote) + sz = sizeof(fb_remote_data); + else +#endif /* LCD_REMOTE_DEPTH / LCD_REMOTE_PIXELFORMAT */ + sz = sizeof(fb_data); + + return get_fb_width(bm, remote) * get_fb_height(bm, remote) * sz; +} /********************************************************************* * read_bmp_file() @@ -35,10 +184,10 @@ int read_bmp_file(const char* filename, struct bitmap *bm, int maxsize, - int format); + unsigned int format); int read_bmp_fd(int fd, struct bitmap *bm, int maxsize, - int format); + unsigned int format); #endif