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 
     27 namespace android {
     28 
     29 /* Encapsulates a converter between YV12, and JPEG formats.
     30  */
     31 class NV21JpegCompressor : protected Yuv420SpToJpegEncoder
     32 {
     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      *  width, height - Image dimensions.
     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,
     57                               int width,
     58                               int height,
     59                               int quality);
     60 
     61     /* Get size of the compressed JPEG buffer.
     62      * This method must be called only after a successful completion of
     63      * compressRawImage call.
     64      * Return:
     65      *  Size of the compressed JPEG buffer.
     66      */
     67     size_t getCompressedSize() const
     68     {
     69         return mStream.getOffset();
     70     }
     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) const
     80     {
     81         mStream.copyTo(buff);
     82     }
     83 
     84     /****************************************************************************
     85      * Class data
     86      ***************************************************************************/
     87 
     88 protected:
     89     /* Memory stream where converted JPEG is saved. */
     90     SkDynamicMemoryWStream  mStream;
     91     /* Strides for Y (the first element), and UV (the second one) panes. */
     92     int                     mStrides[2];
     93 };
     94 
     95 }; /* namespace android */
     96 
     97 #endif  /* HW_EMULATOR_CAMERA_JPEG_COMPRESSOR_H */
     98