1 /* Copyright (C) 2011 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 #ifndef _ANDROID_UTILS_JPEG_COMPRESS_H 13 #define _ANDROID_UTILS_JPEG_COMPRESS_H 14 15 /* 16 * Contains declaration of utility routines that compress an RGB bitmap into 17 * a JPEG image. 18 * 19 * NOTE: This code uses a jpeglib library located in distrib/jpeg-6b. It's a 20 * 3-rd party library that uses its own type definitions that are different from 21 * the ones that are use elsewhere in the emulator code. For instance, in the 22 * emulator built for Windows, sizeof(bool) = 1, while in the jpeglib sizeof(bool) = 4. 23 * So, to simplify dealing with these issues, all the code that uses jpeglib should 24 * be compiled separately, and should include only headers that are used to compile 25 * jpeglib. 26 */ 27 28 29 /* Declares descriptor for a JPEG compression. */ 30 typedef struct AJPEGDesc AJPEGDesc; 31 32 /* Creates a descriptor that will be used for compression. 33 * Param: 34 * header_size - Number of bytes to allocate for a custom header that should 35 * preceed the actual JPEG buffer. This is useful when sending JPEG 36 * somewhere else along with some extra data about the compressed image. 37 * cunk_size - Number of bytes to increment the compressed buffer with each time 38 * compressor requests more memory. 39 * Return: 40 * Initialized compression descriptor. 41 */ 42 extern AJPEGDesc* jpeg_compressor_create(int header_size, int chunk_size); 43 44 /* Destroys compressor descriptor. 45 * Param: 46 * dsc - Compressin descriptor, obtained with jpeg_compressor_create. 47 */ 48 extern void jpeg_compressor_destroy(AJPEGDesc* dsc); 49 50 /* Returns compressed data size. 51 * Param: 52 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 53 * Return: 54 * Compressed data size. 55 */ 56 extern int jpeg_compressor_get_jpeg_size(const AJPEGDesc* dsc); 57 58 /* Returns compressed buffer. 59 * Param: 60 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 61 * Return: 62 * Compressed buffer. NOTE: if 'header_size' parameter passed to the jpeg_compressor_create 63 * for this descriptor was not zero, this routine returns a pointer to the custom 64 * header. Compressed data follows immediately after that header. 65 */ 66 extern void* jpeg_compressor_get_buffer(const AJPEGDesc* dsc); 67 68 /* Returns size of the custom header placed before the compressed data. 69 * Param: 70 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 71 * Return: 72 * Size of the custom header placed before the compressed data. 73 */ 74 extern int jpeg_compressor_get_header_size(const AJPEGDesc* dsc); 75 76 /* Compresses a framebuffer region into JPEG image. 77 * Param: 78 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 79 * x, y, w, h - Coordinates and sizes of framebuffer region to compress. 80 * num_lines - Number of lines in the framebuffer (true height). 81 * bpp - Number of bytes per pixel in the framebuffer. 82 * bpl - Number of bytes per line in the framebuffer. 83 * fb - Beginning of the framebuffer. 84 * jpeg_quality JPEG compression quality. A number from 1 to 100. Note that 85 * value 10 provides pretty decent image for the purpose of multi-touch 86 * emulation. 87 * ydir - Indicates direction in which lines are arranged in the framebuffer. If 88 * this value is negative, lines are arranged in bottom-up format (i.e. the 89 * bottom line is at the beginning of the buffer). 90 */ 91 extern void jpeg_compressor_compress_fb(AJPEGDesc* dsc, 92 int x, int y, int w, int h, 93 int num_lines, 94 int bpp, int bpl, 95 const uint8_t* fb, 96 int jpeg_quality, 97 int ydir); 98 99 #endif /* _ANDROID_UTILS_JPEG_COMPRESS_H */ 100