#include "pv_config.h" #ifdef FBV_SUPPORT_BMP #include "pictureviewer.h" #include #include #include #include #include #define BMP_TORASTER_OFFSET 10 #define BMP_SIZE_OFFSET 18 #define BMP_BPP_OFFSET 28 #define BMP_RLE_OFFSET 30 #define BMP_COLOR_OFFSET 54 #define fill4B(a) ( ( 4 - ( (a) % 4 ) ) & 0x03) struct color { unsigned char red; unsigned char green; unsigned char blue; }; int fh_bmp_id(const char *name) { int fd; char id[2]; fd = open(name, O_RDONLY); if (fd == -1) { // dbout("fh_bmp_id {\n"); return(0); } read(fd, id, 2); close(fd); if ( id[0]=='B' && id[1]=='M' ) { return(1); } return(0); } void fetch_pallete(int fd, struct color pallete[], int count) { // dbout("fetch_palette {\n"); unsigned char buff[4]; int i; lseek(fd, BMP_COLOR_OFFSET, SEEK_SET); for (i=0; i0) bytes++; unsigned char* tbuffer = (unsigned char*) malloc(bytes); if(tbuffer==NULL) { printf("Error: malloc\n"); close(fd); return (FH_ERROR_MALLOC); } for (i=0; i>4; c2 = tbuffer[j] & 0x0f; *wr_buffer++ = pallete[c1].red; *wr_buffer++ = pallete[c1].green; *wr_buffer++ = pallete[c1].blue; *wr_buffer++ = pallete[c2].red; *wr_buffer++ = pallete[c2].green; *wr_buffer++ = pallete[c2].blue; } if (x%2) { c1 = tbuffer[j]>>4; *wr_buffer++ = pallete[c1].red; *wr_buffer++ = pallete[c1].green; *wr_buffer++ = pallete[c1].blue; } if (skip) { read(fd, buff, skip); } wr_buffer -= x*6; /* backoff 2 lines - x*2 *3 */ } free(tbuffer); } break; case 8: /* 8bit palletized */ { skip = fill4B(x); fetch_pallete(fd, pallete, 256); lseek(fd, raster, SEEK_SET); unsigned char* tbuffer = (unsigned char*) malloc(x); if(tbuffer==NULL) { printf("Error: malloc\n"); close(fd); return (FH_ERROR_MALLOC); } for (i=0; i