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 #include "android/utils/compiler.h" 16 17 ANDROID_BEGIN_HEADER 18 19 /* 20 * Contains declaration of utility routines that compress an RGB bitmap into 21 * a JPEG image. 22 * 23 * NOTE: This code uses a jpeglib library located in distrib/jpeg-6b. It's a 24 * 3-rd party library that uses its own type definitions that are different from 25 * the ones that are use elsewhere in the emulator code. For instance, in the 26 * emulator built for Windows, sizeof(bool) = 1, while in the jpeglib sizeof(bool) = 4. 27 * So, to simplify dealing with these issues, all the code that uses jpeglib should 28 * be compiled separately, and should include only headers that are used to compile 29 * jpeglib. 30 */ 31 32 33 /* Declares descriptor for a JPEG compression. */ 34 typedef struct AJPEGDesc AJPEGDesc; 35 36 /* Creates a descriptor that will be used for compression. 37 * Param: 38 * header_size - Number of bytes to allocate for a custom header that should 39 * preceed the actual JPEG buffer. This is useful when sending JPEG 40 * somewhere else along with some extra data about the compressed image. 41 * cunk_size - Number of bytes to increment the compressed buffer with each time 42 * compressor requests more memory. 43 * Return: 44 * Initialized compression descriptor. 45 */ 46 extern AJPEGDesc* jpeg_compressor_create(int header_size, int chunk_size); 47 48 /* Destroys compressor descriptor. 49 * Param: 50 * dsc - Compressin descriptor, obtained with jpeg_compressor_create. 51 */ 52 extern void jpeg_compressor_destroy(AJPEGDesc* dsc); 53 54 /* Returns compressed data size. 55 * Param: 56 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 57 * Return: 58 * Compressed data size. 59 */ 60 extern int jpeg_compressor_get_jpeg_size(const AJPEGDesc* dsc); 61 62 /* Returns compressed buffer. 63 * Param: 64 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 65 * Return: 66 * Compressed buffer. NOTE: if 'header_size' parameter passed to the jpeg_compressor_create 67 * for this descriptor was not zero, this routine returns a pointer to the custom 68 * header. Compressed data follows immediately after that header. 69 */ 70 extern void* jpeg_compressor_get_buffer(const AJPEGDesc* dsc); 71 72 /* Returns size of the custom header placed before the compressed data. 73 * Param: 74 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 75 * Return: 76 * Size of the custom header placed before the compressed data. 77 */ 78 extern int jpeg_compressor_get_header_size(const AJPEGDesc* dsc); 79 80 /* Compresses a framebuffer region into JPEG image. 81 * Param: 82 * dsc - Compression descriptor, obtained with jpeg_compressor_create. 83 * x, y, w, h - Coordinates and sizes of framebuffer region to compress. 84 * num_lines - Number of lines in the framebuffer (true height). 85 * bpp - Number of bytes per pixel in the framebuffer. 86 * bpl - Number of bytes per line in the framebuffer. 87 * fb - Beginning of the framebuffer. 88 * jpeg_quality JPEG compression quality. A number from 1 to 100. Note that 89 * value 10 provides pretty decent image for the purpose of multi-touch 90 * emulation. 91 * ydir - Indicates direction in which lines are arranged in the framebuffer. If 92 * this value is negative, lines are arranged in bottom-up format (i.e. the 93 * bottom line is at the beginning of the buffer). 94 */ 95 extern void jpeg_compressor_compress_fb(AJPEGDesc* dsc, 96 int x, int y, int w, int h, 97 int num_lines, 98 int bpp, int bpl, 99 const uint8_t* fb, 100 int jpeg_quality, 101 int ydir); 102 103 ANDROID_END_HEADER 104 105 #endif /* _ANDROID_UTILS_JPEG_COMPRESS_H */ 106