blob: a1302fd73be2128809a3a651040155b84393d188 [file] [log] [blame]
Chirayu Desai0a336cc2012-07-12 14:37:05 +05301/*
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 * JPEG DRIVER MODULE (JpegEncoder.h)
18 * Author : ge.lee -- initial version
19 * Date : 03 June 2010
20 * Purpose : This file implements the JPEG encoder APIs as needed by Camera HAL
21 */
22#ifndef __JPG_API_H__
23#define __JPG_API_H__
24
25#include <stdint.h>
26#include <sys/ioctl.h>
27
28#include "Exif.h"
29
30namespace android {
Pawit Pornkitprasan674a4f12014-01-03 19:13:37 +070031
32#define LEGACY_SUPPORT
33#ifdef LEGACY_SUPPORT
34
Chirayu Desai0a336cc2012-07-12 14:37:05 +053035#define MAX_JPG_WIDTH 800
36#define MAX_JPG_HEIGHT 480
37#define MAX_JPG_RESOLUTION (MAX_JPG_WIDTH * MAX_JPG_HEIGHT)
38
39#define MAX_JPG_THUMBNAIL_WIDTH 320
40#define MAX_JPG_THUMBNAIL_HEIGHT 240
41#define MAX_JPG_THUMBNAIL_RESOLUTION (MAX_JPG_THUMBNAIL_WIDTH * \
42 MAX_JPG_THUMBNAIL_HEIGHT)
43
44#define MAX_RGB_WIDTH 800
45#define MAX_RGB_HEIGHT 480
46#define MAX_RGB_RESOLUTION (MAX_RGB_WIDTH * MAX_RGB_HEIGHT)
47
48/*******************************************************************************/
49/* define JPG & image memory */
50/* memory area is 4k(PAGE_SIZE) aligned because of VirtualCopyEx() */
51#define JPG_STREAM_BUF_SIZE \
52 (MAX_JPG_RESOLUTION / PAGE_SIZE + 1) * PAGE_SIZE
53#define JPG_STREAM_THUMB_BUF_SIZE \
54 (MAX_JPG_THUMBNAIL_RESOLUTION / PAGE_SIZE + 1) * PAGE_SIZE
55#define JPG_FRAME_BUF_SIZE \
56 ((MAX_JPG_RESOLUTION * 3) / PAGE_SIZE + 1) * PAGE_SIZE
57#define JPG_FRAME_THUMB_BUF_SIZE \
58 ((MAX_JPG_THUMBNAIL_RESOLUTION * 3) / PAGE_SIZE + 1) * PAGE_SIZE
59#define JPG_RGB_BUF_SIZE \
60 ((MAX_RGB_RESOLUTION * 4) / PAGE_SIZE + 1) * PAGE_SIZE
61
62#define JPG_TOTAL_BUF_SIZE (JPG_STREAM_BUF_SIZE + \
63 JPG_STREAM_THUMB_BUF_SIZE + \
64 JPG_FRAME_BUF_SIZE + \
65 JPG_FRAME_THUMB_BUF_SIZE + \
66 JPG_RGB_BUF_SIZE)
67
68#define JPG_MAIN_START 0x00
69#define JPG_THUMB_START JPG_STREAM_BUF_SIZE
70#define IMG_MAIN_START (JPG_STREAM_BUF_SIZE + JPG_STREAM_THUMB_BUF_SIZE)
71#define IMG_THUMB_START (IMG_MAIN_START + JPG_FRAME_BUF_SIZE)
72/*******************************************************************************/
Pawit Pornkitprasan674a4f12014-01-03 19:13:37 +070073#endif
Chirayu Desai0a336cc2012-07-12 14:37:05 +053074
75#define JPG_DRIVER_NAME "/dev/s3c-jpg"
76
77#define JPEG_IOCTL_MAGIC 'J'
78#define IOCTL_JPG_DECODE _IO(JPEG_IOCTL_MAGIC, 1)
79#define IOCTL_JPG_ENCODE _IO(JPEG_IOCTL_MAGIC, 2)
80#define IOCTL_JPG_GET_STRBUF _IO(JPEG_IOCTL_MAGIC, 3)
81#define IOCTL_JPG_GET_FRMBUF _IO(JPEG_IOCTL_MAGIC, 4)
82#define IOCTL_JPG_GET_THUMB_STRBUF _IO(JPEG_IOCTL_MAGIC, 5)
83#define IOCTL_JPG_GET_THUMB_FRMBUF _IO(JPEG_IOCTL_MAGIC, 6)
84#define IOCTL_JPG_GET_PHY_FRMBUF _IO(JPEG_IOCTL_MAGIC, 7)
85#define IOCTL_JPG_GET_PHY_THUMB_FRMBUF _IO(JPEG_IOCTL_MAGIC, 8)
Pawit Pornkitprasan674a4f12014-01-03 19:13:37 +070086#define IOCTL_JPG_GET_INFO _IO(JPEG_IOCTL_MAGIC, 9)
Chirayu Desai0a336cc2012-07-12 14:37:05 +053087
88typedef enum {
89 JPEG_SET_ENCODE_WIDTH,
90 JPEG_SET_ENCODE_HEIGHT,
91 JPEG_SET_ENCODE_QUALITY,
92 JPEG_SET_ENCODE_IN_FORMAT,
93 JPEG_SET_SAMPING_MODE,
94 JPEG_SET_THUMBNAIL_WIDTH,
95 JPEG_SET_THUMBNAIL_HEIGHT
96} jpeg_conf;
97
98typedef enum {
99 JPG_FAIL,
100 JPG_SUCCESS,
101 OK_HD_PARSING,
102 ERR_HD_PARSING,
103 OK_ENC_OR_DEC,
104 ERR_ENC_OR_DEC,
105 ERR_UNKNOWN
106} jpg_return_status;
107
108typedef enum {
109 JPG_RGB16,
110 JPG_YCBYCR,
111 JPG_TYPE_UNKNOWN
112} image_type_t;
113
114typedef enum {
115 JPG_444,
116 JPG_422,
117 JPG_420,
118 JPG_400,
119 RESERVED1,
120 RESERVED2,
121 JPG_411,
122 JPG_SAMPLE_UNKNOWN
123} sample_mode_t;
124
125typedef enum {
126 YCBCR_422,
127 YCBCR_420,
128 YCBCR_SAMPLE_UNKNOWN
129} out_mode_t;
130
131typedef enum {
132 JPG_MODESEL_YCBCR = 1,
133 JPG_MODESEL_RGB,
134 JPG_MODESEL_UNKNOWN
135} in_mode_t;
136
137typedef enum {
138 JPG_MAIN,
139 JPG_THUMBNAIL
140} encode_type_t;
141
142typedef enum {
143 JPG_QUALITY_LEVEL_1, /* high */
144 JPG_QUALITY_LEVEL_2,
145 JPG_QUALITY_LEVEL_3,
146 JPG_QUALITY_LEVEL_4 /* low */
147} image_quality_type_t;
148
149typedef struct {
150 sample_mode_t sample_mode;
151 encode_type_t dec_type;
152 out_mode_t out_format;
153 uint32_t width;
154 uint32_t height;
155 uint32_t data_size;
156 uint32_t file_size;
157} jpg_dec_proc_param;
158
159typedef struct {
160 sample_mode_t sample_mode;
161 encode_type_t enc_type;
162 in_mode_t in_format;
163 image_quality_type_t quality;
164 uint32_t width;
165 uint32_t height;
166 uint32_t data_size;
167 uint32_t file_size;
168 uint32_t set_framebuf;
169} jpg_enc_proc_param;
170
171typedef struct {
172 char *in_buf;
173 char *phy_in_buf;
174 int in_buf_size;
175 char *out_buf;
176 char *phy_out_buf;
177 int out_buf_size;
178 char *in_thumb_buf;
179 char *phy_in_thumb_buf;
180 int in_thumb_buf_size;
181 char *out_thumb_buf;
182 char *phy_out_thumb_buf;
183 int out_thumb_buf_size;
184 char *mmapped_addr;
185 jpg_dec_proc_param *dec_param;
186 jpg_enc_proc_param *enc_param;
187 jpg_enc_proc_param *thumb_enc_param;
188} jpg_args;
189
Pawit Pornkitprasan674a4f12014-01-03 19:13:37 +0700190typedef struct {
191 unsigned int frame_buf_size;
192 unsigned int thumb_frame_buf_size;
193 unsigned int stream_buf_size;
194 unsigned int thumb_stream_buf_size;
195 unsigned int total_buf_size;
196 int max_width;
197 int max_height;
198 int max_thumb_width;
199 int max_thumb_height;
200} jpg_info;
201
Chirayu Desai0a336cc2012-07-12 14:37:05 +0530202class JpegEncoder {
203public:
204 JpegEncoder();
205 virtual ~JpegEncoder();
206
207 int openHardware();
208 jpg_return_status setConfig(jpeg_conf type, int32_t value);
209 void *getInBuf(uint64_t size);
210 void *getOutBuf(uint64_t *size);
211 void *getThumbInBuf(uint64_t size);
212 void *getThumbOutBuf(uint64_t *size);
213 jpg_return_status encode(unsigned int *size, exif_attribute_t *exifInfo);
214 jpg_return_status encodeThumbImg(unsigned int *size, bool useMain = true);
215 jpg_return_status makeExif(unsigned char *exifOut,
216 exif_attribute_t *exifIn,
217 unsigned int *size,
218 bool useMainbufForThumb = false);
219
220private:
221 jpg_return_status checkMcu(sample_mode_t sampleMode, uint32_t width, uint32_t height, bool isThumb);
222 bool pad(char *srcBuf, uint32_t srcWidth, uint32_t srcHight,
223 char *dstBuf, uint32_t dstWidth, uint32_t dstHight);
224 bool scaleDownYuv422(char *srcBuf, uint32_t srcWidth, uint32_t srcHight,
225 char *dstBuf, uint32_t dstWidth, uint32_t dstHight);
226
227 inline void writeExifIfd(unsigned char **pCur,
228 unsigned short tag,
229 unsigned short type,
230 unsigned int count,
231 uint32_t value);
232 inline void writeExifIfd(unsigned char **pCur,
233 unsigned short tag,
234 unsigned short type,
235 unsigned int count,
236 unsigned char *pValue);
237 inline void writeExifIfd(unsigned char **pCur,
238 unsigned short tag,
239 unsigned short type,
240 unsigned int count,
241 rational_t *pValue,
242 unsigned int *offset,
243 unsigned char *start);
244 inline void writeExifIfd(unsigned char **pCur,
245 unsigned short tag,
246 unsigned short type,
247 unsigned int count,
248 unsigned char *pValue,
249 unsigned int *offset,
250 unsigned char *start);
251 int mDevFd;
252 jpg_args mArgs;
Pawit Pornkitprasan674a4f12014-01-03 19:13:37 +0700253 jpg_info mInfo;
Chirayu Desai0a336cc2012-07-12 14:37:05 +0530254
255 bool available;
256
257};
258};
259#endif /* __JPG_API_H__ */