blob: a065fd142cc7f825d4edafbffa7ec3171ad84d69 [file] [log] [blame]
DRC9b28def2011-05-21 14:37:15 +00001/*
2 * Copyright (C)2009-2011 D. R. Commander. All Rights Reserved.
DRC2e7b76b2009-04-03 12:04:24 +00003 *
DRC9b28def2011-05-21 14:37:15 +00004 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
DRC2e7b76b2009-04-03 12:04:24 +00006 *
DRC9b28def2011-05-21 14:37:15 +00007 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of the libjpeg-turbo Project nor the names of its
13 * contributors may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 * 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 BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
DRC2e7b76b2009-04-03 12:04:24 +000027 */
28
DRC3a1bb352011-05-24 09:15:44 +000029#ifndef __TURBOJPEG_H__
30#define __TURBOJPEG_H__
31
DRC9b28def2011-05-21 14:37:15 +000032#if defined(_WIN32) && defined(DLLDEFINE)
DRC2e7b76b2009-04-03 12:04:24 +000033#define DLLEXPORT __declspec(dllexport)
34#else
35#define DLLEXPORT
36#endif
DRC2e7b76b2009-04-03 12:04:24 +000037#define DLLCALL
38
DRC2e7b76b2009-04-03 12:04:24 +000039
DRC9b28def2011-05-21 14:37:15 +000040/**
41 * @addtogroup TurboJPEG
42 * TurboJPEG API. This API provides an interface for generating, decoding, and
43 * transforming planar YUV and JPEG images in memory.
44 *
45 * @{
46 */
DRC2e7b76b2009-04-03 12:04:24 +000047
DRC0a325192011-03-02 09:22:41 +000048
DRC9b28def2011-05-21 14:37:15 +000049/**
50 * The number of chrominance subsampling options
51 */
52#define TJ_NUMSAMP 5
DRCfbb67472010-11-24 04:02:37 +000053
DRC9b28def2011-05-21 14:37:15 +000054/**
55 * Chrominance subsampling options.
DRC9b28def2011-05-21 14:37:15 +000056 * When an image is converted from the RGB to the YCbCr colorspace as part of
57 * the JPEG compression process, some of the Cb and Cr (chrominance) components
58 * can be discarded or averaged together to produce a smaller image with little
59 * perceptible loss of image clarity (the human eye is more sensitive to small
60 * changes in brightness than small changes in color.) This is called
61 * "chrominance subsampling".
62 */
DRC25b995a2011-05-21 15:34:54 +000063enum TJSAMP
DRC109a5782011-03-01 09:53:07 +000064{
DRC9b28def2011-05-21 14:37:15 +000065 /**
66 * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or
67 * YUV image will contain one chrominance component for every pixel in the
68 * source image.
69 */
DRC25b995a2011-05-21 15:34:54 +000070 TJSAMP_444=0,
DRC9b28def2011-05-21 14:37:15 +000071 /**
72 * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one
73 * chrominance component for every 2x1 block of pixels in the source image.
74 */
DRC25b995a2011-05-21 15:34:54 +000075 TJSAMP_422,
DRC9b28def2011-05-21 14:37:15 +000076 /**
77 * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one
78 * chrominance component for every 2x2 block of pixels in the source image.
79 */
DRC25b995a2011-05-21 15:34:54 +000080 TJSAMP_420,
DRC9b28def2011-05-21 14:37:15 +000081 /**
82 * Grayscale. The JPEG or YUV image will contain no chrominance components.
83 */
DRC25b995a2011-05-21 15:34:54 +000084 TJSAMP_GRAY,
DRC9b28def2011-05-21 14:37:15 +000085 /**
86 * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one
87 * chrominance component for every 1x2 block of pixels in the source image.
88 */
DRC25b995a2011-05-21 15:34:54 +000089 TJSAMP_440
DRC890f1e02011-02-26 22:02:37 +000090};
91
DRC9b28def2011-05-21 14:37:15 +000092/**
93 * MCU block width (in pixels) for a given level of chrominance subsampling.
94 * MCU block sizes:
95 * - 8x8 for no subsampling or grayscale
96 * - 16x8 for 4:2:2
97 * - 8x16 for 4:4:0
98 * - 16x16 for 4:2:0
99 */
100static const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8};
DRC890f1e02011-02-26 22:02:37 +0000101
DRC9b28def2011-05-21 14:37:15 +0000102/**
103 * MCU block height (in pixels) for a given level of chrominance subsampling.
104 * MCU block sizes:
105 * - 8x8 for no subsampling or grayscale
106 * - 16x8 for 4:2:2
107 * - 8x16 for 4:4:0
108 * - 16x16 for 4:2:0
109 */
110static const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16};
111
112
113/**
114 * The number of pixel formats
115 */
116#define TJ_NUMPF 7
117
118/**
119 * Pixel formats
DRC9b28def2011-05-21 14:37:15 +0000120 */
DRC25b995a2011-05-21 15:34:54 +0000121enum TJPF
DRC9b28def2011-05-21 14:37:15 +0000122{
123 /**
124 * RGB pixel format. The red, green, and blue components in the image are
125 * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
126 * address within each pixel.
127 */
DRC25b995a2011-05-21 15:34:54 +0000128 TJPF_RGB=0,
DRC9b28def2011-05-21 14:37:15 +0000129 /**
130 * BGR pixel format. The red, green, and blue components in the image are
131 * stored in 3-byte pixels in the order B, G, R from lowest to highest byte
132 * address within each pixel.
133 */
DRC25b995a2011-05-21 15:34:54 +0000134 TJPF_BGR,
DRC9b28def2011-05-21 14:37:15 +0000135 /**
136 * RGBX pixel format. The red, green, and blue components in the image are
137 * stored in 4-byte pixels in the order R, G, B from lowest to highest byte
138 * address within each pixel.
139 */
DRC25b995a2011-05-21 15:34:54 +0000140 TJPF_RGBX,
DRC9b28def2011-05-21 14:37:15 +0000141 /**
142 * BGRX pixel format. The red, green, and blue components in the image are
143 * stored in 4-byte pixels in the order B, G, R from lowest to highest byte
144 * address within each pixel.
145 */
DRC25b995a2011-05-21 15:34:54 +0000146 TJPF_BGRX,
DRC9b28def2011-05-21 14:37:15 +0000147 /**
148 * XBGR pixel format. The red, green, and blue components in the image are
149 * stored in 4-byte pixels in the order R, G, B from highest to lowest byte
150 * address within each pixel.
151 */
DRC25b995a2011-05-21 15:34:54 +0000152 TJPF_XBGR,
DRC9b28def2011-05-21 14:37:15 +0000153 /**
154 * XRGB pixel format. The red, green, and blue components in the image are
155 * stored in 4-byte pixels in the order B, G, R from highest to lowest byte
156 * address within each pixel.
157 */
DRC25b995a2011-05-21 15:34:54 +0000158 TJPF_XRGB,
DRC9b28def2011-05-21 14:37:15 +0000159 /**
160 * Grayscale pixel format. Each 1-byte pixel represents a luminance
161 * (brightness) level from 0 to 255.
162 */
DRC25b995a2011-05-21 15:34:54 +0000163 TJPF_GRAY
DRC9b28def2011-05-21 14:37:15 +0000164};
165
166/**
167 * Red offset (in bytes) for a given pixel format. This specifies the number
168 * of bytes that the red component is offset from the start of the pixel. For
169 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
170 * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>.
171 */
172static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0};
173/**
174 * Green offset (in bytes) for a given pixel format. This specifies the number
175 * of bytes that the green component is offset from the start of the pixel.
176 * For instance, if a pixel of format TJ_BGRX is stored in
177 * <tt>char pixel[]</tt>, then the green component will be
178 * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>.
179 */
180static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0};
181/**
182 * Blue offset (in bytes) for a given pixel format. This specifies the number
183 * of bytes that the Blue component is offset from the start of the pixel. For
184 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
185 * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>.
186 */
187static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0};
188
189/**
190 * Pixel size (in bytes) for a given pixel format.
191 */
192static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1};
193
194
195/**
DRC9b28def2011-05-21 14:37:15 +0000196 * The uncompressed source/destination image is stored in bottom-up (Windows,
197 * OpenGL) order, not top-down (X11) order.
198 */
DRC25b995a2011-05-21 15:34:54 +0000199#define TJFLAG_BOTTOMUP 2
DRC9b28def2011-05-21 14:37:15 +0000200/**
DRC25b995a2011-05-21 15:34:54 +0000201 * Turn off CPU auto-detection and force TurboJPEG to use MMX code (IPP and
202 * 32-bit libjpeg-turbo versions only.)
DRC9b28def2011-05-21 14:37:15 +0000203 */
DRC25b995a2011-05-21 15:34:54 +0000204#define TJFLAG_FORCEMMX 8
DRC9b28def2011-05-21 14:37:15 +0000205/**
DRC25b995a2011-05-21 15:34:54 +0000206 * Turn off CPU auto-detection and force TurboJPEG to use SSE code (32-bit IPP
207 * and 32-bit libjpeg-turbo versions only)
DRC9b28def2011-05-21 14:37:15 +0000208 */
DRC25b995a2011-05-21 15:34:54 +0000209#define TJFLAG_FORCESSE 16
DRC9b28def2011-05-21 14:37:15 +0000210/**
DRC25b995a2011-05-21 15:34:54 +0000211 * Turn off CPU auto-detection and force TurboJPEG to use SSE2 code (32-bit IPP
212 * and 32-bit libjpeg-turbo versions only)
DRC9b28def2011-05-21 14:37:15 +0000213 */
DRC25b995a2011-05-21 15:34:54 +0000214#define TJFLAG_FORCESSE2 32
DRC9b28def2011-05-21 14:37:15 +0000215/**
DRC25b995a2011-05-21 15:34:54 +0000216 * Turn off CPU auto-detection and force TurboJPEG to use SSE3 code (64-bit IPP
217 * version only)
DRC9b28def2011-05-21 14:37:15 +0000218 */
DRC25b995a2011-05-21 15:34:54 +0000219#define TJFLAG_FORCESSE3 128
DRC9b28def2011-05-21 14:37:15 +0000220/**
DRC25b995a2011-05-21 15:34:54 +0000221 * Use fast, inaccurate chrominance upsampling routines in the JPEG
222 * decompressor (libjpeg and libjpeg-turbo versions only)
DRC9b28def2011-05-21 14:37:15 +0000223 */
DRC25b995a2011-05-21 15:34:54 +0000224#define TJFLAG_FASTUPSAMPLE 256
DRC9b28def2011-05-21 14:37:15 +0000225/**
DRC25b995a2011-05-21 15:34:54 +0000226 * Disable buffer (re)allocation. If passed to #tjCompress2() or
227 * #tjTransform(), this flag will cause those functions to generate an error if
228 * the JPEG image buffer is invalid or too small rather than attempting to
229 * allocate or reallocate that buffer. This reproduces the behavior of earlier
230 * versions of TurboJPEG.
DRC9b28def2011-05-21 14:37:15 +0000231 */
DRC25b995a2011-05-21 15:34:54 +0000232#define TJFLAG_NOREALLOC 1024
DRC9b28def2011-05-21 14:37:15 +0000233
234
235/**
236 * Number of transform operations
237 */
DRC25b995a2011-05-21 15:34:54 +0000238#define TJ_NUMXOP 8
DRC9b28def2011-05-21 14:37:15 +0000239
240/**
DRC25b995a2011-05-21 15:34:54 +0000241 * Transform operations for #tjTransform()
DRC9b28def2011-05-21 14:37:15 +0000242 */
DRC25b995a2011-05-21 15:34:54 +0000243enum TJXOP
DRC9b28def2011-05-21 14:37:15 +0000244{
245 /**
246 * Do not transform the position of the image pixels
247 */
DRC25b995a2011-05-21 15:34:54 +0000248 TJXOP_NONE=0,
DRC9b28def2011-05-21 14:37:15 +0000249 /**
250 * Flip (mirror) image horizontally. This transform is imperfect if there
DRC25b995a2011-05-21 15:34:54 +0000251 * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.)
DRC9b28def2011-05-21 14:37:15 +0000252 */
DRC25b995a2011-05-21 15:34:54 +0000253 TJXOP_HFLIP,
DRC9b28def2011-05-21 14:37:15 +0000254 /**
255 * Flip (mirror) image vertically. This transform is imperfect if there are
DRC25b995a2011-05-21 15:34:54 +0000256 * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.)
DRC9b28def2011-05-21 14:37:15 +0000257 */
DRC25b995a2011-05-21 15:34:54 +0000258 TJXOP_VFLIP,
DRC9b28def2011-05-21 14:37:15 +0000259 /**
260 * Transpose image (flip/mirror along upper left to lower right axis.) This
261 * transform is always perfect.
262 */
DRC25b995a2011-05-21 15:34:54 +0000263 TJXOP_TRANSPOSE,
DRC9b28def2011-05-21 14:37:15 +0000264 /**
265 * Transverse transpose image (flip/mirror along upper right to lower left
266 * axis.) This transform is imperfect if there are any partial MCU blocks in
DRC25b995a2011-05-21 15:34:54 +0000267 * the image (see #TJXOPT_PERFECT.)
DRC9b28def2011-05-21 14:37:15 +0000268 */
DRC25b995a2011-05-21 15:34:54 +0000269 TJXOP_TRANSVERSE,
DRC9b28def2011-05-21 14:37:15 +0000270 /**
271 * Rotate image clockwise by 90 degrees. This transform is imperfect if
272 * there are any partial MCU blocks on the bottom edge (see
DRC25b995a2011-05-21 15:34:54 +0000273 * #TJXOPT_PERFECT.)
DRC9b28def2011-05-21 14:37:15 +0000274 */
DRC25b995a2011-05-21 15:34:54 +0000275 TJXOP_ROT90,
DRC9b28def2011-05-21 14:37:15 +0000276 /**
277 * Rotate image 180 degrees. This transform is imperfect if there are any
DRC25b995a2011-05-21 15:34:54 +0000278 * partial MCU blocks in the image (see #TJXOPT_PERFECT.)
DRC9b28def2011-05-21 14:37:15 +0000279 */
DRC25b995a2011-05-21 15:34:54 +0000280 TJXOP_ROT180,
DRC9b28def2011-05-21 14:37:15 +0000281 /**
282 * Rotate image counter-clockwise by 90 degrees. This transform is imperfect
283 * if there are any partial MCU blocks on the right edge (see
DRC25b995a2011-05-21 15:34:54 +0000284 * #TJXOPT_PERFECT.)
DRC9b28def2011-05-21 14:37:15 +0000285 */
DRC25b995a2011-05-21 15:34:54 +0000286 TJXOP_ROT270
DRC9b28def2011-05-21 14:37:15 +0000287};
288
289
290/**
DRC25b995a2011-05-21 15:34:54 +0000291 * This option will cause #tjTransform() to return an error if the transform is
DRC9b28def2011-05-21 14:37:15 +0000292 * not perfect. Lossless transforms operate on MCU blocks, whose size depends
293 * on the level of chrominance subsampling used (see #tjMCUWidth
294 * and #tjMCUHeight.) If the image's width or height is not evenly divisible
295 * by the MCU block size, then there will be partial MCU blocks on the right
296 * and/or bottom edges. It is not possible to move these partial MCU blocks to
297 * the top or left of the image, so any transform that would require that is
298 * "imperfect." If this option is not specified, then any partial MCU blocks
299 * that cannot be transformed will be left in place, which will create
300 * odd-looking strips on the right or bottom edge of the image.
301 */
DRC25b995a2011-05-21 15:34:54 +0000302#define TJXOPT_PERFECT 1
DRC9b28def2011-05-21 14:37:15 +0000303/**
DRC25b995a2011-05-21 15:34:54 +0000304 * This option will cause #tjTransform() to discard any partial MCU blocks that
DRC9b28def2011-05-21 14:37:15 +0000305 * cannot be transformed.
306 */
DRC25b995a2011-05-21 15:34:54 +0000307#define TJXOPT_TRIM 2
DRC9b28def2011-05-21 14:37:15 +0000308/**
DRC25b995a2011-05-21 15:34:54 +0000309 * This option will enable lossless cropping. See #tjTransform() for more
DRC9b28def2011-05-21 14:37:15 +0000310 * information.
311 */
DRC25b995a2011-05-21 15:34:54 +0000312#define TJXOPT_CROP 4
DRC9b28def2011-05-21 14:37:15 +0000313/**
314 * This option will discard the color data in the input image and produce
315 * a grayscale output image.
DRC9b28def2011-05-21 14:37:15 +0000316 */
DRC25b995a2011-05-21 15:34:54 +0000317#define TJXOPT_GRAY 8
DRC7bf04d32011-09-17 00:18:31 +0000318/**
319 * This option will prevent #tjTransform() from outputting a JPEG image for
320 * this particular transform (this can be used in conjunction with a custom
321 * filter to capture the transformed DCT coefficients without transcoding
322 * them.)
323 */
324#define TJXOPT_NOOUTPUT 16
DRC9b28def2011-05-21 14:37:15 +0000325
326
327/**
328 * Scaling factor
329 */
DRC0a079692011-03-02 09:27:49 +0000330typedef struct
331{
DRC9b28def2011-05-21 14:37:15 +0000332 /**
333 * Numerator
334 */
335 int num;
336 /**
337 * Denominator
338 */
339 int denom;
340} tjscalingfactor;
341
342/**
343 * Cropping region
344 */
345typedef struct
346{
347 /**
348 * The left boundary of the cropping region. This must be evenly divisible
349 * by the MCU block width (see #tjMCUWidth.)
350 */
351 int x;
352 /**
353 * The upper boundary of the cropping region. This must be evenly divisible
354 * by the MCU block height (see #tjMCUHeight.)
355 */
356 int y;
357 /**
358 * The width of the cropping region. Setting this to 0 is the equivalent of
359 * setting it to the width of the source JPEG image - x.
360 */
361 int w;
362 /**
363 * The height of the cropping region. Setting this to 0 is the equivalent of
364 * setting it to the height of the source JPEG image - y.
365 */
366 int h;
DRC0a079692011-03-02 09:27:49 +0000367} tjregion;
368
DRC9b28def2011-05-21 14:37:15 +0000369/**
370 * Lossless transform
371 */
DRCf5467112011-09-20 05:02:19 +0000372typedef struct tjtransform
DRC0a079692011-03-02 09:27:49 +0000373{
DRC9b28def2011-05-21 14:37:15 +0000374 /**
375 * Cropping region
376 */
377 tjregion r;
378 /**
DRC25b995a2011-05-21 15:34:54 +0000379 * One of the @ref TJXOP "transform operations"
DRC9b28def2011-05-21 14:37:15 +0000380 */
381 int op;
382 /**
DRC25b995a2011-05-21 15:34:54 +0000383 * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options"
DRC9b28def2011-05-21 14:37:15 +0000384 */
385 int options;
DRC7bf04d32011-09-17 00:18:31 +0000386 /**
DRCf5467112011-09-20 05:02:19 +0000387 * Arbitrary data that can be accessed within the body of the callback
388 * function
389 */
390 void *data;
391 /**
DRC7bf04d32011-09-17 00:18:31 +0000392 * A callback function that can be used to modify the DCT coefficients
393 * after they are losslessly transformed but before they are transcoded to a
394 * new JPEG file. This allows for custom filters or other transformations to
395 * be applied in the frequency domain.
396 *
DRCf5467112011-09-20 05:02:19 +0000397 * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE:
398 * this pointer is not guaranteed to be valid once the callback
399 * returns, so applications wishing to hand off the DCT coefficients
400 * to another function or library should make a copy of them within
401 * the body of the callback.)
402 * @param arrayRegion #tjregion structure containing the width and height of
DRCf69dc282011-09-20 18:20:43 +0000403 * the array pointed to by <tt>coeffs</tt> as well as its offset
404 * relative to the component plane. TurboJPEG implementations may
405 * choose to split each component plane into multiple DCT coefficient
406 * arrays and call the callback function once for each array.
DRCf5467112011-09-20 05:02:19 +0000407 * @param planeRegion #tjregion structure containing the width and height of
408 * the component plane to which <tt>coeffs</tt> belongs
409 * @param componentID ID number of the component plane to which
410 * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of
411 * 0, 1, and 2 in typical JPEG images.)
412 * @param transformID ID number of the transformed image to which
413 * <tt>coeffs</tt> belongs. This is the same as the index of the
414 * transform in the transforms array that was passed to
415 * #tjTransform().
416 * @param transform a pointer to a #tjtransform structure that specifies the
417 * parameters and/or cropping region for this transform
DRC7bf04d32011-09-17 00:18:31 +0000418 *
419 * @return 0 if the callback was successful, or -1 if an error occurred.
420 */
421 int (*customFilter)(short *coeffs, tjregion arrayRegion,
DRCf5467112011-09-20 05:02:19 +0000422 tjregion planeRegion, int componentIndex, int transformIndex,
423 struct tjtransform *transform);
DRC0a079692011-03-02 09:27:49 +0000424} tjtransform;
425
DRC9b28def2011-05-21 14:37:15 +0000426/**
427 * TurboJPEG instance handle
428 */
DRC2e7b76b2009-04-03 12:04:24 +0000429typedef void* tjhandle;
430
DRC9b28def2011-05-21 14:37:15 +0000431
432/**
433 * Pad the given width to the nearest 32-bit boundary
434 */
435#define TJPAD(width) (((width)+3)&(~3))
436
437/**
DRC25b995a2011-05-21 15:34:54 +0000438 * Compute the scaled value of <tt>dimension</tt> using the given scaling
439 * factor. This macro performs the integer equivalent of <tt>ceil(dimension *
DRC9b28def2011-05-21 14:37:15 +0000440 * scalingFactor)</tt>.
441 */
442#define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \
443 + scalingFactor.denom - 1) / scalingFactor.denom)
444
DRC2e7b76b2009-04-03 12:04:24 +0000445
446#ifdef __cplusplus
447extern "C" {
448#endif
449
DRC2e7b76b2009-04-03 12:04:24 +0000450
DRC9b28def2011-05-21 14:37:15 +0000451/**
452 * Create a TurboJPEG compressor instance.
453 *
454 * @return a handle to the newly-created instance, or NULL if an error
455 * occurred (see #tjGetErrorStr().)
456 */
DRC2e7b76b2009-04-03 12:04:24 +0000457DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
458
459
DRC9b28def2011-05-21 14:37:15 +0000460/**
461 * Compress an RGB or grayscale image into a JPEG image.
462 *
463 * @param handle a handle to a TurboJPEG compressor or transformer instance
464 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
465 * to be compressed
466 * @param width width (in pixels) of the source image
467 * @param pitch bytes per line of the source image. Normally, this should be
468 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded,
469 * or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of
470 * the image is padded to the nearest 32-bit boundary, as is the case
471 * for Windows bitmaps. You can also be clever and use this parameter
472 * to skip lines, etc. Setting this parameter to 0 is the equivalent of
473 * setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
474 * @param height height (in pixels) of the source image
DRC25b995a2011-05-21 15:34:54 +0000475 * @param pixelFormat pixel format of the source image (see @ref TJPF
DRC9b28def2011-05-21 14:37:15 +0000476 * "Pixel formats".)
477 * @param jpegBuf address of a pointer to an image buffer that will receive the
478 * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer
479 * to accommodate the size of the JPEG image. Thus, you can choose to:
DRC6b76f752011-05-24 16:52:47 +0000480 * -# pre-allocate the JPEG buffer with an arbitrary size using
481 * #tjAlloc() and let TurboJPEG grow the buffer as needed,
DRC9b28def2011-05-21 14:37:15 +0000482 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the
483 * buffer for you, or
484 * -# pre-allocate the buffer to a "worst case" size determined by
DRC9b49f0e2011-07-12 03:17:23 +0000485 * calling #tjBufSize(). This should ensure that the buffer never has
DRC25b995a2011-05-21 15:34:54 +0000486 * to be re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
DRC9b28def2011-05-21 14:37:15 +0000487 * .
DRCff78e372011-05-24 10:17:32 +0000488 * If you choose option 1, <tt>*jpegSize</tt> should be set to the
DRC9b28def2011-05-21 14:37:15 +0000489 * size of your pre-allocated buffer. In any case, unless you have
DRC25b995a2011-05-21 15:34:54 +0000490 * set #TJFLAG_NOREALLOC, you should always check <tt>*jpegBuf</tt> upon
491 * return from this function, as it may have changed.
DRC9b28def2011-05-21 14:37:15 +0000492 * @param jpegSize pointer to an unsigned long variable which holds the size of
493 * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a
494 * pre-allocated buffer, then <tt>*jpegSize</tt> should be set to the
495 * size of the buffer. Upon return, <tt>*jpegSize</tt> will contain the
496 * size of the JPEG image (in bytes.)
497 * @param jpegSubsamp the level of chrominance subsampling to be used when
DRC25b995a2011-05-21 15:34:54 +0000498 * generating the JPEG image (see @ref TJSAMP
DRC9b28def2011-05-21 14:37:15 +0000499 * "Chrominance subsampling options".)
500 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
501 100 = best)
DRC25b995a2011-05-21 15:34:54 +0000502 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
503 * "flags".
DRC9b28def2011-05-21 14:37:15 +0000504 *
505 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
DRC2e7b76b2009-04-03 12:04:24 +0000506*/
DRC9b28def2011-05-21 14:37:15 +0000507DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf,
508 int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
509 unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags);
DRC2e7b76b2009-04-03 12:04:24 +0000510
DRCb28fc572011-02-22 06:41:29 +0000511
DRC9b28def2011-05-21 14:37:15 +0000512/**
513 * The maximum size of the buffer (in bytes) required to hold a JPEG image with
DRC9b49f0e2011-07-12 03:17:23 +0000514 * the given parameters. The number of bytes returned by this function is
515 * larger than the size of the uncompressed source image. The reason for this
516 * is that the JPEG format uses 16-bit coefficients, and it is thus possible
517 * for a very high-quality JPEG image with very high frequency content to
518 * expand rather than compress when converted to the JPEG format. Such images
519 * represent a very rare corner case, but since there is no way to predict the
520 * size of a JPEG image prior to compression, the corner case has to be
521 * handled.
DRC9b28def2011-05-21 14:37:15 +0000522 *
523 * @param width width of the image (in pixels)
524 * @param height height of the image (in pixels)
DRC9b49f0e2011-07-12 03:17:23 +0000525 * @param jpegSubsamp the level of chrominance subsampling to be used when
526 * generating the JPEG image (see @ref TJSAMP
527 * "Chrominance subsampling options".)
DRC9b28def2011-05-21 14:37:15 +0000528 *
529 * @return the maximum size of the buffer (in bytes) required to hold the
530 * image, or -1 if the arguments are out of bounds.
531 */
DRC9b49f0e2011-07-12 03:17:23 +0000532DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height,
533 int jpegSubsamp);
DRC2e7b76b2009-04-03 12:04:24 +0000534
DRCb28fc572011-02-22 06:41:29 +0000535
DRC9b28def2011-05-21 14:37:15 +0000536/**
537 * The size of the buffer (in bytes) required to hold a YUV planar image with
538 * the given parameters.
539 *
540 * @param width width of the image (in pixels)
541 * @param height height of the image (in pixels)
DRC9b49f0e2011-07-12 03:17:23 +0000542 * @param subsamp level of chrominance subsampling in the image (see
DRC25b995a2011-05-21 15:34:54 +0000543 * @ref TJSAMP "Chrominance subsampling options".)
DRC9b28def2011-05-21 14:37:15 +0000544 *
545 * @return the size of the buffer (in bytes) required to hold the image, or
546 * -1 if the arguments are out of bounds.
547 */
DRC9b49f0e2011-07-12 03:17:23 +0000548DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height,
549 int subsamp);
DRCf3cf9732011-02-22 00:16:14 +0000550
DRCb28fc572011-02-22 06:41:29 +0000551
DRC9b28def2011-05-21 14:37:15 +0000552/**
553 * Encode an RGB or grayscale image into a YUV planar image. This function
554 * uses the accelerated color conversion routines in TurboJPEG's underlying
555 * codec to produce a planar YUV image that is suitable for X Video.
556 * Specifically, if the chrominance components are subsampled along the
557 * horizontal dimension, then the width of the luminance plane is padded to 2
558 * in the output image (same goes for the height of the luminance plane, if the
559 * chrominance components are subsampled along the vertical dimension.) Also,
560 * each line of each plane in the output image is padded to 4 bytes. Although
561 * this will work with any subsampling option, it is really only useful in
562 * combination with TJ_420, which produces an image compatible with the I420
563 * (AKA "YUV420P") format.
564 *
565 * @param handle a handle to a TurboJPEG compressor or transformer instance
566 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
567 * to be encoded
568 * @param width width (in pixels) of the source image
569 * @param pitch bytes per line of the source image. Normally, this should be
570 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded,
571 * or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of
572 * the image is padded to the nearest 32-bit boundary, as is the case
573 * for Windows bitmaps. You can also be clever and use this parameter
574 * to skip lines, etc. Setting this parameter to 0 is the equivalent of
575 * setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
576 * @param height height (in pixels) of the source image
DRC25b995a2011-05-21 15:34:54 +0000577 * @param pixelFormat pixel format of the source image (see @ref TJPF
DRC9b28def2011-05-21 14:37:15 +0000578 * "Pixel formats".)
579 * @param dstBuf pointer to an image buffer which will receive the YUV image.
DRC9b49f0e2011-07-12 03:17:23 +0000580 * Use #tjBufSizeYUV() to determine the appropriate size for this buffer
DRC9b28def2011-05-21 14:37:15 +0000581 * based on the image width, height, and level of chrominance
582 * subsampling.
583 * @param subsamp the level of chrominance subsampling to be used when
DRC25b995a2011-05-21 15:34:54 +0000584 * generating the YUV image (see @ref TJSAMP
DRC9b28def2011-05-21 14:37:15 +0000585 * "Chrominance subsampling options".)
DRC25b995a2011-05-21 15:34:54 +0000586 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
587 * "flags".
DRC9b28def2011-05-21 14:37:15 +0000588 *
589 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
DRC84241602011-02-25 02:08:23 +0000590*/
DRC9b28def2011-05-21 14:37:15 +0000591DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle,
592 unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat,
593 unsigned char *dstBuf, int subsamp, int flags);
DRC84241602011-02-25 02:08:23 +0000594
595
DRC9b28def2011-05-21 14:37:15 +0000596/**
597 * Create a TurboJPEG decompressor instance.
598 *
599 * @return a handle to the newly-created instance, or NULL if an error
600 * occurred (see #tjGetErrorStr().)
DRC2e7b76b2009-04-03 12:04:24 +0000601*/
602DLLEXPORT tjhandle DLLCALL tjInitDecompress(void);
603
604
DRC9b28def2011-05-21 14:37:15 +0000605/**
606 * Retrieve information about a JPEG image without decompressing it.
607 *
608 * @param handle a handle to a TurboJPEG decompressor or transformer instance
609 * @param jpegBuf pointer to a buffer containing a JPEG image
610 * @param jpegSize size of the JPEG image (in bytes)
611 * @param width pointer to an integer variable which will receive the width (in
612 * pixels) of the JPEG image
613 * @param height pointer to an integer variable which will receive the height
614 * (in pixels) of the JPEG image
615 * @param jpegSubsamp pointer to an integer variable which will receive the
616 * level of chrominance subsampling used when compressing the JPEG image
DRC25b995a2011-05-21 15:34:54 +0000617 * (see @ref TJSAMP "Chrominance subsampling options".)
DRC9b28def2011-05-21 14:37:15 +0000618 *
619 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
DRC2e7b76b2009-04-03 12:04:24 +0000620*/
DRC9b28def2011-05-21 14:37:15 +0000621DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle,
622 unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height,
623 int *jpegSubsamp);
DRC2e7b76b2009-04-03 12:04:24 +0000624
625
DRC9b28def2011-05-21 14:37:15 +0000626/**
627 * Returns a list of fractional scaling factors that the JPEG decompressor in
628 * this implementation of TurboJPEG supports.
629 *
630 * @param numscalingfactors pointer to an integer variable that will receive
631 * the number of elements in the list
632 *
633 * @return a pointer to a list of fractional scaling factors, or NULL if an
634 * error is encountered (see #tjGetErrorStr().)
DRCb28fc572011-02-22 06:41:29 +0000635*/
DRC109a5782011-03-01 09:53:07 +0000636DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors);
DRCb28fc572011-02-22 06:41:29 +0000637
638
DRC9b28def2011-05-21 14:37:15 +0000639/**
640 * Decompress a JPEG image to an RGB or grayscale image.
641 *
642 * @param handle a handle to a TurboJPEG decompressor or transformer instance
643 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
644 * @param jpegSize size of the JPEG image (in bytes)
645 * @param dstBuf pointer to an image buffer which will receive the decompressed
646 * image. This buffer should normally be <tt>pitch * scaledHeight</tt>
647 * bytes in size, where <tt>scaledHeight</tt> can be determined by
648 * calling #TJSCALED() with the JPEG image height and one of the scaling
649 * factors returned by #tjGetScalingFactors(). The dstBuf pointer may
650 * also be used to decompress into a specific region of a larger buffer.
651 * @param width desired width (in pixels) of the destination image. If this is
652 * smaller than the width of the JPEG image being decompressed, then
653 * TurboJPEG will use scaling in the JPEG decompressor to generate the
654 * largest possible image that will fit within the desired width. If
655 * width is set to 0, then only the height will be considered when
656 * determining the scaled image size.
657 * @param pitch bytes per line of the destination image. Normally, this is
658 * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed
659 * image is unpadded, else <tt>#TJPAD(scaledWidth *
660 * #tjPixelSize[pixelFormat])</tt> if each line of the decompressed
661 * image is padded to the nearest 32-bit boundary, as is the case for
662 * Windows bitmaps. (NOTE: <tt>scaledWidth</tt> can be determined by
663 * calling #TJSCALED() with the JPEG image width and one of the scaling
664 * factors returned by #tjGetScalingFactors().) You can also be clever
665 * and use the pitch parameter to skip lines, etc. Setting this
666 * parameter to 0 is the equivalent of setting it to <tt>scaledWidth
667 * * #tjPixelSize[pixelFormat]</tt>.
668 * @param height desired height (in pixels) of the destination image. If this
669 * is smaller than the height of the JPEG image being decompressed, then
670 * TurboJPEG will use scaling in the JPEG decompressor to generate the
671 * largest possible image that will fit within the desired height. If
672 * height is set to 0, then only the width will be considered when
673 * determining the scaled image size.
674 * @param pixelFormat pixel format of the destination image (see @ref
DRC25b995a2011-05-21 15:34:54 +0000675 * TJPF "Pixel formats".)
676 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
677 * "flags".
DRC9b28def2011-05-21 14:37:15 +0000678 *
679 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
680 */
681DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
682 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
683 int width, int pitch, int height, int pixelFormat, int flags);
DRC2e7b76b2009-04-03 12:04:24 +0000684
685
DRC9b28def2011-05-21 14:37:15 +0000686/**
687 * Decompress a JPEG image to a YUV planar image. This function performs JPEG
688 * decompression but leaves out the color conversion step, so a planar YUV
689 * image is generated instead of an RGB image. The padding of the planes in
690 * this image is the same as the images generated by #tjEncodeYUV2(). Note
691 * that, if the width or height of the image is not an even multiple of the MCU
692 * block size (see #tjMCUWidth and #tjMCUHeight), then an intermediate buffer
693 * copy will be performed within TurboJPEG.
694 *
695 * @param handle a handle to a TurboJPEG decompressor or transformer instance
696 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
697 * @param jpegSize size of the JPEG image (in bytes)
698 * @param dstBuf pointer to an image buffer which will receive the YUV image.
DRC9b49f0e2011-07-12 03:17:23 +0000699 * Use #tjBufSizeYUV to determine the appropriate size for this buffer
DRC9b28def2011-05-21 14:37:15 +0000700 * based on the image width, height, and level of subsampling.
DRC25b995a2011-05-21 15:34:54 +0000701 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
702 * "flags".
DRC9b28def2011-05-21 14:37:15 +0000703 *
704 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
705 */
706DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle,
707 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
708 int flags);
DRC84241602011-02-25 02:08:23 +0000709
710
DRC9b28def2011-05-21 14:37:15 +0000711/**
712 * Create a new TurboJPEG transformer instance.
713 *
714 * @return a handle to the newly-created instance, or NULL if an error
715 * occurred (see #tjGetErrorStr().)
716 */
DRC890f1e02011-02-26 22:02:37 +0000717DLLEXPORT tjhandle DLLCALL tjInitTransform(void);
718
719
DRC9b28def2011-05-21 14:37:15 +0000720/**
721 * Losslessly transform a JPEG image into another JPEG image. Lossless
722 * transforms work by moving the raw coefficients from one JPEG image structure
723 * to another without altering the values of the coefficients. While this is
724 * typically faster than decompressing the image, transforming it, and
725 * re-compressing it, lossless transforms are not free. Each lossless
726 * transform requires reading and Huffman decoding all of the coefficients in
727 * the source image, regardless of the size of the destination image. Thus,
728 * this function provides a means of generating multiple transformed images
729 * from the same source or of applying multiple transformations simultaneously,
730 * in order to eliminate the need to read the source coefficients multiple
731 * times.
732 *
733 * @param handle a handle to a TurboJPEG transformer instance
734 * @param jpegBuf pointer to a buffer containing the JPEG image to transform
735 * @param jpegSize size of the JPEG image (in bytes)
736 * @param n the number of transformed JPEG images to generate
737 * @param dstBufs pointer to an array of n image buffers. <tt>dstBufs[i]</tt>
738 * will receive a JPEG image that has been transformed using the
739 * parameters in <tt>transforms[i]</tt>. TurboJPEG has the ability to
740 * reallocate the JPEG buffer to accommodate the size of the JPEG image.
741 * Thus, you can choose to:
DRC6b76f752011-05-24 16:52:47 +0000742 * -# pre-allocate the JPEG buffer with an arbitrary size using
743 * #tjAlloc() and let TurboJPEG grow the buffer as needed,
DRC9b28def2011-05-21 14:37:15 +0000744 * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the
745 * buffer for you, or
746 * -# pre-allocate the buffer to a "worst case" size determined by
DRC9b49f0e2011-07-12 03:17:23 +0000747 * calling #tjBufSize() with the cropped width and height. This should
DRC25b995a2011-05-21 15:34:54 +0000748 * ensure that the buffer never has to be re-allocated (setting
749 * #TJFLAG_NOREALLOC guarantees this.)
DRC9b28def2011-05-21 14:37:15 +0000750 * .
DRCff78e372011-05-24 10:17:32 +0000751 * If you choose option 1, <tt>dstSizes[i]</tt> should be set to
DRC9b28def2011-05-21 14:37:15 +0000752 * the size of your pre-allocated buffer. In any case, unless you have
DRC25b995a2011-05-21 15:34:54 +0000753 * set #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt>
754 * upon return from this function, as it may have changed.
DRC9b28def2011-05-21 14:37:15 +0000755 * @param dstSizes pointer to an array of n unsigned long variables which will
756 * receive the actual sizes (in bytes) of each transformed JPEG image.
757 * If <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then
758 * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon
759 * return, <tt>dstSizes[i]</tt> will contain the size of the JPEG image
760 * (in bytes.)
761 * @param transforms pointer to an array of n tjtransform structures, each of
762 * which specifies the transform parameters and/or cropping region for
763 * the corresponding transformed output image.
DRC25b995a2011-05-21 15:34:54 +0000764 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
765 * "flags".
DRC9b28def2011-05-21 14:37:15 +0000766 *
767 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
768 */
769DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf,
770 unsigned long jpegSize, int n, unsigned char **dstBufs,
771 unsigned long *dstSizes, tjtransform *transforms, int flags);
DRC890f1e02011-02-26 22:02:37 +0000772
773
DRC9b28def2011-05-21 14:37:15 +0000774/**
775 * Destroy a TurboJPEG compressor, decompressor, or transformer instance.
776 *
777 * @param handle a handle to a TurboJPEG compressor, decompressor or
778 * transformer instance
779 *
780 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
781 */
782DLLEXPORT int DLLCALL tjDestroy(tjhandle handle);
DRC2e7b76b2009-04-03 12:04:24 +0000783
784
DRC9b28def2011-05-21 14:37:15 +0000785/**
DRC6b76f752011-05-24 16:52:47 +0000786 * Allocate an image buffer for use with TurboJPEG. You should always use
787 * this function to allocate the JPEG destination buffer(s) for #tjCompress2()
788 * and #tjTransform() unless you are disabling automatic buffer
789 * (re)allocation (by setting #TJFLAG_NOREALLOC.)
790 *
791 * @param bytes the number of bytes to allocate
792 *
793 * @return a pointer to a newly-allocated buffer with the specified number of
794 * bytes
DRCd4411072011-05-24 17:00:15 +0000795 *
796 * @sa tjFree()
DRC6b76f752011-05-24 16:52:47 +0000797 */
798DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes);
799
800
801/**
802 * Free an image buffer previously allocated by TurboJPEG. You should always
803 * use this function to free JPEG destination buffer(s) that were automatically
804 * (re)allocated by #tjCompress2() or #tjTransform() or that were manually
805 * allocated using #tjAlloc().
806 *
807 * @param buffer address of the buffer to free
DRCd4411072011-05-24 17:00:15 +0000808 *
809 * @sa tjAlloc()
DRC6b76f752011-05-24 16:52:47 +0000810 */
811DLLEXPORT void DLLCALL tjFree(unsigned char *buffer);
812
813
814/**
DRC9b28def2011-05-21 14:37:15 +0000815 * Returns a descriptive error message explaining why the last command failed.
816 *
817 * @return a descriptive error message explaining why the last command failed.
818 */
DRC2e7b76b2009-04-03 12:04:24 +0000819DLLEXPORT char* DLLCALL tjGetErrorStr(void);
820
DRC9b28def2011-05-21 14:37:15 +0000821
822/* Backward compatibility functions and macros (nothing to see here) */
823#define NUMSUBOPT TJ_NUMSAMP
DRC25b995a2011-05-21 15:34:54 +0000824#define TJ_444 TJSAMP_444
825#define TJ_422 TJSAMP_422
826#define TJ_420 TJSAMP_420
827#define TJ_411 TJSAMP_420
828#define TJ_GRAYSCALE TJSAMP_GRAY
DRC9b28def2011-05-21 14:37:15 +0000829
DRC25b995a2011-05-21 15:34:54 +0000830#define TJ_BGR 1
831#define TJ_BOTTOMUP TJFLAG_BOTTOMUP
832#define TJ_FORCEMMX TJFLAG_FORCEMMX
833#define TJ_FORCESSE TJFLAG_FORCESSE
834#define TJ_FORCESSE2 TJFLAG_FORCESSE2
DRC9b28def2011-05-21 14:37:15 +0000835#define TJ_ALPHAFIRST 64
DRC25b995a2011-05-21 15:34:54 +0000836#define TJ_FORCESSE3 TJFLAG_FORCESSE3
837#define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE
DRC9b28def2011-05-21 14:37:15 +0000838#define TJ_YUV 512
839
DRC9b49f0e2011-07-12 03:17:23 +0000840DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height);
841
842DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height,
843 int jpegSubsamp);
844
DRC9b28def2011-05-21 14:37:15 +0000845DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf,
846 int width, int pitch, int height, int pixelSize, unsigned char *dstBuf,
847 unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags);
848
849DLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle,
850 unsigned char *srcBuf, int width, int pitch, int height, int pixelSize,
851 unsigned char *dstBuf, int subsamp, int flags);
852
853DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle,
854 unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height);
855
856DLLEXPORT int DLLCALL tjDecompress(tjhandle handle,
857 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
858 int width, int pitch, int height, int pixelSize, int flags);
859
860
861/**
862 * @}
863 */
864
DRC2e7b76b2009-04-03 12:04:24 +0000865#ifdef __cplusplus
866}
867#endif
DRC3a1bb352011-05-24 09:15:44 +0000868
869#endif