DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1 | /* |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 2 | * Copyright (C)2009-2015, 2017 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) |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 33 | #define DLLEXPORT __declspec(dllexport) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 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 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [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 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 92 | enum TJSAMP { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 93 | /** |
| 94 | * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or |
| 95 | * YUV image will contain one chrominance component for every pixel in the |
| 96 | * source image. |
| 97 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 98 | TJSAMP_444 = 0, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 99 | /** |
| 100 | * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one |
| 101 | * chrominance component for every 2x1 block of pixels in the source image. |
| 102 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 103 | TJSAMP_422, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 104 | /** |
| 105 | * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one |
| 106 | * chrominance component for every 2x2 block of pixels in the source image. |
| 107 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 108 | TJSAMP_420, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 109 | /** |
| 110 | * Grayscale. The JPEG or YUV image will contain no chrominance components. |
| 111 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 112 | TJSAMP_GRAY, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 113 | /** |
| 114 | * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one |
| 115 | * chrominance component for every 1x2 block of pixels in the source image. |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 116 | * |
| 117 | * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 118 | */ |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 119 | TJSAMP_440, |
| 120 | /** |
| 121 | * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one |
| 122 | * chrominance component for every 4x1 block of pixels in the source image. |
| 123 | * JPEG images compressed with 4:1:1 subsampling will be almost exactly the |
| 124 | * same size as those compressed with 4:2:0 subsampling, and in the |
| 125 | * aggregate, both subsampling methods produce approximately the same |
| 126 | * perceptual quality. However, 4:1:1 is better able to reproduce sharp |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 127 | * horizontal features. |
| 128 | * |
| 129 | * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo. |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 130 | */ |
| 131 | TJSAMP_411 |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 134 | /** |
| 135 | * MCU block width (in pixels) for a given level of chrominance subsampling. |
| 136 | * MCU block sizes: |
| 137 | * - 8x8 for no subsampling or grayscale |
| 138 | * - 16x8 for 4:2:2 |
| 139 | * - 8x16 for 4:4:0 |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 140 | * - 16x16 for 4:2:0 |
| 141 | * - 32x8 for 4:1:1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 142 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 143 | static const int tjMCUWidth[TJ_NUMSAMP] = { 8, 16, 16, 8, 8, 32 }; |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 144 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 145 | /** |
| 146 | * MCU block height (in pixels) for a given level of chrominance subsampling. |
| 147 | * MCU block sizes: |
| 148 | * - 8x8 for no subsampling or grayscale |
| 149 | * - 16x8 for 4:2:2 |
| 150 | * - 8x16 for 4:4:0 |
DRC | 1f3635c | 2013-08-18 10:19:00 +0000 | [diff] [blame] | 151 | * - 16x16 for 4:2:0 |
| 152 | * - 32x8 for 4:1:1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 153 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 154 | static const int tjMCUHeight[TJ_NUMSAMP] = { 8, 8, 16, 8, 16, 8 }; |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 155 | |
| 156 | |
| 157 | /** |
| 158 | * The number of pixel formats |
| 159 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 160 | #define TJ_NUMPF 12 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Pixel formats |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 164 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 165 | enum TJPF { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 166 | /** |
| 167 | * RGB pixel format. The red, green, and blue components in the image are |
| 168 | * stored in 3-byte pixels in the order R, G, B from lowest to highest byte |
| 169 | * address within each pixel. |
| 170 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 171 | TJPF_RGB = 0, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 172 | /** |
| 173 | * BGR pixel format. The red, green, and blue components in the image are |
| 174 | * stored in 3-byte pixels in the order B, G, R from lowest to highest byte |
| 175 | * address within each pixel. |
| 176 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 177 | TJPF_BGR, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 178 | /** |
| 179 | * RGBX pixel format. The red, green, and blue components in the image are |
| 180 | * 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] | 181 | * address within each pixel. The X component is ignored when compressing |
| 182 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 183 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 184 | TJPF_RGBX, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 185 | /** |
| 186 | * BGRX pixel format. The red, green, and blue components in the image are |
| 187 | * 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] | 188 | * address within each pixel. The X component is ignored when compressing |
| 189 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 190 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 191 | TJPF_BGRX, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 192 | /** |
| 193 | * XBGR pixel format. The red, green, and blue components in the image are |
| 194 | * 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] | 195 | * address within each pixel. The X component is ignored when compressing |
| 196 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 197 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 198 | TJPF_XBGR, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 199 | /** |
| 200 | * XRGB pixel format. The red, green, and blue components in the image are |
| 201 | * 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] | 202 | * address within each pixel. The X component is ignored when compressing |
| 203 | * and undefined when decompressing. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 204 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 205 | TJPF_XRGB, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 206 | /** |
| 207 | * Grayscale pixel format. Each 1-byte pixel represents a luminance |
| 208 | * (brightness) level from 0 to 255. |
| 209 | */ |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 210 | TJPF_GRAY, |
| 211 | /** |
| 212 | * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when |
| 213 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 214 | * interpreted as an opaque alpha channel. |
| 215 | */ |
| 216 | TJPF_RGBA, |
| 217 | /** |
| 218 | * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when |
| 219 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 220 | * interpreted as an opaque alpha channel. |
| 221 | */ |
| 222 | TJPF_BGRA, |
| 223 | /** |
| 224 | * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when |
| 225 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 226 | * interpreted as an opaque alpha channel. |
| 227 | */ |
| 228 | TJPF_ABGR, |
| 229 | /** |
| 230 | * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when |
| 231 | * decompressing, the X component is guaranteed to be 0xFF, which can be |
| 232 | * interpreted as an opaque alpha channel. |
| 233 | */ |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 234 | TJPF_ARGB, |
| 235 | /** |
DRC | b2c4745 | 2013-08-23 06:38:59 +0000 | [diff] [blame] | 236 | * CMYK pixel format. Unlike RGB, which is an additive color model used |
| 237 | * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive |
| 238 | * color model used primarily for printing. In the CMYK color model, the |
| 239 | * value of each color component typically corresponds to an amount of cyan, |
| 240 | * magenta, yellow, or black ink that is applied to a white background. In |
| 241 | * order to convert between CMYK and RGB, it is necessary to use a color |
| 242 | * management system (CMS.) A CMS will attempt to map colors within the |
| 243 | * printer's gamut to perceptually similar colors in the display's gamut and |
| 244 | * vice versa, but the mapping is typically not 1:1 or reversible, nor can it |
| 245 | * be defined with a simple formula. Thus, such a conversion is out of scope |
| 246 | * for a codec library. However, the TurboJPEG API allows for compressing |
| 247 | * CMYK pixels into a YCCK JPEG image (see #TJCS_YCCK) and decompressing YCCK |
| 248 | * JPEG images into CMYK pixels. |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 249 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 250 | TJPF_CMYK, |
| 251 | /** |
| 252 | * Unknown pixel format. Currently this is only used by #tjLoadImage(). |
| 253 | */ |
| 254 | TJPF_UNKNOWN = -1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 255 | }; |
| 256 | |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 257 | /** |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 258 | * Red offset (in bytes) for a given pixel format. This specifies the number |
| 259 | * of bytes that the red component is offset from the start of the pixel. For |
| 260 | * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 261 | * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>. This |
| 262 | * will be -1 if the pixel format does not have a red component. |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 263 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 264 | static const int tjRedOffset[TJ_NUMPF] = { |
| 265 | 0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1 |
| 266 | }; |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 267 | /** |
| 268 | * Green offset (in bytes) for a given pixel format. This specifies the number |
| 269 | * of bytes that the green component is offset from the start of the pixel. |
| 270 | * For instance, if a pixel of format TJ_BGRX is stored in |
| 271 | * <tt>char pixel[]</tt>, then the green component will be |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 272 | * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>. This will be -1 if the pixel format |
| 273 | * does not have a green component. |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 274 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 275 | static const int tjGreenOffset[TJ_NUMPF] = { |
| 276 | 1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1 |
| 277 | }; |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 278 | /** |
| 279 | * Blue offset (in bytes) for a given pixel format. This specifies the number |
| 280 | * of bytes that the Blue component is offset from the start of the pixel. For |
| 281 | * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 282 | * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>. This |
| 283 | * will be -1 if the pixel format does not have a blue component. |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 284 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 285 | static const int tjBlueOffset[TJ_NUMPF] = { |
| 286 | 2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1 |
| 287 | }; |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 288 | /** |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 289 | * Alpha offset (in bytes) for a given pixel format. This specifies the number |
| 290 | * of bytes that the Alpha component is offset from the start of the pixel. |
| 291 | * For instance, if a pixel of format TJ_BGRA is stored in |
| 292 | * <tt>char pixel[]</tt>, then the alpha component will be |
| 293 | * <tt>pixel[tjAlphaOffset[TJ_BGRA]]</tt>. This will be -1 if the pixel format |
| 294 | * does not have an alpha component. |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 295 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 296 | static const int tjAlphaOffset[TJ_NUMPF] = { |
| 297 | -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 |
| 298 | }; |
| 299 | /** |
| 300 | * Pixel size (in bytes) for a given pixel format |
| 301 | */ |
| 302 | static const int tjPixelSize[TJ_NUMPF] = { |
| 303 | 3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4 |
| 304 | }; |
DRC | 38cb1ec | 2013-08-23 04:45:43 +0000 | [diff] [blame] | 305 | |
| 306 | |
| 307 | /** |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 308 | * The number of JPEG colorspaces |
| 309 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 310 | #define TJ_NUMCS 5 |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 311 | |
| 312 | /** |
| 313 | * JPEG colorspaces |
| 314 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 315 | enum TJCS { |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 316 | /** |
| 317 | * RGB colorspace. When compressing the JPEG image, the R, G, and B |
| 318 | * components in the source image are reordered into image planes, but no |
| 319 | * colorspace conversion or subsampling is performed. RGB JPEG images can be |
| 320 | * decompressed to any of the extended RGB pixel formats or grayscale, but |
| 321 | * they cannot be decompressed to YUV images. |
| 322 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 323 | TJCS_RGB = 0, |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 324 | /** |
| 325 | * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a |
| 326 | * mathematical transformation of RGB designed solely for storage and |
| 327 | * transmission. YCbCr images must be converted to RGB before they can |
| 328 | * actually be displayed. In the YCbCr colorspace, the Y (luminance) |
| 329 | * component represents the black & white portion of the original image, and |
| 330 | * the Cb and Cr (chrominance) components represent the color portion of the |
| 331 | * original image. Originally, the analog equivalent of this transformation |
| 332 | * allowed the same signal to drive both black & white and color televisions, |
| 333 | * but JPEG images use YCbCr primarily because it allows the color data to be |
| 334 | * optionally subsampled for the purposes of reducing bandwidth or disk |
| 335 | * space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images |
| 336 | * can be compressed from and decompressed to any of the extended RGB pixel |
| 337 | * formats or grayscale, or they can be decompressed to YUV planar images. |
| 338 | */ |
| 339 | TJCS_YCbCr, |
| 340 | /** |
| 341 | * Grayscale colorspace. The JPEG image retains only the luminance data (Y |
| 342 | * component), and any color data from the source image is discarded. |
| 343 | * Grayscale JPEG images can be compressed from and decompressed to any of |
| 344 | * the extended RGB pixel formats or grayscale, or they can be decompressed |
| 345 | * to YUV planar images. |
| 346 | */ |
| 347 | TJCS_GRAY, |
| 348 | /** |
| 349 | * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K |
| 350 | * components in the source image are reordered into image planes, but no |
| 351 | * colorspace conversion or subsampling is performed. CMYK JPEG images can |
| 352 | * only be decompressed to CMYK pixels. |
| 353 | */ |
| 354 | TJCS_CMYK, |
| 355 | /** |
| 356 | * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but |
| 357 | * rather a mathematical transformation of CMYK designed solely for storage |
| 358 | * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be |
| 359 | * reversibly transformed into YCCK, and as with YCbCr, the chrominance |
| 360 | * components in the YCCK pixels can be subsampled without incurring major |
| 361 | * perceptual loss. YCCK JPEG images can only be compressed from and |
| 362 | * decompressed to CMYK pixels. |
| 363 | */ |
| 364 | TJCS_YCCK |
| 365 | }; |
| 366 | |
| 367 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 368 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 369 | * The uncompressed source/destination image is stored in bottom-up (Windows, |
| 370 | * OpenGL) order, not top-down (X11) order. |
| 371 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 372 | #define TJFLAG_BOTTOMUP 2 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 373 | /** |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 374 | * When decompressing an image that was compressed using chrominance |
| 375 | * subsampling, use the fastest chrominance upsampling algorithm available in |
| 376 | * the underlying codec. The default is to use smooth upsampling, which |
| 377 | * creates a smooth transition between neighboring chrominance components in |
| 378 | * order to reduce upsampling artifacts in the decompressed image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 379 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 380 | #define TJFLAG_FASTUPSAMPLE 256 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 381 | /** |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 382 | * Disable buffer (re)allocation. If passed to one of the JPEG compression or |
| 383 | * transform functions, this flag will cause those functions to generate an |
| 384 | * error if the JPEG image buffer is invalid or too small rather than |
| 385 | * attempting to allocate or reallocate that buffer. This reproduces the |
| 386 | * behavior of earlier versions of TurboJPEG. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 387 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 388 | #define TJFLAG_NOREALLOC 1024 |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 389 | /** |
| 390 | * Use the fastest DCT/IDCT algorithm available in the underlying codec. The |
DRC | 3b21982 | 2013-08-18 09:31:45 +0000 | [diff] [blame] | 391 | * default if this flag is not specified is implementation-specific. For |
| 392 | * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast |
| 393 | * algorithm by default when compressing, because this has been shown to have |
| 394 | * only a very slight effect on accuracy, but it uses the accurate algorithm |
| 395 | * when decompressing, because this has been shown to have a larger effect. |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 396 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 397 | #define TJFLAG_FASTDCT 2048 |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 398 | /** |
| 399 | * Use the most accurate DCT/IDCT algorithm available in the underlying codec. |
DRC | 3b21982 | 2013-08-18 09:31:45 +0000 | [diff] [blame] | 400 | * The default if this flag is not specified is implementation-specific. For |
| 401 | * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast |
| 402 | * algorithm by default when compressing, because this has been shown to have |
| 403 | * only a very slight effect on accuracy, but it uses the accurate algorithm |
| 404 | * when decompressing, because this has been shown to have a larger effect. |
DRC | 73d74c1 | 2012-06-29 23:46:38 +0000 | [diff] [blame] | 405 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 406 | #define TJFLAG_ACCURATEDCT 4096 |
| 407 | /** |
| 408 | * Immediately discontinue the current compression/decompression/transform |
| 409 | * operation if the underlying codec throws a warning (non-fatal error). The |
| 410 | * default behavior is to allow the operation to complete unless a fatal error |
| 411 | * is encountered. |
| 412 | */ |
| 413 | #define TJFLAG_STOPONWARNING 8192 |
| 414 | /** |
| 415 | * Use progressive entropy coding in JPEG images generated by the compression |
| 416 | * and transform functions. Progressive entropy coding will generally improve |
| 417 | * compression relative to baseline entropy coding (the default), but it will |
| 418 | * reduce compression and decompression performance considerably. |
| 419 | */ |
| 420 | #define TJFLAG_PROGRESSIVE 16384 |
| 421 | |
| 422 | |
| 423 | /** |
| 424 | * The number of error codes |
| 425 | */ |
| 426 | #define TJ_NUMERR 2 |
| 427 | |
| 428 | /** |
| 429 | * Error codes |
| 430 | */ |
| 431 | enum TJERR { |
| 432 | /** |
| 433 | * The error was non-fatal and recoverable, but the image may still be |
| 434 | * corrupt. |
| 435 | */ |
| 436 | TJERR_WARNING = 0, |
| 437 | /** |
| 438 | * The error was fatal and non-recoverable. |
| 439 | */ |
| 440 | TJERR_FATAL |
| 441 | }; |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 442 | |
| 443 | |
| 444 | /** |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 445 | * The number of transform operations |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 446 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 447 | #define TJ_NUMXOP 8 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 448 | |
| 449 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 450 | * Transform operations for #tjTransform() |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 451 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 452 | enum TJXOP { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 453 | /** |
| 454 | * Do not transform the position of the image pixels |
| 455 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 456 | TJXOP_NONE = 0, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 457 | /** |
| 458 | * Flip (mirror) image horizontally. This transform is imperfect if there |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 459 | * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 460 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 461 | TJXOP_HFLIP, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 462 | /** |
| 463 | * Flip (mirror) image vertically. This transform is imperfect if there are |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 464 | * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 465 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 466 | TJXOP_VFLIP, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 467 | /** |
| 468 | * Transpose image (flip/mirror along upper left to lower right axis.) This |
| 469 | * transform is always perfect. |
| 470 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 471 | TJXOP_TRANSPOSE, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 472 | /** |
| 473 | * Transverse transpose image (flip/mirror along upper right to lower left |
| 474 | * axis.) This transform is imperfect if there are any partial MCU blocks in |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 475 | * the image (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 476 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 477 | TJXOP_TRANSVERSE, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 478 | /** |
| 479 | * Rotate image clockwise by 90 degrees. This transform is imperfect if |
| 480 | * there are any partial MCU blocks on the bottom edge (see |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 481 | * #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 482 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 483 | TJXOP_ROT90, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 484 | /** |
| 485 | * Rotate image 180 degrees. This transform is imperfect if there are any |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 486 | * partial MCU blocks in the image (see #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 487 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 488 | TJXOP_ROT180, |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 489 | /** |
| 490 | * Rotate image counter-clockwise by 90 degrees. This transform is imperfect |
| 491 | * if there are any partial MCU blocks on the right edge (see |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 492 | * #TJXOPT_PERFECT.) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 493 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 494 | TJXOP_ROT270 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 495 | }; |
| 496 | |
| 497 | |
| 498 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 499 | * This option will cause #tjTransform() to return an error if the transform is |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 500 | * not perfect. Lossless transforms operate on MCU blocks, whose size depends |
| 501 | * on the level of chrominance subsampling used (see #tjMCUWidth |
| 502 | * and #tjMCUHeight.) If the image's width or height is not evenly divisible |
| 503 | * by the MCU block size, then there will be partial MCU blocks on the right |
| 504 | * and/or bottom edges. It is not possible to move these partial MCU blocks to |
| 505 | * the top or left of the image, so any transform that would require that is |
| 506 | * "imperfect." If this option is not specified, then any partial MCU blocks |
| 507 | * that cannot be transformed will be left in place, which will create |
| 508 | * odd-looking strips on the right or bottom edge of the image. |
| 509 | */ |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 510 | #define TJXOPT_PERFECT 1 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 511 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 512 | * This option will cause #tjTransform() to discard any partial MCU blocks that |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 513 | * cannot be transformed. |
| 514 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 515 | #define TJXOPT_TRIM 2 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 516 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 517 | * This option will enable lossless cropping. See #tjTransform() for more |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 518 | * information. |
| 519 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 520 | #define TJXOPT_CROP 4 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 521 | /** |
| 522 | * This option will discard the color data in the input image and produce |
| 523 | * a grayscale output image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 524 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 525 | #define TJXOPT_GRAY 8 |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 526 | /** |
| 527 | * This option will prevent #tjTransform() from outputting a JPEG image for |
| 528 | * this particular transform (this can be used in conjunction with a custom |
| 529 | * filter to capture the transformed DCT coefficients without transcoding |
| 530 | * them.) |
| 531 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 532 | #define TJXOPT_NOOUTPUT 16 |
| 533 | /** |
| 534 | * This option will enable progressive entropy coding in the output image |
| 535 | * generated by this particular transform. Progressive entropy coding will |
| 536 | * generally improve compression relative to baseline entropy coding (the |
| 537 | * default), but it will reduce compression and decompression performance |
| 538 | * considerably. |
| 539 | */ |
| 540 | #define TJXOPT_PROGRESSIVE 32 |
| 541 | /** |
| 542 | * This option will prevent #tjTransform() from copying any extra markers |
| 543 | * (including EXIF and ICC profile data) from the source image to the output |
| 544 | * image. |
| 545 | */ |
| 546 | #define TJXOPT_COPYNONE 64 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 547 | |
| 548 | |
| 549 | /** |
| 550 | * Scaling factor |
| 551 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 552 | typedef struct { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 553 | /** |
| 554 | * Numerator |
| 555 | */ |
| 556 | int num; |
| 557 | /** |
| 558 | * Denominator |
| 559 | */ |
| 560 | int denom; |
| 561 | } tjscalingfactor; |
| 562 | |
| 563 | /** |
| 564 | * Cropping region |
| 565 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 566 | typedef struct { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 567 | /** |
| 568 | * The left boundary of the cropping region. This must be evenly divisible |
| 569 | * by the MCU block width (see #tjMCUWidth.) |
| 570 | */ |
| 571 | int x; |
| 572 | /** |
| 573 | * The upper boundary of the cropping region. This must be evenly divisible |
| 574 | * by the MCU block height (see #tjMCUHeight.) |
| 575 | */ |
| 576 | int y; |
| 577 | /** |
| 578 | * The width of the cropping region. Setting this to 0 is the equivalent of |
| 579 | * setting it to the width of the source JPEG image - x. |
| 580 | */ |
| 581 | int w; |
| 582 | /** |
| 583 | * The height of the cropping region. Setting this to 0 is the equivalent of |
| 584 | * setting it to the height of the source JPEG image - y. |
| 585 | */ |
| 586 | int h; |
DRC | 0a07969 | 2011-03-02 09:27:49 +0000 | [diff] [blame] | 587 | } tjregion; |
| 588 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 589 | /** |
| 590 | * Lossless transform |
| 591 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 592 | typedef struct tjtransform { |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 593 | /** |
| 594 | * Cropping region |
| 595 | */ |
| 596 | tjregion r; |
| 597 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 598 | * One of the @ref TJXOP "transform operations" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 599 | */ |
| 600 | int op; |
| 601 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 602 | * 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] | 603 | */ |
| 604 | int options; |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 605 | /** |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 606 | * Arbitrary data that can be accessed within the body of the callback |
| 607 | * function |
| 608 | */ |
| 609 | void *data; |
| 610 | /** |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 611 | * A callback function that can be used to modify the DCT coefficients |
| 612 | * after they are losslessly transformed but before they are transcoded to a |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 613 | * new JPEG image. This allows for custom filters or other transformations |
| 614 | * to be applied in the frequency domain. |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 615 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 616 | * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE: |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 617 | * this pointer is not guaranteed to be valid once the callback returns, so |
| 618 | * applications wishing to hand off the DCT coefficients to another function |
| 619 | * or library should make a copy of them within the body of the callback.) |
| 620 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 621 | * @param arrayRegion #tjregion structure containing the width and height of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 622 | * the array pointed to by <tt>coeffs</tt> as well as its offset relative to |
| 623 | * the component plane. TurboJPEG implementations may choose to split each |
| 624 | * component plane into multiple DCT coefficient arrays and call the callback |
| 625 | * function once for each array. |
| 626 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 627 | * @param planeRegion #tjregion structure containing the width and height of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 628 | * the component plane to which <tt>coeffs</tt> belongs |
| 629 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 630 | * @param componentID ID number of the component plane to which |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 631 | * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1, |
| 632 | * and 2 in typical JPEG images.) |
| 633 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 634 | * @param transformID ID number of the transformed image to which |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 635 | * <tt>coeffs</tt> belongs. This is the same as the index of the transform |
| 636 | * in the <tt>transforms</tt> array that was passed to #tjTransform(). |
| 637 | * |
DRC | f546711 | 2011-09-20 05:02:19 +0000 | [diff] [blame] | 638 | * @param transform a pointer to a #tjtransform structure that specifies the |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 639 | * parameters and/or cropping region for this transform |
DRC | 7bf04d3 | 2011-09-17 00:18:31 +0000 | [diff] [blame] | 640 | * |
| 641 | * @return 0 if the callback was successful, or -1 if an error occurred. |
| 642 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 643 | int (*customFilter) (short *coeffs, tjregion arrayRegion, |
| 644 | tjregion planeRegion, int componentIndex, |
| 645 | int transformIndex, struct tjtransform *transform); |
DRC | 0a07969 | 2011-03-02 09:27:49 +0000 | [diff] [blame] | 646 | } tjtransform; |
| 647 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 648 | /** |
| 649 | * TurboJPEG instance handle |
| 650 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 651 | typedef void *tjhandle; |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 652 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * Pad the given width to the nearest 32-bit boundary |
| 656 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 657 | #define TJPAD(width) (((width) + 3) & (~3)) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 658 | |
| 659 | /** |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 660 | * Compute the scaled value of <tt>dimension</tt> using the given scaling |
| 661 | * factor. This macro performs the integer equivalent of <tt>ceil(dimension * |
DRC | 1a45b81 | 2014-05-09 18:06:58 +0000 | [diff] [blame] | 662 | * scalingFactor)</tt>. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 663 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 664 | #define TJSCALED(dimension, scalingFactor) \ |
| 665 | ((dimension * scalingFactor.num + scalingFactor.denom - 1) / \ |
| 666 | scalingFactor.denom) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 667 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 668 | |
| 669 | #ifdef __cplusplus |
| 670 | extern "C" { |
| 671 | #endif |
| 672 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 673 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 674 | /** |
| 675 | * Create a TurboJPEG compressor instance. |
| 676 | * |
| 677 | * @return a handle to the newly-created instance, or NULL if an error |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 678 | * occurred (see #tjGetErrorStr2().) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 679 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 680 | DLLEXPORT tjhandle tjInitCompress(void); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 681 | |
| 682 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 683 | /** |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 684 | * Compress an RGB, grayscale, or CMYK image into a JPEG image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 685 | * |
| 686 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 687 | * |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 688 | * @param srcBuf pointer to an image buffer containing RGB, grayscale, or |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 689 | * CMYK pixels to be compressed |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 690 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 691 | * @param width width (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 692 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 693 | * @param pitch bytes per line in the source image. Normally, this should be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 694 | * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or |
| 695 | * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image |
| 696 | * is padded to the nearest 32-bit boundary, as is the case for Windows |
| 697 | * bitmaps. You can also be clever and use this parameter to skip lines, etc. |
| 698 | * Setting this parameter to 0 is the equivalent of setting it to |
| 699 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 700 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 701 | * @param height height (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 702 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 703 | * @param pixelFormat pixel format of the source image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 704 | * "Pixel formats".) |
| 705 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 706 | * @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] | 707 | * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer |
| 708 | * to accommodate the size of the JPEG image. Thus, you can choose to: |
| 709 | * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and |
| 710 | * let TurboJPEG grow the buffer as needed, |
| 711 | * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer |
| 712 | * for you, or |
| 713 | * -# pre-allocate the buffer to a "worst case" size determined by calling |
| 714 | * #tjBufSize(). This should ensure that the buffer never has to be |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 715 | * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 716 | * . |
| 717 | * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your |
| 718 | * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC, |
| 719 | * you should always check <tt>*jpegBuf</tt> upon return from this function, as |
| 720 | * it may have changed. |
| 721 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 722 | * @param jpegSize pointer to an unsigned long variable that holds the size of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 723 | * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated |
| 724 | * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer. |
| 725 | * 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] | 726 | * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being |
| 727 | * reused from a previous call to one of the JPEG compression functions, then |
| 728 | * <tt>*jpegSize</tt> is ignored. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 729 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 730 | * @param jpegSubsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 731 | * generating the JPEG image (see @ref TJSAMP |
| 732 | * "Chrominance subsampling options".) |
| 733 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 734 | * @param jpegQual the image quality of the generated JPEG image (1 = worst, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 735 | * 100 = best) |
| 736 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 737 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 738 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 739 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 740 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 741 | * and #tjGetErrorCode().) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 742 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 743 | DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf, |
| 744 | int width, int pitch, int height, int pixelFormat, |
| 745 | unsigned char **jpegBuf, unsigned long *jpegSize, |
| 746 | int jpegSubsamp, int jpegQual, int flags); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 747 | |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 748 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 749 | /** |
DRC | 779bd68 | 2014-08-10 18:30:52 +0000 | [diff] [blame] | 750 | * Compress a YUV planar image into a JPEG image. |
| 751 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 752 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 753 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 754 | * @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] | 755 | * compressed. The size of this buffer should match the value returned by |
| 756 | * #tjBufSizeYUV2() for the given image width, height, padding, and level of |
| 757 | * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be |
| 758 | * stored sequentially in the source buffer (refer to @ref YUVnotes |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 759 | * "YUV Image Format Notes".) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 760 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 761 | * @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] | 762 | * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate |
| 763 | * buffer copy will be performed within TurboJPEG. |
| 764 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 765 | * @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] | 766 | * line in each plane of the YUV image is padded to the nearest multiple of 4 |
| 767 | * bytes, then <tt>pad</tt> should be set to 4. |
| 768 | * |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 769 | * @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] | 770 | * an even multiple of the MCU block height (see #tjMCUHeight), then an |
| 771 | * intermediate buffer copy will be performed within TurboJPEG. |
| 772 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 773 | * @param subsamp the level of chrominance subsampling used in the source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 774 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 775 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 776 | * @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] | 777 | * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to |
| 778 | * accommodate the size of the JPEG image. Thus, you can choose to: |
| 779 | * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and |
| 780 | * let TurboJPEG grow the buffer as needed, |
| 781 | * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer |
| 782 | * for you, or |
| 783 | * -# pre-allocate the buffer to a "worst case" size determined by calling |
| 784 | * #tjBufSize(). This should ensure that the buffer never has to be |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 785 | * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 786 | * . |
| 787 | * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your |
| 788 | * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC, |
| 789 | * you should always check <tt>*jpegBuf</tt> upon return from this function, as |
| 790 | * it may have changed. |
| 791 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 792 | * @param jpegSize pointer to an unsigned long variable that holds the size of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 793 | * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated |
| 794 | * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer. |
| 795 | * 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] | 796 | * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being |
| 797 | * reused from a previous call to one of the JPEG compression functions, then |
| 798 | * <tt>*jpegSize</tt> is ignored. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 799 | * |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 800 | * @param jpegQual the image quality of the generated JPEG image (1 = worst, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 801 | * 100 = best) |
| 802 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 803 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 804 | * "flags" |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 805 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 806 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 807 | * and #tjGetErrorCode().) |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 808 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 809 | DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf, |
| 810 | int width, int pad, int height, int subsamp, |
| 811 | unsigned char **jpegBuf, |
| 812 | unsigned long *jpegSize, int jpegQual, |
| 813 | int flags); |
DRC | 910a357 | 2013-10-30 23:02:57 +0000 | [diff] [blame] | 814 | |
| 815 | |
| 816 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 817 | * Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image. |
| 818 | * |
| 819 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 820 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 821 | * @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] | 822 | * (or just a Y plane, if compressing a grayscale image) that contain a YUV |
| 823 | * image to be compressed. These planes can be contiguous or non-contiguous in |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 824 | * memory. The size of each plane should match the value returned by |
| 825 | * #tjPlaneSizeYUV() for the given image width, height, strides, and level of |
| 826 | * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 827 | * for more details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 828 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 829 | * @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] | 830 | * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate |
| 831 | * buffer copy will be performed within TurboJPEG. |
| 832 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 833 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 834 | * line in the corresponding plane of the YUV source image. Setting the stride |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 835 | * for any plane to 0 is the same as setting it to the plane width (see |
| 836 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
DRC | 7a8c53e | 2015-06-19 16:07:14 +0000 | [diff] [blame] | 837 | * the strides for all planes will be set to their respective plane widths. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 838 | * You can adjust the strides in order to specify an arbitrary amount of line |
| 839 | * padding in each plane or to create a JPEG image from a subregion of a larger |
| 840 | * YUV planar image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 841 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 842 | * @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] | 843 | * an even multiple of the MCU block height (see #tjMCUHeight), then an |
| 844 | * intermediate buffer copy will be performed within TurboJPEG. |
| 845 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 846 | * @param subsamp the level of chrominance subsampling used in the source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 847 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 848 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 849 | * @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] | 850 | * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to |
| 851 | * accommodate the size of the JPEG image. Thus, you can choose to: |
| 852 | * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and |
| 853 | * let TurboJPEG grow the buffer as needed, |
| 854 | * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer |
| 855 | * for you, or |
| 856 | * -# pre-allocate the buffer to a "worst case" size determined by calling |
| 857 | * #tjBufSize(). This should ensure that the buffer never has to be |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 858 | * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 859 | * . |
| 860 | * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your |
| 861 | * pre-allocated buffer. In any case, unless you have set #TJFLAG_NOREALLOC, |
| 862 | * you should always check <tt>*jpegBuf</tt> upon return from this function, as |
| 863 | * it may have changed. |
| 864 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 865 | * @param jpegSize pointer to an unsigned long variable that holds the size of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 866 | * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a pre-allocated |
| 867 | * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer. |
| 868 | * 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] | 869 | * bytes.) If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being |
| 870 | * reused from a previous call to one of the JPEG compression functions, then |
| 871 | * <tt>*jpegSize</tt> is ignored. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 872 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 873 | * @param jpegQual the image quality of the generated JPEG image (1 = worst, |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 874 | * 100 = best) |
| 875 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 876 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 877 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 878 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 879 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 880 | * and #tjGetErrorCode().) |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 881 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 882 | DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle, |
| 883 | const unsigned char **srcPlanes, |
| 884 | int width, const int *strides, |
| 885 | int height, int subsamp, |
| 886 | unsigned char **jpegBuf, |
| 887 | unsigned long *jpegSize, int jpegQual, |
| 888 | int flags); |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 889 | |
| 890 | |
| 891 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 892 | * 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] | 893 | * the given parameters. The number of bytes returned by this function is |
| 894 | * larger than the size of the uncompressed source image. The reason for this |
| 895 | * 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] | 896 | * for a very high-quality JPEG image with very high-frequency content to |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 897 | * expand rather than compress when converted to the JPEG format. Such images |
| 898 | * represent a very rare corner case, but since there is no way to predict the |
| 899 | * size of a JPEG image prior to compression, the corner case has to be |
| 900 | * handled. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 901 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 902 | * @param width width (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 903 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 904 | * @param height height (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 905 | * |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 906 | * @param jpegSubsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 907 | * generating the JPEG image (see @ref TJSAMP |
| 908 | * "Chrominance subsampling options".) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 909 | * |
| 910 | * @return the maximum size of the buffer (in bytes) required to hold the |
| 911 | * image, or -1 if the arguments are out of bounds. |
| 912 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 913 | DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 914 | |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 915 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 916 | /** |
| 917 | * The size of the buffer (in bytes) required to hold a YUV planar image with |
| 918 | * the given parameters. |
| 919 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 920 | * @param width width (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 921 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 922 | * @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] | 923 | * the nearest multiple of this number of bytes (must be a power of 2.) |
| 924 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 925 | * @param height height (in pixels) of the image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 926 | * |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 927 | * @param subsamp level of chrominance subsampling in the image (see |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 928 | * @ref TJSAMP "Chrominance subsampling options".) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 929 | * |
| 930 | * @return the size of the buffer (in bytes) required to hold the image, or |
| 931 | * -1 if the arguments are out of bounds. |
| 932 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 933 | DLLEXPORT unsigned long tjBufSizeYUV2(int width, int pad, int height, |
| 934 | int subsamp); |
DRC | f3cf973 | 2011-02-22 00:16:14 +0000 | [diff] [blame] | 935 | |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 936 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 937 | /** |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 938 | * The size of the buffer (in bytes) required to hold a YUV image plane with |
| 939 | * the given parameters. |
| 940 | * |
| 941 | * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) |
| 942 | * |
| 943 | * @param width width (in pixels) of the YUV image. NOTE: this is the width of |
| 944 | * the whole image, not the plane width. |
| 945 | * |
| 946 | * @param stride bytes per line in the image plane. Setting this to 0 is the |
| 947 | * equivalent of setting it to the plane width. |
| 948 | * |
| 949 | * @param height height (in pixels) of the YUV image. NOTE: this is the height |
| 950 | * of the whole image, not the plane height. |
| 951 | * |
| 952 | * @param subsamp level of chrominance subsampling in the image (see |
| 953 | * @ref TJSAMP "Chrominance subsampling options".) |
| 954 | * |
| 955 | * @return the size of the buffer (in bytes) required to hold the YUV image |
| 956 | * plane, or -1 if the arguments are out of bounds. |
| 957 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 958 | DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride, |
| 959 | int height, int subsamp); |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 960 | |
| 961 | |
| 962 | /** |
| 963 | * The plane width of a YUV image plane with the given parameters. Refer to |
| 964 | * @ref YUVnotes "YUV Image Format Notes" for a description of plane width. |
| 965 | * |
| 966 | * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) |
| 967 | * |
| 968 | * @param width width (in pixels) of the YUV image |
| 969 | * |
| 970 | * @param subsamp level of chrominance subsampling in the image (see |
| 971 | * @ref TJSAMP "Chrominance subsampling options".) |
| 972 | * |
| 973 | * @return the plane width of a YUV image plane with the given parameters, or |
| 974 | * -1 if the arguments are out of bounds. |
| 975 | */ |
| 976 | DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp); |
| 977 | |
| 978 | |
| 979 | /** |
| 980 | * The plane height of a YUV image plane with the given parameters. Refer to |
| 981 | * @ref YUVnotes "YUV Image Format Notes" for a description of plane height. |
| 982 | * |
| 983 | * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) |
| 984 | * |
| 985 | * @param height height (in pixels) of the YUV image |
| 986 | * |
| 987 | * @param subsamp level of chrominance subsampling in the image (see |
| 988 | * @ref TJSAMP "Chrominance subsampling options".) |
| 989 | * |
| 990 | * @return the plane height of a YUV image plane with the given parameters, or |
| 991 | * -1 if the arguments are out of bounds. |
| 992 | */ |
| 993 | DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp); |
| 994 | |
| 995 | |
| 996 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 997 | * Encode an RGB or grayscale image into a YUV planar image. This function |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 998 | * uses the accelerated color conversion routines in the underlying |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 999 | * codec but does not execute any of the other steps in the JPEG compression |
DRC | 7a8c53e | 2015-06-19 16:07:14 +0000 | [diff] [blame] | 1000 | * process. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1001 | * |
| 1002 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1003 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1004 | * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1005 | * to be encoded |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1006 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1007 | * @param width width (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1008 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1009 | * @param pitch bytes per line in the source image. Normally, this should be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1010 | * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or |
| 1011 | * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image |
| 1012 | * is padded to the nearest 32-bit boundary, as is the case for Windows |
| 1013 | * bitmaps. You can also be clever and use this parameter to skip lines, etc. |
| 1014 | * Setting this parameter to 0 is the equivalent of setting it to |
| 1015 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1016 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1017 | * @param height height (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1018 | * |
DRC | 25b995a | 2011-05-21 15:34:54 +0000 | [diff] [blame] | 1019 | * @param pixelFormat pixel format of the source image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1020 | * "Pixel formats".) |
| 1021 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1022 | * @param dstBuf pointer to an image buffer that will receive the YUV image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1023 | * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based |
| 1024 | * on the image width, height, padding, and level of chrominance subsampling. |
| 1025 | * The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the |
| 1026 | * buffer (refer to @ref YUVnotes "YUV Image Format Notes".) |
| 1027 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1028 | * @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] | 1029 | * padded to the nearest multiple of this number of bytes (must be a power of |
| 1030 | * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to |
| 1031 | * 4. |
| 1032 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1033 | * @param subsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1034 | * generating the YUV image (see @ref TJSAMP |
| 1035 | * "Chrominance subsampling options".) To generate images suitable for X |
| 1036 | * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an |
| 1037 | * image compatible with the I420 (AKA "YUV420P") format. |
| 1038 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1039 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1040 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1041 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1042 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1043 | * and #tjGetErrorCode().) |
DRC | 8424160 | 2011-02-25 02:08:23 +0000 | [diff] [blame] | 1044 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1045 | DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf, |
| 1046 | int width, int pitch, int height, int pixelFormat, |
| 1047 | unsigned char *dstBuf, int pad, int subsamp, |
| 1048 | int flags); |
DRC | 8424160 | 2011-02-25 02:08:23 +0000 | [diff] [blame] | 1049 | |
| 1050 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1051 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1052 | * Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image |
| 1053 | * planes. This function uses the accelerated color conversion routines in the |
| 1054 | * underlying codec but does not execute any of the other steps in the JPEG |
| 1055 | * compression process. |
| 1056 | * |
| 1057 | * @param handle a handle to a TurboJPEG compressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1058 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1059 | * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1060 | * to be encoded |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1061 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1062 | * @param width width (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1063 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1064 | * @param pitch bytes per line in the source image. Normally, this should be |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1065 | * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or |
| 1066 | * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image |
| 1067 | * is padded to the nearest 32-bit boundary, as is the case for Windows |
| 1068 | * bitmaps. You can also be clever and use this parameter to skip lines, etc. |
| 1069 | * Setting this parameter to 0 is the equivalent of setting it to |
| 1070 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1071 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1072 | * @param height height (in pixels) of the source image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1073 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1074 | * @param pixelFormat pixel format of the source image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1075 | * "Pixel formats".) |
| 1076 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1077 | * @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] | 1078 | * (or just a Y plane, if generating a grayscale image) that will receive the |
| 1079 | * encoded image. These planes can be contiguous or non-contiguous in memory. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1080 | * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based |
| 1081 | * on the image width, height, strides, and level of chrominance subsampling. |
| 1082 | * Refer to @ref YUVnotes "YUV Image Format Notes" for more details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1083 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1084 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1085 | * line in the corresponding plane of the output image. Setting the stride for |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1086 | * any plane to 0 is the same as setting it to the plane width (see |
| 1087 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
| 1088 | * the strides for all planes will be set to their respective plane widths. |
| 1089 | * You can adjust the strides in order to add an arbitrary amount of line |
| 1090 | * padding to each plane or to encode an RGB or grayscale image into a |
| 1091 | * subregion of a larger YUV planar image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1092 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1093 | * @param subsamp the level of chrominance subsampling to be used when |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1094 | * generating the YUV image (see @ref TJSAMP |
| 1095 | * "Chrominance subsampling options".) To generate images suitable for X |
| 1096 | * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420. This produces an |
| 1097 | * image compatible with the I420 (AKA "YUV420P") format. |
| 1098 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1099 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1100 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1101 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1102 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1103 | * and #tjGetErrorCode().) |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1104 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1105 | DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf, |
| 1106 | int width, int pitch, int height, |
| 1107 | int pixelFormat, unsigned char **dstPlanes, |
| 1108 | int *strides, int subsamp, int flags); |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1109 | |
| 1110 | |
| 1111 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1112 | * Create a TurboJPEG decompressor instance. |
| 1113 | * |
| 1114 | * @return a handle to the newly-created instance, or NULL if an error |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1115 | * occurred (see #tjGetErrorStr2().) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1116 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1117 | DLLEXPORT tjhandle tjInitDecompress(void); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1118 | |
| 1119 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1120 | /** |
| 1121 | * Retrieve information about a JPEG image without decompressing it. |
| 1122 | * |
| 1123 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1124 | * |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1125 | * @param jpegBuf pointer to a buffer containing a JPEG image |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1126 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1127 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1128 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1129 | * @param width pointer to an integer variable that will receive the width (in |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1130 | * pixels) of the JPEG image |
| 1131 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1132 | * @param height pointer to an integer variable that will receive the height |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1133 | * (in pixels) of the JPEG image |
| 1134 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1135 | * @param jpegSubsamp pointer to an integer variable that will receive the |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1136 | * level of chrominance subsampling used when the JPEG image was compressed |
| 1137 | * (see @ref TJSAMP "Chrominance subsampling options".) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1138 | * |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1139 | * @param jpegColorspace pointer to an integer variable that will receive one |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1140 | * of the JPEG colorspace constants, indicating the colorspace of the JPEG |
| 1141 | * image (see @ref TJCS "JPEG colorspaces".) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1142 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1143 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1144 | * and #tjGetErrorCode().) |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1145 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1146 | DLLEXPORT int tjDecompressHeader3(tjhandle handle, |
| 1147 | const unsigned char *jpegBuf, |
| 1148 | unsigned long jpegSize, int *width, |
| 1149 | int *height, int *jpegSubsamp, |
| 1150 | int *jpegColorspace); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1151 | |
| 1152 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1153 | /** |
| 1154 | * Returns a list of fractional scaling factors that the JPEG decompressor in |
| 1155 | * this implementation of TurboJPEG supports. |
| 1156 | * |
| 1157 | * @param numscalingfactors pointer to an integer variable that will receive |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1158 | * the number of elements in the list |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1159 | * |
| 1160 | * @return a pointer to a list of fractional scaling factors, or NULL if an |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1161 | * error is encountered (see #tjGetErrorStr2().) |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 1162 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1163 | DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors); |
DRC | b28fc57 | 2011-02-22 06:41:29 +0000 | [diff] [blame] | 1164 | |
| 1165 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1166 | /** |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1167 | * Decompress a JPEG image to an RGB, grayscale, or CMYK image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1168 | * |
| 1169 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1170 | * |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1171 | * @param jpegBuf pointer to a buffer containing the JPEG image to decompress |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1172 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1173 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1174 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1175 | * @param dstBuf pointer to an image buffer that will receive the decompressed |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1176 | * image. This buffer should normally be <tt>pitch * scaledHeight</tt> bytes |
| 1177 | * in size, where <tt>scaledHeight</tt> can be determined by calling |
| 1178 | * #TJSCALED() with the JPEG image height and one of the scaling factors |
| 1179 | * returned by #tjGetScalingFactors(). The <tt>dstBuf</tt> pointer may also be |
| 1180 | * used to decompress into a specific region of a larger buffer. |
| 1181 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1182 | * @param width desired width (in pixels) of the destination image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1183 | * different than the width of the JPEG image being decompressed, then |
| 1184 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1185 | * possible image that will fit within the desired width. If <tt>width</tt> is |
| 1186 | * set to 0, then only the height will be considered when determining the |
| 1187 | * scaled image size. |
| 1188 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1189 | * @param pitch bytes per line in the destination image. Normally, this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1190 | * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed image |
| 1191 | * is unpadded, else <tt>#TJPAD(scaledWidth * #tjPixelSize[pixelFormat])</tt> |
| 1192 | * if each line of the decompressed image is padded to the nearest 32-bit |
| 1193 | * boundary, as is the case for Windows bitmaps. (NOTE: <tt>scaledWidth</tt> |
| 1194 | * can be determined by calling #TJSCALED() with the JPEG image width and one |
| 1195 | * of the scaling factors returned by #tjGetScalingFactors().) You can also be |
| 1196 | * clever and use the pitch parameter to skip lines, etc. Setting this |
| 1197 | * parameter to 0 is the equivalent of setting it to |
| 1198 | * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>. |
| 1199 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1200 | * @param height desired height (in pixels) of the destination image. If this |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1201 | * is different than the height of the JPEG image being decompressed, then |
| 1202 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1203 | * possible image that will fit within the desired height. If <tt>height</tt> |
| 1204 | * is set to 0, then only the width will be considered when determining the |
| 1205 | * scaled image size. |
| 1206 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1207 | * @param pixelFormat pixel format of the destination image (see @ref |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1208 | * TJPF "Pixel formats".) |
| 1209 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1210 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1211 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1212 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1213 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1214 | * and #tjGetErrorCode().) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1215 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1216 | DLLEXPORT int tjDecompress2(tjhandle handle, const unsigned char *jpegBuf, |
| 1217 | unsigned long jpegSize, unsigned char *dstBuf, |
| 1218 | int width, int pitch, int height, int pixelFormat, |
| 1219 | int flags); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1220 | |
| 1221 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1222 | /** |
| 1223 | * Decompress a JPEG image to a YUV planar image. This function performs JPEG |
| 1224 | * decompression but leaves out the color conversion step, so a planar YUV |
DRC | 493be61 | 2014-08-10 20:12:17 +0000 | [diff] [blame] | 1225 | * image is generated instead of an RGB image. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1226 | * |
| 1227 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1228 | * |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1229 | * @param jpegBuf pointer to a buffer containing the JPEG image to decompress |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1230 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1231 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1232 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1233 | * @param dstBuf pointer to an image buffer that will receive the YUV image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1234 | * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based |
| 1235 | * on the image width, height, padding, and level of subsampling. The Y, |
| 1236 | * U (Cb), and V (Cr) image planes will be stored sequentially in the buffer |
| 1237 | * (refer to @ref YUVnotes "YUV Image Format Notes".) |
| 1238 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1239 | * @param width desired width (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1240 | * different than the width of the JPEG image being decompressed, then |
| 1241 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1242 | * possible image that will fit within the desired width. If <tt>width</tt> is |
| 1243 | * set to 0, then only the height will be considered when determining the |
| 1244 | * scaled image size. If the scaled width is not an even multiple of the MCU |
| 1245 | * block width (see #tjMCUWidth), then an intermediate buffer copy will be |
| 1246 | * performed within TurboJPEG. |
| 1247 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1248 | * @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] | 1249 | * padded to the nearest multiple of this number of bytes (must be a power of |
| 1250 | * 2.) To generate images suitable for X Video, <tt>pad</tt> should be set to |
| 1251 | * 4. |
| 1252 | * |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1253 | * @param height desired height (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1254 | * different than the height of the JPEG image being decompressed, then |
| 1255 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1256 | * possible image that will fit within the desired height. If <tt>height</tt> |
| 1257 | * is set to 0, then only the width will be considered when determining the |
| 1258 | * scaled image size. If the scaled height is not an even multiple of the MCU |
| 1259 | * block height (see #tjMCUHeight), then an intermediate buffer copy will be |
| 1260 | * performed within TurboJPEG. |
| 1261 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1262 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1263 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1264 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1265 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1266 | * and #tjGetErrorCode().) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1267 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1268 | DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf, |
| 1269 | unsigned long jpegSize, unsigned char *dstBuf, |
| 1270 | int width, int pad, int height, int flags); |
DRC | 8424160 | 2011-02-25 02:08:23 +0000 | [diff] [blame] | 1271 | |
| 1272 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1273 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1274 | * Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image |
| 1275 | * planes. This function performs JPEG decompression but leaves out the color |
| 1276 | * conversion step, so a planar YUV image is generated instead of an RGB image. |
| 1277 | * |
| 1278 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1279 | * |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1280 | * @param jpegBuf pointer to a buffer containing the JPEG image to decompress |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1281 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1282 | * @param jpegSize size of the JPEG image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1283 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1284 | * @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] | 1285 | * (or just a Y plane, if decompressing a grayscale image) that will receive |
| 1286 | * the YUV image. These planes can be contiguous or non-contiguous in memory. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1287 | * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based |
| 1288 | * on the scaled image width, scaled image height, strides, and level of |
| 1289 | * chrominance subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" |
| 1290 | * for more details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1291 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1292 | * @param width desired width (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1293 | * different than the width of the JPEG image being decompressed, then |
| 1294 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1295 | * possible image that will fit within the desired width. If <tt>width</tt> is |
| 1296 | * set to 0, then only the height will be considered when determining the |
| 1297 | * scaled image size. If the scaled width is not an even multiple of the MCU |
| 1298 | * block width (see #tjMCUWidth), then an intermediate buffer copy will be |
| 1299 | * performed within TurboJPEG. |
| 1300 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1301 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1302 | * line in the corresponding plane of the output image. Setting the stride for |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1303 | * any plane to 0 is the same as setting it to the scaled plane width (see |
| 1304 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
| 1305 | * the strides for all planes will be set to their respective scaled plane |
| 1306 | * widths. You can adjust the strides in order to add an arbitrary amount of |
| 1307 | * line padding to each plane or to decompress the JPEG image into a subregion |
| 1308 | * of a larger YUV planar image. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1309 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1310 | * @param height desired height (in pixels) of the YUV image. If this is |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1311 | * different than the height of the JPEG image being decompressed, then |
| 1312 | * TurboJPEG will use scaling in the JPEG decompressor to generate the largest |
| 1313 | * possible image that will fit within the desired height. If <tt>height</tt> |
| 1314 | * is set to 0, then only the width will be considered when determining the |
| 1315 | * scaled image size. If the scaled height is not an even multiple of the MCU |
| 1316 | * block height (see #tjMCUHeight), then an intermediate buffer copy will be |
| 1317 | * performed within TurboJPEG. |
| 1318 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1319 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1320 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1321 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1322 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1323 | * and #tjGetErrorCode().) |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1324 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1325 | DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle, |
| 1326 | const unsigned char *jpegBuf, |
| 1327 | unsigned long jpegSize, |
| 1328 | unsigned char **dstPlanes, int width, |
| 1329 | int *strides, int height, int flags); |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1330 | |
| 1331 | |
| 1332 | /** |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1333 | * Decode a YUV planar image into an RGB or grayscale image. This function |
| 1334 | * uses the accelerated color conversion routines in the underlying |
| 1335 | * 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] | 1336 | * process. |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1337 | * |
| 1338 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1339 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1340 | * @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] | 1341 | * decoded. The size of this buffer should match the value returned by |
| 1342 | * #tjBufSizeYUV2() for the given image width, height, padding, and level of |
| 1343 | * chrominance subsampling. The Y, U (Cb), and V (Cr) image planes should be |
| 1344 | * stored sequentially in the source buffer (refer to @ref YUVnotes |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1345 | * "YUV Image Format Notes".) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1346 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1347 | * @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] | 1348 | * plane of the YUV source image is padded to the nearest multiple of this |
| 1349 | * number of bytes (must be a power of 2.) |
| 1350 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1351 | * @param subsamp the level of chrominance subsampling used in the YUV source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1352 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 1353 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1354 | * @param dstBuf pointer to an image buffer that will receive the decoded |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1355 | * image. This buffer should normally be <tt>pitch * height</tt> bytes in |
| 1356 | * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a |
| 1357 | * specific region of a larger buffer. |
| 1358 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1359 | * @param width width (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1360 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1361 | * @param pitch bytes per line in the destination image. Normally, this should |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1362 | * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is |
| 1363 | * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line |
| 1364 | * of the destination image should be padded to the nearest 32-bit boundary, as |
| 1365 | * is the case for Windows bitmaps. You can also be clever and use the pitch |
| 1366 | * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent |
| 1367 | * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1368 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1369 | * @param height height (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1370 | * |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1371 | * @param pixelFormat pixel format of the destination image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1372 | * "Pixel formats".) |
| 1373 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1374 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1375 | * "flags" |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1376 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1377 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1378 | * and #tjGetErrorCode().) |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1379 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1380 | DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf, |
| 1381 | int pad, int subsamp, unsigned char *dstBuf, |
| 1382 | int width, int pitch, int height, int pixelFormat, |
| 1383 | int flags); |
DRC | 34dca05 | 2014-02-28 09:17:14 +0000 | [diff] [blame] | 1384 | |
| 1385 | |
| 1386 | /** |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1387 | * Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale |
| 1388 | * image. This function uses the accelerated color conversion routines in the |
| 1389 | * underlying codec but does not execute any of the other steps in the JPEG |
| 1390 | * decompression process. |
| 1391 | * |
| 1392 | * @param handle a handle to a TurboJPEG decompressor or transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1393 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1394 | * @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] | 1395 | * (or just a Y plane, if decoding a grayscale image) that contain a YUV image |
| 1396 | * to be decoded. These planes can be contiguous or non-contiguous in memory. |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1397 | * The size of each plane should match the value returned by #tjPlaneSizeYUV() |
| 1398 | * for the given image width, height, strides, and level of chrominance |
| 1399 | * subsampling. Refer to @ref YUVnotes "YUV Image Format Notes" for more |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1400 | * details. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1401 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1402 | * @param strides an array of integers, each specifying the number of bytes per |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1403 | * line in the corresponding plane of the YUV source image. Setting the stride |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1404 | * for any plane to 0 is the same as setting it to the plane width (see |
| 1405 | * @ref YUVnotes "YUV Image Format Notes".) If <tt>strides</tt> is NULL, then |
| 1406 | * the strides for all planes will be set to their respective plane widths. |
| 1407 | * You can adjust the strides in order to specify an arbitrary amount of line |
| 1408 | * 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] | 1409 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1410 | * @param subsamp the level of chrominance subsampling used in the YUV source |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1411 | * image (see @ref TJSAMP "Chrominance subsampling options".) |
| 1412 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1413 | * @param dstBuf pointer to an image buffer that will receive the decoded |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1414 | * image. This buffer should normally be <tt>pitch * height</tt> bytes in |
| 1415 | * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a |
| 1416 | * specific region of a larger buffer. |
| 1417 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1418 | * @param width width (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1419 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1420 | * @param pitch bytes per line in the destination image. Normally, this should |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1421 | * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is |
| 1422 | * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line |
| 1423 | * of the destination image should be padded to the nearest 32-bit boundary, as |
| 1424 | * is the case for Windows bitmaps. You can also be clever and use the pitch |
| 1425 | * parameter to skip lines, etc. Setting this parameter to 0 is the equivalent |
| 1426 | * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1427 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1428 | * @param height height (in pixels) of the source and destination images |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1429 | * |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1430 | * @param pixelFormat pixel format of the destination image (see @ref TJPF |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1431 | * "Pixel formats".) |
| 1432 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1433 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1434 | * "flags" |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1435 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1436 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1437 | * and #tjGetErrorCode().) |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1438 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1439 | DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle, |
| 1440 | const unsigned char **srcPlanes, |
| 1441 | const int *strides, int subsamp, |
| 1442 | unsigned char *dstBuf, int width, int pitch, |
| 1443 | int height, int pixelFormat, int flags); |
DRC | aecea38 | 2014-08-11 18:05:41 +0000 | [diff] [blame] | 1444 | |
| 1445 | |
| 1446 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1447 | * Create a new TurboJPEG transformer instance. |
| 1448 | * |
| 1449 | * @return a handle to the newly-created instance, or NULL if an error |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1450 | * occurred (see #tjGetErrorStr2().) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1451 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1452 | DLLEXPORT tjhandle tjInitTransform(void); |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 1453 | |
| 1454 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1455 | /** |
| 1456 | * Losslessly transform a JPEG image into another JPEG image. Lossless |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1457 | * transforms work by moving the raw DCT coefficients from one JPEG image |
| 1458 | * structure to another without altering the values of the coefficients. While |
| 1459 | * this is typically faster than decompressing the image, transforming it, and |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1460 | * re-compressing it, lossless transforms are not free. Each lossless |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 1461 | * transform requires reading and performing Huffman decoding on all of the |
| 1462 | * coefficients in the source image, regardless of the size of the destination |
| 1463 | * image. Thus, this function provides a means of generating multiple |
| 1464 | * transformed images from the same source or applying multiple |
| 1465 | * transformations simultaneously, in order to eliminate the need to read the |
| 1466 | * source coefficients multiple times. |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1467 | * |
| 1468 | * @param handle a handle to a TurboJPEG transformer instance |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1469 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1470 | * @param jpegBuf pointer to a buffer containing the JPEG source image to |
Alex Naidis | 6eb7d37 | 2016-10-16 23:10:08 +0200 | [diff] [blame] | 1471 | * transform |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1472 | * |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1473 | * @param jpegSize size of the JPEG source image (in bytes) |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1474 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1475 | * @param n the number of transformed JPEG images to generate |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1476 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1477 | * @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] | 1478 | * will receive a JPEG image that has been transformed using the parameters in |
| 1479 | * <tt>transforms[i]</tt>. TurboJPEG has the ability to reallocate the JPEG |
| 1480 | * buffer to accommodate the size of the JPEG image. Thus, you can choose to: |
| 1481 | * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and |
| 1482 | * let TurboJPEG grow the buffer as needed, |
| 1483 | * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the buffer |
| 1484 | * for you, or |
| 1485 | * -# pre-allocate the buffer to a "worst case" size determined by calling |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1486 | * #tjBufSize() with the transformed or cropped width and height. Under normal |
| 1487 | * circumstances, this should ensure that the buffer never has to be |
| 1488 | * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.) Note, |
| 1489 | * however, that there are some rare cases (such as transforming images with a |
| 1490 | * large amount of embedded EXIF or ICC profile data) in which the output image |
| 1491 | * will be larger than the worst-case size, and #TJFLAG_NOREALLOC cannot be |
| 1492 | * used in those cases. |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1493 | * . |
| 1494 | * If you choose option 1, <tt>dstSizes[i]</tt> should be set to the size of |
| 1495 | * your pre-allocated buffer. In any case, unless you have set |
| 1496 | * #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> upon return |
| 1497 | * from this function, as it may have changed. |
| 1498 | * |
DRC | 80803ae | 2011-12-15 13:12:59 +0000 | [diff] [blame] | 1499 | * @param dstSizes pointer to an array of n unsigned long variables that will |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1500 | * receive the actual sizes (in bytes) of each transformed JPEG image. If |
| 1501 | * <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then |
| 1502 | * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon return, |
| 1503 | * <tt>dstSizes[i]</tt> will contain the size of the JPEG image (in bytes.) |
| 1504 | * |
DRC | 01fdcc3 | 2013-04-26 08:41:25 +0000 | [diff] [blame] | 1505 | * @param transforms pointer to an array of n #tjtransform structures, each of |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1506 | * which specifies the transform parameters and/or cropping region for the |
| 1507 | * corresponding transformed output image. |
| 1508 | * |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1509 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1510 | * "flags" |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1511 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1512 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2() |
| 1513 | * and #tjGetErrorCode().) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1514 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1515 | DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf, |
| 1516 | unsigned long jpegSize, int n, |
| 1517 | unsigned char **dstBufs, unsigned long *dstSizes, |
| 1518 | tjtransform *transforms, int flags); |
DRC | 890f1e0 | 2011-02-26 22:02:37 +0000 | [diff] [blame] | 1519 | |
| 1520 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1521 | /** |
| 1522 | * Destroy a TurboJPEG compressor, decompressor, or transformer instance. |
| 1523 | * |
| 1524 | * @param handle a handle to a TurboJPEG compressor, decompressor or |
DRC | 9d77dad | 2014-08-12 15:06:30 +0000 | [diff] [blame] | 1525 | * transformer instance |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1526 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1527 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().) |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1528 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1529 | DLLEXPORT int tjDestroy(tjhandle handle); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1530 | |
| 1531 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1532 | /** |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1533 | * Allocate an image buffer for use with TurboJPEG. You should always use |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1534 | * this function to allocate the JPEG destination buffer(s) for the compression |
| 1535 | * and transform functions unless you are disabling automatic buffer |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1536 | * (re)allocation (by setting #TJFLAG_NOREALLOC.) |
| 1537 | * |
| 1538 | * @param bytes the number of bytes to allocate |
DRC | 1a45b81 | 2014-05-09 18:06:58 +0000 | [diff] [blame] | 1539 | * |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1540 | * @return a pointer to a newly-allocated buffer with the specified number of |
DRC | 40dd314 | 2014-08-17 12:23:49 +0000 | [diff] [blame] | 1541 | * bytes. |
DRC | d441107 | 2011-05-24 17:00:15 +0000 | [diff] [blame] | 1542 | * |
| 1543 | * @sa tjFree() |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1544 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1545 | DLLEXPORT unsigned char *tjAlloc(int bytes); |
| 1546 | |
| 1547 | |
| 1548 | /** |
| 1549 | * Load an uncompressed image from disk into memory. |
| 1550 | * |
| 1551 | * @param filename name of a file containing an uncompressed image in Windows |
| 1552 | * BMP or PBMPLUS (PPM/PGM) format |
| 1553 | * |
| 1554 | * @param width pointer to an integer variable that will receive the width (in |
| 1555 | * pixels) of the uncompressed image |
| 1556 | * |
| 1557 | * @param align row alignment of the image buffer to be returned (must be a |
| 1558 | * power of 2.) For instance, setting this parameter to 4 will cause all rows |
| 1559 | * in the image buffer to be padded to the nearest 32-bit boundary, and setting |
| 1560 | * this parameter to 1 will cause all rows in the image buffer to be unpadded. |
| 1561 | * |
| 1562 | * @param height pointer to an integer variable that will receive the height |
| 1563 | * (in pixels) of the uncompressed image |
| 1564 | * |
| 1565 | * @param pixelFormat pointer to an integer variable that specifies or will |
| 1566 | * receive the pixel format of the uncompressed image buffer. The behavior of |
| 1567 | * #tjLoadImage() will vary depending on the value of <tt>*pixelFormat</tt> |
| 1568 | * passed to the function: |
| 1569 | * - @ref TJPF_UNKNOWN : The uncompressed image buffer returned by the function |
| 1570 | * will use the most optimal pixel format for the file type, and |
| 1571 | * <tt>*pixelFormat</tt> will contain the ID of this pixel format upon |
| 1572 | * successful return from the function. |
| 1573 | * - @ref TJPF_GRAY : Only PGM files and 8-bit BMP files with a grayscale |
| 1574 | * colormap can be loaded. |
| 1575 | * - @ref TJPF_CMYK : The RGB or grayscale pixels stored in the file will be |
| 1576 | * converted using a quick & dirty algorithm that is suitable only for testing |
| 1577 | * purposes (proper conversion between CMYK and other formats requires a color |
| 1578 | * management system.) |
| 1579 | * - Other @ref TJPF "pixel formats" : The uncompressed image buffer will use |
| 1580 | * the specified pixel format, and pixel format conversion will be performed if |
| 1581 | * necessary. |
| 1582 | * |
| 1583 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
| 1584 | * "flags". |
| 1585 | * |
| 1586 | * @return a pointer to a newly-allocated buffer containing the uncompressed |
| 1587 | * image, converted to the chosen pixel format and with the chosen row |
| 1588 | * alignment, or NULL if an error occurred (see #tjGetErrorStr2().) This |
| 1589 | * buffer should be freed using #tjFree(). |
| 1590 | */ |
| 1591 | DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width, |
| 1592 | int align, int *height, int *pixelFormat, |
| 1593 | int flags); |
| 1594 | |
| 1595 | |
| 1596 | /** |
| 1597 | * Save an uncompressed image from memory to disk. |
| 1598 | * |
| 1599 | * @param filename name of a file to which to save the uncompressed image. |
| 1600 | * The image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, |
| 1601 | * depending on the file extension. |
| 1602 | * |
| 1603 | * @param buffer pointer to an image buffer containing RGB, grayscale, or |
| 1604 | * CMYK pixels to be saved |
| 1605 | * |
| 1606 | * @param width width (in pixels) of the uncompressed image |
| 1607 | * |
| 1608 | * @param pitch bytes per line in the image buffer. Setting this parameter to |
| 1609 | * 0 is the equivalent of setting it to |
| 1610 | * <tt>width * #tjPixelSize[pixelFormat]</tt>. |
| 1611 | * |
| 1612 | * @param height height (in pixels) of the uncompressed image |
| 1613 | * |
| 1614 | * @param pixelFormat pixel format of the image buffer (see @ref TJPF |
| 1615 | * "Pixel formats".) If this parameter is set to @ref TJPF_GRAY, then the |
| 1616 | * image will be stored in PGM or 8-bit (indexed color) BMP format. Otherwise, |
| 1617 | * the image will be stored in PPM or 24-bit BMP format. If this parameter |
| 1618 | * is set to @ref TJPF_CMYK, then the CMYK pixels will be converted to RGB |
| 1619 | * using a quick & dirty algorithm that is suitable only for testing (proper |
| 1620 | * conversion between CMYK and other formats requires a color management |
| 1621 | * system.) |
| 1622 | * |
| 1623 | * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP |
| 1624 | * "flags". |
| 1625 | * |
| 1626 | * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().) |
| 1627 | */ |
| 1628 | DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer, |
| 1629 | int width, int pitch, int height, int pixelFormat, |
| 1630 | int flags); |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1631 | |
| 1632 | |
| 1633 | /** |
| 1634 | * Free an image buffer previously allocated by TurboJPEG. You should always |
| 1635 | * use this function to free JPEG destination buffer(s) that were automatically |
Leon Scroggins III | bd7903e | 2018-02-28 14:05:04 -0500 | [diff] [blame] | 1636 | * (re)allocated by the compression and transform functions or that were |
| 1637 | * manually allocated using #tjAlloc(). |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1638 | * |
| 1639 | * @param buffer address of the buffer to free |
DRC | d441107 | 2011-05-24 17:00:15 +0000 | [diff] [blame] | 1640 | * |
| 1641 | * @sa tjAlloc() |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1642 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1643 | DLLEXPORT void tjFree(unsigned char *buffer); |
DRC | 6b76f75 | 2011-05-24 16:52:47 +0000 | [diff] [blame] | 1644 | |
| 1645 | |
| 1646 | /** |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1647 | * Returns a descriptive error message explaining why the last command failed. |
| 1648 | * |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1649 | * @param handle a handle to a TurboJPEG compressor, decompressor, or |
| 1650 | * transformer instance, or NULL if the error was generated by a global |
| 1651 | * function (but note that retrieving the error message for a global function |
| 1652 | * is not thread-safe.) |
| 1653 | * |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1654 | * @return a descriptive error message explaining why the last command failed. |
| 1655 | */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1656 | DLLEXPORT char *tjGetErrorStr2(tjhandle handle); |
| 1657 | |
| 1658 | |
| 1659 | /** |
| 1660 | * Returns a code indicating the severity of the last error. See |
| 1661 | * @ref TJERR "Error codes". |
| 1662 | * |
| 1663 | * @param handle a handle to a TurboJPEG compressor, decompressor or |
| 1664 | * transformer instance |
| 1665 | * |
| 1666 | * @return a code indicating the severity of the last error. See |
| 1667 | * @ref TJERR "Error codes". |
| 1668 | */ |
| 1669 | DLLEXPORT int tjGetErrorCode(tjhandle handle); |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1670 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1671 | |
DRC | 07e982d | 2013-10-31 07:11:39 +0000 | [diff] [blame] | 1672 | /* Deprecated functions and macros */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1673 | #define TJFLAG_FORCEMMX 8 |
| 1674 | #define TJFLAG_FORCESSE 16 |
| 1675 | #define TJFLAG_FORCESSE2 32 |
| 1676 | #define TJFLAG_FORCESSE3 128 |
DRC | 07e982d | 2013-10-31 07:11:39 +0000 | [diff] [blame] | 1677 | |
| 1678 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1679 | /* Backward compatibility functions and macros (nothing to see here) */ |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1680 | #define NUMSUBOPT TJ_NUMSAMP |
| 1681 | #define TJ_444 TJSAMP_444 |
| 1682 | #define TJ_422 TJSAMP_422 |
| 1683 | #define TJ_420 TJSAMP_420 |
| 1684 | #define TJ_411 TJSAMP_420 |
| 1685 | #define TJ_GRAYSCALE TJSAMP_GRAY |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1686 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1687 | #define TJ_BGR 1 |
| 1688 | #define TJ_BOTTOMUP TJFLAG_BOTTOMUP |
| 1689 | #define TJ_FORCEMMX TJFLAG_FORCEMMX |
| 1690 | #define TJ_FORCESSE TJFLAG_FORCESSE |
| 1691 | #define TJ_FORCESSE2 TJFLAG_FORCESSE2 |
| 1692 | #define TJ_ALPHAFIRST 64 |
| 1693 | #define TJ_FORCESSE3 TJFLAG_FORCESSE3 |
| 1694 | #define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE |
| 1695 | #define TJ_YUV 512 |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1696 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1697 | DLLEXPORT unsigned long TJBUFSIZE(int width, int height); |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 1698 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1699 | DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int jpegSubsamp); |
DRC | 9b49f0e | 2011-07-12 03:17:23 +0000 | [diff] [blame] | 1700 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1701 | DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp); |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1702 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1703 | DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width, |
| 1704 | int pitch, int height, int pixelSize, |
| 1705 | unsigned char *dstBuf, unsigned long *compressedSize, |
| 1706 | int jpegSubsamp, int jpegQual, int flags); |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1707 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1708 | DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width, |
| 1709 | int pitch, int height, int pixelSize, |
| 1710 | unsigned char *dstBuf, int subsamp, int flags); |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1711 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1712 | DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width, |
| 1713 | int pitch, int height, int pixelFormat, |
| 1714 | unsigned char *dstBuf, int subsamp, int flags); |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1715 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1716 | DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf, |
| 1717 | unsigned long jpegSize, int *width, |
| 1718 | int *height); |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1719 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1720 | DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf, |
| 1721 | unsigned long jpegSize, int *width, |
| 1722 | int *height, int *jpegSubsamp); |
DRC | cd7c3e6 | 2013-08-23 02:49:25 +0000 | [diff] [blame] | 1723 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1724 | DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf, |
| 1725 | unsigned long jpegSize, unsigned char *dstBuf, |
| 1726 | int width, int pitch, int height, int pixelSize, |
| 1727 | int flags); |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1728 | |
Leon Scroggins III | 3993b37 | 2018-07-16 10:43:45 -0400 | [diff] [blame] | 1729 | DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf, |
| 1730 | unsigned long jpegSize, unsigned char *dstBuf, |
| 1731 | int flags); |
| 1732 | |
| 1733 | DLLEXPORT char *tjGetErrorStr(void); |
DRC | f610d61 | 2013-04-26 10:33:29 +0000 | [diff] [blame] | 1734 | |
DRC | 9b28def | 2011-05-21 14:37:15 +0000 | [diff] [blame] | 1735 | |
| 1736 | /** |
| 1737 | * @} |
| 1738 | */ |
| 1739 | |
DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1740 | #ifdef __cplusplus |
| 1741 | } |
| 1742 | #endif |
DRC | 3a1bb35 | 2011-05-24 09:15:44 +0000 | [diff] [blame] | 1743 | |
| 1744 | #endif |