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 <YuvToJpegEncoder.h>
     26 #include <utils/threads.h>
     27 
     28 namespace android {
     29 
     30 /* Encapsulates a converter between YV12, and JPEG formats.
     31  */
     32 class NV21JpegCompressor : protected Yuv420SpToJpegEncoder
     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      * Return:
     54      *  NO_ERROR on success, or an appropriate error status.
     55      *
     56      */
     57     status_t compressRawImage(const void* image,
     58                               int width,
     59                               int height,
     60                               int quality);
     61 
     62     /* Get size of the compressed JPEG buffer.
     63      * This method must be called only after a successful completion of
     64      * compressRawImage call.
     65      * Return:
     66      *  Size of the compressed JPEG buffer.
     67      */
     68     size_t getCompressedSize() const
     69     {
     70         return mStream.getOffset();
     71     }
     72 
     73     /* Copies out compressed JPEG buffer.
     74      * This method must be called only after a successful completion of
     75      * compressRawImage call.
     76      * Param:
     77      *  buff - Buffer where to copy the JPEG. Must be large enough to contain the
     78      *      entire image.
     79      */
     80     void getCompressedImage(void* buff) const
     81     {
     82         mStream.copyTo(buff);
     83     }
     84 
     85     /****************************************************************************
     86      * Class data
     87      ***************************************************************************/
     88 
     89 protected:
     90     /* Memory stream where converted JPEG is saved. */
     91     SkDynamicMemoryWStream  mStream;
     92     /* Strides for Y (the first element), and UV (the second one) panes. */
     93     int                     mStrides[2];
     94 };
     95 
     96 }; /* namespace android */
     97 
     98 #endif  /* HW_EMULATOR_CAMERA_JPEG_COMPRESSOR_H */
     99