Home | History | Annotate | Download | only in camera
      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 <utils/threads.h>
     26 #include "JpegStub.h"
     27 
     28 namespace android {
     29 
     30 /* Encapsulates a converter between YV12, and JPEG formats.
     31  */
     32 class NV21JpegCompressor {
     33  public:
     34   /* Constructs JpegCompressor instance. */
     35   NV21JpegCompressor();
     36   /* Destructs JpegCompressor instance. */
     37   ~NV21JpegCompressor();
     38 
     39   /****************************************************************************
     40    * Public API
     41    ***************************************************************************/
     42 
     43  public:
     44   /* Compresses raw NV21 image into a JPEG.
     45    * The compressed image will be saved in mStream member of this class. Use
     46    * getCompressedSize method to obtain buffer size of the compressed image,
     47    * and getCompressedImage to copy out the compressed image.
     48    * Param:
     49    *  image - Raw NV21 image.
     50    *  metadata - Image metadata (dimensions, location etc).
     51    *  quality - JPEG quality.
     52    * Return:
     53    *  NO_ERROR on success, or an appropriate error status.
     54    *
     55    */
     56   status_t compressRawImage(const void* image, ExifData* exifData,
     57                             int quality, int width, int height);
     58 
     59   /* Get size of the compressed JPEG buffer.
     60    * This method must be called only after a successful completion of
     61    * compressRawImage call.
     62    * Return:
     63    *  Size of the compressed JPEG buffer.
     64    */
     65   size_t getCompressedSize();
     66 
     67   /* Copies out compressed JPEG buffer.
     68    * This method must be called only after a successful completion of
     69    * compressRawImage call.
     70    * Param:
     71    *  buff - Buffer where to copy the JPEG. Must be large enough to contain the
     72    *      entire image.
     73    */
     74   void getCompressedImage(void* buff);
     75 
     76   /****************************************************************************
     77    * Class data
     78    ***************************************************************************/
     79 
     80  protected:
     81   /* Strides for Y (the first element), and UV (the second one) panes. */
     82   int mStrides[2];
     83 
     84  private:
     85   // library handle to dlopen
     86   static void* mDl;
     87   JpegStub mStub;
     88 };
     89 
     90 }; /* namespace android */
     91 
     92 #endif /* HW_EMULATOR_CAMERA_JPEG_COMPRESSOR_H */
     93