1 /*
2 (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use.
3 */
4 #ifndef CHARLS_PUBLICTYPES
5 #define CHARLS_PUBLICTYPES
6
7
8 #ifdef __cplusplus
9
10 #include <cstdint>
11 #include <cstddef>
12
13 namespace charls
14 {
15 /// <summary>
16 /// Defines the result values that are returned by the CharLS API functions.
17 /// </summary>
18 enum class ApiResult
19 {
20 OK = 0, // The operation completed without errors.
21 InvalidJlsParameters = 1, // One of the JLS parameters is invalid.
22 ParameterValueNotSupported = 2, // The parameter value not supported.
23 UncompressedBufferTooSmall = 3, // The uncompressed buffer is too small to hold all the output.
24 CompressedBufferTooSmall = 4, // The compressed buffer too small, more input data was expected.
25 InvalidCompressedData = 5, // This error is returned when the encoded bit stream contains a general structural problem.
26 TooMuchCompressedData = 6, // Too much compressed data.The decoding proccess is ready but the input buffer still contains encoded data.
27 ImageTypeNotSupported = 7, // This error is returned when the bit stream is encoded with an option that is not supported by this implementation.
28 UnsupportedBitDepthForTransform = 8, // The bit depth for transformation is not supported.
29 UnsupportedColorTransform = 9, // The color transformation is not supported.
30 UnsupportedEncoding = 10, // This error is returned when an encoded frame is found that is not encoded with the JPEG-LS algorithm.
31 UnknownJpegMarker = 11, // This error is returned when an unknown JPEG marker code is detected in the encoded bit stream.
32 MissingJpegMarkerStart = 12, // This error is returned when the algorithm expect a 0xFF code (indicates start of a JPEG marker) but none was found.
33 UnspecifiedFailure = 13, // This error is returned when the implementation detected a failure, but no specific error is available.
34 UnexpectedFailure = 14, // This error is returned when the implementation encountered a failure it didn't expect. No guarantees can be given for the state after this error.
35 };
36
37 /// <summary>
38 /// Defines the interleave mode for multi-component (color) pixel data.
39 /// </summary>
40 enum class InterleaveMode
41 {
42 /// <summary>
43 /// The data is encoded and stored as component for component: RRRGGGBBB.
44 /// </summary>
45 None = 0,
46
47 /// <summary>
48 /// The interleave mode is by line. A full line of each component is encoded before moving to the next line.
49 /// </summary>
50 Line = 1,
51
52 /// <summary>
53 /// The data is encoded and stored by sample. For color images this is the format like RGBRGBRGB.
54 /// </summary>
55 Sample = 2
56 };
57
58 enum class ColorTransformation
59 {
60 // Default (RGB)
61 None = 0,
62
63 // Color transforms as defined by HP
64 // Not part of the JPEG-LS standard in any way, provided for compatibility with existing streams.
65 HP1,
66 HP2,
67 HP3,
68
69 // Defined by HP but not supported by CharLS
70 RgbAsYuvLossy,
71 Matrix,
72 BigEndian = 1 << 29,
73 LittleEndian = 1 << 30
74 };
75 }
76
77 typedef charls::ApiResult CharlsApiResultType;
78 typedef charls::InterleaveMode CharlsInterleaveModeType;
79 typedef charls::ColorTransformation CharlsColorTransformationType;
80
81 // Defines the size of the char buffer that should be passed to the CharLS API to get the error message text.
82 const std::size_t ErrorMessageSize = 256;
83
84 #else
85
86 #include <stdint.h>
87
88 enum CharlsApiResult
89 {
90 CHARLS_API_RESULT_OK = 0, // The operation completed without errors.
91 CHARLS_API_RESULT_INVALID_JLS_PARAMETERS = 1, // One of the JLS parameters is invalid.
92 CHARLS_API_RESULT_PARAMETER_VALUE_NOT_SUPPORTED = 2, // The parameter value not supported.
93 CHARLS_API_RESULT_UNCOMPRESSED_BUFFER_TOO_SMALL = 3, // The uncompressed buffer is too small to hold all the output.
94 CHARLS_API_RESULT_COMPRESSED_BUFFER_TOO_SMALL = 4, // The compressed buffer too small, more input data was expected.
95 CHARLS_API_RESULT_INVALID_COMPRESSED_DATA = 5, // This error is returned when the encoded bit stream contains a general structural problem.
96 CHARLS_API_RESULT_TOO_MUCH_COMPRESSED_DATA = 6, // Too much compressed data.The decoding proccess is ready but the input buffer still contains encoded data.
97 CHARLS_API_RESULT_IMAGE_TYPE_NOT_SUPPORTED = 7, // This error is returned when the bit stream is encoded with an option that is not supported by this implementation.
98 CHARLS_API_RESULT_UNSUPPORTED_BIT_DEPTH_FOR_TRANSFORM = 8, // The bit depth for transformation is not supported.
99 CHARLS_API_RESULT_UNSUPPORTED_COLOR_TRANSFORM = 9, // The color transformation is not supported.
100 CHARLS_API_RESULT_UNSUPPORTED_ENCODING = 10, // This error is returned when an encoded frame is found that is not encoded with the JPEG-LS algorithm.
101 CHARLS_API_RESULT_UNKNOWN_JPEG_MARKER = 11, // This error is returned when an unknown JPEG marker code is detected in the encoded bit stream.
102 CHARLS_API_RESULT_MISSING_JPEG_MARKER_START = 12, // This error is returned when the algorithm expect a 0xFF code (indicates start of a JPEG marker) but none was found.
103 CHARLS_API_RESULT_UNSPECIFIED_FAILURE = 13, // This error is returned when the implementation detected a failure, but no specific error is available.
104 CHARLS_API_RESULT_UNEXPECTED_FAILURE = 14, // This error is returned when the implementation encountered a failure it didn't expect. No guarantees can be given for the state after this error.
105 };
106
107 enum CharlsInterleaveMode
108 {
109 CHARLS_IM_NONE = 0,
110 CHARLS_IM_LINE = 1,
111 CHARLS_IM_SAMPLE = 2
112 };
113
114 enum CharlsColorTransformation
115 {
116 CHARLS_COLOR_TRANSFORMATION_NONE = 0,
117 CHARLS_COLOR_TRANSFORMATION_HP1,
118 CHARLS_COLOR_TRANSFORMATION_HP2,
119 CHARLS_COLOR_TRANSFORMATION_HP3,
120 CHARLS_COLOR_TRANSFORMATION_RGB_AS_YUV_LOSSY,
121 CHARLS_COLOR_TRANSFORMATION_MATRIX,
122 CHARLS_COLOR_TRANSFORMATION_BIGENDIAN = 1 << 29,
123 CHARLS_COLOR_TRANSFORMATION_LITTLEENDIAN = 1 << 30
124 };
125
126 typedef enum CharlsApiResult CharlsApiResultType;
127 typedef enum CharlsInterleaveMode CharlsInterleaveModeType;
128 typedef enum CharlsColorTransformation CharlsColorTransformationType;
129
130 // Defines the size of the char buffer that should be passed to the CharLS API to get the error message text.
131 #define CHARLS_ERROR_MESSAGE_SIZE 256
132
133 #endif
134
135
136 struct JlsCustomParameters
137 {
138 int MAXVAL;
139 int T1;
140 int T2;
141 int T3;
142 int RESET;
143 };
144
145
146 struct JlsRect
147 {
148 int X;
149 int Y;
150 int Width;
151 int Height;
152 };
153
154
155 /// <summary>
156 /// Defines the parameters for the JPEG File Interchange Format.
157 /// The format is defined in the JPEG File Interchange Format v1.02 document by Eric Hamilton.
158 /// </summary>
159 /// <remarks>
160 /// The JPEG File Interchange Format is the de-facto standard JPEG interchange format.
161 /// </remarks>
162 struct JfifParameters
163 {
164 /// <summary>
165 /// Version of the JPEG File Interchange Format.
166 /// Should be set to zero to not write a JFIF header or to 1.02, encoded as: (1 * 256) + 2.
167 /// </summary>
168 int32_t version;
169
170 /// <summary>
171 /// Defines the units for the X and Y densities.
172 /// 0: no units, X and Y specify the pixel aspect ratio.
173 /// 1: X and Y are dots per inch.
174 /// 2: X and Y are dots per cm.
175 /// </summary>
176 int32_t units;
177
178 /// <summary>
179 /// Horizontal pixel density
180 /// </summary>
181 int32_t Xdensity;
182
183 /// <summary>
184 /// Vertical pixel density
185 /// </summary>
186 int32_t Ydensity;
187
188 /// <summary>
189 /// Thumbnail horizontal pixel count.
190 /// </summary>
191 int32_t Xthumbnail;
192
193 /// <summary>
194 /// Thumbnail vertical pixel count.
195 /// </summary>
196 int32_t Ythumbnail;
197
198 /// <summary>
199 /// Reference to a buffer with thumbnail pixels of size Xthumbnail * Ythumbnail * 3(RGB).
200 /// This parameter is only used when creating JPEG-LS encoded images.
201 /// </summary>
202 void* thumbnail;
203 };
204
205
206 struct JlsParameters
207 {
208 /// <summary>
209 /// Width of the image in pixels.
210 /// </summary>
211 int width;
212
213 /// <summary>
214 /// Height of the image in pixels.
215 /// </summary>
216 int height;
217
218 /// <summary>
219 /// The number of valid bits per sample to encode.
220 /// Valid range 2 - 16. When greater than 8, pixels are assumed to stored as two bytes per sampe, otherwise one byte per sample is assumed.
221 /// </summary>
222 int bitsPerSample;
223
224 /// <summary>
225 /// The stride is the number of bytes from one row of pixels in memory to the next row of pixels in memory.
226 /// Stride is sometimes called pitch. If padding bytes are present, the stride is wider than the width of the image.
227 /// </summary>
228 int stride;
229
230 /// <summary>
231 /// The number of components.
232 /// Typical 1 for monochrome images and 3 for color images or 4 if alpha channel is present.
233 /// </summary>
234 int components;
235
236 /// <summary>
237 /// Defines the allowed lossy error. Value 0 defines lossless.
238 /// </summary>
239 int allowedLossyError;
240
241 /// <summary>
242 /// Determines the order of the color components in the compressed stream.
243 /// </summary>
244 CharlsInterleaveModeType interleaveMode;
245
246 /// <summary>
247 /// Color transformation used in the compressed stream. The color transformations are all lossless and
248 /// are an HP proprietary extension of the standard. Do not use the color transformations unless
249 /// you know the decoder is capable of decoding it. Color transform typically improve compression ratios only
250 /// for sythetic images (non - photorealistic computer generated images).
251 /// </summary>
252 CharlsColorTransformationType colorTransformation;
253
254 /// <summary>
255 /// If set to true RGB images will be decoded to BGR. BGR is the standard ordering in MS Windows bitmaps.
256 /// </summary>
257 char outputBgr;
258 struct JlsCustomParameters custom;
259 struct JfifParameters jfif;
260 };
261
262
263 #ifdef __cplusplus
264
265 #include <iostream>
266
267
268 //
269 // ByteStreamInfo & FromByteArray helper function
270 //
271 // ByteStreamInfo describes the stream: either set rawStream to a valid stream, or rawData/count, not both.
272 // it's possible to decode to memorystreams, but using rawData will always be faster.
273 //
274 // Example use:
275 // ByteStreamInfo streamInfo = { fileStream.rdbuf() };
276 // or
277 // ByteStreamInfo streamInfo = FromByteArray( bytePtr, byteCount);
278 //
279 struct ByteStreamInfo
280 {
281 std::basic_streambuf<char>* rawStream;
282 uint8_t* rawData;
283 std::size_t count;
284 };
285
286
FromByteArray(const void * bytes,std::size_t count)287 inline ByteStreamInfo FromByteArray(const void* bytes, std::size_t count)
288 {
289 ByteStreamInfo info = ByteStreamInfo();
290 info.rawData = static_cast<uint8_t*>(const_cast<void*>(bytes));
291 info.count = count;
292 return info;
293 }
294
295 #endif
296
297 #endif
298