Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: turbojpeg.h

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « transupp.c ('k') | turbojpeg.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C)2009-2013 D. R. Commander. All Rights Reserved. 2 * Copyright (C)2009-2015 D. R. Commander. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
7 * - Redistributions of source code must retain the above copyright notice, 7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer. 8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice, 9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation 10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution. 11 * and/or other materials provided with the distribution.
12 * - Neither the name of the libjpeg-turbo Project nor the names of its 12 * - Neither the name of the libjpeg-turbo Project nor the names of its
(...skipping 22 matching lines...) Expand all
35 #define DLLEXPORT 35 #define DLLEXPORT
36 #endif 36 #endif
37 #define DLLCALL 37 #define DLLCALL
38 38
39 39
40 /** 40 /**
41 * @addtogroup TurboJPEG 41 * @addtogroup TurboJPEG
42 * TurboJPEG API. This API provides an interface for generating, decoding, and 42 * TurboJPEG API. This API provides an interface for generating, decoding, and
43 * transforming planar YUV and JPEG images in memory. 43 * transforming planar YUV and JPEG images in memory.
44 * 44 *
45 * @anchor YUVnotes
46 * YUV Image Format Notes
47 * ----------------------
48 * Technically, the JPEG format uses the YCbCr colorspace (which is technically
49 * not a colorspace but a color transform), but per the convention of the
50 * digital video community, the TurboJPEG API uses "YUV" to refer to an image
51 * format consisting of Y, Cb, and Cr image planes.
52 *
53 * Each plane is simply a 2D array of bytes, each byte representing the value
54 * of one of the components (Y, Cb, or Cr) at a particular location in the
55 * image. The width and height of each plane are determined by the image
56 * width, height, and level of chrominance subsampling. The luminance plane
57 * width is the image width padded to the nearest multiple of the horizontal
58 * subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of
59 * 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the luminance plane
60 * height is the image height padded to the nearest multiple of the vertical
61 * subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4
62 * or grayscale.) This is irrespective of any additional padding that may be
63 * specified as an argument to the various YUV functions. The chrominance
64 * plane width is equal to the luminance plane width divided by the horizontal
65 * subsampling factor, and the chrominance plane height is equal to the
66 * luminance plane height divided by the vertical subsampling factor.
67 *
68 * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is
69 * used, then the luminance plane would be 36 x 35 bytes, and each of the
70 * chrominance planes would be 18 x 35 bytes. If you specify a line padding of
71 * 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, and
72 * each of the chrominance planes would be 20 x 35 bytes.
73 *
45 * @{ 74 * @{
46 */ 75 */
47 76
48 77
49 /** 78 /**
50 * The number of chrominance subsampling options 79 * The number of chrominance subsampling options
51 */ 80 */
52 #define TJ_NUMSAMP 5 81 #define TJ_NUMSAMP 6
53 82
54 /** 83 /**
55 * Chrominance subsampling options. 84 * Chrominance subsampling options.
56 * When an image is converted from the RGB to the YCbCr colorspace as part of 85 * When pixels are converted from RGB to YCbCr (see #TJCS_YCbCr) or from CMYK
57 * the JPEG compression process, some of the Cb and Cr (chrominance) components 86 * to YCCK (see #TJCS_YCCK) as part of the JPEG compression process, some of
58 * can be discarded or averaged together to produce a smaller image with little 87 * the Cb and Cr (chrominance) components can be discarded or averaged together
59 * perceptible loss of image clarity (the human eye is more sensitive to small 88 * to produce a smaller image with little perceptible loss of image clarity
60 * changes in brightness than small changes in color.) This is called 89 * (the human eye is more sensitive to small changes in brightness than to
61 * "chrominance subsampling". 90 * small changes in color.) This is called "chrominance subsampling".
62 * <p>
63 * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the
64 * convention of the digital video community, the TurboJPEG API uses "YUV" to
65 * refer to an image format consisting of Y, Cb, and Cr image planes.
66 */ 91 */
67 enum TJSAMP 92 enum TJSAMP
68 { 93 {
69 /** 94 /**
70 * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or 95 * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or
71 * YUV image will contain one chrominance component for every pixel in the 96 * YUV image will contain one chrominance component for every pixel in the
72 * source image. 97 * source image.
73 */ 98 */
74 TJSAMP_444=0, 99 TJSAMP_444=0,
75 /** 100 /**
76 * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one 101 * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one
77 * chrominance component for every 2x1 block of pixels in the source image. 102 * chrominance component for every 2x1 block of pixels in the source image.
78 */ 103 */
79 TJSAMP_422, 104 TJSAMP_422,
80 /** 105 /**
81 * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one 106 * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one
82 * chrominance component for every 2x2 block of pixels in the source image. 107 * chrominance component for every 2x2 block of pixels in the source image.
83 */ 108 */
84 TJSAMP_420, 109 TJSAMP_420,
85 /** 110 /**
86 * Grayscale. The JPEG or YUV image will contain no chrominance components. 111 * Grayscale. The JPEG or YUV image will contain no chrominance components.
87 */ 112 */
88 TJSAMP_GRAY, 113 TJSAMP_GRAY,
89 /** 114 /**
90 * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one 115 * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one
91 * chrominance component for every 1x2 block of pixels in the source image. 116 * chrominance component for every 1x2 block of pixels in the source image.
92 * Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo. 117 *
118 * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
93 */ 119 */
94 TJSAMP_440 120 TJSAMP_440,
121 /**
122 * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one
123 * chrominance component for every 4x1 block of pixels in the source image.
124 * JPEG images compressed with 4:1:1 subsampling will be almost exactly the
125 * same size as those compressed with 4:2:0 subsampling, and in the
126 * aggregate, both subsampling methods produce approximately the same
127 * perceptual quality. However, 4:1:1 is better able to reproduce sharp
128 * horizontal features.
129 *
130 * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo.
131 */
132 TJSAMP_411
95 }; 133 };
96 134
97 /** 135 /**
98 * MCU block width (in pixels) for a given level of chrominance subsampling. 136 * MCU block width (in pixels) for a given level of chrominance subsampling.
99 * MCU block sizes: 137 * MCU block sizes:
100 * - 8x8 for no subsampling or grayscale 138 * - 8x8 for no subsampling or grayscale
101 * - 16x8 for 4:2:2 139 * - 16x8 for 4:2:2
102 * - 8x16 for 4:4:0 140 * - 8x16 for 4:4:0
103 * - 16x16 for 4:2:0 141 * - 16x16 for 4:2:0
142 * - 32x8 for 4:1:1
104 */ 143 */
105 static const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8}; 144 static const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8, 32};
106 145
107 /** 146 /**
108 * MCU block height (in pixels) for a given level of chrominance subsampling. 147 * MCU block height (in pixels) for a given level of chrominance subsampling.
109 * MCU block sizes: 148 * MCU block sizes:
110 * - 8x8 for no subsampling or grayscale 149 * - 8x8 for no subsampling or grayscale
111 * - 16x8 for 4:2:2 150 * - 16x8 for 4:2:2
112 * - 8x16 for 4:4:0 151 * - 8x16 for 4:4:0
113 * - 16x16 for 4:2:0 152 * - 16x16 for 4:2:0
153 * - 32x8 for 4:1:1
114 */ 154 */
115 static const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16}; 155 static const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16, 8};
116 156
117 157
118 /** 158 /**
119 * The number of pixel formats 159 * The number of pixel formats
120 */ 160 */
121 #define TJ_NUMPF 11 161 #define TJ_NUMPF 12
122 162
123 /** 163 /**
124 * Pixel formats 164 * Pixel formats
125 */ 165 */
126 enum TJPF 166 enum TJPF
127 { 167 {
128 /** 168 /**
129 * RGB pixel format. The red, green, and blue components in the image are 169 * RGB pixel format. The red, green, and blue components in the image are
130 * stored in 3-byte pixels in the order R, G, B from lowest to highest byte 170 * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
131 * address within each pixel. 171 * address within each pixel.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when 226 * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when
187 * decompressing, the X component is guaranteed to be 0xFF, which can be 227 * decompressing, the X component is guaranteed to be 0xFF, which can be
188 * interpreted as an opaque alpha channel. 228 * interpreted as an opaque alpha channel.
189 */ 229 */
190 TJPF_ABGR, 230 TJPF_ABGR,
191 /** 231 /**
192 * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when 232 * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when
193 * decompressing, the X component is guaranteed to be 0xFF, which can be 233 * decompressing, the X component is guaranteed to be 0xFF, which can be
194 * interpreted as an opaque alpha channel. 234 * interpreted as an opaque alpha channel.
195 */ 235 */
196 TJPF_ARGB 236 TJPF_ARGB,
237 /**
238 * CMYK pixel format. Unlike RGB, which is an additive color model used
239 * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive
240 * color model used primarily for printing. In the CMYK color model, the
241 * value of each color component typically corresponds to an amount of cyan,
242 * magenta, yellow, or black ink that is applied to a white background. In
243 * order to convert between CMYK and RGB, it is necessary to use a color
244 * management system (CMS.) A CMS will attempt to map colors within the
245 * printer's gamut to perceptually similar colors in the display's gamut and
246 * vice versa, but the mapping is typically not 1:1 or reversible, nor can it
247 * be defined with a simple formula. Thus, such a conversion is out of scope
248 * for a codec library. However, the TurboJPEG API allows for compressing
249 * CMYK pixels into a YCCK JPEG image (see #TJCS_YCCK) and decompressing YCCK
250 * JPEG images into CMYK pixels.
251 */
252 TJPF_CMYK
197 }; 253 };
198 254
255
199 /** 256 /**
200 * Red offset (in bytes) for a given pixel format. This specifies the number 257 * Red offset (in bytes) for a given pixel format. This specifies the number
201 * of bytes that the red component is offset from the start of the pixel. For 258 * of bytes that the red component is offset from the start of the pixel. For
202 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, 259 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
203 * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>. 260 * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>.
204 */ 261 */
205 static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1}; 262 static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1};
206 /** 263 /**
207 * Green offset (in bytes) for a given pixel format. This specifies the number 264 * Green offset (in bytes) for a given pixel format. This specifies the number
208 * of bytes that the green component is offset from the start of the pixel. 265 * of bytes that the green component is offset from the start of the pixel.
209 * For instance, if a pixel of format TJ_BGRX is stored in 266 * For instance, if a pixel of format TJ_BGRX is stored in
210 * <tt>char pixel[]</tt>, then the green component will be 267 * <tt>char pixel[]</tt>, then the green component will be
211 * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>. 268 * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>.
212 */ 269 */
213 static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2}; 270 static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1} ;
214 /** 271 /**
215 * Blue offset (in bytes) for a given pixel format. This specifies the number 272 * Blue offset (in bytes) for a given pixel format. This specifies the number
216 * of bytes that the Blue component is offset from the start of the pixel. For 273 * of bytes that the Blue component is offset from the start of the pixel. For
217 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, 274 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
218 * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>. 275 * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>.
219 */ 276 */
220 static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3}; 277 static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1};
221 278
222 /** 279 /**
223 * Pixel size (in bytes) for a given pixel format. 280 * Pixel size (in bytes) for a given pixel format.
224 */ 281 */
225 static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4}; 282 static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4};
283
284
285 /**
286 * The number of JPEG colorspaces
287 */
288 #define TJ_NUMCS 5
289
290 /**
291 * JPEG colorspaces
292 */
293 enum TJCS
294 {
295 /**
296 * RGB colorspace. When compressing the JPEG image, the R, G, and B
297 * components in the source image are reordered into image planes, but no
298 * colorspace conversion or subsampling is performed. RGB JPEG images can be
299 * decompressed to any of the extended RGB pixel formats or grayscale, but
300 * they cannot be decompressed to YUV images.
301 */
302 TJCS_RGB=0,
303 /**
304 * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a
305 * mathematical transformation of RGB designed solely for storage and
306 * transmission. YCbCr images must be converted to RGB before they can
307 * actually be displayed. In the YCbCr colorspace, the Y (luminance)
308 * component represents the black & white portion of the original image, and
309 * the Cb and Cr (chrominance) components represent the color portion of the
310 * original image. Originally, the analog equivalent of this transformation
311 * allowed the same signal to drive both black & white and color televisions,
312 * but JPEG images use YCbCr primarily because it allows the color data to be
313 * optionally subsampled for the purposes of reducing bandwidth or disk
314 * space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images
315 * can be compressed from and decompressed to any of the extended RGB pixel
316 * formats or grayscale, or they can be decompressed to YUV planar images.
317 */
318 TJCS_YCbCr,
319 /**
320 * Grayscale colorspace. The JPEG image retains only the luminance data (Y
321 * component), and any color data from the source image is discarded.
322 * Grayscale JPEG images can be compressed from and decompressed to any of
323 * the extended RGB pixel formats or grayscale, or they can be decompressed
324 * to YUV planar images.
325 */
326 TJCS_GRAY,
327 /**
328 * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K
329 * components in the source image are reordered into image planes, but no
330 * colorspace conversion or subsampling is performed. CMYK JPEG images can
331 * only be decompressed to CMYK pixels.
332 */
333 TJCS_CMYK,
334 /**
335 * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but
336 * rather a mathematical transformation of CMYK designed solely for storage
337 * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be
338 * reversibly transformed into YCCK, and as with YCbCr, the chrominance
339 * components in the YCCK pixels can be subsampled without incurring major
340 * perceptual loss. YCCK JPEG images can only be compressed from and
341 * decompressed to CMYK pixels.
342 */
343 TJCS_YCCK
344 };
226 345
227 346
228 /** 347 /**
229 * The uncompressed source/destination image is stored in bottom-up (Windows, 348 * The uncompressed source/destination image is stored in bottom-up (Windows,
230 * OpenGL) order, not top-down (X11) order. 349 * OpenGL) order, not top-down (X11) order.
231 */ 350 */
232 #define TJFLAG_BOTTOMUP 2 351 #define TJFLAG_BOTTOMUP 2
233 /** 352 /**
234 * Turn off CPU auto-detection and force TurboJPEG to use MMX code (if the
235 * underlying codec supports it.)
236 */
237 #define TJFLAG_FORCEMMX 8
238 /**
239 * Turn off CPU auto-detection and force TurboJPEG to use SSE code (if the
240 * underlying codec supports it.)
241 */
242 #define TJFLAG_FORCESSE 16
243 /**
244 * Turn off CPU auto-detection and force TurboJPEG to use SSE2 code (if the
245 * underlying codec supports it.)
246 */
247 #define TJFLAG_FORCESSE2 32
248 /**
249 * Turn off CPU auto-detection and force TurboJPEG to use SSE3 code (if the
250 * underlying codec supports it.)
251 */
252 #define TJFLAG_FORCESSE3 128
253 /**
254 * When decompressing an image that was compressed using chrominance 353 * When decompressing an image that was compressed using chrominance
255 * subsampling, use the fastest chrominance upsampling algorithm available in 354 * subsampling, use the fastest chrominance upsampling algorithm available in
256 * the underlying codec. The default is to use smooth upsampling, which 355 * the underlying codec. The default is to use smooth upsampling, which
257 * creates a smooth transition between neighboring chrominance components in 356 * creates a smooth transition between neighboring chrominance components in
258 * order to reduce upsampling artifacts in the decompressed image. 357 * order to reduce upsampling artifacts in the decompressed image.
259 */ 358 */
260 #define TJFLAG_FASTUPSAMPLE 256 359 #define TJFLAG_FASTUPSAMPLE 256
261 /** 360 /**
262 * Disable buffer (re)allocation. If passed to #tjCompress2() or 361 * Disable buffer (re)allocation. If passed to #tjCompress2() or
263 * #tjTransform(), this flag will cause those functions to generate an error if 362 * #tjTransform(), this flag will cause those functions to generate an error if
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 * function 541 * function
443 */ 542 */
444 void *data; 543 void *data;
445 /** 544 /**
446 * A callback function that can be used to modify the DCT coefficients 545 * A callback function that can be used to modify the DCT coefficients
447 * after they are losslessly transformed but before they are transcoded to a 546 * after they are losslessly transformed but before they are transcoded to a
448 * new JPEG image. This allows for custom filters or other transformations 547 * new JPEG image. This allows for custom filters or other transformations
449 * to be applied in the frequency domain. 548 * to be applied in the frequency domain.
450 * 549 *
451 * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE: 550 * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE:
452 * this pointer is not guaranteed to be valid once the callback 551 * this pointer is not guaranteed to be valid once the callback returns, so
453 * returns, so applications wishing to hand off the DCT coefficients 552 * applications wishing to hand off the DCT coefficients to another function
454 * to another function or library should make a copy of them within 553 * or library should make a copy of them within the body of the callback.)
455 * the body of the callback.) 554 *
456 * @param arrayRegion #tjregion structure containing the width and height of 555 * @param arrayRegion #tjregion structure containing the width and height of
457 * the array pointed to by <tt>coeffs</tt> as well as its offset 556 * the array pointed to by <tt>coeffs</tt> as well as its offset relative to
458 * relative to the component plane. TurboJPEG implementations may 557 * the component plane. TurboJPEG implementations may choose to split each
459 * choose to split each component plane into multiple DCT coefficient 558 * component plane into multiple DCT coefficient arrays and call the callback
460 * arrays and call the callback function once for each array. 559 * function once for each array.
560 *
461 * @param planeRegion #tjregion structure containing the width and height of 561 * @param planeRegion #tjregion structure containing the width and height of
462 * the component plane to which <tt>coeffs</tt> belongs 562 * the component plane to which <tt>coeffs</tt> belongs
563 *
463 * @param componentID ID number of the component plane to which 564 * @param componentID ID number of the component plane to which
464 * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 565 * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1,
465 * 0, 1, and 2 in typical JPEG images.) 566 * and 2 in typical JPEG images.)
567 *
466 * @param transformID ID number of the transformed image to which 568 * @param transformID ID number of the transformed image to which
467 * <tt>coeffs</tt> belongs. This is the same as the index of the 569 * <tt>coeffs</tt> belongs. This is the same as the index of the transform
468 * transform in the <tt>transforms</tt> array that was passed to 570 * in the <tt>transforms</tt> array that was passed to #tjTransform().
469 * #tjTransform(). 571 *
470 * @param transform a pointer to a #tjtransform structure that specifies the 572 * @param transform a pointer to a #tjtransform structure that specifies the
471 * parameters and/or cropping region for this transform 573 * parameters and/or cropping region for this transform
472 * 574 *
473 * @return 0 if the callback was successful, or -1 if an error occurred. 575 * @return 0 if the callback was successful, or -1 if an error occurred.
474 */ 576 */
475 int (*customFilter)(short *coeffs, tjregion arrayRegion, 577 int (*customFilter)(short *coeffs, tjregion arrayRegion,
476 tjregion planeRegion, int componentIndex, int transformIndex, 578 tjregion planeRegion, int componentIndex, int transformIndex,
477 struct tjtransform *transform); 579 struct tjtransform *transform);
478 } tjtransform; 580 } tjtransform;
479 581
480 /** 582 /**
481 * TurboJPEG instance handle 583 * TurboJPEG instance handle
482 */ 584 */
483 typedef void* tjhandle; 585 typedef void* tjhandle;
484 586
485 587
486 /** 588 /**
487 * Pad the given width to the nearest 32-bit boundary 589 * Pad the given width to the nearest 32-bit boundary
488 */ 590 */
489 #define TJPAD(width) (((width)+3)&(~3)) 591 #define TJPAD(width) (((width)+3)&(~3))
490 592
491 /** 593 /**
492 * Compute the scaled value of <tt>dimension</tt> using the given scaling 594 * Compute the scaled value of <tt>dimension</tt> using the given scaling
493 * factor. This macro performs the integer equivalent of <tt>ceil(dimension * 595 * factor. This macro performs the integer equivalent of <tt>ceil(dimension *
494 * scalingFactor)</tt>. 596 * scalingFactor)</tt>.
495 */ 597 */
496 #define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \ 598 #define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \
497 + scalingFactor.denom - 1) / scalingFactor.denom) 599 + scalingFactor.denom - 1) / scalingFactor.denom)
498 600
499 601
500 #ifdef __cplusplus 602 #ifdef __cplusplus
501 extern "C" { 603 extern "C" {
502 #endif 604 #endif
503 605
504 606
505 /** 607 /**
506 * Create a TurboJPEG compressor instance. 608 * Create a TurboJPEG compressor instance.
507 * 609 *
508 * @return a handle to the newly-created instance, or NULL if an error 610 * @return a handle to the newly-created instance, or NULL if an error
509 * occurred (see #tjGetErrorStr().) 611 * occurred (see #tjGetErrorStr().)
510 */ 612 */
511 DLLEXPORT tjhandle DLLCALL tjInitCompress(void); 613 DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
512 614
513 615
514 /** 616 /**
515 * Compress an RGB or grayscale image into a JPEG image. 617 * Compress an RGB, grayscale, or CMYK image into a JPEG image.
516 * 618 *
517 * @param handle a handle to a TurboJPEG compressor or transformer instance 619 * @param handle a handle to a TurboJPEG compressor or transformer instance
518 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels 620 *
519 * to be compressed 621 * @param srcBuf pointer to an image buffer containing RGB, grayscale, or
622 * CMYK pixels to be compressed
623 *
520 * @param width width (in pixels) of the source image 624 * @param width width (in pixels) of the source image
521 * @param pitch bytes per line of the source image. Normally, this should be 625 *
522 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, 626 * @param pitch bytes per line in the source image. Normally, this should be
523 * or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of 627 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
524 * the image is padded to the nearest 32-bit boundary, as is the case 628 * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
525 * for Windows bitmaps. You can also be clever and use this parameter 629 * is padded to the nearest 32-bit boundary, as is the case for Windows
526 * to skip lines, etc. Setting this parameter to 0 is the equivalent of 630 * bitmaps. You can also be clever and use this parameter to skip lines, etc.
527 * setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. 631 * Setting this parameter to 0 is the equivalent of setting it to
632 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
633 *
528 * @param height height (in pixels) of the source image 634 * @param height height (in pixels) of the source image
635 *
529 * @param pixelFormat pixel format of the source image (see @ref TJPF 636 * @param pixelFormat pixel format of the source image (see @ref TJPF
530 * "Pixel formats".) 637 * "Pixel formats".)
638 *
531 * @param jpegBuf address of a pointer to an image buffer that will receive the 639 * @param jpegBuf address of a pointer to an image buffer that will receive the
532 * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer 640 * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer
533 * to accommodate the size of the JPEG image. Thus, you can choose to: 641 * to accommodate the size of the JPEG image. Thus, you can choose to:
534 * -# pre-allocate the JPEG buffer with an arbitrary size using 642 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
535 * #tjAlloc() and let TurboJPEG grow the buffer as needed, 643 * let TurboJPEG grow the buffer as needed,
536 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the 644 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
537 * buffer for you, or 645 * for you, or
538 * -# pre-allocate the buffer to a "worst case" size determined by 646 * -# pre-allocate the buffer to a "worst case" size determined by calling
539 * calling #tjBufSize(). This should ensure that the buffer never has 647 * #tjBufSize(). This should ensure that the buffer never has to be
540 * to be re-allocated (setting #TJFLAG_NOREALLOC guarantees this.) 648 * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
541 * . 649 * .
542 * If you choose option 1, <tt>*jpegSize</tt> should be set to the 650 * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
543 * size of your pre-allocated buffer. In any case, unless you have 651 * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
544 * set #TJFLAG_NOREALLOC, you should always check <tt>*jpegBuf</tt> upon 652 * you should always check <tt>*jpegBuf</tt> upon return from this function, as
545 * return from this function, as it may have changed. 653 * it may have changed.
654 *
546 * @param jpegSize pointer to an unsigned long variable that holds the size of 655 * @param jpegSize pointer to an unsigned long variable that holds the size of
547 * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a 656 * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated
548 * pre-allocated buffer, then <tt>*jpegSize</tt> should be set to the 657 * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
549 * size of the buffer. Upon return, <tt>*jpegSize</tt> will contain the 658 * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
550 * size of the JPEG image (in bytes.) 659 * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
660 * reused from a previous call to one of the JPEG compression functions, then
661 * <tt>*jpegSize</tt> is ignored.
662 *
551 * @param jpegSubsamp the level of chrominance subsampling to be used when 663 * @param jpegSubsamp the level of chrominance subsampling to be used when
552 * generating the JPEG image (see @ref TJSAMP 664 * generating the JPEG image (see @ref TJSAMP
553 * "Chrominance subsampling options".) 665 * "Chrominance subsampling options".)
666 *
554 * @param jpegQual the image quality of the generated JPEG image (1 = worst, 667 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
555 100 = best) 668 * 100 = best)
669 *
556 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 670 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
557 * "flags". 671 * "flags"
558 * 672 *
559 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 673 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
560 */ 674 */
561 DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, 675 DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf,
562 int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, 676 int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
563 unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags); 677 unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags);
564 678
565 679
566 /** 680 /**
681 * Compress a YUV planar image into a JPEG image.
682 *
683 * @param handle a handle to a TurboJPEG compressor or transformer instance
684 *
685 * @param srcBuf pointer to an image buffer containing a YUV planar image to be
686 * compressed. The size of this buffer should match the value returned by
687 * #tjBufSizeYUV2() for the given image width, height, padding, and level of
688 * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be
689 * stored sequentially in the source buffer (refer to @ref YUVnotes
690 * "YUV Image Format Notes".)
691 *
692 * @param width width (in pixels) of the source image. If the width is not an
693 * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
694 * buffer copy will be performed within TurboJPEG.
695 *
696 * @param pad the line padding used in the source image. For instance, if each
697 * line in each plane of the YUV image is padded to the nearest multiple of 4
698 * bytes, then <tt>pad</tt> should be set to 4.
699 *
700 * @param height height (in pixels) of the source image. If the height is not
701 * an even multiple of the MCU block height (see #tjMCUHeight), then an
702 * intermediate buffer copy will be performed within TurboJPEG.
703 *
704 * @param subsamp the level of chrominance subsampling used in the source
705 * image (see @ref TJSAMP "Chrominance subsampling options".)
706 *
707 * @param jpegBuf address of a pointer to an image buffer that will receive the
708 * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
709 * accommodate the size of the JPEG image. Thus, you can choose to:
710 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
711 * let TurboJPEG grow the buffer as needed,
712 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
713 * for you, or
714 * -# pre-allocate the buffer to a "worst case" size determined by calling
715 * #tjBufSize(). This should ensure that the buffer never has to be
716 * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
717 * .
718 * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
719 * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
720 * you should always check <tt>*jpegBuf</tt> upon return from this function, as
721 * it may have changed.
722 *
723 * @param jpegSize pointer to an unsigned long variable that holds the size of
724 * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated
725 * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
726 * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
727 * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
728 * reused from a previous call to one of the JPEG compression functions, then
729 * <tt>*jpegSize</tt> is ignored.
730 *
731 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
732 * 100 = best)
733 *
734 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
735 * "flags"
736 *
737 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
738 */
739 DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle,
740 const unsigned char *srcBuf, int width, int pad, int height, int subsamp,
741 unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags);
742
743
744 /**
745 * Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image.
746 *
747 * @param handle a handle to a TurboJPEG compressor or transformer instance
748 *
749 * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
750 * (or just a Y plane, if compressing a grayscale image) that contain a YUV
751 * image to be compressed. These planes can be contiguous or non-contiguous in
752 * memory. The size of each plane should match the value returned by
753 * #tjPlaneSizeYUV() for the given image width, height, strides, and level of
754 * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes"
755 * for more details.
756 *
757 * @param width width (in pixels) of the source image. If the width is not an
758 * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
759 * buffer copy will be performed within TurboJPEG.
760 *
761 * @param strides an array of integers, each specifying the number of bytes per
762 * line in the corresponding plane of the YUV source image. Setting the stride
763 * for any plane to 0 is the same as setting it to the plane width (see
764 * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
765 * the strides for all planes will be set to their respective plane widths.
766 * You can adjust the strides in order to specify an arbitrary amount of line
767 * padding in each plane or to create a JPEG image from a subregion of a larger
768 * YUV planar image.
769 *
770 * @param height height (in pixels) of the source image. If the height is not
771 * an even multiple of the MCU block height (see #tjMCUHeight), then an
772 * intermediate buffer copy will be performed within TurboJPEG.
773 *
774 * @param subsamp the level of chrominance subsampling used in the source
775 * image (see @ref TJSAMP "Chrominance subsampling options".)
776 *
777 * @param jpegBuf address of a pointer to an image buffer that will receive the
778 * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to
779 * accommodate the size of the JPEG image. Thus, you can choose to:
780 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
781 * let TurboJPEG grow the buffer as needed,
782 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
783 * for you, or
784 * -# pre-allocate the buffer to a "worst case" size determined by calling
785 * #tjBufSize(). This should ensure that the buffer never has to be
786 * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.)
787 * .
788 * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
789 * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC,
790 * you should always check <tt>*jpegBuf</tt> upon return from this function, as
791 * it may have changed.
792 *
793 * @param jpegSize pointer to an unsigned long variable that holds the size of
794 * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated
795 * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
796 * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
797 * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
798 * reused from a previous call to one of the JPEG compression functions, then
799 * <tt>*jpegSize</tt> is ignored.
800 *
801 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
802 * 100 = best)
803 *
804 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
805 * "flags"
806 *
807 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
808 */
809 DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle,
810 const unsigned char **srcPlanes, int width, const int *strides, int height,
811 int subsamp, unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual,
812 int flags);
813
814
815 /**
567 * The maximum size of the buffer (in bytes) required to hold a JPEG image with 816 * The maximum size of the buffer (in bytes) required to hold a JPEG image with
568 * the given parameters. The number of bytes returned by this function is 817 * the given parameters. The number of bytes returned by this function is
569 * larger than the size of the uncompressed source image. The reason for this 818 * larger than the size of the uncompressed source image. The reason for this
570 * is that the JPEG format uses 16-bit coefficients, and it is thus possible 819 * is that the JPEG format uses 16-bit coefficients, and it is thus possible
571 * for a very high-quality JPEG image with very high-frequency content to 820 * for a very high-quality JPEG image with very high-frequency content to
572 * expand rather than compress when converted to the JPEG format. Such images 821 * expand rather than compress when converted to the JPEG format. Such images
573 * represent a very rare corner case, but since there is no way to predict the 822 * represent a very rare corner case, but since there is no way to predict the
574 * size of a JPEG image prior to compression, the corner case has to be 823 * size of a JPEG image prior to compression, the corner case has to be
575 * handled. 824 * handled.
576 * 825 *
577 * @param width width of the image (in pixels) 826 * @param width width (in pixels) of the image
578 * @param height height of the image (in pixels) 827 *
828 * @param height height (in pixels) of the image
829 *
579 * @param jpegSubsamp the level of chrominance subsampling to be used when 830 * @param jpegSubsamp the level of chrominance subsampling to be used when
580 * generating the JPEG image (see @ref TJSAMP 831 * generating the JPEG image (see @ref TJSAMP
581 * "Chrominance subsampling options".) 832 * "Chrominance subsampling options".)
582 * 833 *
583 * @return the maximum size of the buffer (in bytes) required to hold the 834 * @return the maximum size of the buffer (in bytes) required to hold the
584 * image, or -1 if the arguments are out of bounds. 835 * image, or -1 if the arguments are out of bounds.
585 */ 836 */
586 DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, 837 DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height,
587 int jpegSubsamp); 838 int jpegSubsamp);
588 839
589 840
590 /** 841 /**
591 * The size of the buffer (in bytes) required to hold a YUV planar image with 842 * The size of the buffer (in bytes) required to hold a YUV planar image with
592 * the given parameters. 843 * the given parameters.
593 * 844 *
594 * @param width width of the image (in pixels) 845 * @param width width (in pixels) of the image
595 * @param height height of the image (in pixels) 846 *
847 * @param pad the width of each line in each plane of the image is padded to
848 * the nearest multiple of this number of bytes (must be a power of 2.)
849 *
850 * @param height height (in pixels) of the image
851 *
596 * @param subsamp level of chrominance subsampling in the image (see 852 * @param subsamp level of chrominance subsampling in the image (see
597 * @ref TJSAMP "Chrominance subsampling options".) 853 * @ref TJSAMP "Chrominance subsampling options".)
598 * 854 *
599 * @return the size of the buffer (in bytes) required to hold the image, or 855 * @return the size of the buffer (in bytes) required to hold the image, or
600 * -1 if the arguments are out of bounds. 856 * -1 if the arguments are out of bounds.
601 */ 857 */
602 DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height, 858 DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height,
603 int subsamp); 859 int subsamp);
604 860
605 861
606 /** 862 /**
863 * The size of the buffer (in bytes) required to hold a YUV image plane with
864 * the given parameters.
865 *
866 * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
867 *
868 * @param width width (in pixels) of the YUV image. NOTE: this is the width of
869 * the whole image, not the plane width.
870 *
871 * @param stride bytes per line in the image plane. Setting this to 0 is the
872 * equivalent of setting it to the plane width.
873 *
874 * @param height height (in pixels) of the YUV image. NOTE: this is the height
875 * of the whole image, not the plane height.
876 *
877 * @param subsamp level of chrominance subsampling in the image (see
878 * @ref TJSAMP "Chrominance subsampling options".)
879 *
880 * @return the size of the buffer (in bytes) required to hold the YUV image
881 * plane, or -1 if the arguments are out of bounds.
882 */
883 DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV(int componentID, int width,
884 int stride, int height, int subsamp);
885
886
887 /**
888 * The plane width of a YUV image plane with the given parameters. Refer to
889 * @ref YUVnotes "YUV Image Format Notes" for a description of plane width.
890 *
891 * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
892 *
893 * @param width width (in pixels) of the YUV image
894 *
895 * @param subsamp level of chrominance subsampling in the image (see
896 * @ref TJSAMP "Chrominance subsampling options".)
897 *
898 * @return the plane width of a YUV image plane with the given parameters, or
899 * -1 if the arguments are out of bounds.
900 */
901 DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp);
902
903
904 /**
905 * The plane height of a YUV image plane with the given parameters. Refer to
906 * @ref YUVnotes "YUV Image Format Notes" for a description of plane height.
907 *
908 * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
909 *
910 * @param height height (in pixels) of the YUV image
911 *
912 * @param subsamp level of chrominance subsampling in the image (see
913 * @ref TJSAMP "Chrominance subsampling options".)
914 *
915 * @return the plane height of a YUV image plane with the given parameters, or
916 * -1 if the arguments are out of bounds.
917 */
918 DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp);
919
920
921 /**
607 * Encode an RGB or grayscale image into a YUV planar image. This function 922 * Encode an RGB or grayscale image into a YUV planar image. This function
608 * uses the accelerated color conversion routines in TurboJPEG's underlying 923 * uses the accelerated color conversion routines in the underlying
609 * codec to produce a planar YUV image that is suitable for X Video. 924 * codec but does not execute any of the other steps in the JPEG compression
610 * Specifically, if the chrominance components are subsampled along the 925 * process.
611 * horizontal dimension, then the width of the luminance plane is padded to the
612 * nearest multiple of 2 in the output image (same goes for the height of the
613 * luminance plane, if the chrominance components are subsampled along the
614 * vertical dimension.) Also, each line of each plane in the output image is
615 * padded to 4 bytes. Although this will work with any subsampling option, it
616 * is really only useful in combination with TJ_420, which produces an image
617 * compatible with the I420 (AKA "YUV420P") format.
618 * <p>
619 * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the
620 * convention of the digital video community, the TurboJPEG API uses "YUV" to
621 * refer to an image format consisting of Y, Cb, and Cr image planes.
622 * 926 *
623 * @param handle a handle to a TurboJPEG compressor or transformer instance 927 * @param handle a handle to a TurboJPEG compressor or transformer instance
928 *
624 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels 929 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
625 * to be encoded 930 * to be encoded
931 *
626 * @param width width (in pixels) of the source image 932 * @param width width (in pixels) of the source image
627 * @param pitch bytes per line of the source image. Normally, this should be 933 *
628 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, 934 * @param pitch bytes per line in the source image. Normally, this should be
629 * or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of 935 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
630 * the image is padded to the nearest 32-bit boundary, as is the case 936 * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
631 * for Windows bitmaps. You can also be clever and use this parameter 937 * is padded to the nearest 32-bit boundary, as is the case for Windows
632 * to skip lines, etc. Setting this parameter to 0 is the equivalent of 938 * bitmaps. You can also be clever and use this parameter to skip lines, etc.
633 * setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. 939 * Setting this parameter to 0 is the equivalent of setting it to
940 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
941 *
634 * @param height height (in pixels) of the source image 942 * @param height height (in pixels) of the source image
943 *
635 * @param pixelFormat pixel format of the source image (see @ref TJPF 944 * @param pixelFormat pixel format of the source image (see @ref TJPF
636 * "Pixel formats".) 945 * "Pixel formats".)
946 *
637 * @param dstBuf pointer to an image buffer that will receive the YUV image. 947 * @param dstBuf pointer to an image buffer that will receive the YUV image.
638 * Use #tjBufSizeYUV() to determine the appropriate size for this buffer 948 * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based
639 * based on the image width, height, and level of chrominance 949 * on the image width, height, padding, and level of chrominance subsampling.
640 * subsampling. 950 * The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the
951 * buffer (refer to @ref YUVnotes "YUV Image Format Notes".)
952 *
953 * @param pad the width of each line in each plane of the YUV image will be
954 * padded to the nearest multiple of this number of bytes (must be a power of
955 * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to
956 * 4.
957 *
641 * @param subsamp the level of chrominance subsampling to be used when 958 * @param subsamp the level of chrominance subsampling to be used when
642 * generating the YUV image (see @ref TJSAMP 959 * generating the YUV image (see @ref TJSAMP
643 * "Chrominance subsampling options".) 960 * "Chrominance subsampling options".) To generate images suitable for X
961 * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an
962 * image compatible with the I420 (AKA "YUV420P") format.
963 *
644 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 964 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
645 * "flags". 965 * "flags"
646 * 966 *
647 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 967 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
648 */ 968 */
649 DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle, 969 DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle,
650 unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, 970 const unsigned char *srcBuf, int width, int pitch, int height,
651 unsigned char *dstBuf, int subsamp, int flags); 971 int pixelFormat, unsigned char *dstBuf, int pad, int subsamp, int flags);
652 972
653 973
654 /** 974 /**
975 * Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image
976 * planes. This function uses the accelerated color conversion routines in the
977 * underlying codec but does not execute any of the other steps in the JPEG
978 * compression process.
979 *
980 * @param handle a handle to a TurboJPEG compressor or transformer instance
981 *
982 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
983 * to be encoded
984 *
985 * @param width width (in pixels) of the source image
986 *
987 * @param pitch bytes per line in the source image. Normally, this should be
988 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
989 * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
990 * is padded to the nearest 32-bit boundary, as is the case for Windows
991 * bitmaps. You can also be clever and use this parameter to skip lines, etc.
992 * Setting this parameter to 0 is the equivalent of setting it to
993 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
994 *
995 * @param height height (in pixels) of the source image
996 *
997 * @param pixelFormat pixel format of the source image (see @ref TJPF
998 * "Pixel formats".)
999 *
1000 * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
1001 * (or just a Y plane, if generating a grayscale image) that will receive the
1002 * encoded image. These planes can be contiguous or non-contiguous in memory.
1003 * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
1004 * on the image width, height, strides, and level of chrominance subsampling.
1005 * Refer to @ref YUVnotes "YUV Image Format Notes" for more details.
1006 *
1007 * @param strides an array of integers, each specifying the number of bytes per
1008 * line in the corresponding plane of the output image. Setting the stride for
1009 * any plane to 0 is the same as setting it to the plane width (see
1010 * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
1011 * the strides for all planes will be set to their respective plane widths.
1012 * You can adjust the strides in order to add an arbitrary amount of line
1013 * padding to each plane or to encode an RGB or grayscale image into a
1014 * subregion of a larger YUV planar image.
1015 *
1016 * @param subsamp the level of chrominance subsampling to be used when
1017 * generating the YUV image (see @ref TJSAMP
1018 * "Chrominance subsampling options".) To generate images suitable for X
1019 * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an
1020 * image compatible with the I420 (AKA "YUV420P") format.
1021 *
1022 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1023 * "flags"
1024 *
1025 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
1026 */
1027 DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle,
1028 const unsigned char *srcBuf, int width, int pitch, int height,
1029 int pixelFormat, unsigned char **dstPlanes, int *strides, int subsamp,
1030 int flags);
1031
1032
1033 /**
655 * Create a TurboJPEG decompressor instance. 1034 * Create a TurboJPEG decompressor instance.
656 * 1035 *
657 * @return a handle to the newly-created instance, or NULL if an error 1036 * @return a handle to the newly-created instance, or NULL if an error
658 * occurred (see #tjGetErrorStr().) 1037 * occurred (see #tjGetErrorStr().)
659 */ 1038 */
660 DLLEXPORT tjhandle DLLCALL tjInitDecompress(void); 1039 DLLEXPORT tjhandle DLLCALL tjInitDecompress(void);
661 1040
662 1041
663 /** 1042 /**
664 * Retrieve information about a JPEG image without decompressing it. 1043 * Retrieve information about a JPEG image without decompressing it.
665 * 1044 *
666 * @param handle a handle to a TurboJPEG decompressor or transformer instance 1045 * @param handle a handle to a TurboJPEG decompressor or transformer instance
1046 *
667 * @param jpegBuf pointer to a buffer containing a JPEG image 1047 * @param jpegBuf pointer to a buffer containing a JPEG image
1048 *
668 * @param jpegSize size of the JPEG image (in bytes) 1049 * @param jpegSize size of the JPEG image (in bytes)
1050 *
669 * @param width pointer to an integer variable that will receive the width (in 1051 * @param width pointer to an integer variable that will receive the width (in
670 * pixels) of the JPEG image 1052 * pixels) of the JPEG image
1053 *
671 * @param height pointer to an integer variable that will receive the height 1054 * @param height pointer to an integer variable that will receive the height
672 * (in pixels) of the JPEG image 1055 * (in pixels) of the JPEG image
1056 *
673 * @param jpegSubsamp pointer to an integer variable that will receive the 1057 * @param jpegSubsamp pointer to an integer variable that will receive the
674 * level of chrominance subsampling used when compressing the JPEG image 1058 * level of chrominance subsampling used when the JPEG image was compressed
675 * (see @ref TJSAMP "Chrominance subsampling options".) 1059 * (see @ref TJSAMP "Chrominance subsampling options".)
1060 *
1061 * @param jpegColorspace pointer to an integer variable that will receive one
1062 * of the JPEG colorspace constants, indicating the colorspace of the JPEG
1063 * image (see @ref TJCS "JPEG colorspaces".)
676 * 1064 *
677 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 1065 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
678 */ 1066 */
679 DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle, 1067 DLLEXPORT int DLLCALL tjDecompressHeader3(tjhandle handle,
680 unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, 1068 const unsigned char *jpegBuf, unsigned long jpegSize, int *width,
681 int *jpegSubsamp); 1069 int *height, int *jpegSubsamp, int *jpegColorspace);
682 1070
683 1071
684 /** 1072 /**
685 * Returns a list of fractional scaling factors that the JPEG decompressor in 1073 * Returns a list of fractional scaling factors that the JPEG decompressor in
686 * this implementation of TurboJPEG supports. 1074 * this implementation of TurboJPEG supports.
687 * 1075 *
688 * @param numscalingfactors pointer to an integer variable that will receive 1076 * @param numscalingfactors pointer to an integer variable that will receive
689 * the number of elements in the list 1077 * the number of elements in the list
690 * 1078 *
691 * @return a pointer to a list of fractional scaling factors, or NULL if an 1079 * @return a pointer to a list of fractional scaling factors, or NULL if an
692 * error is encountered (see #tjGetErrorStr().) 1080 * error is encountered (see #tjGetErrorStr().)
693 */ 1081 */
694 DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); 1082 DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors);
695 1083
696 1084
697 /** 1085 /**
698 * Decompress a JPEG image to an RGB or grayscale image. 1086 * Decompress a JPEG image to an RGB, grayscale, or CMYK image.
699 * 1087 *
700 * @param handle a handle to a TurboJPEG decompressor or transformer instance 1088 * @param handle a handle to a TurboJPEG decompressor or transformer instance
1089 *
701 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress 1090 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
1091 *
702 * @param jpegSize size of the JPEG image (in bytes) 1092 * @param jpegSize size of the JPEG image (in bytes)
1093 *
703 * @param dstBuf pointer to an image buffer that will receive the decompressed 1094 * @param dstBuf pointer to an image buffer that will receive the decompressed
704 * image. This buffer should normally be <tt>pitch * scaledHeight</tt> 1095 * image. This buffer should normally be <tt>pitch * scaledHeight</tt> bytes
705 * bytes in size, where <tt>scaledHeight</tt> can be determined by 1096 * in size, where <tt>scaledHeight</tt> can be determined by calling
706 * calling #TJSCALED() with the JPEG image height and one of the scaling 1097 * #TJSCALED() with the JPEG image height and one of the scaling factors
707 * factors returned by #tjGetScalingFactors(). The <tt>dstBuf</tt> 1098 * returned by #tjGetScalingFactors(). The <tt>dstBuf</tt> pointer may also be
708 * pointer may also be used to decompress into a specific region of a 1099 * used to decompress into a specific region of a larger buffer.
709 * larger buffer. 1100 *
710 * @param width desired width (in pixels) of the destination image. If this is 1101 * @param width desired width (in pixels) of the destination image. If this is
711 * different than the width of the JPEG image being decompressed, then 1102 * different than the width of the JPEG image being decompressed, then
712 * TurboJPEG will use scaling in the JPEG decompressor to generate the 1103 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
713 * largest possible image that will fit within the desired width. If 1104 * possible image that will fit within the desired width. If <tt>width</tt> is
714 * <tt>width</tt> is set to 0, then only the height will be considered 1105 * set to 0, then only the height will be considered when determining the
715 * when determining the scaled image size. 1106 * scaled image size.
716 * @param pitch bytes per line of the destination image. Normally, this is 1107 *
717 * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed 1108 * @param pitch bytes per line in the destination image. Normally, this is
718 * image is unpadded, else <tt>#TJPAD(scaledWidth * 1109 * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed image
719 * #tjPixelSize[pixelFormat])</tt> if each line of the decompressed 1110 * is unpadded, else <tt>#TJPAD(scaledWidth * #tjPixelSize[pixelFormat])</tt>
720 * image is padded to the nearest 32-bit boundary, as is the case for 1111 * if each line of the decompressed image is padded to the nearest 32-bit
721 * Windows bitmaps. (NOTE: <tt>scaledWidth</tt> can be determined by 1112 * boundary, as is the case for Windows bitmaps. (NOTE: <tt>scaledWidth</tt>
722 * calling #TJSCALED() with the JPEG image width and one of the scaling 1113 * can be determined by calling #TJSCALED() with the JPEG image width and one
723 * factors returned by #tjGetScalingFactors().) You can also be clever 1114 * of the scaling factors returned by #tjGetScalingFactors().) You can also be
724 * and use the pitch parameter to skip lines, etc. Setting this 1115 * clever and use the pitch parameter to skip lines, etc. Setting this
725 * parameter to 0 is the equivalent of setting it to <tt>scaledWidth 1116 * parameter to 0 is the equivalent of setting it to
726 * * #tjPixelSize[pixelFormat]</tt>. 1117 * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>.
1118 *
727 * @param height desired height (in pixels) of the destination image. If this 1119 * @param height desired height (in pixels) of the destination image. If this
728 * is different than the height of the JPEG image being decompressed, 1120 * is different than the height of the JPEG image being decompressed, then
729 * then TurboJPEG will use scaling in the JPEG decompressor to generate 1121 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
730 * the largest possible image that will fit within the desired height. 1122 * possible image that will fit within the desired height. If <tt>height</tt>
731 * If <tt>height</tt> is set to 0, then only the width will be 1123 * is set to 0, then only the width will be considered when determining the
732 * considered when determining the scaled image size. 1124 * scaled image size.
1125 *
733 * @param pixelFormat pixel format of the destination image (see @ref 1126 * @param pixelFormat pixel format of the destination image (see @ref
734 * TJPF "Pixel formats".) 1127 * TJPF "Pixel formats".)
735 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 1128 *
736 * "flags". 1129 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1130 * "flags"
737 * 1131 *
738 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 1132 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
739 */ 1133 */
740 DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, 1134 DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
741 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, 1135 const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
742 int width, int pitch, int height, int pixelFormat, int flags); 1136 int width, int pitch, int height, int pixelFormat, int flags);
743 1137
744 1138
745 /** 1139 /**
746 * Decompress a JPEG image to a YUV planar image. This function performs JPEG 1140 * Decompress a JPEG image to a YUV planar image. This function performs JPEG
747 * decompression but leaves out the color conversion step, so a planar YUV 1141 * decompression but leaves out the color conversion step, so a planar YUV
748 * image is generated instead of an RGB image. The padding of the planes in 1142 * image is generated instead of an RGB image.
749 * this image is the same as in the images generated by #tjEncodeYUV2(). Note 1143 *
750 * that, if the width or height of the image is not an even multiple of the MCU 1144 * @param handle a handle to a TurboJPEG decompressor or transformer instance
751 * block size (see #tjMCUWidth and #tjMCUHeight), then an intermediate buffer 1145 *
752 * copy will be performed within TurboJPEG.
753 * <p>
754 * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the
755 * convention of the digital video community, the TurboJPEG API uses "YUV" to
756 * refer to an image format consisting of Y, Cb, and Cr image planes.
757 *
758 * @param handle a handle to a TurboJPEG decompressor or transformer instance
759 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress 1146 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
1147 *
760 * @param jpegSize size of the JPEG image (in bytes) 1148 * @param jpegSize size of the JPEG image (in bytes)
1149 *
761 * @param dstBuf pointer to an image buffer that will receive the YUV image. 1150 * @param dstBuf pointer to an image buffer that will receive the YUV image.
762 * Use #tjBufSizeYUV() to determine the appropriate size for this buffer 1151 * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based
763 * based on the image width, height, and level of subsampling. 1152 * on the image width, height, padding, and level of subsampling. The Y,
764 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 1153 * U (Cb), and V (Cr) image planes will be stored sequentially in the buffer
765 * "flags". 1154 * (refer to @ref YUVnotes "YUV Image Format Notes".)
766 * 1155 *
767 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 1156 * @param width desired width (in pixels) of the YUV image. If this is
768 */ 1157 * different than the width of the JPEG image being decompressed, then
769 DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle, 1158 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
770 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, 1159 * possible image that will fit within the desired width. If <tt>width</tt> is
1160 * set to 0, then only the height will be considered when determining the
1161 * scaled image size. If the scaled width is not an even multiple of the MCU
1162 * block width (see #tjMCUWidth), then an intermediate buffer copy will be
1163 * performed within TurboJPEG.
1164 *
1165 * @param pad the width of each line in each plane of the YUV image will be
1166 * padded to the nearest multiple of this number of bytes (must be a power of
1167 * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to
1168 * 4.
1169 *
1170 * @param height desired height (in pixels) of the YUV image. If this is
1171 * different than the height of the JPEG image being decompressed, then
1172 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1173 * possible image that will fit within the desired height. If <tt>height</tt>
1174 * is set to 0, then only the width will be considered when determining the
1175 * scaled image size. If the scaled height is not an even multiple of the MCU
1176 * block height (see #tjMCUHeight), then an intermediate buffer copy will be
1177 * performed within TurboJPEG.
1178 *
1179 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1180 * "flags"
1181 *
1182 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
1183 */
1184 DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
1185 const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
1186 int width, int pad, int height, int flags);
1187
1188
1189 /**
1190 * Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image
1191 * planes. This function performs JPEG decompression but leaves out the color
1192 * conversion step, so a planar YUV image is generated instead of an RGB image.
1193 *
1194 * @param handle a handle to a TurboJPEG decompressor or transformer instance
1195 *
1196 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
1197 *
1198 * @param jpegSize size of the JPEG image (in bytes)
1199 *
1200 * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
1201 * (or just a Y plane, if decompressing a grayscale image) that will receive
1202 * the YUV image. These planes can be contiguous or non-contiguous in memory.
1203 * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
1204 * on the scaled image width, scaled image height, strides, and level of
1205 * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes"
1206 * for more details.
1207 *
1208 * @param width desired width (in pixels) of the YUV image. If this is
1209 * different than the width of the JPEG image being decompressed, then
1210 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1211 * possible image that will fit within the desired width. If <tt>width</tt> is
1212 * set to 0, then only the height will be considered when determining the
1213 * scaled image size. If the scaled width is not an even multiple of the MCU
1214 * block width (see #tjMCUWidth), then an intermediate buffer copy will be
1215 * performed within TurboJPEG.
1216 *
1217 * @param strides an array of integers, each specifying the number of bytes per
1218 * line in the corresponding plane of the output image. Setting the stride for
1219 * any plane to 0 is the same as setting it to the scaled plane width (see
1220 * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
1221 * the strides for all planes will be set to their respective scaled plane
1222 * widths. You can adjust the strides in order to add an arbitrary amount of
1223 * line padding to each plane or to decompress the JPEG image into a subregion
1224 * of a larger YUV planar image.
1225 *
1226 * @param height desired height (in pixels) of the YUV image. If this is
1227 * different than the height of the JPEG image being decompressed, then
1228 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
1229 * possible image that will fit within the desired height. If <tt>height</tt>
1230 * is set to 0, then only the width will be considered when determining the
1231 * scaled image size. If the scaled height is not an even multiple of the MCU
1232 * block height (see #tjMCUHeight), then an intermediate buffer copy will be
1233 * performed within TurboJPEG.
1234 *
1235 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1236 * "flags"
1237 *
1238 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
1239 */
1240 DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle,
1241 const unsigned char *jpegBuf, unsigned long jpegSize,
1242 unsigned char **dstPlanes, int width, int *strides, int height, int flags);
1243
1244
1245 /**
1246 * Decode a YUV planar image into an RGB or grayscale image. This function
1247 * uses the accelerated color conversion routines in the underlying
1248 * codec but does not execute any of the other steps in the JPEG decompression
1249 * process.
1250 *
1251 * @param handle a handle to a TurboJPEG decompressor or transformer instance
1252 *
1253 * @param srcBuf pointer to an image buffer containing a YUV planar image to be
1254 * decoded. The size of this buffer should match the value returned by
1255 * #tjBufSizeYUV2() for the given image width, height, padding, and level of
1256 * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be
1257 * stored sequentially in the source buffer (refer to @ref YUVnotes
1258 * "YUV Image Format Notes".)
1259 *
1260 * @param pad Use this parameter to specify that the width of each line in each
1261 * plane of the YUV source image is padded to the nearest multiple of this
1262 * number of bytes (must be a power of 2.)
1263 *
1264 * @param subsamp the level of chrominance subsampling used in the YUV source
1265 * image (see @ref TJSAMP "Chrominance subsampling options".)
1266 *
1267 * @param dstBuf pointer to an image buffer that will receive the decoded
1268 * image. This buffer should normally be <tt>pitch * height</tt> bytes in
1269 * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a
1270 * specific region of a larger buffer.
1271 *
1272 * @param width width (in pixels) of the source and destination images
1273 *
1274 * @param pitch bytes per line in the destination image. Normally, this should
1275 * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is
1276 * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line
1277 * of the destination image should be padded to the nearest 32-bit boundary, as
1278 * is the case for Windows bitmaps. You can also be clever and use the pitch
1279 * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent
1280 * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
1281 *
1282 * @param height height (in pixels) of the source and destination images
1283 *
1284 * @param pixelFormat pixel format of the destination image (see @ref TJPF
1285 * "Pixel formats".)
1286 *
1287 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1288 * "flags"
1289 *
1290 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
1291 */
1292 DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
1293 int pad, int subsamp, unsigned char *dstBuf, int width, int pitch,
1294 int height, int pixelFormat, int flags);
1295
1296
1297 /**
1298 * Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale
1299 * image. This function uses the accelerated color conversion routines in the
1300 * underlying codec but does not execute any of the other steps in the JPEG
1301 * decompression process.
1302 *
1303 * @param handle a handle to a TurboJPEG decompressor or transformer instance
1304 *
1305 * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
1306 * (or just a Y plane, if decoding a grayscale image) that contain a YUV image
1307 * to be decoded. These planes can be contiguous or non-contiguous in memory.
1308 * The size of each plane should match the value returned by #tjPlaneSizeYUV()
1309 * for the given image width, height, strides, and level of chrominance
1310 * subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" for more
1311 * details.
1312 *
1313 * @param strides an array of integers, each specifying the number of bytes per
1314 * line in the corresponding plane of the YUV source image. Setting the stride
1315 * for any plane to 0 is the same as setting it to the plane width (see
1316 * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then
1317 * the strides for all planes will be set to their respective plane widths.
1318 * You can adjust the strides in order to specify an arbitrary amount of line
1319 * padding in each plane or to decode a subregion of a larger YUV planar image.
1320 *
1321 * @param subsamp the level of chrominance subsampling used in the YUV source
1322 * image (see @ref TJSAMP "Chrominance subsampling options".)
1323 *
1324 * @param dstBuf pointer to an image buffer that will receive the decoded
1325 * image. This buffer should normally be <tt>pitch * height</tt> bytes in
1326 * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a
1327 * specific region of a larger buffer.
1328 *
1329 * @param width width (in pixels) of the source and destination images
1330 *
1331 * @param pitch bytes per line in the destination image. Normally, this should
1332 * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is
1333 * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line
1334 * of the destination image should be padded to the nearest 32-bit boundary, as
1335 * is the case for Windows bitmaps. You can also be clever and use the pitch
1336 * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent
1337 * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
1338 *
1339 * @param height height (in pixels) of the source and destination images
1340 *
1341 * @param pixelFormat pixel format of the destination image (see @ref TJPF
1342 * "Pixel formats".)
1343 *
1344 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
1345 * "flags"
1346 *
1347 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
1348 */
1349 DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle,
1350 const unsigned char **srcPlanes, const int *strides, int subsamp,
1351 unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat,
771 int flags); 1352 int flags);
772 1353
773 1354
774 /** 1355 /**
775 * Create a new TurboJPEG transformer instance. 1356 * Create a new TurboJPEG transformer instance.
776 * 1357 *
777 * @return a handle to the newly-created instance, or NULL if an error 1358 * @return a handle to the newly-created instance, or NULL if an error
778 * occurred (see #tjGetErrorStr().) 1359 * occurred (see #tjGetErrorStr().)
779 */ 1360 */
780 DLLEXPORT tjhandle DLLCALL tjInitTransform(void); 1361 DLLEXPORT tjhandle DLLCALL tjInitTransform(void);
781 1362
782 1363
783 /** 1364 /**
784 * Losslessly transform a JPEG image into another JPEG image. Lossless 1365 * Losslessly transform a JPEG image into another JPEG image. Lossless
785 * transforms work by moving the raw coefficients from one JPEG image structure 1366 * transforms work by moving the raw DCT coefficients from one JPEG image
786 * to another without altering the values of the coefficients. While this is 1367 * structure to another without altering the values of the coefficients. While
787 * typically faster than decompressing the image, transforming it, and 1368 * this is typically faster than decompressing the image, transforming it, and
788 * re-compressing it, lossless transforms are not free. Each lossless 1369 * re-compressing it, lossless transforms are not free. Each lossless
789 * transform requires reading and performing Huffman decoding on all of the 1370 * transform requires reading and performing Huffman decoding on all of the
790 * coefficients in the source image, regardless of the size of the destination 1371 * coefficients in the source image, regardless of the size of the destination
791 * image. Thus, this function provides a means of generating multiple 1372 * image. Thus, this function provides a means of generating multiple
792 * transformed images from the same source or applying multiple 1373 * transformed images from the same source or applying multiple
793 * transformations simultaneously, in order to eliminate the need to read the 1374 * transformations simultaneously, in order to eliminate the need to read the
794 * source coefficients multiple times. 1375 * source coefficients multiple times.
795 * 1376 *
796 * @param handle a handle to a TurboJPEG transformer instance 1377 * @param handle a handle to a TurboJPEG transformer instance
797 * @param jpegBuf pointer to a buffer containing the JPEG image to transform 1378 *
798 * @param jpegSize size of the JPEG image (in bytes) 1379 * @param jpegBuf pointer to a buffer containing the JPEG source image to
1380 * transform
1381 *
1382 * @param jpegSize size of the JPEG source image (in bytes)
1383 *
799 * @param n the number of transformed JPEG images to generate 1384 * @param n the number of transformed JPEG images to generate
1385 *
800 * @param dstBufs pointer to an array of n image buffers. <tt>dstBufs[i]</tt> 1386 * @param dstBufs pointer to an array of n image buffers. <tt>dstBufs[i]</tt>
801 * will receive a JPEG image that has been transformed using the 1387 * will receive a JPEG image that has been transformed using the parameters in
802 * parameters in <tt>transforms[i]</tt>. TurboJPEG has the ability to 1388 * <tt>transforms[i]</tt>. TurboJPEG has the ability to reallocate the JPEG
803 * reallocate the JPEG buffer to accommodate the size of the JPEG image. 1389 * buffer to accommodate the size of the JPEG image. Thus, you can choose to:
804 * Thus, you can choose to: 1390 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
805 * -# pre-allocate the JPEG buffer with an arbitrary size using 1391 * let TurboJPEG grow the buffer as needed,
806 * #tjAlloc() and let TurboJPEG grow the buffer as needed, 1392 * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the buffer
807 * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the 1393 * for you, or
808 * buffer for you, or 1394 * -# pre-allocate the buffer to a "worst case" size determined by calling
809 * -# pre-allocate the buffer to a "worst case" size determined by 1395 * #tjBufSize() with the transformed or cropped width and height. This should
810 * calling #tjBufSize() with the transformed or cropped width and 1396 * ensure that the buffer never has to be re-allocated (setting
811 * height. This should ensure that the buffer never has to be 1397 * #TJFLAG_NOREALLOC guarantees this.)
812 * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.) 1398 * .
813 * . 1399 * If you choose option 1, <tt>dstSizes[i]</tt> should be set to the size of
814 * If you choose option 1, <tt>dstSizes[i]</tt> should be set to 1400 * your pre-allocated buffer. In any case, unless you have set
815 * the size of your pre-allocated buffer. In any case, unless you have 1401 * #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> upon return
816 * set #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> 1402 * from this function, as it may have changed.
817 * upon return from this function, as it may have changed. 1403 *
818 * @param dstSizes pointer to an array of n unsigned long variables that will 1404 * @param dstSizes pointer to an array of n unsigned long variables that will
819 * receive the actual sizes (in bytes) of each transformed JPEG image. 1405 * receive the actual sizes (in bytes) of each transformed JPEG image. If
820 * If <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then 1406 * <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then
821 * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon 1407 * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon return,
822 * return, <tt>dstSizes[i]</tt> will contain the size of the JPEG image 1408 * <tt>dstSizes[i]</tt> will contain the size of the JPEG image (in bytes.)
823 * (in bytes.) 1409 *
824 * @param transforms pointer to an array of n #tjtransform structures, each of 1410 * @param transforms pointer to an array of n #tjtransform structures, each of
825 * which specifies the transform parameters and/or cropping region for 1411 * which specifies the transform parameters and/or cropping region for the
826 * the corresponding transformed output image. 1412 * corresponding transformed output image.
1413 *
827 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 1414 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
828 * "flags". 1415 * "flags"
829 * 1416 *
830 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 1417 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
831 */ 1418 */
832 DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf, 1419 DLLEXPORT int DLLCALL tjTransform(tjhandle handle,
833 unsigned long jpegSize, int n, unsigned char **dstBufs, 1420 const unsigned char *jpegBuf, unsigned long jpegSize, int n,
834 unsigned long *dstSizes, tjtransform *transforms, int flags); 1421 unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms,
1422 int flags);
835 1423
836 1424
837 /** 1425 /**
838 * Destroy a TurboJPEG compressor, decompressor, or transformer instance. 1426 * Destroy a TurboJPEG compressor, decompressor, or transformer instance.
839 * 1427 *
840 * @param handle a handle to a TurboJPEG compressor, decompressor or 1428 * @param handle a handle to a TurboJPEG compressor, decompressor or
841 * transformer instance 1429 * transformer instance
842 * 1430 *
843 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 1431 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().)
844 */ 1432 */
845 DLLEXPORT int DLLCALL tjDestroy(tjhandle handle); 1433 DLLEXPORT int DLLCALL tjDestroy(tjhandle handle);
846 1434
847 1435
848 /** 1436 /**
849 * Allocate an image buffer for use with TurboJPEG. You should always use 1437 * Allocate an image buffer for use with TurboJPEG. You should always use
850 * this function to allocate the JPEG destination buffer(s) for #tjCompress2() 1438 * this function to allocate the JPEG destination buffer(s) for #tjCompress2()
851 * and #tjTransform() unless you are disabling automatic buffer 1439 * and #tjTransform() unless you are disabling automatic buffer
852 * (re)allocation (by setting #TJFLAG_NOREALLOC.) 1440 * (re)allocation (by setting #TJFLAG_NOREALLOC.)
853 * 1441 *
854 * @param bytes the number of bytes to allocate 1442 * @param bytes the number of bytes to allocate
855 * 1443 *
856 * @return a pointer to a newly-allocated buffer with the specified number of 1444 * @return a pointer to a newly-allocated buffer with the specified number of
857 * bytes 1445 * bytes.
858 * 1446 *
859 * @sa tjFree() 1447 * @sa tjFree()
860 */ 1448 */
861 DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes); 1449 DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes);
862 1450
863 1451
864 /** 1452 /**
865 * Free an image buffer previously allocated by TurboJPEG. You should always 1453 * Free an image buffer previously allocated by TurboJPEG. You should always
866 * use this function to free JPEG destination buffer(s) that were automatically 1454 * use this function to free JPEG destination buffer(s) that were automatically
867 * (re)allocated by #tjCompress2() or #tjTransform() or that were manually 1455 * (re)allocated by #tjCompress2() or #tjTransform() or that were manually
868 * allocated using #tjAlloc(). 1456 * allocated using #tjAlloc().
869 * 1457 *
870 * @param buffer address of the buffer to free 1458 * @param buffer address of the buffer to free
871 * 1459 *
872 * @sa tjAlloc() 1460 * @sa tjAlloc()
873 */ 1461 */
874 DLLEXPORT void DLLCALL tjFree(unsigned char *buffer); 1462 DLLEXPORT void DLLCALL tjFree(unsigned char *buffer);
875 1463
876 1464
877 /** 1465 /**
878 * Returns a descriptive error message explaining why the last command failed. 1466 * Returns a descriptive error message explaining why the last command failed.
879 * 1467 *
880 * @return a descriptive error message explaining why the last command failed. 1468 * @return a descriptive error message explaining why the last command failed.
881 */ 1469 */
882 DLLEXPORT char* DLLCALL tjGetErrorStr(void); 1470 DLLEXPORT char* DLLCALL tjGetErrorStr(void);
883 1471
884 1472
1473 /* Deprecated functions and macros */
1474 #define TJFLAG_FORCEMMX 8
1475 #define TJFLAG_FORCESSE 16
1476 #define TJFLAG_FORCESSE2 32
1477 #define TJFLAG_FORCESSE3 128
1478
1479
885 /* Backward compatibility functions and macros (nothing to see here) */ 1480 /* Backward compatibility functions and macros (nothing to see here) */
886 #define NUMSUBOPT TJ_NUMSAMP 1481 #define NUMSUBOPT TJ_NUMSAMP
887 #define TJ_444 TJSAMP_444 1482 #define TJ_444 TJSAMP_444
888 #define TJ_422 TJSAMP_422 1483 #define TJ_422 TJSAMP_422
889 #define TJ_420 TJSAMP_420 1484 #define TJ_420 TJSAMP_420
890 #define TJ_411 TJSAMP_420 1485 #define TJ_411 TJSAMP_420
891 #define TJ_GRAYSCALE TJSAMP_GRAY 1486 #define TJ_GRAYSCALE TJSAMP_GRAY
892 1487
893 #define TJ_BGR 1 1488 #define TJ_BGR 1
894 #define TJ_BOTTOMUP TJFLAG_BOTTOMUP 1489 #define TJ_BOTTOMUP TJFLAG_BOTTOMUP
895 #define TJ_FORCEMMX TJFLAG_FORCEMMX 1490 #define TJ_FORCEMMX TJFLAG_FORCEMMX
896 #define TJ_FORCESSE TJFLAG_FORCESSE 1491 #define TJ_FORCESSE TJFLAG_FORCESSE
897 #define TJ_FORCESSE2 TJFLAG_FORCESSE2 1492 #define TJ_FORCESSE2 TJFLAG_FORCESSE2
898 #define TJ_ALPHAFIRST 64 1493 #define TJ_ALPHAFIRST 64
899 #define TJ_FORCESSE3 TJFLAG_FORCESSE3 1494 #define TJ_FORCESSE3 TJFLAG_FORCESSE3
900 #define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE 1495 #define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE
901 #define TJ_YUV 512 1496 #define TJ_YUV 512
902 1497
903 DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height); 1498 DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height);
904 1499
905 DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height, 1500 DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height,
906 int jpegSubsamp); 1501 int jpegSubsamp);
907 1502
1503 DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height,
1504 int subsamp);
1505
908 DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf, 1506 DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf,
909 int width, int pitch, int height, int pixelSize, unsigned char *dstBuf, 1507 int width, int pitch, int height, int pixelSize, unsigned char *dstBuf,
910 unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags); 1508 unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags);
911 1509
912 DLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle, 1510 DLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle,
913 unsigned char *srcBuf, int width, int pitch, int height, int pixelSize, 1511 unsigned char *srcBuf, int width, int pitch, int height, int pixelSize,
914 unsigned char *dstBuf, int subsamp, int flags); 1512 unsigned char *dstBuf, int subsamp, int flags);
915 1513
1514 DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle,
1515 unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat,
1516 unsigned char *dstBuf, int subsamp, int flags);
1517
916 DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle, 1518 DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle,
917 unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height); 1519 unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height);
918 1520
1521 DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle,
1522 unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height,
1523 int *jpegSubsamp);
1524
919 DLLEXPORT int DLLCALL tjDecompress(tjhandle handle, 1525 DLLEXPORT int DLLCALL tjDecompress(tjhandle handle,
920 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, 1526 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
921 int width, int pitch, int height, int pixelSize, int flags); 1527 int width, int pitch, int height, int pixelSize, int flags);
922 1528
1529 DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle,
1530 unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
1531 int flags);
1532
923 1533
924 /** 1534 /**
925 * @} 1535 * @}
926 */ 1536 */
927 1537
928 #ifdef __cplusplus 1538 #ifdef __cplusplus
929 } 1539 }
930 #endif 1540 #endif
931 1541
932 #endif 1542 #endif
OLDNEW
« no previous file with comments | « transupp.c ('k') | turbojpeg.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698