diff -ru rockbox_orig/apps/gui/gwps-common.c rockbox/apps/gui/gwps-common.c --- rockbox_orig/apps/gui/gwps-common.c 2006-07-19 01:17:54.000000000 +0900 +++ rockbox/apps/gui/gwps-common.c 2006-07-19 11:06:28.000000000 +0900 @@ -291,7 +291,7 @@ data->progressbar.bm.data=data->img_buf_ptr; ret = read_bmp_file(imgname, &data->progressbar.bm, data->img_buf_free, - FORMAT_ANY|FORMAT_TRANSPARENT); + FORMAT_ANY|FORMAT_TRANSPARENT,0,0); if (ret > 0) { @@ -405,7 +405,7 @@ data->img[n].bm.data = data->img_buf_ptr; ret = read_bmp_file(imgname, &data->img[n].bm, data->img_buf_free, - FORMAT_ANY|FORMAT_TRANSPARENT); + FORMAT_ANY|FORMAT_TRANSPARENT,0,0); if (ret > 0) { @@ -2866,8 +2866,10 @@ if (gui_wps->data->wps_has_albumart && gwps->state->id3->albumart_found) { - if (strcasecmp(cur_displayed_albumart_path, - gwps->state->id3->albumart_path) != 0) + if ((strcasecmp(cur_displayed_albumart_path, + gwps->state->id3->albumart_path) != 0) || + (cur_displayed_albumart_width != gui_wps->data->albumart_max_width) || + (cur_displayed_albumart_height != gui_wps->data->albumart_max_height)) { /* load the cover art bitmap */ int rc; @@ -2875,7 +2877,8 @@ temp_bm.data = gui_wps->data->img_buf_ptr; rc = read_bmp_file(gwps->state->id3->albumart_path, &temp_bm, gui_wps->data->img_buf_free, - FORMAT_ANY|FORMAT_TRANSPARENT); + FORMAT_ANY|FORMAT_TRANSPARENT, + gui_wps->data->albumart_max_width, gui_wps->data->albumart_max_height); if (rc > 0) { //gwps->state->id3->albumart_size = cur_displayed_albumart_size = rc; diff -ru rockbox_orig/apps/plugins/rockpaint.c rockbox/apps/plugins/rockpaint.c --- rockbox_orig/apps/plugins/rockpaint.c 2006-07-22 04:17:27.265625000 +0900 +++ rockbox/apps/plugins/rockpaint.c 2006-07-22 04:20:15.671875000 +0900 @@ -2732,7 +2732,7 @@ bool ret; bm.data = (char*)save_buffer; ret = rb->read_bmp_file( file, &bm, ROWS*COLS*sizeof( fb_data ), - FORMAT_NATIVE ); + FORMAT_NATIVE, 0, 0 ); if( bm.width < COLS ) { int l; diff -ru rockbox_orig/apps/recorder/backdrop.c rockbox/apps/recorder/backdrop.c --- rockbox_orig/apps/recorder/backdrop.c 2006-05-21 13:00:02.000000000 +0900 +++ rockbox/apps/recorder/backdrop.c 2006-07-19 11:06:28.000000000 +0900 @@ -36,7 +36,7 @@ /* load the image */ bm.data=(char*)backdrop_buffer; - ret = read_bmp_file(filename, &bm, sizeof(main_backdrop), FORMAT_NATIVE); + ret = read_bmp_file(filename, &bm, sizeof(main_backdrop), FORMAT_NATIVE, 0, 0); if ((ret > 0) && (bm.width == LCD_WIDTH) && (bm.height == LCD_HEIGHT)) { diff -ru rockbox_orig/apps/recorder/bmp.c rockbox/apps/recorder/bmp.c --- rockbox_orig/apps/recorder/bmp.c 2006-04-24 17:52:04.000000000 +0900 +++ rockbox/apps/recorder/bmp.c 2006-07-22 09:46:00.015625000 +0900 @@ -94,6 +94,7 @@ return (bmpbuf[a] & (1 << b)) != 0; } + unsigned char bmpbuf[1024*sizeof(struct rgb_quad)]; /* Buffer for one line */ /****************************************************************************** * read_bmp_file() @@ -104,7 +105,9 @@ int read_bmp_file(char* filename, struct bitmap *bm, int maxsize, - int format) + int format, + int dst_x, + int dst_y) { struct Fileheader fh; int width, height, PaddedWidth, PaddedHeight, dst_width; @@ -115,8 +118,25 @@ int depth; int totalsize; char *bitmap = bm->data; - - unsigned char bmpbuf[LCD_WIDTH*sizeof(struct rgb_quad)]; /* Buffer for one line */ + int e_x; + int e_y; + int src_x; + int src_y; + int r_x; + int r_y; + int r_t; + int tr_x; + int tr_x1; + int tr_x2; + int tr_y; + int tr_y1; + int tr_y2; + int w_flag; + int c_y; + int l_y; + int p_buf[LCD_WIDTH][3] = { {0, 0, 0} }; + +// unsigned char bmpbuf[512*sizeof(struct rgb_quad)]; /* Buffer for one line */ #if LCD_DEPTH == 1 format = FORMAT_MONO; @@ -152,17 +172,17 @@ } /* Exit if too wide */ - if (readlong(&fh.Width) > LCD_WIDTH) { - DEBUGF("error - Bitmap is too wide (%d pixels, max is %d)\n", - readlong(&fh.Width), LCD_WIDTH); + if (dst_x > LCD_WIDTH) { + DEBUGF("error - X size is too wide (%d pixels, max is %d)\n", + dst_x, LCD_WIDTH); close(fd); return -5; } /* Exit if too high */ - if (readlong(&fh.Height) > LCD_HEIGHT) { - DEBUGF("error - Bitmap is too high (%d pixels, max is %d)\n", - readlong(&fh.Height), LCD_HEIGHT); + if (dst_y > LCD_HEIGHT) { + DEBUGF("error - Y size is too high (%d pixels, max is %d)\n", + dst_y, LCD_HEIGHT); close(fd); return -6; } @@ -172,35 +192,72 @@ width = readlong(&fh.Width); depth = readshort(&fh.BitCount); - /* 4-byte boundary aligned */ - PaddedWidth = ((width * depth + 31) / 8) & ~3; + /* Exit if too wide(bmp file) */ + if (width > 1024) { + DEBUGF("error - Bitmap is too wide (%d pixels, max is 1024)\n",width); + close(fd); + return -5; + } -#if LCD_DEPTH > 1 + if ((dst_x == 0) || (dst_y == 0)) { + dst_x = width; + dst_y = height; + } + + e_x = 0; + e_y = 0; + src_x = width; + src_y = height; + c_y = 0; + + r_x = 1024 * dst_x / src_x; + r_y = 1024 * dst_y / src_y; + r_t = (r_x 1 if(format == FORMAT_ANY) { if(depth == 1) format = FORMAT_MONO; else format = FORMAT_NATIVE; } -#endif +#endif*/ /* PaddedHeight is for rockbox format. */ if(format == FORMAT_MONO) { - PaddedHeight = (height + 7) / 8; - dst_width = width; + PaddedHeight = (dst_y + 7) / 8; + dst_width = dst_x; totalsize = PaddedHeight * dst_width; } else { #if LCD_DEPTH == 2 #if LCD_PIXELFORMAT == VERTICAL_PACKING - PaddedHeight = (height + 3) / 4; - dst_width = width; + PaddedHeight = (dst_y + 3) / 4; + dst_width = dst_x; #else - PaddedHeight = height; - dst_width = (width + 3) / 4; + PaddedHeight = dst_y; + dst_width = (dst_x + 3) / 4; #endif #else - PaddedHeight = height; - dst_width = width; + PaddedHeight = dst_y; + dst_width = dst_x; #endif totalsize = PaddedHeight * dst_width * sizeof(fb_data); } @@ -209,7 +266,7 @@ if (totalsize > maxsize) { DEBUGF("error - Bitmap is too large to fit the supplied buffer: " - "%d bytes.\n", (PaddedHeight * dst_width)); + "%d bytes.%d:%d\n", (PaddedHeight * dst_width),totalsize,maxsize); close(fd); return -7; } @@ -248,67 +305,188 @@ #endif /* loop to read rows and put them to buffer */ - for (row = 0; row < height; row++) { + e_y = 0; + c_y = 1; + w_flag = 1; + l_y = 1; + /* read one row */ + ret = read(fd, bmpbuf, PaddedWidth); /* src_y++ */ + if (ret != PaddedWidth) { + DEBUGF("error reading image, read returned: %d expected was: " + "%d\n", ret, PaddedWidth); + close(fd); + return -9; + } + for (row = 0; row < dst_y; row++ ) { unsigned char *p; - - /* read one row */ - ret = read(fd, bmpbuf, PaddedWidth); - if (ret != PaddedWidth) { - DEBUGF("error reading image, read returned: %d expected was: " - "%d\n", ret, PaddedWidth); - close(fd); - return -9; - } - switch(depth) { case 1: #if LCD_DEPTH > 1 if(format == FORMAT_MONO) { #endif /* Mono -> Mono */ - for (col = 0; col < width; col++) { - ret = getpix(col, bmpbuf) ^ invert_pixel; - if (ret) { - bitmap[width * ((height - row - 1) / 8) + col] - |= 1 << ((height - row - 1) % 8); + e_x = 0; + int p0, i, pt; + p0 = 0; + i = 1; + pt = 0; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + ret = getpix(pt, bmpbuf) ^ invert_pixel; + p_buf[col][0] += (ret + p0) / i; + if (w_flag == 1) { + ret = p_buf[col][0]/l_y; + if (ret) { + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + |= 1 << ((dst_y - row - 1) % 8); + } else { + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + &= ~ 1 << ((dst_y - row - 1) % 8); + } + p_buf[col][0] = 0; + } + e_x += width; + i = 1; + p0 = 0; + while ( e_x >= tr_x ) { + pt++; + ret = getpix(pt, bmpbuf) ^ invert_pixel; + i++; + p0 += ret; + e_x -= tr_x; + } } else { - bitmap[width * ((height - row - 1) / 8) + col] - &= ~ 1 << ((height - row - 1) % 8); + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + &= ~ 1 << ((dst_y - row - 1) % 8); } } + if (w_flag == 1) { + l_y = 1; + } #if LCD_DEPTH == 2 #if LCD_PIXELFORMAT == VERTICAL_PACKING } else { /* Mono -> 2gray (iriver H1xx) */ - for (col = 0; col < width; col++) { - ret = getpix(col, bmpbuf) ^ invert_pixel; - - if (ret) - dest[((height - row - 1)/4) * width + col] |= - 0xC0 >> (2 * (~(height - row - 1) & 3)); + e_x = 0; + int p0, i, pt; + p0 = 0; + i = 1; + pt = 0; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + ret = getpix(pt, bmpbuf) ^ invert_pixel; + p_buf[col][0] += (ret + p0) / i; + if (w_flag == 1) { + ret = p_buf[col][0]/l_y; + if (ret) { + dest[((dst_y - row - 1)/4) * dst_x + col] |= + 0xC0 >> (2 * (~(dst_y - row - 1) & 3)); + } + p_buf[col][0] = 0; + } + e_x += width; + i = 1; + p0 = 0; + while ( e_x >= tr_x ) { + pt++; + ret = getpix(pt, bmpbuf) ^ invert_pixel; + i++; + p0 += ret; + e_x -= tr_x; + } + } else { + dest[((dst_y - row - 1)/4) * dst_x + col] |= + 0x00 >> (2 * (~(dst_y - row - 1) & 3)); + } + } + if (w_flag == 1) { + l_y = 1; } } #else } else { /* Mono -> 2gray (ipod) */ - for (col = 0; col < width; col++) { - ret = getpix(col, bmpbuf) ^ invert_pixel; - - if (ret) - dest[(height - row - 1) * dst_width + col/4] |= - 0xC0 >> (2 * (col & 3)); + e_x = 0; + int p0, i, pt; + p0 = 0; + i = 1; + pt = 0; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + ret = getpix(pt, bmpbuf) ^ invert_pixel; + p_buf[col][0] += (ret + p0) / i; + if (w_flag == 1) { + ret = p_buf[col][0]/l_y; + if (ret) { + dest[(dst_y - row - 1) * dst_x + col/4] |= + 0xC0 >> (2 * (col & 3)); + } + p_buf[col][0] = 0; + } + e_x += width; + i = 1; + p0 = 0; + while ( e_x >= tr_x ) { + pt++; + ret = getpix(pt, bmpbuf) ^ invert_pixel; + i++; + p0 += ret; + e_x -= tr_x; + } + } else { + dest[(dst_y - row - 1) * dst_x + col/4] |= + 0x00 >> (2 * (col & 3)); + } + } + if (w_flag == 1) { + l_y = 1; } } #endif #elif LCD_DEPTH == 16 } else { /* Mono -> RGB16 */ - for (col = 0; col < width; col++) { - ret = getpix(col, bmpbuf); - unsigned short rgb16 = LCD_RGBPACK(palette[ret].red, - palette[ret].green, - palette[ret].blue); - dest[width * (height - row - 1) + col] = rgb16; + e_x = 0; + int p0, p1, p2, i, pt; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + pt = 0; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + ret = getpix(pt, bmpbuf); + p_buf[col][2] += (palette[ret].red+p2)/i; + p_buf[col][1] += (palette[ret].green+p1)/i; + p_buf[col][0] += (palette[ret].blue+p0)/i; + if (w_flag == 1) { + unsigned short rgb16 = LCD_RGBPACK((p_buf[col][2]/l_y),(p_buf[col][1]/l_y),(p_buf[col][0]/l_y)); + DEBUGF("%d,%d,%d\n",palette[ret].red,palette[ret].green,palette[ret].blue); + dest[dst_x * (dst_y - row - 1) + col] = rgb16; + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x += width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + pt++; + ret = getpix(pt, bmpbuf); + i++; + p2 += palette[ret].red; + p1 += palette[ret].green; + p0 += palette[ret].blue; + e_x -= tr_x; + } + } else { + dest[dst_x * (dst_y - row - 1) + col] = TRANSPARENT_COLOR; + } + } + if (w_flag == 1) { + l_y = 1; } } #endif @@ -321,53 +499,198 @@ if(format == FORMAT_MONO) { #endif /* 8-bit RGB24 palette -> mono */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb = palette[*p]; - ret = brightness(rgb); - if (ret > 96) { - bitmap[width * ((height - row - 1) / 8) + col] - &= ~ 1 << ((height - row - 1) % 8); + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + struct rgb_quad rgb = palette[*p]; + p_buf[col][2] += (rgb.red+p2)/i; + p_buf[col][1] += (rgb.green+p1)/i; + p_buf[col][0] += (rgb.blue+p0)/i; + if (w_flag == 1) { + rgb.red = p_buf[col][2] / l_y; + rgb.green = p_buf[col][1] / l_y; + rgb.blue = p_buf[col][0] / l_y; + ret = brightness(rgb); + if (ret > 96) { + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + &= ~ 1 << ((dst_y - row - 1) % 8); + } else { + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + |= 1 << ((dst_y - row - 1) % 8); + } + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x += width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p++; + struct rgb_quad rgb2 = palette[*p]; + i++; + p2 += rgb2.red; + p1 += rgb2.green; + p0 += rgb2.blue; + e_x -= tr_x; + } } else { - bitmap[width * ((height - row - 1) / 8) + col] - |= 1 << ((height - row - 1) % 8); + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + |= 1 << ((dst_y - row - 1) % 8); } - p++; + } + if (w_flag == 1) { + l_y = 1; } #if LCD_DEPTH == 2 #if LCD_PIXELFORMAT == VERTICAL_PACKING } else { /* 8-bit RGB24 palette -> 2gray (iriver H1xx) */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb = palette[*p]; - ret = brightness(rgb); - - dest[((height - row - 1)/4) * width + col] |= - (~ret & 0xC0) >> (2 * (~(height - row - 1) & 3)); - p++; + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + struct rgb_quad rgb = palette[*p]; + p_buf[col][2] += (rgb.red+p2)/i; + p_buf[col][1] += (rgb.green+p1)/i; + p_buf[col][0] += (rgb.blue+p0)/i; + if (w_flag == 1) { + rgb.red = p_buf[col][2] / l_y; + rgb.green = p_buf[col][1] / l_y; + rgb.blue = p_buf[col][0] / l_y; + ret = brightness(rgb); + dest[((dst_y - row - 1)/4) * dst_x + col] |= + (~ret & 0xC0) >> (2 * (~(dst_y - row - 1) & 3)); + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x += width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p++; + struct rgb_quad rgb2 = palette[*p]; + i++; + p2 += rgb2.red; + p1 += rgb2.green; + p0 += rgb2.blue; + e_x -= tr_x; + } + } else { + dest[((dst_y - row - 1)/4) * dst_x + col] |= + (0 & 0xC0) >> (2 * (~(dst_y - row - 1) & 3)); + } + } + if (w_flag == 1) { + l_y = 1; } } #else } else { /* 8-bit RGB24 palette -> 2gray (ipod) */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb = palette[*p]; - ret = brightness(rgb); - - dest[(height - row - 1) * dst_width + col/4] |= - (~ret & 0xC0) >> (2 * (col & 3)); - p++; + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + struct rgb_quad rgb = palette[*p]; + p_buf[col][2] += (rgb.red+p2)/i; + p_buf[col][1] += (rgb.green+p1)/i; + p_buf[col][0] += (rgb.blue+p0)/i; + if (w_flag == 1) { + rgb.red = p_buf[col][2] / l_y; + rgb.green = p_buf[col][1] / l_y; + rgb.blue = p_buf[col][0] / l_y; + ret = brightness(rgb); + dest[(dst_y - row - 1) * dst_x + col/4] |= + (~ret & 0xC0) >> (2 * (col & 3)); + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x += width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p++; + struct rgb_quad rgb2 = palette[*p]; + i++; + p2 += rgb2.red; + p1 += rgb2.green; + p0 += rgb2.blue; + e_x -= tr_x; + } + } else { + dest[(dst_y - row - 1) * dst_x + col/4] |= + (0 & 0xC0) >> (2 * (col & 3)); + } + } + if (w_flag == 1) { + l_y = 1; } } #endif #elif LCD_DEPTH == 16 } else { /* 8-bit RGB24 palette -> RGB16 */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb = palette[*p]; - unsigned short rgb16 = - LCD_RGBPACK(rgb.red, rgb.green, rgb.blue); - dest[width * (height - row - 1) + col] = rgb16; - p++; + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + struct rgb_quad rgb = palette[*p]; + p_buf[col][2] += (rgb.red+p2)/i; + p_buf[col][1] += (rgb.green+p1)/i; + p_buf[col][0] += (rgb.blue+p0)/i; + if (w_flag == 1) { + unsigned short rgb16 = LCD_RGBPACK((p_buf[col][2]/l_y),(p_buf[col][1]/l_y),(p_buf[col][0]/l_y)); + dest[dst_x * (dst_y - row - 1) + col] = rgb16; + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x += width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p++; + struct rgb_quad rgb2 = palette[*p]; + i++; + p2 += rgb2.red; + p1 += rgb2.green; + p0 += rgb2.blue; + e_x -= tr_x; + } + } else { + dest[dst_x * (dst_y - row - 1) + col] = TRANSPARENT_COLOR; + } + } + if (w_flag == 1) { + l_y = 1; } } #endif @@ -379,72 +702,223 @@ if(format == FORMAT_MONO) { #endif /* RGB24 -> mono */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb; - rgb.red = p[2]; - rgb.green = p[1]; - rgb.blue = p[0]; - ret = brightness(rgb); - if (ret > 96) { - bitmap[width * ((height - row - 1) / 8) + col] - &= ~ 1 << ((height - row - 1) % 8); + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2) ) { + struct rgb_quad rgb; + p_buf[col][0] += (p[0]+p0)/i; + p_buf[col][1] += (p[1]+p1)/i; + p_buf[col][2] += (p[2]+p2)/i; + if (w_flag == 1) { + rgb.red = p_buf[col][2]/l_y; + rgb.green = p_buf[col][1]/l_y; + rgb.blue = p_buf[col][0]/l_y; + ret = brightness(rgb); + if (ret > 96) { + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + &= ~ 1 << ((dst_y - row - 1) % 8); + } else { + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + |= 1 << ((dst_y - row - 1) % 8); + } + } + e_x = e_x + width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p += 3; /* src_x++ */ + i++; + p0 += p[0]; + p1 += p[1]; + p2 += p[2]; + e_x = e_x - tr_x; + } } else { - bitmap[width * ((height - row - 1) / 8) + col] - |= 1 << ((height - row - 1) % 8); + bitmap[dst_x * ((dst_y - row - 1) / 8) + col] + |= 1 << ((dst_y - row - 1) % 8); } - p += 3; + } + if (w_flag == 1) { + l_y = 1; } #if LCD_DEPTH == 2 #if LCD_PIXELFORMAT == VERTICAL_PACKING } else { /* RGB24 -> 2gray (iriver H1xx) */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb; - rgb.red = p[2]; - rgb.green = p[1]; - rgb.blue = p[0]; - ret = brightness(rgb); - - dest[((height - row - 1)/4) * width + col] |= - (~ret & 0xC0) >> (2 * (~(height - row - 1) & 3)); - p += 3; + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2) ) { + struct rgb_quad rgb; + p_buf[col][0] += (p[0]+p0)/i; + p_buf[col][1] += (p[1]+p1)/i; + p_buf[col][2] += (p[2]+p2)/i; + if (w_flag == 1) { + rgb.red = p_buf[col][2]/l_y; + rgb.green = p_buf[col][1]/l_y; + rgb.blue = p_buf[col][0]/l_y; + ret = brightness(rgb); + dest[((dst_y - row - 1)/4) * dst_x + col] |= + (~ret & 0xC0) >> (2 * (~(dst_y - row - 1) & 3)); + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x = e_x + width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p += 3; /* src_x++ */ + i++; + p0 += p[0]; + p1 += p[1]; + p2 += p[2]; + e_x -= tr_x; + } + } else { + dest[((dst_y - row - 1)/4) * dst_x + col] |= + (0 & 0xC0) >> (2 * (~(dst_y - row - 1) & 3)); + } + } + if (w_flag == 1) { + l_y = 1; } } #else } else { /* RGB24 -> 2gray (ipod) */ - for (col = 0; col < width; col++) { - struct rgb_quad rgb; - rgb.red = p[2]; - rgb.green = p[1]; - rgb.blue = p[0]; - ret = brightness(rgb); - - dest[(height - row - 1) * dst_width + col/4] |= - (~ret & 0xC0) >> (2 * (col & 3)); - p += 3; + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2) ) { + struct rgb_quad rgb; + p_buf[col][0] += (p[0]+p0)/i; + p_buf[col][1] += (p[1]+p1)/i; + p_buf[col][2] += (p[2]+p2)/i; + if (w_flag == 1) { + rgb.red = p_buf[col][2]/l_y; + rgb.green = p_buf[col][1]/l_y; + rgb.blue = p_buf[col][0]/l_y; + ret = brightness(rgb); + dest[(dst_y - row - 1) * dst_x + col/4] |= + (~ret & 0xC0) >> (2 * (col & 3)); + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x = e_x + width; + while ( e_x >= tr_x ) { + p += 3; /* src_x++ */ + i++; + p0 += p[0]; + p1 += p[1]; + p2 += p[2]; + e_x -=tr_x; + } + } else { + dest[(dst_y - row - 1) * dst_x + col/4] = + (0 & 0xC0) >> (2 * (col & 3)); + } + } + if (w_flag == 1) { + l_y = 1; } } #endif #elif LCD_DEPTH == 16 } else { /* RGB24 -> RGB16 */ - for (col = 0; col < width; col++) { - unsigned short rgb = LCD_RGBPACK(p[2],p[1],p[0]); - dest[width * (height - row - 1) + col] = rgb; - p += 3; + e_x = 0; + int p0, p1, p2, i; + p0 = 0; + p1 = 0; + p2 = 0; + i = 1; + for (col = 0; col < dst_x; col++) { + if ((tr_x1 <= col) && (col <= tr_x2) && (tr_y1 <= row) && (row <= tr_y2)) { + p_buf[col][0] += (p[0]+p0)/i; + p_buf[col][1] += (p[1]+p1)/i; + p_buf[col][2] += (p[2]+p2)/i; + if (w_flag == 1) { + unsigned short rgb = LCD_RGBPACK((p_buf[col][2]/l_y),(p_buf[col][1]/l_y),(p_buf[col][0]/l_y)); + dest[dst_x * (dst_y - row - 1) + col] = rgb; + p_buf[col][0] = 0; + p_buf[col][1] = 0; + p_buf[col][2] = 0; + } + e_x += width; + i = 1; + p0 = 0; + p1 = 0; + p2 = 0; + while ( e_x >= tr_x ) { + p += 3; /* src_x++ */ + i++; + p0 += p[0]; + p1 += p[1]; + p2 += p[2]; + e_x -= tr_x; + } + } else { + dest[dst_x * (dst_y - row - 1) + col] = TRANSPARENT_COLOR; + } + } + if (w_flag == 1) { + l_y = 1; } } #endif break; } + if ((tr_y1 <= row) && (row <= tr_y2)) { + if (w_flag == 1) e_y += height; + if (e_y >= tr_y) { + c_y++; + if (c_y <= height) { + ret = read(fd, bmpbuf, PaddedWidth); /* src_y++ */ + if (ret != PaddedWidth) { + DEBUGF("error reading image, read returned: %d expected was: " + "%d\n", ret, PaddedWidth); + close(fd); + return -9; + } + } + e_y -= tr_y; + if (e_y >= tr_y) { + row--; + l_y++; + w_flag = 0; + } else { + w_flag = 1; + } + } else { + w_flag = 1; + } + } } close(fd); /* returning image size: */ - bm->width = width; - bm->height = height; + bm->width = dst_x; + bm->height = dst_y; #if LCD_DEPTH > 1 bm->format = format; #endif diff -ru rockbox_orig/apps/recorder/bmp.h rockbox/apps/recorder/bmp.h --- rockbox_orig/apps/recorder/bmp.h 2006-01-28 13:12:42.000000000 +0900 +++ rockbox/apps/recorder/bmp.h 2006-07-19 11:06:28.000000000 +0900 @@ -32,5 +32,7 @@ int read_bmp_file(char* filename, struct bitmap *bm, int maxsize, - int format); + int format, + int dst_x, // if x_size=0 or y_size=0, load original size + int dst_y); // #endif