diff options
Diffstat (limited to 'android/utils')
-rw-r--r-- | android/utils/jpeg-compress.c | 20 | ||||
-rw-r--r-- | android/utils/jpeg-compress.h | 8 |
2 files changed, 22 insertions, 6 deletions
diff --git a/android/utils/jpeg-compress.c b/android/utils/jpeg-compress.c index 2b42a00..cd45bf5 100644 --- a/android/utils/jpeg-compress.c +++ b/android/utils/jpeg-compress.c @@ -151,12 +151,14 @@ jpeg_compressor_get_header_size(const AJPEGDesc* dsc) void jpeg_compressor_compress_fb(AJPEGDesc* dsc, - int x, int y, int w, int h, + int x, int y, int w, int h, int num_lines, int bpp, int bpl, const uint8_t* fb, - int jpeg_quality){ + int jpeg_quality, + int ydir){ struct jpeg_compress_struct cinfo = {0}; struct jpeg_error_mgr err_mgr; + const int x_shift = x * bpp; /* * Initialize compressin information structure, and start compression @@ -186,9 +188,17 @@ jpeg_compressor_compress_fb(AJPEGDesc* dsc, jpeg_start_compress(&cinfo, TRUE); /* Line by line compress the region. */ - while (cinfo.next_scanline < cinfo.image_height) { - JSAMPROW rgb = (JSAMPROW)(fb + (cinfo.next_scanline + y) * bpl + x * bpp); - jpeg_write_scanlines(&cinfo, (JSAMPARRAY)&rgb, 1); + if (ydir >= 0) { + while (cinfo.next_scanline < cinfo.image_height) { + JSAMPROW rgb = (JSAMPROW)(fb + (cinfo.next_scanline + y) * bpl + x_shift); + jpeg_write_scanlines(&cinfo, (JSAMPARRAY)&rgb, 1); + } + } else { + const int y_shift = num_lines - y - 1; + while (cinfo.next_scanline < cinfo.image_height) { + JSAMPROW rgb = (JSAMPROW)(fb + (y_shift - cinfo.next_scanline) * bpl + x_shift); + jpeg_write_scanlines(&cinfo, (JSAMPARRAY)&rgb, 1); + } } /* Complete the compression. */ diff --git a/android/utils/jpeg-compress.h b/android/utils/jpeg-compress.h index 4e0e61a..1f84a5d 100644 --- a/android/utils/jpeg-compress.h +++ b/android/utils/jpeg-compress.h @@ -77,17 +77,23 @@ extern int jpeg_compressor_get_header_size(const AJPEGDesc* dsc); * Param: * dsc - Compression descriptor, obtained with jpeg_compressor_create. * x, y, w, h - Coordinates and sizes of framebuffer region to compress. + * num_lines - Number of lines in the framebuffer (true height). * bpp - Number of bytes per pixel in the framebuffer. * bpl - Number of bytes per line in the framebuffer. * fb - Beginning of the framebuffer. * jpeg_quality JPEG compression quality. A number from 1 to 100. Note that * value 10 provides pretty decent image for the purpose of multi-touch * emulation. + * ydir - Indicates direction in which lines are arranged in the framebuffer. If + * this value is negative, lines are arranged in bottom-up format (i.e. the + * bottom line is at the beginning of the buffer). */ extern void jpeg_compressor_compress_fb(AJPEGDesc* dsc, int x, int y, int w, int h, + int num_lines, int bpp, int bpl, const uint8_t* fb, - int jpeg_quality); + int jpeg_quality, + int ydir); #endif /* _ANDROID_UTILS_JPEG_COMPRESS_H */ |