1 /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef MM_JPEG_INTERFACE_H_
30 #define MM_JPEG_INTERFACE_H_
31 #include "QCamera_Intf.h"
32 
33 typedef struct {
34     int width;
35     int height;
36 } image_resolution;
37 
38 typedef enum {
39     JPEG_SRC_IMAGE_FMT_YUV,
40     JPEG_SRC_IMAGE_FMT_BITSTREAM
41 } jpeg_enc_src_img_fmt_t;
42 
43 typedef enum {
44     JPEG_SRC_IMAGE_TYPE_MAIN,
45     JPEG_SRC_IMAGE_TYPE_THUMB,
46     JPEG_SRC_IMAGE_TYPE_MAX
47 } jpeg_enc_src_img_type_t;
48 
49 typedef struct  {
50     int32_t offset_x;
51     int32_t offset_y;
52     int32_t width;
53     int32_t height;
54 } image_crop_t;
55 
56 typedef struct {
57     uint8_t sequence;                /*for jpeg bit streams, assembling is based on sequence. sequence starts from 0*/
58     uint8_t *buf_vaddr;              /*ptr to buf*/
59     int fd;                          /*fd of buf*/
60     uint32_t buf_size;               /* total size of buf (header + image) */
61     uint32_t data_offset;            /*data offset*/
62 } src_bitstream_buffer_t;
63 
64 typedef struct {
65     uint8_t *buf_vaddr;              /*ptr to buf*/
66     int fd;                          /*fd of buf*/
67     cam_frame_len_offset_t offset;   /*alway use multi-planar, offset is used to skip the metadata header*/
68 } src_image_buffer_t;
69 
70 typedef enum {
71     MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2,
72     MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2,
73     MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1,
74     MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1,
75     MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2,
76     MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2,
77     MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1,
78     MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1,
79     MM_JPEG_COLOR_FORMAT_RGB565,
80     MM_JPEG_COLOR_FORMAT_RGB888,
81     MM_JPEG_COLOR_FORMAT_RGBa,
82     MM_JPEG_COLOR_FORMAT_BITSTREAM,
83     MM_JPEG_COLOR_FORMAT_MAX
84 } mm_jpeg_color_format;
85 
86 #define MAX_SRC_BUF_NUM 2
87 typedef struct {
88     /* src img format: YUV, Bitstream */
89     jpeg_enc_src_img_fmt_t img_fmt;
90 
91 	/* num of buf in src img */
92     uint8_t num_bufs;
93 
94 	/* src img bufs */
95     union {
96         src_bitstream_buffer_t bit_stream[MAX_SRC_BUF_NUM];
97         src_image_buffer_t src_image[MAX_SRC_BUF_NUM];
98     };
99 
100     /* src img type: main or thumbnail */
101     jpeg_enc_src_img_type_t type;
102 
103     /* color format */
104     mm_jpeg_color_format color_format;
105 
106     /* src img dimension */
107     image_resolution src_dim;
108 
109     /* jpeg output dimension */
110     image_resolution out_dim;
111 
112     /* crop information */
113     image_crop_t crop;
114 
115     /* jpeg quality: range 0~100 */
116     uint32_t quality;
117 } src_image_buffer_info;
118 
119 typedef struct {
120   uint8_t *buf_vaddr;              /*ptr to buf*/
121   int fd;                          /*fd of buf*/
122   int buf_len;
123 } out_image_buffer_info;
124 
125 typedef struct {
126     /* num of src imgs: e.g. main/thumbnail img
127      * if main img only: src_img_num = 1;
128      * if main+thumbnail: src_img_num = 2;
129      * No support for thumbnail only case */
130     uint8_t src_img_num;
131 
132     /* index 0 is always for main image
133      * if thumbnail presented, it will be in index 1 */
134     src_image_buffer_info src_img[JPEG_SRC_IMAGE_TYPE_MAX];
135 
136     /* flag indicating if buffer is from video stream (special case for video-sized live snapshot) */
137     uint8_t is_video_frame;
138 } src_image_buffer_config;
139 
140 typedef struct {
141     src_image_buffer_config src_imgs;
142     out_image_buffer_info sink_img;
143 } jpeg_image_buffer_config;
144 
145 typedef struct {
146     /* config for scr images */
147     jpeg_image_buffer_config buf_info;
148 
149     /* rotation informaiton */
150     int rotation;
151 
152     /* num of exif entries */
153     int exif_numEntries;
154 
155     /* buf to exif entries, caller needs to
156      * take care of the memory manage with insider ptr */
157     exif_tags_info_t *exif_data;
158 
159     /*for mobicat support*/
160     const uint8_t * mobicat_data;
161     int32_t mobicat_data_length;
162     int hasmobicat;
163 } mm_jpeg_encode_params;
164 
165 typedef enum {
166   JPEG_JOB_STATUS_DONE = 0,
167   JPEG_JOB_STATUS_ERROR
168 } jpeg_job_status_t;
169 
170 typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status,
171                                        uint8_t thumbnailDroppedFlag,
172                                        uint32_t client_hdl,
173                                        uint32_t jobId,
174                                        uint8_t* out_data,
175                                        uint32_t data_size,
176                                        void *userData);
177 
178 typedef struct {
179     mm_jpeg_encode_params encode_parm;
180     jpeg_encode_callback_t jpeg_cb;
181     void* userdata;
182 } mm_jpeg_encode_job;
183 
184 typedef enum {
185     JPEG_JOB_TYPE_ENCODE,
186     //JPEG_JOB_TYPE_DECODE, /*enable decode later*/
187     JPEG_JOB_TYPE_MAX
188 } mm_jpeg_job_type_t;
189 
190 typedef struct {
191     mm_jpeg_job_type_t job_type;
192     union {
193         mm_jpeg_encode_job encode_job;
194     };
195 } mm_jpeg_job;
196 
197 typedef struct {
198     /* start a job -- async call
199      * the result of job (DONE/ERROR) will rcvd through CB */
200     int32_t (* start_job) (uint32_t client_hdl, mm_jpeg_job* job, uint32_t* jobId);
201 
202     /* abort a job -- sync call */
203     int32_t  (* abort_job) (uint32_t client_hdl, uint32_t jobId);
204 
205     /* close a jpeg client -- sync call */
206     int32_t  (* close) (uint32_t clientHdl);
207 } mm_jpeg_ops_t;
208 
209 /* open a jpeg client -- sync call
210  * returns client_handle.
211  * failed if client_handle=0
212  * jpeg ops tbl will be filled in if open succeeds */
213 uint32_t jpeg_open(mm_jpeg_ops_t *ops);
214 
215 #endif /* MM_JPEG_INTERFACE_H_ */
216 
217 
218