diff options
author | David Huang <d-huang@ti.com> | 2016-11-04 08:21:42 -0600 |
---|---|---|
committer | David Huang <d-huang@ti.com> | 2016-11-10 17:01:09 -0600 |
commit | 30b8502c95531fc7269882007945c1a779ae90d4 (patch) | |
tree | 6eb8ae632d9107486b73307b66165c91868e53c3 | |
parent | cdbdcd92b5df839e8cdb4b893ac3541bbc0cd897 (diff) | |
download | dra7xx-30b8502c95531fc7269882007945c1a779ae90d4.tar.gz |
dra7xx: camera: Cleanup remove libjpeg
Remove libjpeg and references. Unused and also
causing some of the build issues in N.
Change-Id: Id5e6cac048aae062c68989208032fbd4a4ef4874
Signed-off-by: David Huang <d-huang@ti.com>
-rw-r--r-- | camera/Android.mk | 2 | ||||
-rw-r--r-- | camera/AppCallbackNotifier.cpp | 306 | ||||
-rw-r--r-- | camera/Decoder_libjpeg.cpp | 301 | ||||
-rw-r--r-- | camera/Encoder_libjpeg.cpp | 549 | ||||
-rw-r--r-- | camera/inc/Decoder_libjpeg.h | 58 | ||||
-rw-r--r-- | camera/inc/Encoder_libjpeg.h | 226 | ||||
-rw-r--r-- | camera/inc/V4LCameraAdapter/V4LCameraAdapter.h | 1 |
7 files changed, 0 insertions, 1443 deletions
diff --git a/camera/Android.mk b/camera/Android.mk index ad454dc..86a220d 100644 --- a/camera/Android.mk +++ b/camera/Android.mk @@ -66,8 +66,6 @@ TI_CAMERAHAL_COMMON_SRC := \ CameraProperties.cpp \ BaseCameraAdapter.cpp \ DrmMemoryManager.cpp \ - Encoder_libjpeg.cpp \ - Decoder_libjpeg.cpp \ NV12_resize.cpp \ CameraParameters.cpp \ TICameraParameters.cpp \ diff --git a/camera/AppCallbackNotifier.cpp b/camera/AppCallbackNotifier.cpp index 8bc10b1..376e8e4 100644 --- a/camera/AppCallbackNotifier.cpp +++ b/camera/AppCallbackNotifier.cpp @@ -16,7 +16,6 @@ #include "CameraHal.h" #include "VideoMetadata.h" -#include "Encoder_libjpeg.h" #include <MetadataBufferType.h> #include <ui/GraphicBuffer.h> #include <ui/GraphicBufferMapper.h> @@ -27,143 +26,9 @@ namespace Ti { namespace Camera { const int AppCallbackNotifier::NOTIFIER_TIMEOUT = -1; -android::KeyedVector<void*, android::sp<Encoder_libjpeg> > gEncoderQueue; - -void AppCallbackNotifierEncoderCallback(void* main_jpeg, - void* thumb_jpeg, - CameraFrame::FrameType type, - void* cookie1, - void* cookie2, - void* cookie3, - void* cookie4, - bool canceled) -{ - if (cookie1 && !canceled) { - AppCallbackNotifier* cb = (AppCallbackNotifier*) cookie1; - cb->EncoderDoneCb(main_jpeg, thumb_jpeg, type, cookie2, cookie3, cookie4); - } - - if (main_jpeg) { - free(main_jpeg); - } - - if (thumb_jpeg) { - if (((Encoder_libjpeg::params *) thumb_jpeg)->dst) { - free(((Encoder_libjpeg::params *) thumb_jpeg)->dst); - } - free(thumb_jpeg); - } -} /*--------------------NotificationHandler Class STARTS here-----------------------------*/ -void AppCallbackNotifier::EncoderDoneCb(void* main_jpeg, void* thumb_jpeg, CameraFrame::FrameType type, void* cookie1, void* cookie2, void *cookie3) -{ - camera_memory_t* encoded_mem = NULL; - Encoder_libjpeg::params *main_param = NULL, *thumb_param = NULL; - size_t jpeg_size; - uint8_t* src = NULL; - CameraBuffer *camera_buffer; - android::sp<Encoder_libjpeg> encoder = NULL; - - LOG_FUNCTION_NAME; - - camera_memory_t* picture = NULL; - - { - android::AutoMutex lock(mLock); - - if (!main_jpeg) { - goto exit; - } - - encoded_mem = (camera_memory_t*) cookie1; - main_param = (Encoder_libjpeg::params *) main_jpeg; - jpeg_size = main_param->jpeg_size; - camera_buffer = (CameraBuffer *)cookie3; - src = main_param->src; - - if(encoded_mem && encoded_mem->data && (jpeg_size > 0)) { - if (cookie2) { - ExifElementsTable* exif = (ExifElementsTable*) cookie2; - Section_t* exif_section = NULL; - - exif->insertExifToJpeg((unsigned char*) encoded_mem->data, jpeg_size); - - if(thumb_jpeg) { - thumb_param = (Encoder_libjpeg::params *) thumb_jpeg; - exif->insertExifThumbnailImage((const char*)thumb_param->dst, - (int)thumb_param->jpeg_size); - } - - exif_section = FindSection(M_EXIF); - - if (exif_section) { - picture = mRequestMemory(-1, jpeg_size + exif_section->Size, 1, NULL); - if (picture && picture->data) { - exif->saveJpeg((unsigned char*) picture->data, jpeg_size + exif_section->Size); - } - } - delete exif; - cookie2 = NULL; - } else { - picture = mRequestMemory(-1, jpeg_size, 1, NULL); - if (picture && picture->data) { - memcpy(picture->data, encoded_mem->data, jpeg_size); - } - } - } - } // scope for mutex lock - - if (!mRawAvailable) { - dummyRaw(); - } else { - mRawAvailable = false; - } - - // Send the callback to the application only if the notifier is started and the message is enabled - if(picture && (mNotifierState==AppCallbackNotifier::NOTIFIER_STARTED) && - (mCameraHal->msgTypeEnabled(CAMERA_MSG_COMPRESSED_IMAGE))) - { - android::AutoMutex lock(mBurstLock); - -#ifdef OMAP_ENHANCEMENT_BURST_CAPTURE - if ( mBurst ) - { - mDataCb(CAMERA_MSG_COMPRESSED_BURST_IMAGE, picture, 0, NULL, mCallbackCookie); - - } - else -#endif - { - mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, picture, 0, NULL, mCallbackCookie); - } - } - - exit: - - if (picture) { - picture->release(picture); - } - - if (mNotifierState == AppCallbackNotifier::NOTIFIER_STARTED) { - if (encoded_mem) { - encoded_mem->release(encoded_mem); - } - if (cookie2) { - delete (ExifElementsTable*) cookie2; - } - encoder = gEncoderQueue.valueFor(src); - if (encoder.get()) { - gEncoderQueue.removeItem(src); - encoder.clear(); - } - mFrameProvider->returnFrame(camera_buffer, type); - } - - LOG_FUNCTION_NAME_EXIT; -} - /** * NotificationHandler class */ @@ -1015,154 +880,6 @@ void AppCallbackNotifier::notifyFrame() mRawAvailable = true; } - else if ( (CameraFrame::IMAGE_FRAME == frame->mFrameType) && - (NULL != mCameraHal) && - (NULL != mDataCb) && - (CameraFrame::ENCODE_RAW_YUV422I_TO_JPEG & frame->mQuirks) ) - { - - int encode_quality = 100, tn_quality = 100; - int tn_width, tn_height; - unsigned int current_snapshot = 0; - Encoder_libjpeg::params *main_jpeg = NULL, *tn_jpeg = NULL; - void* exif_data = NULL; - const char *previewFormat = NULL; - camera_memory_t* raw_picture = mRequestMemory(-1, frame->mLength, 1, NULL); - - if(raw_picture) { - buf = raw_picture->data; - } - - android::CameraParameters parameters; - char *params = mCameraHal->getParameters(); - const android::String8 strParams(params); - parameters.unflatten(strParams); - - encode_quality = parameters.getInt(android::CameraParameters::KEY_JPEG_QUALITY); - if (encode_quality < 0 || encode_quality > 100) { - encode_quality = 100; - } - - tn_quality = parameters.getInt(android::CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY); - if (tn_quality < 0 || tn_quality > 100) { - tn_quality = 100; - } - - if (CameraFrame::HAS_EXIF_DATA & frame->mQuirks) { - exif_data = frame->mCookie2; - } - - main_jpeg = (Encoder_libjpeg::params*) - malloc(sizeof(Encoder_libjpeg::params)); - - // Video snapshot with LDCNSF on adds a few bytes start offset - // and a few bytes on every line. They must be skipped. - int rightCrop = frame->mAlignment/2 - frame->mWidth; - - CAMHAL_LOGDB("Video snapshot right crop = %d", rightCrop); - CAMHAL_LOGDB("Video snapshot offset = %d", frame->mOffset); - - if (main_jpeg) { - main_jpeg->src = (uint8_t *)frame->mBuffer->mapped; - main_jpeg->src_size = frame->mLength; - main_jpeg->dst = (uint8_t*) buf; - main_jpeg->dst_size = frame->mLength; - main_jpeg->quality = encode_quality; - main_jpeg->in_width = frame->mAlignment/2; // use stride here - main_jpeg->in_height = frame->mHeight; - main_jpeg->out_width = frame->mAlignment/2; - main_jpeg->out_height = frame->mHeight; - main_jpeg->right_crop = rightCrop; - main_jpeg->start_offset = frame->mOffset; - if ( CameraFrame::FORMAT_YUV422I_UYVY & frame->mQuirks) { - main_jpeg->format = TICameraParameters::PIXEL_FORMAT_YUV422I_UYVY; - } - else { //if ( CameraFrame::FORMAT_YUV422I_YUYV & frame->mQuirks) - main_jpeg->format = android::CameraParameters::PIXEL_FORMAT_YUV422I; - } - } - - tn_width = parameters.getInt(android::CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH); - tn_height = parameters.getInt(android::CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT); - previewFormat = parameters.getPreviewFormat(); - - if ((tn_width > 0) && (tn_height > 0) && ( NULL != previewFormat )) { - tn_jpeg = (Encoder_libjpeg::params*) - malloc(sizeof(Encoder_libjpeg::params)); - // if malloc fails just keep going and encode main jpeg - if (!tn_jpeg) { - tn_jpeg = NULL; - } - } - - if (tn_jpeg) { - int width, height; - parameters.getPreviewSize(&width,&height); - current_snapshot = (mPreviewBufCount + MAX_BUFFERS - 1) % MAX_BUFFERS; - tn_jpeg->src = (uint8_t *)mPreviewBuffers[current_snapshot].mapped; - tn_jpeg->src_size = mPreviewMemory->size / MAX_BUFFERS; - tn_jpeg->dst_size = CameraHal::calculateBufferSize(previewFormat, - tn_width, - tn_height); - tn_jpeg->dst = (uint8_t*) malloc(tn_jpeg->dst_size); - tn_jpeg->quality = tn_quality; - tn_jpeg->in_width = width; - tn_jpeg->in_height = height; - tn_jpeg->out_width = tn_width; - tn_jpeg->out_height = tn_height; - tn_jpeg->right_crop = 0; - tn_jpeg->start_offset = 0; - tn_jpeg->format = android::CameraParameters::PIXEL_FORMAT_YUV420SP;; - } - - android::sp<Encoder_libjpeg> encoder = new Encoder_libjpeg(main_jpeg, - tn_jpeg, - AppCallbackNotifierEncoderCallback, - (CameraFrame::FrameType)frame->mFrameType, - this, - raw_picture, - exif_data, frame->mBuffer); - gEncoderQueue.add(frame->mBuffer->mapped, encoder); - encoder->run(); - encoder.clear(); - if (params != NULL) - { - mCameraHal->putParameters(params); - } - } - else if ( ( CameraFrame::IMAGE_FRAME == frame->mFrameType ) && - ( NULL != mCameraHal ) && - ( NULL != mDataCb) ) - { - - // CTS, MTS requirements: Every 'takePicture()' call - // who registers a raw callback should receive one - // as well. This is not always the case with - // CameraAdapters though. - if (!mCameraHal->msgTypeEnabled(CAMERA_MSG_RAW_IMAGE)) { - dummyRaw(); - } else { - mRawAvailable = false; - } - -#ifdef COPY_IMAGE_BUFFER - { - android::AutoMutex lock(mBurstLock); -#ifdef OMAP_ENHANCEMENT_BURST_CAPTURE - if ( mBurst ) - { - copyAndSendPictureFrame(frame, CAMERA_MSG_COMPRESSED_BURST_IMAGE); - } - else -#endif - { - copyAndSendPictureFrame(frame, CAMERA_MSG_COMPRESSED_IMAGE); - } - } -#else - //TODO: Find a way to map a Tiler buffer to a MemoryHeapBase -#endif - } else if ( ( CameraFrame::VIDEO_FRAME_SYNC == frame->mFrameType ) && ( NULL != mCameraHal ) && ( NULL != mDataCb) && @@ -1943,8 +1660,6 @@ status_t AppCallbackNotifier::start() mNotifierState = AppCallbackNotifier::NOTIFIER_STARTED; CAMHAL_LOGDA(" --> AppCallbackNotifier NOTIFIER_STARTED \n"); - gEncoderQueue.clear(); - LOG_FUNCTION_NAME_EXIT; return NO_ERROR; @@ -1968,27 +1683,6 @@ status_t AppCallbackNotifier::stop() CAMHAL_LOGDA(" --> AppCallbackNotifier NOTIFIER_STOPPED \n"); } - while(!gEncoderQueue.isEmpty()) { - android::sp<Encoder_libjpeg> encoder = gEncoderQueue.valueAt(0); - camera_memory_t* encoded_mem = NULL; - ExifElementsTable* exif = NULL; - - if(encoder.get()) { - encoder->cancel(); - - encoder->getCookies(NULL, (void**) &encoded_mem, (void**) &exif); - if (encoded_mem) { - encoded_mem->release(encoded_mem); - } - if (exif) { - delete exif; - } - - encoder.clear(); - } - gEncoderQueue.removeItemsAt(0); - } - LOG_FUNCTION_NAME_EXIT; return NO_ERROR; } diff --git a/camera/Decoder_libjpeg.cpp b/camera/Decoder_libjpeg.cpp deleted file mode 100644 index 35c343f..0000000 --- a/camera/Decoder_libjpeg.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Decoder_libjpeg.h" - -extern "C" { - #include "jpeglib.h" - #include "jerror.h" -} - -#define NUM_COMPONENTS_IN_YUV 3 - -namespace Ti { -namespace Camera { - -/* JPEG DHT Segment omitted from MJPEG data */ -static unsigned char jpeg_odml_dht[0x1a6] = { - 0xff, 0xd8, /* Start of Image */ - 0xff, 0xc4, 0x01, 0xa2, /* Define Huffman Table */ - - 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, - - 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, - - 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d, - 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, - 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, - 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, - 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa, - - 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, - 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, - 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, - 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, - 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, - 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, - 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, - 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa -}; - -struct libjpeg_source_mgr : jpeg_source_mgr { - libjpeg_source_mgr(unsigned char *buffer_ptr, int len); - ~libjpeg_source_mgr(); - - unsigned char *mBufferPtr; - int mFilledLen; -}; - -static void libjpeg_init_source(j_decompress_ptr cinfo) { - libjpeg_source_mgr* src = (libjpeg_source_mgr*)cinfo->src; - src->next_input_byte = (const JOCTET*)src->mBufferPtr; - src->bytes_in_buffer = 0; - src->current_offset = 0; -} - -static boolean libjpeg_seek_input_data(j_decompress_ptr cinfo, long byte_offset) { - libjpeg_source_mgr* src = (libjpeg_source_mgr*)cinfo->src; - src->current_offset = byte_offset; - src->next_input_byte = (const JOCTET*)src->mBufferPtr + byte_offset; - src->bytes_in_buffer = 0; - return TRUE; -} - -static boolean libjpeg_fill_input_buffer(j_decompress_ptr cinfo) { - libjpeg_source_mgr* src = (libjpeg_source_mgr*)cinfo->src; - src->current_offset += src->mFilledLen; - src->next_input_byte = src->mBufferPtr; - src->bytes_in_buffer = src->mFilledLen; - return TRUE; -} - -static void libjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) { - libjpeg_source_mgr* src = (libjpeg_source_mgr*)cinfo->src; - - if (num_bytes > (long)src->bytes_in_buffer) { - CAMHAL_LOGEA("\n\n\n libjpeg_skip_input_data - num_bytes > (long)src->bytes_in_buffer \n\n\n"); - } else { - src->next_input_byte += num_bytes; - src->bytes_in_buffer -= num_bytes; - } -} - -static boolean libjpeg_resync_to_restart(j_decompress_ptr cinfo, int desired) { - libjpeg_source_mgr* src = (libjpeg_source_mgr*)cinfo->src; - src->next_input_byte = (const JOCTET*)src->mBufferPtr; - src->bytes_in_buffer = 0; - return TRUE; -} - -static void libjpeg_term_source(j_decompress_ptr /*cinfo*/) {} - -libjpeg_source_mgr::libjpeg_source_mgr(unsigned char *buffer_ptr, int len) : mBufferPtr(buffer_ptr), mFilledLen(len) { - init_source = libjpeg_init_source; - fill_input_buffer = libjpeg_fill_input_buffer; - skip_input_data = libjpeg_skip_input_data; - resync_to_restart = libjpeg_resync_to_restart; - term_source = libjpeg_term_source; - seek_input_data = libjpeg_seek_input_data; -} - -libjpeg_source_mgr::~libjpeg_source_mgr() {} - -Decoder_libjpeg::Decoder_libjpeg() -{ - mWidth = 0; - mHeight = 0; - Y_Plane = NULL; - U_Plane = NULL; - V_Plane = NULL; - UV_Plane = NULL; -} - -Decoder_libjpeg::~Decoder_libjpeg() -{ - release(); -} - -void Decoder_libjpeg::release() -{ - if (Y_Plane) { - free(Y_Plane); - Y_Plane = NULL; - } - if (U_Plane) { - free(U_Plane); - U_Plane = NULL; - } - if (V_Plane) { - free(V_Plane); - V_Plane = NULL; - } - if (UV_Plane) { - free(UV_Plane); - UV_Plane = NULL; - } -} - -int Decoder_libjpeg::readDHTSize() -{ - return sizeof(jpeg_odml_dht); -} - -// 0xFF 0xC4 - DHT (Define Huffman Table) marker -// 0xFF 0xD9 - SOI (Start Of Image) marker -// 0xFF 0xD9 - EOI (End Of Image) marker -// This function return true if if found DHT -bool Decoder_libjpeg::isDhtExist(unsigned char *jpeg_src, int filled_len) { - if (filled_len <= 0) { - return false; - } - - for (int i = 1; i < filled_len; i++) { - if((jpeg_src[i - 1] == 0xFF) && (jpeg_src[i] == 0xC4)) { - CAMHAL_LOGD("Found DHT (Define Huffman Table) marker"); - return true; - } - } - return false; -} - -int Decoder_libjpeg::appendDHT(unsigned char *jpeg_src, int filled_len, unsigned char *jpeg_with_dht_buffer, int buff_size) -{ - /* Appending DHT to JPEG */ - - int len = filled_len + sizeof(jpeg_odml_dht) - 2; // final length of jpeg data - if (len > buff_size) { - CAMHAL_LOGEA("\n\n\n Buffer size too small. filled_len=%d, buff_size=%d, sizeof(jpeg_odml_dht)=%d\n\n\n", filled_len, buff_size, sizeof(jpeg_odml_dht)); - return 0; - } - - memcpy(jpeg_with_dht_buffer, jpeg_odml_dht, sizeof(jpeg_odml_dht)); - memcpy((jpeg_with_dht_buffer + sizeof(jpeg_odml_dht)), jpeg_src + 2, (filled_len - 2)); - return len; -} - - -bool Decoder_libjpeg::decode(unsigned char *jpeg_src, int filled_len, unsigned char *nv12_buffer, int stride) -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - struct libjpeg_source_mgr s_mgr(jpeg_src, filled_len); - - if (filled_len == 0) - return false; - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - - cinfo.src = &s_mgr; - int status = jpeg_read_header(&cinfo, true); - if (status != JPEG_HEADER_OK) { - CAMHAL_LOGEA("jpeg header corrupted"); - return false; - } - - cinfo.out_color_space = JCS_YCbCr; - cinfo.raw_data_out = true; - status = jpeg_start_decompress(&cinfo); - if (!status){ - CAMHAL_LOGEA("jpeg_start_decompress failed"); - return false; - } - - if (mWidth == 0){ - mWidth = cinfo.output_width; - mHeight = cinfo.output_height; - CAMHAL_LOGEA("w x h = %d x %d. stride=%d", cinfo.output_width, cinfo.output_height, stride); - } - else if ((cinfo.output_width > mWidth) || (cinfo.output_height > mHeight)) { - CAMHAL_LOGEA(" Free the existing buffers so that they are reallocated for new w x h. Old WxH = %dx%d. New WxH = %dx%d", - mWidth, mHeight, cinfo.output_width, cinfo.output_height); - release(); - mWidth = cinfo.output_width; - mHeight = cinfo.output_height; - } - - unsigned int decoded_uv_buffer_size = cinfo.output_width * cinfo.output_height / 2; - if (Y_Plane == NULL)Y_Plane = (unsigned char **)malloc(cinfo.output_height * sizeof(unsigned char *)); - if (U_Plane == NULL)U_Plane = (unsigned char **)malloc(cinfo.output_height * sizeof(unsigned char *)); - if (V_Plane == NULL)V_Plane = (unsigned char **)malloc(cinfo.output_height * sizeof(unsigned char *)); - if (UV_Plane == NULL) UV_Plane = (unsigned char *)malloc(decoded_uv_buffer_size); - - unsigned char **YUV_Planes[NUM_COMPONENTS_IN_YUV]; - YUV_Planes[0] = Y_Plane; - YUV_Planes[1] = U_Plane; - YUV_Planes[2] = V_Plane; - - unsigned char *row = &nv12_buffer[0]; - - // Y Component - for (unsigned int j = 0; j < cinfo.output_height; j++, row += stride) - YUV_Planes[0][j] = row; - - row = &UV_Plane[0]; - - // U Component - for (unsigned int j = 0; j < cinfo.output_height; j+=2, row += cinfo.output_width / 2){ - YUV_Planes[1][j+0] = row; - YUV_Planes[1][j+1] = row; - } - - // V Component - for (unsigned int j = 0; j < cinfo.output_height; j+=2, row += cinfo.output_width / 2){ - YUV_Planes[2][j+0] = row; - YUV_Planes[2][j+1] = row; - } - - // Interleaving U and V - for (unsigned int i = 0; i < cinfo.output_height; i += 8) { - jpeg_read_raw_data(&cinfo, YUV_Planes, 8); - YUV_Planes[0] += 8; - YUV_Planes[1] += 8; - YUV_Planes[2] += 8; - } - - unsigned char *uv_ptr = nv12_buffer + (stride * cinfo.output_height); - unsigned char *u_ptr = UV_Plane; - unsigned char *v_ptr = UV_Plane + (decoded_uv_buffer_size / 2); - for(unsigned int i = 0; i < cinfo.output_height / 2; i++){ - for(unsigned int j = 0; j < cinfo.output_width; j+=2){ - *(uv_ptr + j) = *u_ptr; u_ptr++; - *(uv_ptr + j + 1) = *v_ptr; v_ptr++; - } - uv_ptr = uv_ptr + stride; - } - - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - - return true; -} - -} // namespace Camera -} // namespace Ti - diff --git a/camera/Encoder_libjpeg.cpp b/camera/Encoder_libjpeg.cpp deleted file mode 100644 index 1cd09d3..0000000 --- a/camera/Encoder_libjpeg.cpp +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** -* @file Encoder_libjpeg.cpp -* -* This file encodes a YUV422I buffer to a jpeg -* TODO(XXX): Need to support formats other than yuv422i -* Change interface to pre/post-proc algo framework -* -*/ - -#include "Encoder_libjpeg.h" -#include "NV12_resize.h" -#include "TICameraParameters.h" - -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <math.h> - -extern "C" { - #include "jpeglib.h" - #include "jerror.h" -} - -#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0])) -#define MIN(x,y) ((x < y) ? x : y) - -namespace Ti { -namespace Camera { - -struct integer_string_pair { - unsigned int integer; - const char* string; -}; - -static integer_string_pair degress_to_exif_lut [] = { - // degrees, exif_orientation - {0, "1"}, - {90, "6"}, - {180, "3"}, - {270, "8"}, -}; -struct libjpeg_destination_mgr : jpeg_destination_mgr { - libjpeg_destination_mgr(uint8_t* input, int size); - - uint8_t* buf; - int bufsize; - size_t jpegsize; -}; - -static void libjpeg_init_destination (j_compress_ptr cinfo) { - libjpeg_destination_mgr* dest = (libjpeg_destination_mgr*)cinfo->dest; - - dest->next_output_byte = dest->buf; - dest->free_in_buffer = dest->bufsize; - dest->jpegsize = 0; -} - -static boolean libjpeg_empty_output_buffer(j_compress_ptr cinfo) { - libjpeg_destination_mgr* dest = (libjpeg_destination_mgr*)cinfo->dest; - - dest->next_output_byte = dest->buf; - dest->free_in_buffer = dest->bufsize; - return TRUE; // ? -} - -static void libjpeg_term_destination (j_compress_ptr cinfo) { - libjpeg_destination_mgr* dest = (libjpeg_destination_mgr*)cinfo->dest; - dest->jpegsize = dest->bufsize - dest->free_in_buffer; -} - -libjpeg_destination_mgr::libjpeg_destination_mgr(uint8_t* input, int size) { - this->init_destination = libjpeg_init_destination; - this->empty_output_buffer = libjpeg_empty_output_buffer; - this->term_destination = libjpeg_term_destination; - - this->buf = input; - this->bufsize = size; - - jpegsize = 0; -} - -/* private static functions */ -static void nv21_to_yuv(uint8_t* dst, uint8_t* y, uint8_t* uv, int width) { - if (!dst || !y || !uv) { - return; - } - - while ((width--) > 0) { - uint8_t y0 = y[0]; - uint8_t v0 = uv[0]; - uint8_t u0 = *(uv+1); - dst[0] = y0; - dst[1] = u0; - dst[2] = v0; - dst += 3; - y++; - if(!(width % 2)) uv+=2; - } -} - -static void uyvy_to_yuv(uint8_t* dst, uint32_t* src, int width) { - if (!dst || !src) { - return; - } - - if (width % 2) { - return; // not supporting odd widths - } - -#ifdef ARCH_ARM_HAVE_NEON - // currently, neon routine only supports multiple of 16 width - if ((width % 16) == 0) { - int n = width; - asm volatile ( - " pld [%[src], %[src_stride], lsl #2] \n\t" - " cmp %[n], #16 \n\t" - " blt 5f \n\t" - "0: @ 16 pixel swap \n\t" - " vld2.8 {q0, q1} , [%[src]]! @ q0 = uv q1 = y \n\t" - " vuzp.8 q0, q2 @ d0 = u d4 = v \n\t" - " vmov d1, d0 @ q0 = u0u1u2..u0u1u2... \n\t" - " vmov d5, d4 @ q2 = v0v1v2..v0v1v2... \n\t" - " vzip.8 d0, d1 @ q0 = u0u0u1u1u2u2... \n\t" - " vzip.8 d4, d5 @ q2 = v0v0v1v1v2v2... \n\t" - " vswp q0, q1 @ now q0 = y q1 = u q2 = v \n\t" - " vst3.8 {d0,d2,d4},[%[dst]]! \n\t" - " vst3.8 {d1,d3,d5},[%[dst]]! \n\t" - " sub %[n], %[n], #16 \n\t" - " cmp %[n], #16 \n\t" - " bge 0b \n\t" - "5: @ end \n\t" -#ifdef NEEDS_ARM_ERRATA_754319_754320 - " vmov s0,s0 @ add noop for errata item \n\t" -#endif - : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) - : [src_stride] "r" (width) - : "cc", "memory", "q0", "q1", "q2" - ); - } else -#endif - { - while ((width-=2) >= 0) { - uint8_t u0 = (src[0] >> 0) & 0xFF; - uint8_t y0 = (src[0] >> 8) & 0xFF; - uint8_t v0 = (src[0] >> 16) & 0xFF; - uint8_t y1 = (src[0] >> 24) & 0xFF; - dst[0] = y0; - dst[1] = u0; - dst[2] = v0; - dst[3] = y1; - dst[4] = u0; - dst[5] = v0; - dst += 6; - src++; - } - } -} - -static void yuyv_to_yuv(uint8_t* dst, uint32_t* src, int width) { - if (!dst || !src) { - return; - } - - if (width % 2) { - return; // not supporting odd widths - } - -#ifdef ARCH_ARM_HAVE_NEON - // currently, neon routine only supports multiple of 16 width - if ((width % 16) == 0) { - int n = width; - asm volatile ( - " pld [%[src], %[src_stride], lsl #2] \n\t" - " cmp %[n], #16 \n\t" - " blt 5f \n\t" - "0: @ 16 pixel swap \n\t" - " vld2.8 {q0, q1} , [%[src]]! @ q0 = yyyy.. q1 = uvuv.. \n\t" - " vuzp.8 q1, q2 @ d2 = u d4 = v \n\t" - " vmov d3, d2 @ q1 = u0u1u2..u0u1u2... \n\t" - " vmov d5, d4 @ q2 = v0v1v2..v0v1v2... \n\t" - " vzip.8 d2, d3 @ q1 = u0u0u1u1u2u2... \n\t" - " vzip.8 d4, d5 @ q2 = v0v0v1v1v2v2... \n\t" - " @ now q0 = y q1 = u q2 = v \n\t" - " vst3.8 {d0,d2,d4},[%[dst]]! \n\t" - " vst3.8 {d1,d3,d5},[%[dst]]! \n\t" - " sub %[n], %[n], #16 \n\t" - " cmp %[n], #16 \n\t" - " bge 0b \n\t" - "5: @ end \n\t" -#ifdef NEEDS_ARM_ERRATA_754319_754320 - " vmov s0,s0 @ add noop for errata item \n\t" -#endif - : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) - : [src_stride] "r" (width) - : "cc", "memory", "q0", "q1", "q2" - ); - } else -#endif - { - while ((width-=2) >= 0) { - uint8_t y0 = (src[0] >> 0) & 0xFF; - uint8_t u0 = (src[0] >> 8) & 0xFF; - uint8_t y1 = (src[0] >> 16) & 0xFF; - uint8_t v0 = (src[0] >> 24) & 0xFF; - dst[0] = y0; - dst[1] = u0; - dst[2] = v0; - dst[3] = y1; - dst[4] = u0; - dst[5] = v0; - dst += 6; - src++; - } - } -} - -static void resize_nv12(Encoder_libjpeg::params* params, uint8_t* dst_buffer) { - structConvImage o_img_ptr, i_img_ptr; - - if (!params || !dst_buffer) { - return; - } - - //input - i_img_ptr.uWidth = params->in_width; - i_img_ptr.uStride = i_img_ptr.uWidth; - i_img_ptr.uHeight = params->in_height; - i_img_ptr.eFormat = IC_FORMAT_YCbCr420_lp; - i_img_ptr.imgPtr = (uint8_t*) params->src; - i_img_ptr.clrPtr = i_img_ptr.imgPtr + (i_img_ptr.uWidth * i_img_ptr.uHeight); - i_img_ptr.uOffset = 0; - - //ouput - o_img_ptr.uWidth = params->out_width; - o_img_ptr.uStride = o_img_ptr.uWidth; - o_img_ptr.uHeight = params->out_height; - o_img_ptr.eFormat = IC_FORMAT_YCbCr420_lp; - o_img_ptr.imgPtr = dst_buffer; - o_img_ptr.clrPtr = o_img_ptr.imgPtr + (o_img_ptr.uWidth * o_img_ptr.uHeight); - o_img_ptr.uOffset = 0; - - VT_resizeFrame_Video_opt2_lp(&i_img_ptr, &o_img_ptr, NULL, 0); -} - -/* public static functions */ -const char* ExifElementsTable::degreesToExifOrientation(unsigned int degrees) { - for (unsigned int i = 0; i < ARRAY_SIZE(degress_to_exif_lut); i++) { - if (degrees == degress_to_exif_lut[i].integer) { - return degress_to_exif_lut[i].string; - } - } - return NULL; -} - -void ExifElementsTable::stringToRational(const char* str, unsigned int* num, unsigned int* den) { - int len; - char * tempVal = NULL; - - if (str != NULL) { - len = strlen(str); - tempVal = (char*) malloc( sizeof(char) * (len + 1)); - } - - if (tempVal != NULL) { - // convert the decimal string into a rational - size_t den_len; - char *ctx; - unsigned int numerator = 0; - unsigned int denominator = 0; - char* temp = NULL; - - memset(tempVal, '\0', len + 1); - strncpy(tempVal, str, len); - temp = strtok_r(tempVal, ".", &ctx); - - if (temp != NULL) - numerator = atoi(temp); - - if (!numerator) - numerator = 1; - - temp = strtok_r(NULL, ".", &ctx); - if (temp != NULL) { - den_len = strlen(temp); - if(HUGE_VAL == den_len ) { - den_len = 0; - } - - denominator = static_cast<unsigned int>(pow(10, den_len)); - numerator = numerator * denominator + atoi(temp); - } else { - denominator = 1; - } - - free(tempVal); - - *num = numerator; - *den = denominator; - } -} - -bool ExifElementsTable::isAsciiTag(const char* tag) { - // TODO(XXX): Add tags as necessary - return (strcmp(tag, TAG_GPS_PROCESSING_METHOD) == 0); -} - -void ExifElementsTable::insertExifToJpeg(unsigned char* jpeg, size_t jpeg_size) { - ReadMode_t read_mode = (ReadMode_t)(READ_METADATA | READ_IMAGE); - - ResetJpgfile(); - if (ReadJpegSectionsFromBuffer(jpeg, jpeg_size, read_mode)) { - jpeg_opened = true; -#ifdef ANDROID_API_JB_OR_LATER - create_EXIF(table, exif_tag_count, gps_tag_count, has_datetime_tag); -#else - create_EXIF(table, exif_tag_count, gps_tag_count); -#endif - } -} - -status_t ExifElementsTable::insertExifThumbnailImage(const char* thumb, int len) { - status_t ret = NO_ERROR; - - if ((len > 0) && jpeg_opened) { - ret = ReplaceThumbnailFromBuffer(thumb, len) ? NO_ERROR : UNKNOWN_ERROR; - CAMHAL_LOGDB("insertExifThumbnailImage. ReplaceThumbnail(). ret=%d", ret); - } - - return ret; -} - -void ExifElementsTable::saveJpeg(unsigned char* jpeg, size_t jpeg_size) { - if (jpeg_opened) { - WriteJpegToBuffer(jpeg, jpeg_size); - DiscardData(); - jpeg_opened = false; - } -} - -/* public functions */ -ExifElementsTable::~ExifElementsTable() { - int num_elements = gps_tag_count + exif_tag_count; - - for (int i = 0; i < num_elements; i++) { - if (table[i].Value) { - free(table[i].Value); - } - } - - if (jpeg_opened) { - DiscardData(); - } -} - -status_t ExifElementsTable::insertElement(const char* tag, const char* value) { - unsigned int value_length = 0; - status_t ret = NO_ERROR; - - if (!value || !tag) { - return -EINVAL; - } - - if (position >= MAX_EXIF_TAGS_SUPPORTED) { - CAMHAL_LOGEA("Max number of EXIF elements already inserted"); - return NO_MEMORY; - } - - if (isAsciiTag(tag)) { - value_length = sizeof(ExifAsciiPrefix) + strlen(value + sizeof(ExifAsciiPrefix)); - } else { - value_length = strlen(value); - } - - if (IsGpsTag(tag)) { - table[position].GpsTag = TRUE; - table[position].Tag = GpsTagNameToValue(tag); - gps_tag_count++; - } else { - table[position].GpsTag = FALSE; - table[position].Tag = TagNameToValue(tag); - exif_tag_count++; - - if (strcmp(tag, TAG_DATETIME) == 0) { -#ifdef ANDROID_API_JB_OR_LATER - has_datetime_tag = true; -#else - // jhead isn't taking datetime tag...this is a WA - ImageInfo.numDateTimeTags = 1; - memcpy(ImageInfo.DateTime, value, - MIN(ARRAY_SIZE(ImageInfo.DateTime), value_length + 1)); -#endif - } - } - - table[position].DataLength = 0; - table[position].Value = (char*) malloc(sizeof(char) * (value_length + 1)); - - if (table[position].Value) { - memcpy(table[position].Value, value, value_length + 1); - table[position].DataLength = value_length + 1; - } - - position++; - return ret; -} - -/* private member functions */ -size_t Encoder_libjpeg::encode(params* input) { - jpeg_compress_struct cinfo; - jpeg_error_mgr jerr; - jpeg_destination_mgr jdest; - uint8_t* src = NULL, *resize_src = NULL; - uint8_t* row_tmp = NULL; - uint8_t* row_src = NULL; - uint8_t* row_uv = NULL; // used only for NV12 - int out_width = 0, in_width = 0; - int out_height = 0, in_height = 0; - int bpp = 2; // for uyvy - int right_crop = 0, start_offset = 0; - - if (!input) { - return 0; - } - - out_width = input->out_width; - in_width = input->in_width; - out_height = input->out_height; - in_height = input->in_height; - right_crop = input->right_crop; - start_offset = input->start_offset; - src = input->src; - input->jpeg_size = 0; - - libjpeg_destination_mgr dest_mgr(input->dst, input->dst_size); - - // param check... - if ((in_width < 2) || (out_width < 2) || (in_height < 2) || (out_height < 2) || - (src == NULL) || (input->dst == NULL) || (input->quality < 1) || (input->src_size < 1) || - (input->dst_size < 1) || (input->format == NULL)) { - goto exit; - } - - if (strcmp(input->format, android::CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { - bpp = 1; - if ((in_width != out_width) || (in_height != out_height)) { - resize_src = (uint8_t*) malloc(input->dst_size); - resize_nv12(input, resize_src); - if (resize_src) src = resize_src; - } - } else if (strcmp(input->format, android::CameraParameters::PIXEL_FORMAT_YUV422I) && - strcmp(input->format, TICameraParameters::PIXEL_FORMAT_YUV422I_UYVY)) { - // we currently only support yuv422i and yuv420sp - CAMHAL_LOGEB("Encoder: format not supported: %s", input->format); - goto exit; - } else if ((in_width != out_width) || (in_height != out_height)) { - CAMHAL_LOGEB("Encoder: resizing is not supported for this format: %s", input->format); - goto exit; - } - - cinfo.err = jpeg_std_error(&jerr); - - jpeg_create_compress(&cinfo); - - CAMHAL_LOGDB("encoding... \n\t" - "width: %d \n\t" - "height:%d \n\t" - "dest %p \n\t" - "dest size:%d \n\t" - "mSrc %p \n\t" - "format: %s", - out_width, out_height, input->dst, - input->dst_size, src, input->format); - - cinfo.dest = &dest_mgr; - cinfo.image_width = out_width - right_crop; - cinfo.image_height = out_height; - cinfo.input_components = 3; - cinfo.in_color_space = JCS_YCbCr; - cinfo.input_gamma = 1; - - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, input->quality, TRUE); - cinfo.dct_method = JDCT_IFAST; - - jpeg_start_compress(&cinfo, TRUE); - - row_tmp = (uint8_t*)malloc((out_width - right_crop) * 3); - row_src = src + start_offset; - row_uv = src + out_width * out_height * bpp; - - while ((cinfo.next_scanline < cinfo.image_height) && !mCancelEncoding) { - JSAMPROW row[1]; /* pointer to JSAMPLE row[s] */ - - // convert input yuv format to yuv444 - if (strcmp(input->format, android::CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { - nv21_to_yuv(row_tmp, row_src, row_uv, out_width - right_crop); - } else if (strcmp(input->format, TICameraParameters::PIXEL_FORMAT_YUV422I_UYVY) == 0) { - uyvy_to_yuv(row_tmp, (uint32_t*)row_src, out_width - right_crop); - } else if (strcmp(input->format, android::CameraParameters::PIXEL_FORMAT_YUV422I) == 0) { - yuyv_to_yuv(row_tmp, (uint32_t*)row_src, out_width - right_crop); - } - - row[0] = row_tmp; - jpeg_write_scanlines(&cinfo, row, 1); - row_src = row_src + out_width*bpp; - - // move uv row if input format needs it - if (strcmp(input->format, android::CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) { - if (!(cinfo.next_scanline % 2)) - row_uv = row_uv + out_width * bpp; - } - } - - // no need to finish encoding routine if we are prematurely stopping - // we will end up crashing in dest_mgr since data is incomplete - if (!mCancelEncoding) - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); - - if (resize_src) free(resize_src); - if (row_tmp) free(row_tmp); - - exit: - input->jpeg_size = dest_mgr.jpegsize; - return dest_mgr.jpegsize; -} - -} // namespace Camera -} // namespace Ti diff --git a/camera/inc/Decoder_libjpeg.h b/camera/inc/Decoder_libjpeg.h deleted file mode 100644 index 425ebf1..0000000 --- a/camera/inc/Decoder_libjpeg.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_CAMERA_HARDWARE_DECODER_LIBJPEG_H -#define ANDROID_CAMERA_HARDWARE_DECODER_LIBJPEG_H - -#include "CameraHal.h" - -extern "C" { -#include "jhead.h" - -#undef TRUE -#undef FALSE - -} - - -namespace Ti { -namespace Camera { - -class Decoder_libjpeg -{ - -public: - Decoder_libjpeg(); - ~Decoder_libjpeg(); - static int readDHTSize(); - static bool isDhtExist(unsigned char *jpeg_src, int filled_len); - static int appendDHT(unsigned char *jpeg_src, int filled_len, unsigned char *jpeg_with_dht_buffer, int buff_size); - bool decode(unsigned char *jpeg_src, int filled_len, unsigned char *nv12_buffer, int stride); - -private: - void release(); - unsigned char **Y_Plane; - unsigned char **U_Plane; - unsigned char **V_Plane; - unsigned char *UV_Plane; - unsigned int mWidth, mHeight; -}; - -} // namespace Camera -} // namespace Ti - -#endif - diff --git a/camera/inc/Encoder_libjpeg.h b/camera/inc/Encoder_libjpeg.h deleted file mode 100644 index 72feb08..0000000 --- a/camera/inc/Encoder_libjpeg.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** -* @file Encoder_libjpeg.h -* -* This defines API for camerahal to encode YUV using libjpeg -* -*/ - -#ifndef ANDROID_CAMERA_HARDWARE_ENCODER_LIBJPEG_H -#define ANDROID_CAMERA_HARDWARE_ENCODER_LIBJPEG_H - -#include <utils/threads.h> -#include <utils/RefBase.h> - -extern "C" { -#include "jhead.h" - -#undef TRUE -#undef FALSE - -} - -#include "CameraHal.h" - -#define CANCEL_TIMEOUT 5000000 // 5 seconds - -namespace Ti { -namespace Camera { - -/** - * libjpeg encoder class - uses libjpeg to encode yuv - */ - -#define MAX_EXIF_TAGS_SUPPORTED 30 -typedef void (*encoder_libjpeg_callback_t) (void* main_jpeg, - void* thumb_jpeg, - CameraFrame::FrameType type, - void* cookie1, - void* cookie2, - void* cookie3, - void* cookie4, - bool canceled); - -// these have to match strings defined in external/jhead/exif.c -static const char TAG_MODEL[] = "Model"; -static const char TAG_MAKE[] = "Make"; -static const char TAG_FOCALLENGTH[] = "FocalLength"; -static const char TAG_DATETIME[] = "DateTime"; -static const char TAG_IMAGE_WIDTH[] = "ImageWidth"; -static const char TAG_IMAGE_LENGTH[] = "ImageLength"; -static const char TAG_GPS_LAT[] = "GPSLatitude"; -static const char TAG_GPS_LAT_REF[] = "GPSLatitudeRef"; -static const char TAG_GPS_LONG[] = "GPSLongitude"; -static const char TAG_GPS_LONG_REF[] = "GPSLongitudeRef"; -static const char TAG_GPS_ALT[] = "GPSAltitude"; -static const char TAG_GPS_ALT_REF[] = "GPSAltitudeRef"; -static const char TAG_GPS_MAP_DATUM[] = "GPSMapDatum"; -static const char TAG_GPS_PROCESSING_METHOD[] = "GPSProcessingMethod"; -static const char TAG_GPS_VERSION_ID[] = "GPSVersionID"; -static const char TAG_GPS_TIMESTAMP[] = "GPSTimeStamp"; -static const char TAG_GPS_DATESTAMP[] = "GPSDateStamp"; -static const char TAG_ORIENTATION[] = "Orientation"; -static const char TAG_FLASH[] = "Flash"; -static const char TAG_DIGITALZOOMRATIO[] = "DigitalZoomRatio"; -static const char TAG_EXPOSURETIME[] = "ExposureTime"; -static const char TAG_APERTURE[] = "ApertureValue"; -static const char TAG_ISO_EQUIVALENT[] = "ISOSpeedRatings"; -static const char TAG_WHITEBALANCE[] = "WhiteBalance"; -static const char TAG_LIGHT_SOURCE[] = "LightSource"; -static const char TAG_METERING_MODE[] = "MeteringMode"; -static const char TAG_EXPOSURE_PROGRAM[] = "ExposureProgram"; -static const char TAG_COLOR_SPACE[] = "ColorSpace"; -static const char TAG_CPRS_BITS_PER_PIXEL[] = "CompressedBitsPerPixel"; -static const char TAG_FNUMBER[] = "FNumber"; -static const char TAG_SHUTTERSPEED[] = "ShutterSpeedValue"; -static const char TAG_SENSING_METHOD[] = "SensingMethod"; -static const char TAG_CUSTOM_RENDERED[] = "CustomRendered"; - -class ExifElementsTable { - public: - ExifElementsTable() : - gps_tag_count(0), exif_tag_count(0), position(0), - jpeg_opened(false) - { -#ifdef ANDROID_API_JB_OR_LATER - has_datetime_tag = false; -#endif - } - ~ExifElementsTable(); - - status_t insertElement(const char* tag, const char* value); - void insertExifToJpeg(unsigned char* jpeg, size_t jpeg_size); - status_t insertExifThumbnailImage(const char*, int); - void saveJpeg(unsigned char* picture, size_t jpeg_size); - static const char* degreesToExifOrientation(unsigned int); - static void stringToRational(const char*, unsigned int*, unsigned int*); - static bool isAsciiTag(const char* tag); - private: - ExifElement_t table[MAX_EXIF_TAGS_SUPPORTED]; - unsigned int gps_tag_count; - unsigned int exif_tag_count; - unsigned int position; - bool jpeg_opened; -#ifdef ANDROID_API_JB_OR_LATER - bool has_datetime_tag; -#endif -}; - -class Encoder_libjpeg : public android::Thread { - /* public member types and variables */ - public: - struct params { - uint8_t* src; - int src_size; - uint8_t* dst; - int dst_size; - int quality; - int in_width; - int in_height; - int out_width; - int out_height; - int right_crop; - int start_offset; - const char* format; - size_t jpeg_size; - }; - /* public member functions */ - public: - Encoder_libjpeg(params* main_jpeg, - params* tn_jpeg, - encoder_libjpeg_callback_t cb, - CameraFrame::FrameType type, - void* cookie1, - void* cookie2, - void* cookie3, void *cookie4) - : android::Thread(false), mMainInput(main_jpeg), mThumbnailInput(tn_jpeg), mCb(cb), - mCancelEncoding(false), mCookie1(cookie1), mCookie2(cookie2), mCookie3(cookie3), mCookie4(cookie4), - mType(type), mThumb(NULL) { - this->incStrong(this); - mCancelSem.Create(0); - } - - ~Encoder_libjpeg() { - CAMHAL_LOGVB("~Encoder_libjpeg(%p)", this); - } - - virtual bool threadLoop() { - size_t size = 0; - if (mThumbnailInput) { - // start thread to encode thumbnail - mThumb = new Encoder_libjpeg(mThumbnailInput, NULL, NULL, mType, NULL, NULL, NULL, NULL); - mThumb->run(); - } - - // encode our main image - size = encode(mMainInput); - - // signal cancel semaphore incase somebody is waiting - mCancelSem.Signal(); - - // check if it is main jpeg thread - if(mThumb.get()) { - // wait until tn jpeg thread exits. - mThumb->join(); - mThumb.clear(); - mThumb = NULL; - } - - if(mCb) { - mCb(mMainInput, mThumbnailInput, mType, mCookie1, mCookie2, mCookie3, mCookie4, mCancelEncoding); - } - - // encoder thread runs, self-destructs, and then exits - this->decStrong(this); - return false; - } - - void cancel() { - mCancelEncoding = true; - if (mThumb.get()) { - mThumb->cancel(); - mCancelSem.WaitTimeout(CANCEL_TIMEOUT); - } - } - - void getCookies(void **cookie1, void **cookie2, void **cookie3) { - if (cookie1) *cookie1 = mCookie1; - if (cookie2) *cookie2 = mCookie2; - if (cookie3) *cookie3 = mCookie3; - } - - private: - params* mMainInput; - params* mThumbnailInput; - encoder_libjpeg_callback_t mCb; - bool mCancelEncoding; - void* mCookie1; - void* mCookie2; - void* mCookie3; - void* mCookie4; - CameraFrame::FrameType mType; - android::sp<Encoder_libjpeg> mThumb; - Utils::Semaphore mCancelSem; - - size_t encode(params*); -}; - -} // namespace Camera -} // namespace Ti - -#endif diff --git a/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h b/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h index 728032b..2311879 100644 --- a/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h +++ b/camera/inc/V4LCameraAdapter/V4LCameraAdapter.h @@ -24,7 +24,6 @@ #include "CameraHal.h" #include "BaseCameraAdapter.h" #include "DebugUtils.h" -#include "Decoder_libjpeg.h" #include "FrameDecoder.h" |