blob: c7390f9e57c0e551e7928d117f956a800106484f [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
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 __SEC_JPG_ENC_H__
19#define __SEC_JPG_ENC_H__
20
21#include "Exif.h"
22
23#include "SecJpegCodecHal.h"
24
25#include <sys/mman.h>
26#include "ion.h"
27
28#define JPEG_THUMBNAIL_QUALITY 60
29#define EXIF_LIMIT_SIZE 64*1024
30//#define JPEG_WA_FOR_PAGEFAULT
31#define JPEG_WA_BUFFER_SIZE 64
32
33class SecJpegEncoder {
34public :
35 ;
36 enum ERROR {
37 ERROR_ALREADY_CREATE = -0x200,
38 ERROR_CANNOT_CREATE_SEC_JPEG_ENC_HAL,
39 ERROR_NOT_YET_CREATED,
40 ERROR_ALREADY_DESTROY,
41 ERROR_INPUT_DATA_SIZE_TOO_LARGE,
42 ERROR_OUT_BUFFER_SIZE_TOO_SMALL,
43 ERROR_EXIFOUT_ALLOC_FAIL,
44 ERROR_MAKE_EXIF_FAIL,
45 ERROR_INVALID_SCALING_WIDTH_HEIGHT,
46 ERROR_CANNOT_CREATE_SEC_THUMB,
47 ERROR_THUMB_JPEG_SIZE_TOO_SMALL,
48 ERROR_IMPLEMENT_NOT_YET,
49 ERROR_JPEG_DEVICE_ALREADY_CREATE = -0x100,
50 ERROR_CANNOT_OPEN_JPEG_DEVICE,
51 ERROR_JPEG_DEVICE_ALREADY_CLOSED,
52 ERROR_JPEG_DEVICE_ALREADY_DESTROY,
53 ERROR_JPEG_DEVICE_NOT_CREATE_YET,
54 ERROR_INVALID_COLOR_FORMAT,
55 ERROR_INVALID_JPEG_FORMAT,
56 ERROR_JPEG_CONFIG_POINTER_NULL,
57 ERROR_INVALID_JPEG_CONFIG,
58 ERROR_IN_BUFFER_CREATE_FAIL,
59 ERROR_OUT_BUFFER_CREATE_FAIL,
60 ERROR_EXCUTE_FAIL,
61 ERROR_JPEG_SIZE_TOO_SMALL,
62 ERROR_CANNOT_CHANGE_CACHE_SETTING,
63 ERROR_SIZE_NOT_SET_YET,
64 ERROR_BUFFR_IS_NULL,
65 ERROR_BUFFER_TOO_SMALL,
66 ERROR_GET_SIZE_FAIL,
67 ERROR_REQBUF_FAIL,
68 ERROR_INVALID_V4l2_BUF_TYPE = -0x80,
69 ERROR_MMAP_FAILED,
70 ERROR_FAIL,
71 ERROR_NONE = 0
72 };
73
74 SecJpegEncoder();
75 virtual ~SecJpegEncoder();
76
77 bool flagCreate();
78 int create(void);
79 int destroy(void);
80
81 int setSize(int w, int h);
82 int setQuality(int quality);
83 int setColorFormat(int colorFormat);
84 int setJpegFormat(int jpegFormat);
85
86 int updateConfig(void);
87
88 char *getInBuf(int *input_size);
89 char *getOutBuf(int *output_size);
90 int setInBuf(char *buf, int size);
91 int setOutBuf(char *buf, int size);
92
93 int encode(int *size, exif_attribute_t *exifInfo);
94
95 int setThumbnailSize(int w, int h);
96
97 int makeExif(unsigned char *exifOut,
98 exif_attribute_t *exifIn,
99 unsigned int *size,
100 bool useMainbufForThumb = false);
101
102private:
103 inline void writeExifIfd(unsigned char **pCur,
104 unsigned short tag,
105 unsigned short type,
106 unsigned int count,
107 uint32_t value);
108 inline void writeExifIfd(unsigned char **pCur,
109 unsigned short tag,
110 unsigned short type,
111 unsigned int count,
112 unsigned char *pValue);
113 inline void writeExifIfd(unsigned char **pCur,
114 unsigned short tag,
115 unsigned short type,
116 unsigned int count,
117 rational_t *pValue,
118 unsigned int *offset,
119 unsigned char *start);
120 inline void writeExifIfd(unsigned char **pCur,
121 unsigned short tag,
122 unsigned short type,
123 unsigned int count,
124 unsigned char *pValue,
125 unsigned int *offset,
126 unsigned char *start);
127 int m_scaleDownYuv422(char *srcBuf, uint32_t srcWidth, uint32_t srcHight,
128 char *dstBuf, uint32_t dstWidth, uint32_t dstHight);
129 // thumbnail
130 int encodeThumbnail(unsigned int *size, bool useMain = true);
131
132 int allocJpegIonMemory(ion_client ionClient, ion_buffer *ionBuffer, char **buffer, int size);
133 void freeJpegIonMemory(ion_client ionClient, ion_buffer *ionBuffer, char **buffer, int size);
134
135 bool m_flagCreate;
136
137 SecJpegEncoderHal *m_jpegMain;
138 SecJpegEncoderHal *m_jpegThumb;
139
140 char *m_pThumbInputBuffer;
141 char *m_pThumbOutputBuffer;
142#ifdef JPEG_WA_FOR_PAGEFAULT
143 char *m_pExtInBuf;
144 char *m_pJpegInputBuffer;
145 int m_iInBufSize;
146#endif // JPEG_WA_FOR_PAGEFAULT
147 ion_client m_ionJpegClient;
148 ion_buffer m_ionThumbInBuffer, m_ionThumbOutBuffer;
149#ifdef JPEG_WA_FOR_PAGEFAULT
150 ion_buffer m_ionJpegInBuffer;
151#endif // JPEG_WA_FOR_PAGEFAULT
152
153 int m_thumbnailW;
154 int m_thumbnailH;
155};
156
157#endif /* __SEC_JPG_ENC_H__ */