• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
18  * Contains implementation of a class NV21JpegCompressor that encapsulates a
19  * converter between NV21, and JPEG formats.
20  */
21 
22 #define LOG_NDEBUG 0
23 #define LOG_TAG "EmulatedCamera_JPEG"
24 #include <cutils/log.h>
25 #include "JpegCompressor.h"
26 
27 namespace android {
28 
NV21JpegCompressor()29 NV21JpegCompressor::NV21JpegCompressor()
30     : Yuv420SpToJpegEncoder(mStrides)
31 {
32 }
33 
~NV21JpegCompressor()34 NV21JpegCompressor::~NV21JpegCompressor()
35 {
36 }
37 
38 /****************************************************************************
39  * Public API
40  ***************************************************************************/
41 
compressRawImage(const void * image,int width,int height,int quality)42 status_t NV21JpegCompressor::compressRawImage(const void* image,
43                                               int width,
44                                               int height,
45                                               int quality)
46 {
47     ALOGV("%s: %p[%dx%d]", __FUNCTION__, image, width, height);
48     void* pY = const_cast<void*>(image);
49     int offsets[2];
50     offsets[0] = 0;
51     offsets[1] = width * height;
52     mStrides[0] = width;
53     mStrides[1] = width;
54     if (encode(&mStream, pY, width, height, offsets, quality)) {
55         ALOGV("%s: Compressed JPEG: %d[%dx%d] -> %d bytes",
56              __FUNCTION__, (width * height * 12) / 8, width, height, mStream.getOffset());
57         return NO_ERROR;
58     } else {
59         ALOGE("%s: JPEG compression failed", __FUNCTION__);
60         return errno ? errno : EINVAL;
61     }
62 }
63 
64 }; /* namespace android */
65