1 /* 2 * Copyright Samsung Electronics Co.,LTD. 3 * Copyright (C) 2010 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef EXYNOS_JPEG_ENCODER_FOR_CAMERA_H_ 19 #define EXYNOS_JPEG_ENCODER_FOR_CAMERA_H_ 20 21 #include "ExynosExif.h" 22 23 #include "ExynosJpegApi.h" 24 25 #include <sys/mman.h> 26 #include "ion.h" 27 28 #define MAX_IMAGE_PLANE_NUM (3) 29 30 class ExynosJpegEncoderForCamera { 31 public : 32 ; 33 enum ERROR { 34 ERROR_ALREADY_CREATE = -0x200, 35 ERROR_CANNOT_CREATE_EXYNOS_JPEG_ENC_HAL, 36 ERROR_NOT_YET_CREATED, 37 ERROR_ALREADY_DESTROY, 38 ERROR_INPUT_DATA_SIZE_TOO_LARGE, 39 ERROR_OUT_BUFFER_SIZE_TOO_SMALL, 40 ERROR_EXIFOUT_ALLOC_FAIL, 41 ERROR_MAKE_EXIF_FAIL, 42 ERROR_INVALID_SCALING_WIDTH_HEIGHT, 43 ERROR_CANNOT_CREATE_SEC_THUMB, 44 ERROR_THUMB_JPEG_SIZE_TOO_SMALL, 45 ERROR_IMPLEMENT_NOT_YET, 46 ERROR_MEM_ALLOC_FAIL, 47 ERROR_JPEG_DEVICE_ALREADY_CREATE = -0x100, 48 ERROR_CANNOT_OPEN_JPEG_DEVICE, 49 ERROR_JPEG_DEVICE_ALREADY_CLOSED, 50 ERROR_JPEG_DEVICE_ALREADY_DESTROY, 51 ERROR_JPEG_DEVICE_NOT_CREATE_YET, 52 ERROR_INVALID_COLOR_FORMAT, 53 ERROR_INVALID_JPEG_FORMAT, 54 ERROR_JPEG_CONFIG_POINTER_NULL, 55 ERROR_INVALID_JPEG_CONFIG, 56 ERROR_IN_BUFFER_CREATE_FAIL, 57 ERROR_OUT_BUFFER_CREATE_FAIL, 58 ERROR_EXCUTE_FAIL, 59 ERROR_JPEG_SIZE_TOO_SMALL, 60 ERROR_CANNOT_CHANGE_CACHE_SETTING, 61 ERROR_SIZE_NOT_SET_YET, 62 ERROR_BUFFR_IS_NULL, 63 ERROR_BUFFER_TOO_SMALL, 64 ERROR_GET_SIZE_FAIL, 65 ERROR_REQBUF_FAIL, 66 ERROR_INVALID_V4l2_BUF_TYPE = -0x80, 67 ERROR_MMAP_FAILED, 68 ERROR_FAIL, 69 ERROR_NONE = 0 70 }; 71 72 ExynosJpegEncoderForCamera(); 73 virtual ~ExynosJpegEncoderForCamera(); 74 75 bool flagCreate(); 76 int create(void); 77 int destroy(void); 78 79 int setSize(int w, int h); 80 int setQuality(int quality); 81 int setColorFormat(int colorFormat); 82 int setJpegFormat(int jpegFormat); 83 84 int updateConfig(void); 85 86 int setInBuf(int *buf, char** vBuf, int *size); 87 int setOutBuf(int buf, char* vBuf, int size); 88 89 int encode(int *size, exif_attribute_t *exifInfo); 90 91 int setThumbnailSize(int w, int h); 92 int setThumbnailQuality(int quality); 93 94 int makeExif(unsigned char *exifOut, 95 exif_attribute_t *exifIn, 96 unsigned int *size, 97 bool useMainbufForThumb = false); 98 99 private: 100 inline void writeExifIfd(unsigned char **pCur, 101 unsigned short tag, 102 unsigned short type, 103 unsigned int count, 104 uint32_t value); 105 inline void writeExifIfd(unsigned char **pCur, 106 unsigned short tag, 107 unsigned short type, 108 unsigned int count, 109 unsigned char *pValue); 110 inline void writeExifIfd(unsigned char **pCur, 111 unsigned short tag, 112 unsigned short type, 113 unsigned int count, 114 rational_t *pValue, 115 unsigned int *offset, 116 unsigned char *start); 117 inline void writeExifIfd(unsigned char **pCur, 118 unsigned short tag, 119 unsigned short type, 120 unsigned int count, 121 unsigned char *pValue, 122 unsigned int *offset, 123 unsigned char *start); 124 int scaleDownYuv422(char **srcBuf, unsigned int srcW, unsigned int srcH, 125 char **dstBuf, unsigned int dstW, unsigned int dstH); 126 int scaleDownYuv422_2p(char **srcBuf, unsigned int srcW, unsigned int srcH, 127 char **dstBuf, unsigned int dstW, unsigned int dstH); 128 // thumbnail 129 int encodeThumbnail(unsigned int *size, bool useMain = true); 130 131 struct stJpegMem { 132 ion_client ionClient; 133 ion_buffer ionBuffer[MAX_IMAGE_PLANE_NUM]; 134 char *pcBuf[MAX_IMAGE_PLANE_NUM]; 135 int iSize[MAX_IMAGE_PLANE_NUM]; 136 }; 137 138 int createIonClient(ion_client ionClient); 139 int deleteIonClient(ion_client ionClient); 140 int allocJpegMemory(struct stJpegMem *pstMem, int iMemoryNum); 141 void freeJpegMemory(struct stJpegMem *pstMem, int iMemoryNum); 142 void initJpegMemory(struct stJpegMem *pstMem, int iMemoryNum); 143 144 bool m_flagCreate; 145 146 ExynosJpegEncoder *m_jpegMain; 147 ExynosJpegEncoder *m_jpegThumb; 148 149 ion_client m_ionJpegClient; 150 struct stJpegMem m_stThumbInBuf; 151 struct stJpegMem m_stThumbOutBuf; 152 struct stJpegMem m_stMainInBuf; 153 struct stJpegMem m_stMainOutBuf; 154 155 int m_thumbnailW; 156 int m_thumbnailH; 157 int m_thumbnailQuality; 158 }; 159 160 #endif /* __SEC_JPG_ENC_H__ */ 161