1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - SSP - include
3   File:     jpegenc.h
4 
5   Copyright 2007-2008 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:: 2008-12-03#$
14   $Rev: 9496 $
15   $Author: kitase_hirotake $
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 must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
53                 src, dst, and wrk 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 must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
81                 src, dst, and wrk 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 
107     (void)SSP_SetJpegEncoderSignMode(sign);
108     result = SSP_StartJpegEncoder(src, dst, limit, wrk, width, height, quality, sampling, option);
109     (void)SSP_SetJpegEncoderSignMode(FALSE);
110 
111     return result;
112 }
113 
114 /*---------------------------------------------------------------------------*
115   Name:         SSP_ConvertJpegEncodeData
116 
117   Description:  Converts input data into a format used to perform JPEG encoding.
118                 The input data can be cleared after this function has finished.
119                 The width and height must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
120                 src, dst, and wrk must be 4-byte aligned.
121 
122 
123   Arguments:    src:     Image data (RGB555/YUV422 data from the upper left to the lower right)
124                 wrk:        Work area
125                 width:      Image width
126                 height:     Image height
127                 sampling:   Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
128                 option: Options (bitwise logical OR)
129                            SSP_JPEG_RGB555: Encode from the RGB555 format.
130                            SSP_JPEG_YUV422: Encode from the YUV422 format.
131                                   If unspecified, the format is considered to be RGB555.
132                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
133 
134   Returns:      TRUE on success.
135  *---------------------------------------------------------------------------*/
136 BOOL SSP_ConvertJpegEncodeData(const void* src, u8 *wrk,
137                          u32 width, u32 height, u32 sampling, u32 option);
138 
139 /*---------------------------------------------------------------------------*
140   Name:         SSP_StartJpegEncoderWithEncodeData
141 
142   Description:  Encodes a JPEG from data that was converted in advance for encoding.
143                 You must call the SSP_ConvertJpegEncodeData function before this one.
144                 The width and height must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
145                 dst and wrk must be 4-byte aligned.
146 
147 
148   Arguments:    dst:      Location to put the encoded JPEG data
149                 limit:      Size limit for dst (encoding will fail if this is exceeded)
150                 wrk:        Work area
151                 width:      Image width
152                 height:     Image height
153                 quality:    Encoding quality (1-100)
154                 sampling:   Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
155                 option: Options (bitwise logical OR)
156                            SSP_JPEG_RGB555: Encode from the RGB555 format.
157                            SSP_JPEG_YUV422: Encode from the YUV422 format.
158                                   If unspecified, the format is considered to be RGB555.
159                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
160 
161   Returns:      Encoded JPEG size (when this is 0, encoding failed)
162  *---------------------------------------------------------------------------*/
163 u32 SSP_StartJpegEncoderWithEncodeData(u8 *dst, u32 limit, u8 *wrk,
164                          u32 width, u32 height,
165                          u32 quality, u32 sampling, u32 option);
166 
167 /*---------------------------------------------------------------------------*
168   Name:         SSP_StartJpegEncoderWithEncodeDataEx
169 
170   Description:  Specifies whether to use a signature and encodes a JPEG from data that was converted in advance for encoding.
171                 You must call the SSP_ConvertJpegEncodeData function before this one.
172                 The width and height must be multiples of 8 if sampling is 1 and multiples of 16 if sampling is 2.
173                 dst and wrk must be 4-byte aligned.
174 
175 
176   Arguments:    dst:      Location to put the encoded JPEG data
177                 limit:      Size limit for dst (encoding will fail if this is exceeded)
178                 wrk:        Work area
179                 width:      Image width
180                 height:     Image height
181                 quality:    Encoding quality (1-100)
182                 sampling:   Main image sampling (1=YUV444, 2=YUV420, 3=YUV422. Thumbnails are internally fixed to 3)
183                 option: Options (bitwise logical OR)
184                            SSP_JPEG_RGB555: Encode from the RGB555 format.
185                            SSP_JPEG_YUV422: Encode from the YUV422 format.
186                                   If unspecified, the format is considered to be RGB555.
187                            SSP_JPEG_THUMBNAIL: Encode with a thumbnail.
188                 sign:       Specify TRUE to add a signature.
189 
190   Returns:      Encoded JPEG size (when this is 0, encoding failed)
191  *---------------------------------------------------------------------------*/
SSP_StartJpegEncoderWithEncodeDataEx(u8 * dst,u32 limit,u8 * wrk,u32 width,u32 height,u32 quality,u32 sampling,u32 option,BOOL sign)192 static inline u32 SSP_StartJpegEncoderWithEncodeDataEx(u8 *dst, u32 limit, u8 *wrk,
193                          u32 width, u32 height,
194                          u32 quality, u32 sampling, u32 option, BOOL sign)
195 {
196     u32 result;
197 
198     (void)SSP_SetJpegEncoderSignMode(sign);
199     result = SSP_StartJpegEncoderWithEncodeData(dst, limit, wrk, width, height, quality, sampling, option);
200     (void)SSP_SetJpegEncoderSignMode(FALSE);
201 
202     return result;
203 }
204 
205 #ifdef __cplusplus
206 } /* extern "C" */
207 #endif
208 
209 /* TWL_SSP_JPEGENC_H_ */
210 #endif
211