1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef HW_EMULATOR_CAMERA_JPEG_COMPRESSOR_H 18 #define HW_EMULATOR_CAMERA_JPEG_COMPRESSOR_H 19 20 /* 21 * Contains declaration of a class NV21JpegCompressor that encapsulates a 22 * converter between YV21, and JPEG formats. 23 */ 24 25 #include "jpeg-stub/JpegStub.h" 26 #include <utils/threads.h> 27 28 namespace android { 29 30 /* Encapsulates a converter between YV12, and JPEG formats. 31 */ 32 class NV21JpegCompressor 33 { 34 public: 35 /* Constructs JpegCompressor instance. */ 36 NV21JpegCompressor(); 37 /* Destructs JpegCompressor instance. */ 38 ~NV21JpegCompressor(); 39 40 /**************************************************************************** 41 * Public API 42 ***************************************************************************/ 43 44 public: 45 /* Compresses raw NV21 image into a JPEG. 46 * The compressed image will be saved in mStream member of this class. Use 47 * getCompressedSize method to obtain buffer size of the compressed image, 48 * and getCompressedImage to copy out the compressed image. 49 * Param: 50 * image - Raw NV21 image. 51 * width, height - Image dimensions. 52 * quality - JPEG quality. 53 * exifData - an EXIF data structure to attach to the image, may be null 54 * Return: 55 * NO_ERROR on success, or an appropriate error status. 56 * 57 */ 58 status_t compressRawImage(const void* image, 59 int width, 60 int height, 61 int quality, 62 ExifData* exifData); 63 64 /* Get size of the compressed JPEG buffer. 65 * This method must be called only after a successful completion of 66 * compressRawImage call. 67 * Return: 68 * Size of the compressed JPEG buffer. 69 */ 70 size_t getCompressedSize(); 71 72 /* Copies out compressed JPEG buffer. 73 * This method must be called only after a successful completion of 74 * compressRawImage call. 75 * Param: 76 * buff - Buffer where to copy the JPEG. Must be large enough to contain the 77 * entire image. 78 */ 79 void getCompressedImage(void* buff); 80 81 /**************************************************************************** 82 * Class data 83 ***************************************************************************/ 84 85 private: 86 // library handle to dlopen 87 static void* mDl; 88 JpegStub mStub; 89 }; 90 91 }; /* namespace android */ 92 93 #endif /* HW_EMULATOR_CAMERA_JPEG_COMPRESSOR_H */ 94