1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - SSP - include
3   File:     jpegenc.h
4 
5   Copyright 2007-2009 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date:: 2009-06-04#$
14   $Rev: 10698 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef TWL_SSP_JPEGENC_H_
19 #define TWL_SSP_JPEGENC_H_
20 
21 #include <twl/ssp/common/ssp_jpeg_type.h>
22 #include <twl/ssp/ARM9/exifenc.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include <twl/types.h>
29 
30 /*---------------------------------------------------------------------------*
31   Name:         SSP_GetJpegEncoderBufferSize
32 
33   Description:  Returns the work size required for encoding.
34 
35   Arguments:    width: Image width
36                 height: Image height
37                 sampling: Sampling (1 or 2)
38                 option: Options (bitwise logical OR)
39                            SSP_JPEG_RGB555: Encode from the RGB555 format.
40                            SSP_JPEG_YUV422: Encode from the YUV422 format.
41                                   If unspecified, the format is considered to be RGB555.
42                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
43 
44   Returns:      The required memory size.
45  *---------------------------------------------------------------------------*/
46 u32 SSP_GetJpegEncoderBufferSize(u32 width, u32 height, u32 sampling, u32 option);
47 
48 /*---------------------------------------------------------------------------*
49   Name:         SSP_StartJpegEncoder
50 
51   Description:  Encodes a JPEG.
52                 The width and height values must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
53                 The src, dst, and wrk values must be 4-byte aligned.
54 
55 
56   Arguments:    src: Image data (RGB555/YUV422 data from the upper left to the lower right)
57                 dst: Location to put the encoded JPEG data
58                 limit: Size limit for dst (encoding will fail if this is exceeded)
59                 wrk: Work area
60                 width: Image width
61                 height: Image height
62                 quality: Encoding quality (1-100)
63                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
64                 option: Options (bitwise logical OR)
65                            SSP_JPEG_RGB555: Encode from the RGB555 format.
66                            SSP_JPEG_YUV422: Encode from the YUV422 format.
67                                   If unspecified, the format is considered to be RGB555.
68                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
69 
70   Returns:      Encoded JPEG size (when this is 0, encoding failed).
71  *---------------------------------------------------------------------------*/
72 u32 SSP_StartJpegEncoder(const void* src, u8 *dst, u32 limit, u8 *wrk,
73                          u32 width, u32 height,
74                          u32 quality, u32 sampling, u32 option);
75 
76 /*---------------------------------------------------------------------------*
77   Name:         SSP_StartJpegEncoderEx
78 
79   Description:  Specifies whether to use a signature and encodes a JPEG.
80                 The width and height values must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
81                 The src, dst, and wrk values must be 4-byte aligned.
82 
83 
84   Arguments:    src: Image data (RGB555/YUV422 data from the upper left to the lower right)
85                 dst: Location to put the encoded JPEG data
86                 limit: Size limit for dst (encoding will fail if this is exceeded)
87                 wrk: Work area
88                 width: Image width
89                 height: Image height
90                 quality: Encoding quality (1-100)
91                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
92                 option: Options (bitwise logical OR)
93                            SSP_JPEG_RGB555: Encode from the RGB555 format.
94                            SSP_JPEG_YUV422: Encode from the YUV422 format.
95                                   If unspecified, the format is considered to be RGB555.
96                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
97                 sign: Specify TRUE to add a signature
98 
99   Returns:      Encoded JPEG size (when this is 0, encoding failed).
100  *---------------------------------------------------------------------------*/
SSP_StartJpegEncoderEx(const void * src,u8 * dst,u32 limit,u8 * wrk,u32 width,u32 height,u32 quality,u32 sampling,u32 option,BOOL sign)101 static inline u32 SSP_StartJpegEncoderEx(const void* src, u8 *dst, u32 limit, u8 *wrk,
102                          u32 width, u32 height,
103                          u32 quality, u32 sampling, u32 option, BOOL sign)
104 {
105     u32 result;
106     BOOL old_sign;
107 
108     old_sign = SSP_SetJpegEncoderSignMode(sign);
109     result = SSP_StartJpegEncoder(src, dst, limit, wrk, width, height, quality, sampling, option);
110     (void)SSP_SetJpegEncoderSignMode(old_sign);
111 
112     return result;
113 }
114 
115 /*---------------------------------------------------------------------------*
116   Name:         SSP_ConvertJpegEncodeData
117 
118   Description:  Converts input data into a format used to perform JPEG encoding.
119                 The input data can be cleared after this function has finished.
120                 The width and height value must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
121                 The src, dst, and wrk value must be 4-byte aligned.
122 
123 
124   Arguments:    src: Image data (RGB555/YUV422 data from the upper left to the lower right)
125                 wrk: Work area
126                 width: Image width
127                 height: Image height
128                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
129                 option: Options (bitwise logical OR)
130                            SSP_JPEG_RGB555: Encode from the RGB555 format.
131                            SSP_JPEG_YUV422: Encode from the YUV422 format.
132                                   If unspecified, the format is considered to be RGB555.
133                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
134 
135   Returns:      TRUE on success.
136  *---------------------------------------------------------------------------*/
137 BOOL SSP_ConvertJpegEncodeData(const void* src, u8 *wrk,
138                          u32 width, u32 height, u32 sampling, u32 option);
139 
140 /*---------------------------------------------------------------------------*
141   Name:         SSP_StartJpegEncoderWithEncodeData
142 
143   Description:  Encodes a JPEG from data that was converted in advance for encoding.
144                 You must call the SSP_ConvertJpegEncodeData function before this one.
145                 The width and height values must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
146                 The dst and wrk values must be 4-byte aligned.
147 
148 
149   Arguments:    dst: Location to put the encoded JPEG data
150                 limit: Size limit for dst (encoding will fail if this is exceeded)
151                 wrk: Work area
152                 width: Image width
153                 height: Image height
154                 quality: Encoding quality (1-100)
155                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
156                 option: Options (bitwise logical OR)
157                            SSP_JPEG_RGB555: Encode from the RGB555 format.
158                            SSP_JPEG_YUV422: Encode from the YUV422 format.
159                                   If unspecified, the format is considered to be RGB555.
160                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
161 
162   Returns:      Encoded JPEG size (when this is 0, encoding failed).
163  *---------------------------------------------------------------------------*/
164 u32 SSP_StartJpegEncoderWithEncodeData(u8 *dst, u32 limit, u8 *wrk,
165                          u32 width, u32 height,
166                          u32 quality, u32 sampling, u32 option);
167 
168 /*---------------------------------------------------------------------------*
169   Name:         SSP_StartJpegEncoderWithEncodeDataEx
170 
171   Description:  Specifies whether to use a signature and encodes a JPEG from data that was converted in advance for encoding.
172                 You must call the SSP_ConvertJpegEncodeData function before this one.
173                 The width and height values must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
174                 The dst and wrk values must be 4-byte aligned.
175 
176 
177   Arguments:    dst: Location to put the encoded JPEG data
178                 limit: Size limit for dst (encoding will fail if this is exceeded)
179                 wrk: Work area
180                 width: Image width
181                 height: Image height
182                 quality: Encoding quality (1-100)
183                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
184                 option: Options (bitwise logical OR)
185                            SSP_JPEG_RGB555: Encode from the RGB555 format.
186                            SSP_JPEG_YUV422: Encode from the YUV422 format.
187                                   If unspecified, the format is considered to be RGB555.
188                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
189                 sign: Specify TRUE to add a signature
190 
191   Returns:      Encoded JPEG size (when this is 0, encoding failed).
192  *---------------------------------------------------------------------------*/
SSP_StartJpegEncoderWithEncodeDataEx(u8 * dst,u32 limit,u8 * wrk,u32 width,u32 height,u32 quality,u32 sampling,u32 option,BOOL sign)193 static inline u32 SSP_StartJpegEncoderWithEncodeDataEx(u8 *dst, u32 limit, u8 *wrk,
194                          u32 width, u32 height,
195                          u32 quality, u32 sampling, u32 option, BOOL sign)
196 {
197     u32 result;
198     BOOL old_sign;
199 
200     old_sign = SSP_SetJpegEncoderSignMode(sign);
201     result = SSP_StartJpegEncoderWithEncodeData(dst, limit, wrk, width, height, quality, sampling, option);
202     (void)SSP_SetJpegEncoderSignMode(old_sign);
203 
204     return result;
205 }
206 
207 /*---------------------------------------------------------------------------*
208   Name:         SSP_GetJpegEncoderLiteBufferSize
209 
210   Description:  Returns the work size required for encoding (reduced-memory version).
211                 This work size is used by SSP_StartJpegEncoderLite.
212 
213   Arguments:    option: Options (bitwise logical OR)
214                            SSP_JPEG_RGB555: Encode from the RGB555 format.
215                            SSP_JPEG_YUV422: Encode from the YUV422 format.
216                                   If unspecified, the format is considered to be RGB555.
217                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
218 
219   Returns:      The required memory size.
220  *---------------------------------------------------------------------------*/
221 u32 SSP_GetJpegEncoderLiteBufferSize(u32 option);
222 
223 /*---------------------------------------------------------------------------*
224   Name:         SSP_StartJpegEncoderLite
225 
226   Description:  Encodes a JPEG (reduced-memory version).
227                 Note: This is unrelated to SSP_StartJpegEncoderEx.
228                 The width and height values must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
229                 The width value must be a multiple of 16, and the height value must be a multiple of 8 if sampling is 3.
230 
231                 The src, dst, and wrk values must be 4-byte aligned.
232 
233   Arguments:    src: Image data (RGB555/YUV422 data from the upper left to the lower right)
234                 dst: Location to put the encoded JPEG data
235                 limit: Size limit for dst (encoding will fail if this is exceeded)
236                 wrk: Work area
237                 width: Image width
238                 height: Image height
239                 quality: Encoding quality (1-100)
240                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
241                 option: Options (bitwise logical OR)
242                            SSP_JPEG_RGB555: Encode from the RGB555 format.
243                            SSP_JPEG_YUV422: Encode from the YUV422 format.
244                                   Failure to specify a format will result in an error.
245                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
246 
247   Returns:      Encoded JPEG size (when this is 0, encoding failed).
248  *---------------------------------------------------------------------------*/
249 u32 SSP_StartJpegEncoderLite(const void* src, u8 *dst, u32 limit, u8 *wrk,
250                              u32 width, u32 height,
251                              u32 quality, u32 sampling, u32 option);
252 
253 /*---------------------------------------------------------------------------*
254   Name:         SSP_StartJpegEncoderLiteEx
255 
256   Description:  Encodes a JPEG (reduced-memory version).
257                 Note: This is unrelated to SSP_StartJpegEncoderEx.
258                 The width and height value must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
259                 The width value must be a multiple of 16, and the height value must be a multiple of 8 if sampling is 3.
260 
261                 The src, dst, and wrk value must be 4-byte aligned.
262 
263   Arguments:    src: Image data (RGB555/YUV422 data from the upper left to the lower right)
264                 dst: Location to put the encoded JPEG data
265                 limit: Size limit for dst (encoding will fail if this is exceeded)
266                 wrk: Work area
267                 width: Image width
268                 height: Image height
269                 quality: Encoding quality (1-100)
270                 sampling: Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
271                 option: Options (bitwise logical OR)
272                            SSP_JPEG_RGB555: Encode from the RGB555 format.
273                            SSP_JPEG_YUV422: Encode from the YUV422 format.
274                                   Failure to specify a format will result in an error.
275                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
276                 sign: Specify TRUE to add a signature
277 
278   Returns:      Encoded JPEG size (when this is 0, encoding failed).
279  *---------------------------------------------------------------------------*/
SSP_StartJpegEncoderLiteEx(const void * src,u8 * dst,u32 limit,u8 * wrk,u32 width,u32 height,u32 quality,u32 sampling,u32 option,BOOL sign)280 static inline u32 SSP_StartJpegEncoderLiteEx(const void* src, u8 *dst, u32 limit, u8 *wrk,
281                              u32 width, u32 height,
282                              u32 quality, u32 sampling, u32 option, BOOL sign)
283 {
284     u32 result;
285     BOOL old_sign;
286 
287     old_sign = SSP_SetJpegEncoderSignMode(sign);
288     result = SSP_StartJpegEncoderLite(src, dst, limit, wrk, width, height, quality, sampling, option);
289     (void)SSP_SetJpegEncoderSignMode(old_sign);
290 
291     return result;
292 }
293 
294 #ifdef __cplusplus
295 } /* extern "C" */
296 #endif
297 
298 /* TWL_SSP_JPEGENC_H_ */
299 #endif
300