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