DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1 | /* |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 2 | * Copyright (C)2009-2014 D. R. Commander. All Rights Reserved. |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 3 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 6 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 7 | * - 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. |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
DRC | 3a1bb35 | 2011-05-24 09:15:44 +0000 | [diff] [blame] | 29 | #ifndef __TURBOJPEG_H__ |
| 30 | #define __TURBOJPEG_H__ |
| 31 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 32 | #if defined(_WIN32) && defined(DLLDEFINE) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 33 | #define DLLEXPORT __declspec(dllexport) |
| 34 | #else |
| 35 | #define DLLEXPORT |
| 36 | #endif |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 37 | #define DLLCALL |
| 38 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 39 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 40 | /** |
| 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 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 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 |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 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. |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 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. |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 73 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 74 | * @{ |
| 75 | */ |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 76 | |
DRC | 0a32519 | 2011-03-02 09:22:41 +0000 | [diff] [blame] | 77 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 78 | /** |
| 79 | * The number of chrominance subsampling options |
| 80 | */ |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 81 | #define TJ_NUMSAMP 6 |
DRC | fbb6747 | 2010-11-24 04:02:37 +0000 | [diff] [blame] | 82 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 83 | /** |
| 84 | * Chrominance subsampling options. |
DRC | b2c4745 | 2013-08-23 06:38:59 +0000 | [diff] [blame] | 85 | * When pixels are converted from RGB to YCbCr (see #TJCS_YCbCr) or from CMYK |
| 86 | * to YCCK (see #TJCS_YCCK) as part of the JPEG compression process, some of |
| 87 | * the Cb and Cr (chrominance) components can be discarded or averaged together |
| 88 | * to produce a smaller image with little perceptible loss of image clarity |
| 89 | * (the human eye is more sensitive to small changes in brightness than to |
| 90 | * small changes in color.) This is called "chrominance subsampling". |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 91 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 92 | enum TJSAMP |
DRC | 109a578 | 2011-03-01 09:53:07 +0000 | [diff] [blame] | 93 | { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 94 | /** |
| 95 | * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or |
| 96 | * YUV image will contain one chrominance component for every pixel in the |
| 97 | * source image. |
| 98 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 99 | TJSAMP_444=0, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 100 | /** |
| 101 | * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one |
| 102 | * chrominance component for every 2x1 block of pixels in the source image. |
| 103 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 104 | TJSAMP_422, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 105 | /** |
| 106 | * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one |
| 107 | * chrominance component for every 2x2 block of pixels in the source image. |
| 108 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 109 | TJSAMP_420, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 110 | /** |
| 111 | * Grayscale. The JPEG or YUV image will contain no chrominance components. |
| 112 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 113 | TJSAMP_GRAY, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 114 | /** |
| 115 | * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one |
| 116 | * chrominance component for every 1x2 block of pixels in the source image. |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 117 | * |
| 118 | * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 119 | */ |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 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 |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 128 | * horizontal features. |
| 129 | * |
| 130 | * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo. |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 131 | */ |
| 132 | TJSAMP_411 |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 135 | /** |
| 136 | * MCU block width (in pixels) for a given level of chrominance subsampling. |
| 137 | * MCU block sizes: |
| 138 | * - 8x8 for no subsampling or grayscale |
| 139 | * - 16x8 for 4:2:2 |
| 140 | * - 8x16 for 4:4:0 |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 141 | * - 16x16 for 4:2:0 |
| 142 | * - 32x8 for 4:1:1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 143 | */ |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 144 | static const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8, 32}; |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 145 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 146 | /** |
| 147 | * MCU block height (in pixels) for a given level of chrominance subsampling. |
| 148 | * MCU block sizes: |
| 149 | * - 8x8 for no subsampling or grayscale |
| 150 | * - 16x8 for 4:2:2 |
| 151 | * - 8x16 for 4:4:0 |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 152 | * - 16x16 for 4:2:0 |
| 153 | * - 32x8 for 4:1:1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 154 | */ |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 155 | static const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16, 8}; |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 156 | |
| 157 | |
| 158 | /** |
| 159 | * The number of pixel formats |
| 160 | */ |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 161 | #define TJ_NUMPF 12 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * Pixel formats |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 165 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 166 | enum TJPF |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 167 | { |
| 168 | /** |
| 169 | * RGB pixel format. The red, green, and blue components in the image are |
| 170 | * stored in 3-byte pixels in the order R, G, B from lowest to highest byte |
| 171 | * address within each pixel. |
| 172 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 173 | TJPF_RGB=0, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 174 | /** |
| 175 | * BGR pixel format. The red, green, and blue components in the image are |
| 176 | * stored in 3-byte pixels in the order B, G, R from lowest to highest byte |
| 177 | * address within each pixel. |
| 178 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 179 | TJPF_BGR, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 180 | /** |
| 181 | * RGBX pixel format. The red, green, and blue components in the image are |
| 182 | * stored in 4-byte pixels in the order R, G, B from lowest to highest byte |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 183 | * address within each pixel. The X component is ignored when compressing |
| 184 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 185 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 186 | TJPF_RGBX, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 187 | /** |
| 188 | * BGRX pixel format. The red, green, and blue components in the image are |
| 189 | * stored in 4-byte pixels in the order B, G, R from lowest to highest byte |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 190 | * address within each pixel. The X component is ignored when compressing |
| 191 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 192 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 193 | TJPF_BGRX, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 194 | /** |
| 195 | * XBGR pixel format. The red, green, and blue components in the image are |
| 196 | * stored in 4-byte pixels in the order R, G, B from highest to lowest byte |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 197 | * address within each pixel. The X component is ignored when compressing |
| 198 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 199 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 200 | TJPF_XBGR, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 201 | /** |
| 202 | * XRGB pixel format. The red, green, and blue components in the image are |
| 203 | * stored in 4-byte pixels in the order B, G, R from highest to lowest byte |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 204 | * address within each pixel. The X component is ignored when compressing |
| 205 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 206 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 207 | TJPF_XRGB, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 208 | /** |
| 209 | * Grayscale pixel format. Each 1-byte pixel represents a luminance |
| 210 | * (brightness) level from 0 to 255. |
| 211 | */ |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 212 | TJPF_GRAY, |
| 213 | /** |
| 214 | * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when |
| 215 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 216 | * interpreted as an opaque alpha channel. |
| 217 | */ |
| 218 | TJPF_RGBA, |
| 219 | /** |
| 220 | * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when |
| 221 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 222 | * interpreted as an opaque alpha channel. |
| 223 | */ |
| 224 | TJPF_BGRA, |
| 225 | /** |
| 226 | * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when |
| 227 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 228 | * interpreted as an opaque alpha channel. |
| 229 | */ |
| 230 | TJPF_ABGR, |
| 231 | /** |
| 232 | * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when |
| 233 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 234 | * interpreted as an opaque alpha channel. |
| 235 | */ |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 236 | TJPF_ARGB, |
| 237 | /** |
DRC | b2c4745 | 2013-08-23 06:38:59 +0000 | [diff] [blame] | 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. |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 251 | */ |
| 252 | TJPF_CMYK |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 255 | |
| 256 | /** |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 257 | * Red offset (in bytes) for a given pixel format. This specifies the number |
| 258 | * of bytes that the red component is offset from the start of the pixel. For |
| 259 | * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, |
| 260 | * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>. |
| 261 | */ |
| 262 | static const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1}; |
| 263 | /** |
| 264 | * Green offset (in bytes) for a given pixel format. This specifies the number |
| 265 | * of bytes that the green component is offset from the start of the pixel. |
| 266 | * For instance, if a pixel of format TJ_BGRX is stored in |
| 267 | * <tt>char pixel[]</tt>, then the green component will be |
| 268 | * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>. |
| 269 | */ |
| 270 | static const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1}; |
| 271 | /** |
| 272 | * Blue offset (in bytes) for a given pixel format. This specifies the number |
| 273 | * of bytes that the Blue component is offset from the start of the pixel. For |
| 274 | * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, |
| 275 | * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>. |
| 276 | */ |
| 277 | static const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1}; |
| 278 | |
| 279 | /** |
| 280 | * Pixel size (in bytes) for a given pixel format. |
| 281 | */ |
| 282 | static const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4}; |
| 283 | |
| 284 | |
| 285 | /** |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 286 | * The number of JPEG colorspaces |
| 287 | */ |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 288 | #define TJ_NUMCS 5 |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 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 | }; |
| 345 | |
| 346 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 347 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 348 | * The uncompressed source/destination image is stored in bottom-up (Windows, |
| 349 | * OpenGL) order, not top-down (X11) order. |
| 350 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 351 | #define TJFLAG_BOTTOMUP 2 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 352 | /** |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 353 | * When decompressing an image that was compressed using chrominance |
| 354 | * subsampling, use the fastest chrominance upsampling algorithm available in |
| 355 | * the underlying codec. The default is to use smooth upsampling, which |
| 356 | * creates a smooth transition between neighboring chrominance components in |
| 357 | * order to reduce upsampling artifacts in the decompressed image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 358 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 359 | #define TJFLAG_FASTUPSAMPLE 256 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 360 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 361 | * Disable buffer (re)allocation. If passed to #tjCompress2() or |
| 362 | * #tjTransform(), this flag will cause those functions to generate an error if |
| 363 | * the JPEG image buffer is invalid or too small rather than attempting to |
| 364 | * allocate or reallocate that buffer. This reproduces the behavior of earlier |
| 365 | * versions of TurboJPEG. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 366 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 367 | #define TJFLAG_NOREALLOC 1024 |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 368 | /** |
| 369 | * Use the fastest DCT/IDCT algorithm available in the underlying codec. The |
DRC | 3b21982 | 2013-08-18 09:31:45 +0000 | [diff] [blame] | 370 | * default if this flag is not specified is implementation-specific. For |
| 371 | * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast |
| 372 | * algorithm by default when compressing, because this has been shown to have |
| 373 | * only a very slight effect on accuracy, but it uses the accurate algorithm |
| 374 | * when decompressing, because this has been shown to have a larger effect. |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 375 | */ |
| 376 | #define TJFLAG_FASTDCT 2048 |
| 377 | /** |
| 378 | * Use the most accurate DCT/IDCT algorithm available in the underlying codec. |
DRC | 3b21982 | 2013-08-18 09:31:45 +0000 | [diff] [blame] | 379 | * The default if this flag is not specified is implementation-specific. For |
| 380 | * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast |
| 381 | * algorithm by default when compressing, because this has been shown to have |
| 382 | * only a very slight effect on accuracy, but it uses the accurate algorithm |
| 383 | * when decompressing, because this has been shown to have a larger effect. |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 384 | */ |
| 385 | #define TJFLAG_ACCURATEDCT 4096 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 386 | |
| 387 | |
| 388 | /** |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 389 | * The number of transform operations |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 390 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 391 | #define TJ_NUMXOP 8 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 392 | |
| 393 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 394 | * Transform operations for #tjTransform() |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 395 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 396 | enum TJXOP |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 397 | { |
| 398 | /** |
| 399 | * Do not transform the position of the image pixels |
| 400 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 401 | TJXOP_NONE=0, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 402 | /** |
| 403 | * Flip (mirror) image horizontally. This transform is imperfect if there |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 404 | * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 405 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 406 | TJXOP_HFLIP, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 407 | /** |
| 408 | * Flip (mirror) image vertically. This transform is imperfect if there are |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 409 | * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 410 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 411 | TJXOP_VFLIP, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 412 | /** |
| 413 | * Transpose image (flip/mirror along upper left to lower right axis.) This |
| 414 | * transform is always perfect. |
| 415 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 416 | TJXOP_TRANSPOSE, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 417 | /** |
| 418 | * Transverse transpose image (flip/mirror along upper right to lower left |
| 419 | * axis.) This transform is imperfect if there are any partial MCU blocks in |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 420 | * the image (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 421 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 422 | TJXOP_TRANSVERSE, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 423 | /** |
| 424 | * Rotate image clockwise by 90 degrees. This transform is imperfect if |
| 425 | * there are any partial MCU blocks on the bottom edge (see |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 426 | * #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 427 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 428 | TJXOP_ROT90, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 429 | /** |
| 430 | * Rotate image 180 degrees. This transform is imperfect if there are any |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 431 | * partial MCU blocks in the image (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 432 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 433 | TJXOP_ROT180, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 434 | /** |
| 435 | * Rotate image counter-clockwise by 90 degrees. This transform is imperfect |
| 436 | * if there are any partial MCU blocks on the right edge (see |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 437 | * #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 438 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 439 | TJXOP_ROT270 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | |
| 443 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 444 | * This option will cause #tjTransform() to return an error if the transform is |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 445 | * not perfect. Lossless transforms operate on MCU blocks, whose size depends |
| 446 | * on the level of chrominance subsampling used (see #tjMCUWidth |
| 447 | * and #tjMCUHeight.) If the image's width or height is not evenly divisible |
| 448 | * by the MCU block size, then there will be partial MCU blocks on the right |
| 449 | * and/or bottom edges. It is not possible to move these partial MCU blocks to |
| 450 | * the top or left of the image, so any transform that would require that is |
| 451 | * "imperfect." If this option is not specified, then any partial MCU blocks |
| 452 | * that cannot be transformed will be left in place, which will create |
| 453 | * odd-looking strips on the right or bottom edge of the image. |
| 454 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 455 | #define TJXOPT_PERFECT 1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 456 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 457 | * This option will cause #tjTransform() to discard any partial MCU blocks that |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 458 | * cannot be transformed. |
| 459 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 460 | #define TJXOPT_TRIM 2 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 461 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 462 | * This option will enable lossless cropping. See #tjTransform() for more |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 463 | * information. |
| 464 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 465 | #define TJXOPT_CROP 4 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 466 | /** |
| 467 | * This option will discard the color data in the input image and produce |
| 468 | * a grayscale output image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 469 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 470 | #define TJXOPT_GRAY 8 |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 471 | /** |
| 472 | * This option will prevent #tjTransform() from outputting a JPEG image for |
| 473 | * this particular transform (this can be used in conjunction with a custom |
| 474 | * filter to capture the transformed DCT coefficients without transcoding |
| 475 | * them.) |
| 476 | */ |
| 477 | #define TJXOPT_NOOUTPUT 16 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 478 | |
| 479 | |
| 480 | /** |
| 481 | * Scaling factor |
| 482 | */ |
DRC | 0a07969 | 2011-03-02 09:27:49 +0000 | [diff] [blame] | 483 | typedef struct |
| 484 | { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 485 | /** |
| 486 | * Numerator |
| 487 | */ |
| 488 | int num; |
| 489 | /** |
| 490 | * Denominator |
| 491 | */ |
| 492 | int denom; |
| 493 | } tjscalingfactor; |
| 494 | |
| 495 | /** |
| 496 | * Cropping region |
| 497 | */ |
| 498 | typedef struct |
| 499 | { |
| 500 | /** |
| 501 | * The left boundary of the cropping region. This must be evenly divisible |
| 502 | * by the MCU block width (see #tjMCUWidth.) |
| 503 | */ |
| 504 | int x; |
| 505 | /** |
| 506 | * The upper boundary of the cropping region. This must be evenly divisible |
| 507 | * by the MCU block height (see #tjMCUHeight.) |
| 508 | */ |
| 509 | int y; |
| 510 | /** |
| 511 | * The width of the cropping region. Setting this to 0 is the equivalent of |
| 512 | * setting it to the width of the source JPEG image - x. |
| 513 | */ |
| 514 | int w; |
| 515 | /** |
| 516 | * The height of the cropping region. Setting this to 0 is the equivalent of |
| 517 | * setting it to the height of the source JPEG image - y. |
| 518 | */ |
| 519 | int h; |
DRC | 0a07969 | 2011-03-02 09:27:49 +0000 | [diff] [blame] | 520 | } tjregion; |
| 521 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 522 | /** |
| 523 | * Lossless transform |
| 524 | */ |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 525 | typedef struct tjtransform |
DRC | 0a07969 | 2011-03-02 09:27:49 +0000 | [diff] [blame] | 526 | { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 527 | /** |
| 528 | * Cropping region |
| 529 | */ |
| 530 | tjregion r; |
| 531 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 532 | * One of the @ref TJXOP "transform operations" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 533 | */ |
| 534 | int op; |
| 535 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 536 | * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 537 | */ |
| 538 | int options; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 539 | /** |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 540 | * Arbitrary data that can be accessed within the body of the callback |
| 541 | * function |
| 542 | */ |
| 543 | void *data; |
| 544 | /** |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 545 | * A callback function that can be used to modify the DCT coefficients |
| 546 | * after they are losslessly transformed but before they are transcoded to a |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 547 | * new JPEG image. This allows for custom filters or other transformations |
| 548 | * to be applied in the frequency domain. |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 549 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 550 | * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE: |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 551 | * this pointer is not guaranteed to be valid once the callback returns, so |
| 552 | * applications wishing to hand off the DCT coefficients to another function |
| 553 | * or library should make a copy of them within the body of the callback.) |
| 554 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 555 | * @param arrayRegion #tjregion structure containing the width and height of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 556 | * the array pointed to by <tt>coeffs</tt> as well as its offset relative to |
| 557 | * the component plane. TurboJPEG implementations may choose to split each |
| 558 | * component plane into multiple DCT coefficient arrays and call the callback |
| 559 | * function once for each array. |
| 560 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 561 | * @param planeRegion #tjregion structure containing the width and height of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 562 | * the component plane to which <tt>coeffs</tt> belongs |
| 563 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 564 | * @param componentID ID number of the component plane to which |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 565 | * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1, |
| 566 | * and 2 in typical JPEG images.) |
| 567 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 568 | * @param transformID ID number of the transformed image to which |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 569 | * <tt>coeffs</tt> belongs. This is the same as the index of the transform |
| 570 | * in the <tt>transforms</tt> array that was passed to #tjTransform(). |
| 571 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 572 | * @param transform a pointer to a #tjtransform structure that specifies the |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 573 | * parameters and/or cropping region for this transform |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 574 | * |
| 575 | * @return 0 if the callback was successful, or -1 if an error occurred. |
| 576 | */ |
| 577 | int (*customFilter)(short *coeffs, tjregion arrayRegion, |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 578 | tjregion planeRegion, int componentIndex, int transformIndex, |
| 579 | struct tjtransform *transform); |
DRC | 0a07969 | 2011-03-02 09:27:49 +0000 | [diff] [blame] | 580 | } tjtransform; |
| 581 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 582 | /** |
| 583 | * TurboJPEG instance handle |
| 584 | */ |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 585 | typedef void* tjhandle; |
| 586 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 587 | |
| 588 | /** |
| 589 | * Pad the given width to the nearest 32-bit boundary |
| 590 | */ |
| 591 | #define TJPAD(width) (((width)+3)&(~3)) |
| 592 | |
| 593 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 594 | * Compute the scaled value of <tt>dimension</tt> using the given scaling |
| 595 | * factor. This macro performs the integer equivalent of <tt>ceil(dimension * |
DRC | 1a45b81 | 2014-05-09 18:06:58 +0000 | [diff] [blame] | 596 | * scalingFactor)</tt>. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 597 | */ |
| 598 | #define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \ |
| 599 | + scalingFactor.denom - 1) / scalingFactor.denom) |
| 600 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 601 | |
| 602 | #ifdef __cplusplus |
| 603 | extern "C" { |
| 604 | #endif |
| 605 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 606 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 607 | /** |
| 608 | * Create a TurboJPEG compressor instance. |
| 609 | * |
| 610 | * @return a handle to the newly-created instance, or NULL if an error |
| 611 | * occurred (see #tjGetErrorStr().) |
| 612 | */ |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 613 | DLLEXPORT tjhandle DLLCALL tjInitCompress(void); |
| 614 | |
| 615 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 616 | /** |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 617 | * Compress an RGB, grayscale, or CMYK image into a JPEG image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 618 | * |
| 619 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 620 | * |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 621 | * @param srcBuf pointer to an image buffer containing RGB, grayscale, or |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 622 | * CMYK pixels to be compressed |
| 623 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 624 | * @param width width (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 625 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 626 | * @param pitch bytes per line in the source image. Normally, this should be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 627 | * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or |
| 628 | * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image |
| 629 | * is padded to the nearest 32-bit boundary, as is the case for Windows |
| 630 | * bitmaps. You can also be clever and use this parameter to skip lines, etc. |
| 631 | * Setting this parameter to 0 is the equivalent of setting it to |
| 632 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 633 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 634 | * @param height height (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 635 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 636 | * @param pixelFormat pixel format of the source image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 637 | * "Pixel formats".) |
| 638 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 639 | * @param jpegBuf address of a pointer to an image buffer that will receive the |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 640 | * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer |
| 641 | * to accommodate the size of the JPEG image. Thus, you can choose to: |
| 642 | * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and |
| 643 | * let TurboJPEG grow the buffer as needed, |
| 644 | * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer |
| 645 | * for you, or |
| 646 | * -# pre-allocate the buffer to a "worst case" size determined by calling |
| 647 | * #tjBufSize(). This should ensure that the buffer never has to be |
| 648 | * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.) |
| 649 | * . |
| 650 | * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your |
| 651 | * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC, |
| 652 | * you should always check <tt>*jpegBuf</tt> upon return from this function, as |
| 653 | * it may have changed. |
| 654 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 655 | * @param jpegSize pointer to an unsigned long variable that holds the size of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 656 | * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated |
| 657 | * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer. |
| 658 | * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in |
DRC | fe80ec2 | 2014-08-21 15:51:47 +0000 | [diff] [blame] | 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. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 662 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 663 | * @param jpegSubsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 664 | * generating the JPEG image (see @ref TJSAMP |
| 665 | * "Chrominance subsampling options".) |
| 666 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 667 | * @param jpegQual the image quality of the generated JPEG image (1 = worst, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 668 | * 100 = best) |
| 669 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 670 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 671 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 672 | * |
| 673 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 674 | */ |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 675 | DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, |
| 676 | int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, |
| 677 | unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 678 | |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 679 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 680 | /** |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 681 | * Compress a YUV planar image into a JPEG image. |
| 682 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 683 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 684 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 685 | * @param srcBuf pointer to an image buffer containing a YUV planar image to be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 692 | * @param width width (in pixels) of the source image. If the width is not an |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 693 | * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate |
| 694 | * buffer copy will be performed within TurboJPEG. |
| 695 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 696 | * @param pad the line padding used in the source image. For instance, if each |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 700 | * @param height height (in pixels) of the source image. If the height is not |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 701 | * an even multiple of the MCU block height (see #tjMCUHeight), then an |
| 702 | * intermediate buffer copy will be performed within TurboJPEG. |
| 703 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 704 | * @param subsamp the level of chrominance subsampling used in the source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 705 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 706 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 707 | * @param jpegBuf address of a pointer to an image buffer that will receive the |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 723 | * @param jpegSize pointer to an unsigned long variable that holds the size of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 |
DRC | fe80ec2 | 2014-08-21 15:51:47 +0000 | [diff] [blame] | 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. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 730 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 731 | * @param jpegQual the image quality of the generated JPEG image (1 = worst, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 732 | * 100 = best) |
| 733 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 734 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 735 | * "flags" |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 736 | * |
| 737 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 738 | */ |
| 739 | DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, |
| 740 | int width, int pad, int height, int subsamp, unsigned char **jpegBuf, |
| 741 | unsigned long *jpegSize, int jpegQual, int flags); |
| 742 | |
| 743 | |
| 744 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 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 |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 748 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 749 | * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 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. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 756 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 757 | * @param width width (in pixels) of the source image. If the width is not an |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 758 | * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate |
| 759 | * buffer copy will be performed within TurboJPEG. |
| 760 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 761 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 762 | * line in the corresponding plane of the YUV source image. Setting the stride |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 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. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 769 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 770 | * @param height height (in pixels) of the source image. If the height is not |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 771 | * an even multiple of the MCU block height (see #tjMCUHeight), then an |
| 772 | * intermediate buffer copy will be performed within TurboJPEG. |
| 773 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 774 | * @param subsamp the level of chrominance subsampling used in the source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 775 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 776 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 777 | * @param jpegBuf address of a pointer to an image buffer that will receive the |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 793 | * @param jpegSize pointer to an unsigned long variable that holds the size of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 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 |
DRC | fe80ec2 | 2014-08-21 15:51:47 +0000 | [diff] [blame] | 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. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 800 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 801 | * @param jpegQual the image quality of the generated JPEG image (1 = worst, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 802 | * 100 = best) |
| 803 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 804 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 805 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 806 | * |
| 807 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 808 | */ |
| 809 | DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 810 | unsigned char **srcPlanes, int width, int *strides, int height, int subsamp, |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 811 | unsigned char **jpegBuf, unsigned long *jpegSize, int jpegQual, int flags); |
| 812 | |
| 813 | |
| 814 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 815 | * The maximum size of the buffer (in bytes) required to hold a JPEG image with |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 816 | * the given parameters. The number of bytes returned by this function is |
| 817 | * larger than the size of the uncompressed source image. The reason for this |
| 818 | * is that the JPEG format uses 16-bit coefficients, and it is thus possible |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 819 | * for a very high-quality JPEG image with very high-frequency content to |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 820 | * expand rather than compress when converted to the JPEG format. Such images |
| 821 | * represent a very rare corner case, but since there is no way to predict the |
| 822 | * size of a JPEG image prior to compression, the corner case has to be |
| 823 | * handled. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 824 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 825 | * @param width width (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 826 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 827 | * @param height height (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 828 | * |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 829 | * @param jpegSubsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 830 | * generating the JPEG image (see @ref TJSAMP |
| 831 | * "Chrominance subsampling options".) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 832 | * |
| 833 | * @return the maximum size of the buffer (in bytes) required to hold the |
| 834 | * image, or -1 if the arguments are out of bounds. |
| 835 | */ |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 836 | DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, |
| 837 | int jpegSubsamp); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 838 | |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 839 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 840 | /** |
| 841 | * The size of the buffer (in bytes) required to hold a YUV planar image with |
| 842 | * the given parameters. |
| 843 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 844 | * @param width width (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 845 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 846 | * @param pad the width of each line in each plane of the image is padded to |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 847 | * the nearest multiple of this number of bytes (must be a power of 2.) |
| 848 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 849 | * @param height height (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 850 | * |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 851 | * @param subsamp level of chrominance subsampling in the image (see |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 852 | * @ref TJSAMP "Chrominance subsampling options".) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 853 | * |
| 854 | * @return the size of the buffer (in bytes) required to hold the image, or |
| 855 | * -1 if the arguments are out of bounds. |
| 856 | */ |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 857 | DLLEXPORT unsigned long DLLCALL tjBufSizeYUV2(int width, int pad, int height, |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 858 | int subsamp); |
DRC | f3cf973 | 2011-02-22 00:16:14 +0000 | [diff] [blame] | 859 | |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 860 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 861 | /** |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 862 | * The size of the buffer (in bytes) required to hold a YUV image plane with |
| 863 | * the given parameters. |
| 864 | * |
| 865 | * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) |
| 866 | * |
| 867 | * @param width width (in pixels) of the YUV image. NOTE: this is the width of |
| 868 | * the whole image, not the plane width. |
| 869 | * |
| 870 | * @param stride bytes per line in the image plane. Setting this to 0 is the |
| 871 | * equivalent of setting it to the plane width. |
| 872 | * |
| 873 | * @param height height (in pixels) of the YUV image. NOTE: this is the height |
| 874 | * of the whole image, not the plane height. |
| 875 | * |
| 876 | * @param subsamp level of chrominance subsampling in the image (see |
| 877 | * @ref TJSAMP "Chrominance subsampling options".) |
| 878 | * |
| 879 | * @return the size of the buffer (in bytes) required to hold the YUV image |
| 880 | * plane, or -1 if the arguments are out of bounds. |
| 881 | */ |
| 882 | DLLEXPORT unsigned long DLLCALL tjPlaneSizeYUV(int componentID, int width, |
| 883 | int stride, int height, int subsamp); |
| 884 | |
| 885 | |
| 886 | /** |
| 887 | * The plane width of a YUV image plane with the given parameters. Refer to |
| 888 | * @ref YUVnotes "YUV Image Format Notes" for a description of plane width. |
| 889 | * |
| 890 | * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) |
| 891 | * |
| 892 | * @param width width (in pixels) of the YUV image |
| 893 | * |
| 894 | * @param subsamp level of chrominance subsampling in the image (see |
| 895 | * @ref TJSAMP "Chrominance subsampling options".) |
| 896 | * |
| 897 | * @return the plane width of a YUV image plane with the given parameters, or |
| 898 | * -1 if the arguments are out of bounds. |
| 899 | */ |
| 900 | DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp); |
| 901 | |
| 902 | |
| 903 | /** |
| 904 | * The plane height of a YUV image plane with the given parameters. Refer to |
| 905 | * @ref YUVnotes "YUV Image Format Notes" for a description of plane height. |
| 906 | * |
| 907 | * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) |
| 908 | * |
| 909 | * @param height height (in pixels) of the YUV image |
| 910 | * |
| 911 | * @param subsamp level of chrominance subsampling in the image (see |
| 912 | * @ref TJSAMP "Chrominance subsampling options".) |
| 913 | * |
| 914 | * @return the plane height of a YUV image plane with the given parameters, or |
| 915 | * -1 if the arguments are out of bounds. |
| 916 | */ |
| 917 | DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp); |
| 918 | |
| 919 | |
| 920 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 921 | * Encode an RGB or grayscale image into a YUV planar image. This function |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 922 | * uses the accelerated color conversion routines in the underlying |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 923 | * codec but does not execute any of the other steps in the JPEG compression |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 924 | * process. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 925 | * |
| 926 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 927 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 928 | * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 929 | * to be encoded |
| 930 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 931 | * @param width width (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 932 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 933 | * @param pitch bytes per line in the source image. Normally, this should be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 934 | * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or |
| 935 | * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image |
| 936 | * is padded to the nearest 32-bit boundary, as is the case for Windows |
| 937 | * bitmaps. You can also be clever and use this parameter to skip lines, etc. |
| 938 | * Setting this parameter to 0 is the equivalent of setting it to |
| 939 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 940 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 941 | * @param height height (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 942 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 943 | * @param pixelFormat pixel format of the source image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 944 | * "Pixel formats".) |
| 945 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 946 | * @param dstBuf pointer to an image buffer that will receive the YUV image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 947 | * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based |
| 948 | * on the image width, height, padding, and level of chrominance subsampling. |
| 949 | * The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the |
| 950 | * buffer (refer to @ref YUVnotes "YUV Image Format Notes".) |
| 951 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 952 | * @param pad the width of each line in each plane of the YUV image will be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 953 | * padded to the nearest multiple of this number of bytes (must be a power of |
| 954 | * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to |
| 955 | * 4. |
| 956 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 957 | * @param subsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 958 | * generating the YUV image (see @ref TJSAMP |
| 959 | * "Chrominance subsampling options".) To generate images suitable for X |
| 960 | * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an |
| 961 | * image compatible with the I420 (AKA "YUV420P") format. |
| 962 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 963 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 964 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 965 | * |
| 966 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
DRC | 8424160 | 2011-02-25 02:08:23 +0000 | [diff] [blame] | 967 | */ |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 968 | DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 969 | unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 970 | unsigned char *dstBuf, int pad, int subsamp, int flags); |
DRC | 8424160 | 2011-02-25 02:08:23 +0000 | [diff] [blame] | 971 | |
| 972 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 973 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 974 | * Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image |
| 975 | * planes. This function uses the accelerated color conversion routines in the |
| 976 | * underlying codec but does not execute any of the other steps in the JPEG |
| 977 | * compression process. |
| 978 | * |
| 979 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 980 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 981 | * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 982 | * to be encoded |
| 983 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 984 | * @param width width (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 985 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 986 | * @param pitch bytes per line in the source image. Normally, this should be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 987 | * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or |
| 988 | * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image |
| 989 | * is padded to the nearest 32-bit boundary, as is the case for Windows |
| 990 | * bitmaps. You can also be clever and use this parameter to skip lines, etc. |
| 991 | * Setting this parameter to 0 is the equivalent of setting it to |
| 992 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 993 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 994 | * @param height height (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 995 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 996 | * @param pixelFormat pixel format of the source image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 997 | * "Pixel formats".) |
| 998 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 999 | * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1000 | * (or just a Y plane, if generating a grayscale image) that will receive the |
| 1001 | * encoded image. These planes can be contiguous or non-contiguous in memory. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1002 | * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based |
| 1003 | * on the image width, height, strides, and level of chrominance subsampling. |
| 1004 | * Refer to @ref YUVnotes "YUV Image Format Notes" for more details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1005 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1006 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1007 | * line in the corresponding plane of the output image. Setting the stride for |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1008 | * any plane to 0 is the same as setting it to the plane width (see |
| 1009 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
| 1010 | * the strides for all planes will be set to their respective plane widths. |
| 1011 | * You can adjust the strides in order to add an arbitrary amount of line |
| 1012 | * padding to each plane or to encode an RGB or grayscale image into a |
| 1013 | * subregion of a larger YUV planar image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1014 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1015 | * @param subsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1016 | * generating the YUV image (see @ref TJSAMP |
| 1017 | * "Chrominance subsampling options".) To generate images suitable for X |
| 1018 | * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an |
| 1019 | * image compatible with the I420 (AKA "YUV420P") format. |
| 1020 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1021 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1022 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1023 | * |
| 1024 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1025 | */ |
| 1026 | DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle, |
| 1027 | unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, |
| 1028 | unsigned char **dstPlanes, int *strides, int subsamp, int flags); |
| 1029 | |
| 1030 | |
| 1031 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1032 | * Create a TurboJPEG decompressor instance. |
| 1033 | * |
| 1034 | * @return a handle to the newly-created instance, or NULL if an error |
| 1035 | * occurred (see #tjGetErrorStr().) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1036 | */ |
| 1037 | DLLEXPORT tjhandle DLLCALL tjInitDecompress(void); |
| 1038 | |
| 1039 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1040 | /** |
| 1041 | * Retrieve information about a JPEG image without decompressing it. |
| 1042 | * |
| 1043 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1044 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1045 | * @param jpegBuf pointer to a buffer containing a JPEG image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1046 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1047 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1048 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1049 | * @param width pointer to an integer variable that will receive the width (in |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1050 | * pixels) of the JPEG image |
| 1051 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1052 | * @param height pointer to an integer variable that will receive the height |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1053 | * (in pixels) of the JPEG image |
| 1054 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1055 | * @param jpegSubsamp pointer to an integer variable that will receive the |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1056 | * level of chrominance subsampling used when the JPEG image was compressed |
| 1057 | * (see @ref TJSAMP "Chrominance subsampling options".) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1058 | * |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1059 | * @param jpegColorspace pointer to an integer variable that will receive one |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1060 | * of the JPEG colorspace constants, indicating the colorspace of the JPEG |
| 1061 | * image (see @ref TJCS "JPEG colorspaces".) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1062 | * |
| 1063 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1064 | */ |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1065 | DLLEXPORT int DLLCALL tjDecompressHeader3(tjhandle handle, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1066 | unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1067 | int *jpegSubsamp, int *jpegColorspace); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1068 | |
| 1069 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1070 | /** |
| 1071 | * Returns a list of fractional scaling factors that the JPEG decompressor in |
| 1072 | * this implementation of TurboJPEG supports. |
| 1073 | * |
| 1074 | * @param numscalingfactors pointer to an integer variable that will receive |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1075 | * the number of elements in the list |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1076 | * |
| 1077 | * @return a pointer to a list of fractional scaling factors, or NULL if an |
| 1078 | * error is encountered (see #tjGetErrorStr().) |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 1079 | */ |
DRC | 109a578 | 2011-03-01 09:53:07 +0000 | [diff] [blame] | 1080 | DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 1081 | |
| 1082 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1083 | /** |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1084 | * Decompress a JPEG image to an RGB, grayscale, or CMYK image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1085 | * |
| 1086 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1087 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1088 | * @param jpegBuf pointer to a buffer containing the JPEG image to decompress |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1089 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1090 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1091 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1092 | * @param dstBuf pointer to an image buffer that will receive the decompressed |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1093 | * image. This buffer should normally be <tt>pitch * scaledHeight</tt> bytes |
| 1094 | * in size, where <tt>scaledHeight</tt> can be determined by calling |
| 1095 | * #TJSCALED() with the JPEG image height and one of the scaling factors |
| 1096 | * returned by #tjGetScalingFactors(). The <tt>dstBuf</tt> pointer may also be |
| 1097 | * used to decompress into a specific region of a larger buffer. |
| 1098 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1099 | * @param width desired width (in pixels) of the destination image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1100 | * different than the width of the JPEG image being decompressed, then |
| 1101 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1102 | * possible image that will fit within the desired width. If <tt>width</tt> is |
| 1103 | * set to 0, then only the height will be considered when determining the |
| 1104 | * scaled image size. |
| 1105 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1106 | * @param pitch bytes per line in the destination image. Normally, this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1107 | * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed image |
| 1108 | * is unpadded, else <tt>#TJPAD(scaledWidth * #tjPixelSize[pixelFormat])</tt> |
| 1109 | * if each line of the decompressed image is padded to the nearest 32-bit |
| 1110 | * boundary, as is the case for Windows bitmaps. (NOTE: <tt>scaledWidth</tt> |
| 1111 | * can be determined by calling #TJSCALED() with the JPEG image width and one |
| 1112 | * of the scaling factors returned by #tjGetScalingFactors().) You can also be |
| 1113 | * clever and use the pitch parameter to skip lines, etc. Setting this |
| 1114 | * parameter to 0 is the equivalent of setting it to |
| 1115 | * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>. |
| 1116 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1117 | * @param height desired height (in pixels) of the destination image. If this |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1118 | * is different than the height of the JPEG image being decompressed, then |
| 1119 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1120 | * possible image that will fit within the desired height. If <tt>height</tt> |
| 1121 | * is set to 0, then only the width will be considered when determining the |
| 1122 | * scaled image size. |
| 1123 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1124 | * @param pixelFormat pixel format of the destination image (see @ref |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1125 | * TJPF "Pixel formats".) |
| 1126 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1127 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1128 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1129 | * |
| 1130 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1131 | */ |
| 1132 | DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, |
| 1133 | unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, |
| 1134 | int width, int pitch, int height, int pixelFormat, int flags); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1135 | |
| 1136 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1137 | /** |
| 1138 | * Decompress a JPEG image to a YUV planar image. This function performs JPEG |
| 1139 | * decompression but leaves out the color conversion step, so a planar YUV |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 1140 | * image is generated instead of an RGB image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1141 | * |
| 1142 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1143 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1144 | * @param jpegBuf pointer to a buffer containing the JPEG image to decompress |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1145 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1146 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1147 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1148 | * @param dstBuf pointer to an image buffer that will receive the YUV image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1149 | * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based |
| 1150 | * on the image width, height, padding, and level of subsampling. The Y, |
| 1151 | * U (Cb), and V (Cr) image planes will be stored sequentially in the buffer |
| 1152 | * (refer to @ref YUVnotes "YUV Image Format Notes".) |
| 1153 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1154 | * @param width desired width (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1155 | * different than the width of the JPEG image being decompressed, then |
| 1156 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1157 | * possible image that will fit within the desired width. If <tt>width</tt> is |
| 1158 | * set to 0, then only the height will be considered when determining the |
| 1159 | * scaled image size. If the scaled width is not an even multiple of the MCU |
| 1160 | * block width (see #tjMCUWidth), then an intermediate buffer copy will be |
| 1161 | * performed within TurboJPEG. |
| 1162 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1163 | * @param pad the width of each line in each plane of the YUV image will be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1164 | * padded to the nearest multiple of this number of bytes (must be a power of |
| 1165 | * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to |
| 1166 | * 4. |
| 1167 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1168 | * @param height desired height (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1169 | * different than the height of the JPEG image being decompressed, then |
| 1170 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1171 | * possible image that will fit within the desired height. If <tt>height</tt> |
| 1172 | * is set to 0, then only the width will be considered when determining the |
| 1173 | * scaled image size. If the scaled height is not an even multiple of the MCU |
| 1174 | * block height (see #tjMCUHeight), then an intermediate buffer copy will be |
| 1175 | * performed within TurboJPEG. |
| 1176 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1177 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1178 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1179 | * |
| 1180 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1181 | */ |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1182 | DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1183 | unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1184 | int width, int pad, int height, int flags); |
DRC | 8424160 | 2011-02-25 02:08:23 +0000 | [diff] [blame] | 1185 | |
| 1186 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1187 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1188 | * Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image |
| 1189 | * planes. This function performs JPEG decompression but leaves out the color |
| 1190 | * conversion step, so a planar YUV image is generated instead of an RGB image. |
| 1191 | * |
| 1192 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1193 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1194 | * @param jpegBuf pointer to a buffer containing the JPEG image to decompress |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1195 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1196 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1197 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1198 | * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1199 | * (or just a Y plane, if decompressing a grayscale image) that will receive |
| 1200 | * the YUV image. These planes can be contiguous or non-contiguous in memory. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1201 | * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based |
| 1202 | * on the scaled image width, scaled image height, strides, and level of |
| 1203 | * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" |
| 1204 | * for more details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1205 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1206 | * @param width desired width (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1207 | * different than the width of the JPEG image being decompressed, then |
| 1208 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1209 | * possible image that will fit within the desired width. If <tt>width</tt> is |
| 1210 | * set to 0, then only the height will be considered when determining the |
| 1211 | * scaled image size. If the scaled width is not an even multiple of the MCU |
| 1212 | * block width (see #tjMCUWidth), then an intermediate buffer copy will be |
| 1213 | * performed within TurboJPEG. |
| 1214 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1215 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1216 | * line in the corresponding plane of the output image. Setting the stride for |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1217 | * any plane to 0 is the same as setting it to the scaled plane width (see |
| 1218 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
| 1219 | * the strides for all planes will be set to their respective scaled plane |
| 1220 | * widths. You can adjust the strides in order to add an arbitrary amount of |
| 1221 | * line padding to each plane or to decompress the JPEG image into a subregion |
| 1222 | * of a larger YUV planar image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1223 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1224 | * @param height desired height (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1225 | * different than the height of the JPEG image being decompressed, then |
| 1226 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1227 | * possible image that will fit within the desired height. If <tt>height</tt> |
| 1228 | * is set to 0, then only the width will be considered when determining the |
| 1229 | * scaled image size. If the scaled height is not an even multiple of the MCU |
| 1230 | * block height (see #tjMCUHeight), then an intermediate buffer copy will be |
| 1231 | * performed within TurboJPEG. |
| 1232 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1233 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1234 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1235 | * |
| 1236 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1237 | */ |
| 1238 | DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle, |
| 1239 | unsigned char *jpegBuf, unsigned long jpegSize, unsigned char **dstPlanes, |
| 1240 | int width, int *strides, int height, int flags); |
| 1241 | |
| 1242 | |
| 1243 | /** |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1244 | * Decode a YUV planar image into an RGB or grayscale image. This function |
| 1245 | * uses the accelerated color conversion routines in the underlying |
| 1246 | * codec but does not execute any of the other steps in the JPEG decompression |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 1247 | * process. |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1248 | * |
| 1249 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1250 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1251 | * @param srcBuf pointer to an image buffer containing a YUV planar image to be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1252 | * decoded. The size of this buffer should match the value returned by |
| 1253 | * #tjBufSizeYUV2() for the given image width, height, padding, and level of |
| 1254 | * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be |
| 1255 | * stored sequentially in the source buffer (refer to @ref YUVnotes |
| 1256 | * "YUV Image Format Notes".) |
| 1257 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1258 | * @param pad Use this parameter to specify that the width of each line in each |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1259 | * plane of the YUV source image is padded to the nearest multiple of this |
| 1260 | * number of bytes (must be a power of 2.) |
| 1261 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1262 | * @param subsamp the level of chrominance subsampling used in the YUV source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1263 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 1264 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1265 | * @param dstBuf pointer to an image buffer that will receive the decoded |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1266 | * image. This buffer should normally be <tt>pitch * height</tt> bytes in |
| 1267 | * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a |
| 1268 | * specific region of a larger buffer. |
| 1269 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1270 | * @param width width (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1271 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1272 | * @param pitch bytes per line in the destination image. Normally, this should |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1273 | * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is |
| 1274 | * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line |
| 1275 | * of the destination image should be padded to the nearest 32-bit boundary, as |
| 1276 | * is the case for Windows bitmaps. You can also be clever and use the pitch |
| 1277 | * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent |
| 1278 | * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1279 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1280 | * @param height height (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1281 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1282 | * @param pixelFormat pixel format of the destination image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1283 | * "Pixel formats".) |
| 1284 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1285 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1286 | * "flags" |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1287 | * |
| 1288 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1289 | */ |
| 1290 | DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, |
| 1291 | int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, |
| 1292 | int height, int pixelFormat, int flags); |
| 1293 | |
| 1294 | |
| 1295 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1296 | * Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale |
| 1297 | * image. This function uses the accelerated color conversion routines in the |
| 1298 | * underlying codec but does not execute any of the other steps in the JPEG |
| 1299 | * decompression process. |
| 1300 | * |
| 1301 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1302 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1303 | * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1304 | * (or just a Y plane, if decoding a grayscale image) that contain a YUV image |
| 1305 | * to be decoded. These planes can be contiguous or non-contiguous in memory. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1306 | * The size of each plane should match the value returned by #tjPlaneSizeYUV() |
| 1307 | * for the given image width, height, strides, and level of chrominance |
| 1308 | * subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" for more |
| 1309 | * details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1310 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1311 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1312 | * line in the corresponding plane of the YUV source image. Setting the stride |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1313 | * for any plane to 0 is the same as setting it to the plane width (see |
| 1314 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
| 1315 | * the strides for all planes will be set to their respective plane widths. |
| 1316 | * You can adjust the strides in order to specify an arbitrary amount of line |
| 1317 | * padding in each plane or to decode a subregion of a larger YUV planar image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1318 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1319 | * @param subsamp the level of chrominance subsampling used in the YUV source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1320 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 1321 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1322 | * @param dstBuf pointer to an image buffer that will receive the decoded |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1323 | * image. This buffer should normally be <tt>pitch * height</tt> bytes in |
| 1324 | * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a |
| 1325 | * specific region of a larger buffer. |
| 1326 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1327 | * @param width width (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1328 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1329 | * @param pitch bytes per line in the destination image. Normally, this should |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1330 | * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is |
| 1331 | * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line |
| 1332 | * of the destination image should be padded to the nearest 32-bit boundary, as |
| 1333 | * is the case for Windows bitmaps. You can also be clever and use the pitch |
| 1334 | * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent |
| 1335 | * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1336 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1337 | * @param height height (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1338 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1339 | * @param pixelFormat pixel format of the destination image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1340 | * "Pixel formats".) |
| 1341 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1342 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1343 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1344 | * |
| 1345 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1346 | */ |
| 1347 | DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle, |
| 1348 | unsigned char **srcPlanes, int *strides, int subsamp, unsigned char *dstBuf, |
| 1349 | int width, int pitch, int height, int pixelFormat, int flags); |
| 1350 | |
| 1351 | |
| 1352 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1353 | * Create a new TurboJPEG transformer instance. |
| 1354 | * |
| 1355 | * @return a handle to the newly-created instance, or NULL if an error |
| 1356 | * occurred (see #tjGetErrorStr().) |
| 1357 | */ |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 1358 | DLLEXPORT tjhandle DLLCALL tjInitTransform(void); |
| 1359 | |
| 1360 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1361 | /** |
| 1362 | * Losslessly transform a JPEG image into another JPEG image. Lossless |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1363 | * transforms work by moving the raw DCT coefficients from one JPEG image |
| 1364 | * structure to another without altering the values of the coefficients. While |
| 1365 | * this is typically faster than decompressing the image, transforming it, and |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1366 | * re-compressing it, lossless transforms are not free. Each lossless |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 1367 | * transform requires reading and performing Huffman decoding on all of the |
| 1368 | * coefficients in the source image, regardless of the size of the destination |
| 1369 | * image. Thus, this function provides a means of generating multiple |
| 1370 | * transformed images from the same source or applying multiple |
| 1371 | * transformations simultaneously, in order to eliminate the need to read the |
| 1372 | * source coefficients multiple times. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1373 | * |
| 1374 | * @param handle a handle to a TurboJPEG transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1375 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1376 | * @param jpegBuf pointer to a buffer containing the JPEG source image to |
| 1377 | * transform |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1378 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1379 | * @param jpegSize size of the JPEG source image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1380 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1381 | * @param n the number of transformed JPEG images to generate |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1382 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1383 | * @param dstBufs pointer to an array of n image buffers. <tt>dstBufs[i]</tt> |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1384 | * will receive a JPEG image that has been transformed using the parameters in |
| 1385 | * <tt>transforms[i]</tt>. TurboJPEG has the ability to reallocate the JPEG |
| 1386 | * buffer to accommodate the size of the JPEG image. Thus, you can choose to: |
| 1387 | * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and |
| 1388 | * let TurboJPEG grow the buffer as needed, |
| 1389 | * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the buffer |
| 1390 | * for you, or |
| 1391 | * -# pre-allocate the buffer to a "worst case" size determined by calling |
| 1392 | * #tjBufSize() with the transformed or cropped width and height. This should |
| 1393 | * ensure that the buffer never has to be re-allocated (setting |
| 1394 | * #TJFLAG_NOREALLOC guarantees this.) |
| 1395 | * . |
| 1396 | * If you choose option 1, <tt>dstSizes[i]</tt> should be set to the size of |
| 1397 | * your pre-allocated buffer. In any case, unless you have set |
| 1398 | * #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> upon return |
| 1399 | * from this function, as it may have changed. |
| 1400 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1401 | * @param dstSizes pointer to an array of n unsigned long variables that will |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1402 | * receive the actual sizes (in bytes) of each transformed JPEG image. If |
| 1403 | * <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then |
| 1404 | * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon return, |
| 1405 | * <tt>dstSizes[i]</tt> will contain the size of the JPEG image (in bytes.) |
| 1406 | * |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 1407 | * @param transforms pointer to an array of n #tjtransform structures, each of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1408 | * which specifies the transform parameters and/or cropping region for the |
| 1409 | * corresponding transformed output image. |
| 1410 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1411 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1412 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1413 | * |
| 1414 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1415 | */ |
| 1416 | DLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf, |
| 1417 | unsigned long jpegSize, int n, unsigned char **dstBufs, |
| 1418 | unsigned long *dstSizes, tjtransform *transforms, int flags); |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 1419 | |
| 1420 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1421 | /** |
| 1422 | * Destroy a TurboJPEG compressor, decompressor, or transformer instance. |
| 1423 | * |
| 1424 | * @param handle a handle to a TurboJPEG compressor, decompressor or |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1425 | * transformer instance |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1426 | * |
| 1427 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) |
| 1428 | */ |
| 1429 | DLLEXPORT int DLLCALL tjDestroy(tjhandle handle); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1430 | |
| 1431 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1432 | /** |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1433 | * Allocate an image buffer for use with TurboJPEG. You should always use |
| 1434 | * this function to allocate the JPEG destination buffer(s) for #tjCompress2() |
| 1435 | * and #tjTransform() unless you are disabling automatic buffer |
| 1436 | * (re)allocation (by setting #TJFLAG_NOREALLOC.) |
| 1437 | * |
| 1438 | * @param bytes the number of bytes to allocate |
DRC | 1a45b81 | 2014-05-09 18:06:58 +0000 | [diff] [blame] | 1439 | * |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1440 | * @return a pointer to a newly-allocated buffer with the specified number of |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1441 | * bytes. |
DRC | d441107 | 2011-05-24 17:00:15 +0000 | [diff] [blame] | 1442 | * |
| 1443 | * @sa tjFree() |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1444 | */ |
| 1445 | DLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes); |
| 1446 | |
| 1447 | |
| 1448 | /** |
| 1449 | * Free an image buffer previously allocated by TurboJPEG. You should always |
| 1450 | * use this function to free JPEG destination buffer(s) that were automatically |
| 1451 | * (re)allocated by #tjCompress2() or #tjTransform() or that were manually |
| 1452 | * allocated using #tjAlloc(). |
| 1453 | * |
| 1454 | * @param buffer address of the buffer to free |
DRC | d441107 | 2011-05-24 17:00:15 +0000 | [diff] [blame] | 1455 | * |
| 1456 | * @sa tjAlloc() |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1457 | */ |
| 1458 | DLLEXPORT void DLLCALL tjFree(unsigned char *buffer); |
| 1459 | |
| 1460 | |
| 1461 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1462 | * Returns a descriptive error message explaining why the last command failed. |
| 1463 | * |
| 1464 | * @return a descriptive error message explaining why the last command failed. |
| 1465 | */ |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1466 | DLLEXPORT char* DLLCALL tjGetErrorStr(void); |
| 1467 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1468 | |
DRC | 07e982d | 2013-10-31 07:11:39 +0000 | [diff] [blame] | 1469 | /* Deprecated functions and macros */ |
| 1470 | #define TJFLAG_FORCEMMX 8 |
| 1471 | #define TJFLAG_FORCESSE 16 |
| 1472 | #define TJFLAG_FORCESSE2 32 |
| 1473 | #define TJFLAG_FORCESSE3 128 |
| 1474 | |
| 1475 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1476 | /* Backward compatibility functions and macros (nothing to see here) */ |
| 1477 | #define NUMSUBOPT TJ_NUMSAMP |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1478 | #define TJ_444 TJSAMP_444 |
| 1479 | #define TJ_422 TJSAMP_422 |
| 1480 | #define TJ_420 TJSAMP_420 |
| 1481 | #define TJ_411 TJSAMP_420 |
| 1482 | #define TJ_GRAYSCALE TJSAMP_GRAY |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1483 | |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1484 | #define TJ_BGR 1 |
| 1485 | #define TJ_BOTTOMUP TJFLAG_BOTTOMUP |
| 1486 | #define TJ_FORCEMMX TJFLAG_FORCEMMX |
| 1487 | #define TJ_FORCESSE TJFLAG_FORCESSE |
| 1488 | #define TJ_FORCESSE2 TJFLAG_FORCESSE2 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1489 | #define TJ_ALPHAFIRST 64 |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1490 | #define TJ_FORCESSE3 TJFLAG_FORCESSE3 |
| 1491 | #define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1492 | #define TJ_YUV 512 |
| 1493 | |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 1494 | DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height); |
| 1495 | |
| 1496 | DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height, |
| 1497 | int jpegSubsamp); |
| 1498 | |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1499 | DLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height, |
| 1500 | int subsamp); |
| 1501 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1502 | DLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf, |
| 1503 | int width, int pitch, int height, int pixelSize, unsigned char *dstBuf, |
| 1504 | unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags); |
| 1505 | |
| 1506 | DLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle, |
| 1507 | unsigned char *srcBuf, int width, int pitch, int height, int pixelSize, |
| 1508 | unsigned char *dstBuf, int subsamp, int flags); |
| 1509 | |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1510 | DLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle, |
| 1511 | unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, |
| 1512 | unsigned char *dstBuf, int subsamp, int flags); |
| 1513 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1514 | DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle, |
| 1515 | unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height); |
| 1516 | |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1517 | DLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle, |
| 1518 | unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, |
| 1519 | int *jpegSubsamp); |
| 1520 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1521 | DLLEXPORT int DLLCALL tjDecompress(tjhandle handle, |
| 1522 | unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, |
| 1523 | int width, int pitch, int height, int pixelSize, int flags); |
| 1524 | |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1525 | DLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle, |
| 1526 | unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, |
| 1527 | int flags); |
| 1528 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1529 | |
| 1530 | /** |
| 1531 | * @} |
| 1532 | */ |
| 1533 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1534 | #ifdef __cplusplus |
| 1535 | } |
| 1536 | #endif |
DRC | 3a1bb35 | 2011-05-24 09:15:44 +0000 | [diff] [blame] | 1537 | |
| 1538 | #endif |