2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Contains implementation of a class NV21JpegCompressor that encapsulates a
19 * converter between NV21, and JPEG formats.
23 #define LOG_TAG "EmulatedCamera_JPEG"
24 #include <cutils/log.h>
27 #include "JpegCompressor.h"
31 void* NV21JpegCompressor::mDl = NULL;
33 static void* getSymbol(void* dl, const char* signature) {
34 void* res = dlsym(dl, signature);
40 typedef void (*InitFunc)(JpegStub* stub, int* strides);
41 typedef void (*CleanupFunc)(JpegStub* stub);
42 typedef int (*CompressFunc)(JpegStub* stub, const void* image,
43 int width, int height, int quality);
44 typedef void (*GetCompressedImageFunc)(JpegStub* stub, void* buff);
45 typedef size_t (*GetCompressedSizeFunc)(JpegStub* stub);
47 NV21JpegCompressor::NV21JpegCompressor()
49 const char dlName[] = "/system/lib/hw/camera.goldfish.jpeg.so";
51 mDl = dlopen(dlName, RTLD_NOW);
55 InitFunc f = (InitFunc)getSymbol(mDl, "JpegStub_init");
56 (*f)(&mStub, mStrides);
59 NV21JpegCompressor::~NV21JpegCompressor()
61 CleanupFunc f = (CleanupFunc)getSymbol(mDl, "JpegStub_cleanup");
65 /****************************************************************************
67 ***************************************************************************/
69 status_t NV21JpegCompressor::compressRawImage(const void* image,
76 CompressFunc f = (CompressFunc)getSymbol(mDl, "JpegStub_compress");
77 return (status_t)(*f)(&mStub, image, width, height, quality);
81 size_t NV21JpegCompressor::getCompressedSize()
83 GetCompressedSizeFunc f = (GetCompressedSizeFunc)getSymbol(mDl,
84 "JpegStub_getCompressedSize");
88 void NV21JpegCompressor::getCompressedImage(void* buff)
90 GetCompressedImageFunc f = (GetCompressedImageFunc)getSymbol(mDl,
91 "JpegStub_getCompressedImage");
95 }; /* namespace android */