From 1a820e90d8848c6b0ac7c78b5a2e8b28c9738a3a Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Wed, 11 Apr 2012 13:22:48 -0700 Subject: Enable multi-touch emulation with -gpu on This CL implements a callback that gets invoked by OpenGLES emulator on it framebuffer updates. This allows transferring framebuffer changes to the supporting device. Proper implementation of this new callback also required changes to JPEG compression, addressing: 1. OpenGLES framebuffer format is RGBA8889, which required implementing line conversion for this format. 2. OpenGLES framebuffer is (or at least could be) bottom-up arranged. This requires changes to the compressor, so it compresses the FB starting from the bottom, so the resulting image is up-bottom. Change-Id: Icd4efbe4a251c838adfa3518decbfc43a7ef06c8 --- android/utils/jpeg-compress.c | 20 +++++++++++++++----- android/utils/jpeg-compress.h | 8 +++++++- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'android/utils') 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 */ -- cgit v1.1