shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Copyright (C)2009-2015, 2017, 2020 D. R. Commander.  All Rights Reserved.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * Redistribution and use in source and binary forms, with or without
shun-iwasawa 82a8f5
 * modification, are permitted provided that the following conditions are met:
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * - Redistributions of source code must retain the above copyright notice,
shun-iwasawa 82a8f5
 *   this list of conditions and the following disclaimer.
shun-iwasawa 82a8f5
 * - Redistributions in binary form must reproduce the above copyright notice,
shun-iwasawa 82a8f5
 *   this list of conditions and the following disclaimer in the documentation
shun-iwasawa 82a8f5
 *   and/or other materials provided with the distribution.
shun-iwasawa 82a8f5
 * - Neither the name of the libjpeg-turbo Project nor the names of its
shun-iwasawa 82a8f5
 *   contributors may be used to endorse or promote products derived from this
shun-iwasawa 82a8f5
 *   software without specific prior written permission.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
shun-iwasawa 82a8f5
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
shun-iwasawa 82a8f5
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
shun-iwasawa 82a8f5
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
shun-iwasawa 82a8f5
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
shun-iwasawa 82a8f5
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
shun-iwasawa 82a8f5
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
shun-iwasawa 82a8f5
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
shun-iwasawa 82a8f5
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
shun-iwasawa 82a8f5
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
shun-iwasawa 82a8f5
 * POSSIBILITY OF SUCH DAMAGE.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifndef __TURBOJPEG_H__
shun-iwasawa 82a8f5
#define __TURBOJPEG_H__
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if defined(_WIN32) && defined(DLLDEFINE)
shun-iwasawa 82a8f5
#define DLLEXPORT  __declspec(dllexport)
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define DLLEXPORT
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
#define DLLCALL
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * @addtogroup TurboJPEG
shun-iwasawa 82a8f5
 * TurboJPEG API.  This API provides an interface for generating, decoding, and
shun-iwasawa 82a8f5
 * transforming planar YUV and JPEG images in memory.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @anchor YUVnotes
shun-iwasawa 82a8f5
 * YUV Image Format Notes
shun-iwasawa 82a8f5
 * ----------------------
shun-iwasawa 82a8f5
 * Technically, the JPEG format uses the YCbCr colorspace (which is technically
shun-iwasawa 82a8f5
 * not a colorspace but a color transform), but per the convention of the
shun-iwasawa 82a8f5
 * digital video community, the TurboJPEG API uses "YUV" to refer to an image
shun-iwasawa 82a8f5
 * format consisting of Y, Cb, and Cr image planes.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * Each plane is simply a 2D array of bytes, each byte representing the value
shun-iwasawa 82a8f5
 * of one of the components (Y, Cb, or Cr) at a particular location in the
shun-iwasawa 82a8f5
 * image.  The width and height of each plane are determined by the image
shun-iwasawa 82a8f5
 * width, height, and level of chrominance subsampling.   The luminance plane
shun-iwasawa 82a8f5
 * width is the image width padded to the nearest multiple of the horizontal
shun-iwasawa 82a8f5
 * subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of
shun-iwasawa 82a8f5
 * 4:1:1, 1 in the case of 4:4:4 or grayscale.)  Similarly, the luminance plane
shun-iwasawa 82a8f5
 * height is the image height padded to the nearest multiple of the vertical
shun-iwasawa 82a8f5
 * subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4
shun-iwasawa 82a8f5
 * or grayscale.)  This is irrespective of any additional padding that may be
shun-iwasawa 82a8f5
 * specified as an argument to the various YUV functions.  The chrominance
shun-iwasawa 82a8f5
 * plane width is equal to the luminance plane width divided by the horizontal
shun-iwasawa 82a8f5
 * subsampling factor, and the chrominance plane height is equal to the
shun-iwasawa 82a8f5
 * luminance plane height divided by the vertical subsampling factor.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is
shun-iwasawa 82a8f5
 * used, then the luminance plane would be 36 x 35 bytes, and each of the
shun-iwasawa 82a8f5
 * chrominance planes would be 18 x 35 bytes.  If you specify a line padding of
shun-iwasawa 82a8f5
 * 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, and
shun-iwasawa 82a8f5
 * each of the chrominance planes would be 20 x 35 bytes.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @{
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The number of chrominance subsampling options
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJ_NUMSAMP  6
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Chrominance subsampling options.
shun-iwasawa 82a8f5
 * When pixels are converted from RGB to YCbCr (see #TJCS_YCbCr) or from CMYK
shun-iwasawa 82a8f5
 * to YCCK (see #TJCS_YCCK) as part of the JPEG compression process, some of
shun-iwasawa 82a8f5
 * the Cb and Cr (chrominance) components can be discarded or averaged together
shun-iwasawa 82a8f5
 * to produce a smaller image with little perceptible loss of image clarity
shun-iwasawa 82a8f5
 * (the human eye is more sensitive to small changes in brightness than to
shun-iwasawa 82a8f5
 * small changes in color.)  This is called "chrominance subsampling".
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
enum TJSAMP {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * 4:4:4 chrominance subsampling (no chrominance subsampling).  The JPEG or
shun-iwasawa 82a8f5
   * YUV image will contain one chrominance component for every pixel in the
shun-iwasawa 82a8f5
   * source image.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJSAMP_444 = 0,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * 4:2:2 chrominance subsampling.  The JPEG or YUV image will contain one
shun-iwasawa 82a8f5
   * chrominance component for every 2x1 block of pixels in the source image.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJSAMP_422,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * 4:2:0 chrominance subsampling.  The JPEG or YUV image will contain one
shun-iwasawa 82a8f5
   * chrominance component for every 2x2 block of pixels in the source image.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJSAMP_420,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Grayscale.  The JPEG or YUV image will contain no chrominance components.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJSAMP_GRAY,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * 4:4:0 chrominance subsampling.  The JPEG or YUV image will contain one
shun-iwasawa 82a8f5
   * chrominance component for every 1x2 block of pixels in the source image.
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJSAMP_440,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * 4:1:1 chrominance subsampling.  The JPEG or YUV image will contain one
shun-iwasawa 82a8f5
   * chrominance component for every 4x1 block of pixels in the source image.
shun-iwasawa 82a8f5
   * JPEG images compressed with 4:1:1 subsampling will be almost exactly the
shun-iwasawa 82a8f5
   * same size as those compressed with 4:2:0 subsampling, and in the
shun-iwasawa 82a8f5
   * aggregate, both subsampling methods produce approximately the same
shun-iwasawa 82a8f5
   * perceptual quality.  However, 4:1:1 is better able to reproduce sharp
shun-iwasawa 82a8f5
   * horizontal features.
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJSAMP_411
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * MCU block width (in pixels) for a given level of chrominance subsampling.
shun-iwasawa 82a8f5
 * MCU block sizes:
shun-iwasawa 82a8f5
 * - 8x8 for no subsampling or grayscale
shun-iwasawa 82a8f5
 * - 16x8 for 4:2:2
shun-iwasawa 82a8f5
 * - 8x16 for 4:4:0
shun-iwasawa 82a8f5
 * - 16x16 for 4:2:0
shun-iwasawa 82a8f5
 * - 32x8 for 4:1:1
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjMCUWidth[TJ_NUMSAMP]  = { 8, 16, 16, 8, 8, 32 };
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * MCU block height (in pixels) for a given level of chrominance subsampling.
shun-iwasawa 82a8f5
 * MCU block sizes:
shun-iwasawa 82a8f5
 * - 8x8 for no subsampling or grayscale
shun-iwasawa 82a8f5
 * - 16x8 for 4:2:2
shun-iwasawa 82a8f5
 * - 8x16 for 4:4:0
shun-iwasawa 82a8f5
 * - 16x16 for 4:2:0
shun-iwasawa 82a8f5
 * - 32x8 for 4:1:1
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjMCUHeight[TJ_NUMSAMP] = { 8, 8, 16, 8, 16, 8 };
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The number of pixel formats
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJ_NUMPF  12
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Pixel formats
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
enum TJPF {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * RGB pixel format.  The red, green, and blue components in the image are
shun-iwasawa 82a8f5
   * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
shun-iwasawa 82a8f5
   * address within each pixel.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_RGB = 0,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * BGR pixel format.  The red, green, and blue components in the image are
shun-iwasawa 82a8f5
   * stored in 3-byte pixels in the order B, G, R from lowest to highest byte
shun-iwasawa 82a8f5
   * address within each pixel.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_BGR,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * RGBX pixel format.  The red, green, and blue components in the image are
shun-iwasawa 82a8f5
   * stored in 4-byte pixels in the order R, G, B from lowest to highest byte
shun-iwasawa 82a8f5
   * address within each pixel.  The X component is ignored when compressing
shun-iwasawa 82a8f5
   * and undefined when decompressing.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_RGBX,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * BGRX pixel format.  The red, green, and blue components in the image are
shun-iwasawa 82a8f5
   * stored in 4-byte pixels in the order B, G, R from lowest to highest byte
shun-iwasawa 82a8f5
   * address within each pixel.  The X component is ignored when compressing
shun-iwasawa 82a8f5
   * and undefined when decompressing.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_BGRX,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * XBGR pixel format.  The red, green, and blue components in the image are
shun-iwasawa 82a8f5
   * stored in 4-byte pixels in the order R, G, B from highest to lowest byte
shun-iwasawa 82a8f5
   * address within each pixel.  The X component is ignored when compressing
shun-iwasawa 82a8f5
   * and undefined when decompressing.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_XBGR,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * XRGB pixel format.  The red, green, and blue components in the image are
shun-iwasawa 82a8f5
   * stored in 4-byte pixels in the order B, G, R from highest to lowest byte
shun-iwasawa 82a8f5
   * address within each pixel.  The X component is ignored when compressing
shun-iwasawa 82a8f5
   * and undefined when decompressing.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_XRGB,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Grayscale pixel format.  Each 1-byte pixel represents a luminance
shun-iwasawa 82a8f5
   * (brightness) level from 0 to 255.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_GRAY,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * RGBA pixel format.  This is the same as @ref TJPF_RGBX, except that when
shun-iwasawa 82a8f5
   * decompressing, the X component is guaranteed to be 0xFF, which can be
shun-iwasawa 82a8f5
   * interpreted as an opaque alpha channel.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_RGBA,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * BGRA pixel format.  This is the same as @ref TJPF_BGRX, except that when
shun-iwasawa 82a8f5
   * decompressing, the X component is guaranteed to be 0xFF, which can be
shun-iwasawa 82a8f5
   * interpreted as an opaque alpha channel.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_BGRA,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * ABGR pixel format.  This is the same as @ref TJPF_XBGR, except that when
shun-iwasawa 82a8f5
   * decompressing, the X component is guaranteed to be 0xFF, which can be
shun-iwasawa 82a8f5
   * interpreted as an opaque alpha channel.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_ABGR,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * ARGB pixel format.  This is the same as @ref TJPF_XRGB, except that when
shun-iwasawa 82a8f5
   * decompressing, the X component is guaranteed to be 0xFF, which can be
shun-iwasawa 82a8f5
   * interpreted as an opaque alpha channel.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_ARGB,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * CMYK pixel format.  Unlike RGB, which is an additive color model used
shun-iwasawa 82a8f5
   * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive
shun-iwasawa 82a8f5
   * color model used primarily for printing.  In the CMYK color model, the
shun-iwasawa 82a8f5
   * value of each color component typically corresponds to an amount of cyan,
shun-iwasawa 82a8f5
   * magenta, yellow, or black ink that is applied to a white background.  In
shun-iwasawa 82a8f5
   * order to convert between CMYK and RGB, it is necessary to use a color
shun-iwasawa 82a8f5
   * management system (CMS.)  A CMS will attempt to map colors within the
shun-iwasawa 82a8f5
   * printer's gamut to perceptually similar colors in the display's gamut and
shun-iwasawa 82a8f5
   * vice versa, but the mapping is typically not 1:1 or reversible, nor can it
shun-iwasawa 82a8f5
   * be defined with a simple formula.  Thus, such a conversion is out of scope
shun-iwasawa 82a8f5
   * for a codec library.  However, the TurboJPEG API allows for compressing
shun-iwasawa 82a8f5
   * CMYK pixels into a YCCK JPEG image (see #TJCS_YCCK) and decompressing YCCK
shun-iwasawa 82a8f5
   * JPEG images into CMYK pixels.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_CMYK,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Unknown pixel format.  Currently this is only used by #tjLoadImage().
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJPF_UNKNOWN = -1
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Red offset (in bytes) for a given pixel format.  This specifies the number
shun-iwasawa 82a8f5
 * of bytes that the red component is offset from the start of the pixel.  For
shun-iwasawa 82a8f5
 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
shun-iwasawa 82a8f5
 * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>.  This
shun-iwasawa 82a8f5
 * will be -1 if the pixel format does not have a red component.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjRedOffset[TJ_NUMPF] = {
shun-iwasawa 82a8f5
  0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Green offset (in bytes) for a given pixel format.  This specifies the number
shun-iwasawa 82a8f5
 * of bytes that the green component is offset from the start of the pixel.
shun-iwasawa 82a8f5
 * For instance, if a pixel of format TJ_BGRX is stored in
shun-iwasawa 82a8f5
 * <tt>char pixel[]</tt>, then the green component will be
shun-iwasawa 82a8f5
 * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>.  This will be -1 if the pixel format
shun-iwasawa 82a8f5
 * does not have a green component.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjGreenOffset[TJ_NUMPF] = {
shun-iwasawa 82a8f5
  1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Blue offset (in bytes) for a given pixel format.  This specifies the number
shun-iwasawa 82a8f5
 * of bytes that the Blue component is offset from the start of the pixel.  For
shun-iwasawa 82a8f5
 * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>,
shun-iwasawa 82a8f5
 * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>.  This
shun-iwasawa 82a8f5
 * will be -1 if the pixel format does not have a blue component.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjBlueOffset[TJ_NUMPF] = {
shun-iwasawa 82a8f5
  2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Alpha offset (in bytes) for a given pixel format.  This specifies the number
shun-iwasawa 82a8f5
 * of bytes that the Alpha component is offset from the start of the pixel.
shun-iwasawa 82a8f5
 * For instance, if a pixel of format TJ_BGRA is stored in
shun-iwasawa 82a8f5
 * <tt>char pixel[]</tt>, then the alpha component will be
shun-iwasawa 82a8f5
 * <tt>pixel[tjAlphaOffset[TJ_BGRA]]</tt>.  This will be -1 if the pixel format
shun-iwasawa 82a8f5
 * does not have an alpha component.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjAlphaOffset[TJ_NUMPF] = {
shun-iwasawa 82a8f5
  -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Pixel size (in bytes) for a given pixel format
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
static const int tjPixelSize[TJ_NUMPF] = {
shun-iwasawa 82a8f5
  3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The number of JPEG colorspaces
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJ_NUMCS  5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * JPEG colorspaces
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
enum TJCS {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * RGB colorspace.  When compressing the JPEG image, the R, G, and B
shun-iwasawa 82a8f5
   * components in the source image are reordered into image planes, but no
shun-iwasawa 82a8f5
   * colorspace conversion or subsampling is performed.  RGB JPEG images can be
shun-iwasawa 82a8f5
   * decompressed to any of the extended RGB pixel formats or grayscale, but
shun-iwasawa 82a8f5
   * they cannot be decompressed to YUV images.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJCS_RGB = 0,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * YCbCr colorspace.  YCbCr is not an absolute colorspace but rather a
shun-iwasawa 82a8f5
   * mathematical transformation of RGB designed solely for storage and
shun-iwasawa 82a8f5
   * transmission.  YCbCr images must be converted to RGB before they can
shun-iwasawa 82a8f5
   * actually be displayed.  In the YCbCr colorspace, the Y (luminance)
shun-iwasawa 82a8f5
   * component represents the black & white portion of the original image, and
shun-iwasawa 82a8f5
   * the Cb and Cr (chrominance) components represent the color portion of the
shun-iwasawa 82a8f5
   * original image.  Originally, the analog equivalent of this transformation
shun-iwasawa 82a8f5
   * allowed the same signal to drive both black & white and color televisions,
shun-iwasawa 82a8f5
   * but JPEG images use YCbCr primarily because it allows the color data to be
shun-iwasawa 82a8f5
   * optionally subsampled for the purposes of reducing bandwidth or disk
shun-iwasawa 82a8f5
   * space.  YCbCr is the most common JPEG colorspace, and YCbCr JPEG images
shun-iwasawa 82a8f5
   * can be compressed from and decompressed to any of the extended RGB pixel
shun-iwasawa 82a8f5
   * formats or grayscale, or they can be decompressed to YUV planar images.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJCS_YCbCr,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Grayscale colorspace.  The JPEG image retains only the luminance data (Y
shun-iwasawa 82a8f5
   * component), and any color data from the source image is discarded.
shun-iwasawa 82a8f5
   * Grayscale JPEG images can be compressed from and decompressed to any of
shun-iwasawa 82a8f5
   * the extended RGB pixel formats or grayscale, or they can be decompressed
shun-iwasawa 82a8f5
   * to YUV planar images.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJCS_GRAY,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * CMYK colorspace.  When compressing the JPEG image, the C, M, Y, and K
shun-iwasawa 82a8f5
   * components in the source image are reordered into image planes, but no
shun-iwasawa 82a8f5
   * colorspace conversion or subsampling is performed.  CMYK JPEG images can
shun-iwasawa 82a8f5
   * only be decompressed to CMYK pixels.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJCS_CMYK,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * YCCK colorspace.  YCCK (AKA "YCbCrK") is not an absolute colorspace but
shun-iwasawa 82a8f5
   * rather a mathematical transformation of CMYK designed solely for storage
shun-iwasawa 82a8f5
   * and transmission.  It is to CMYK as YCbCr is to RGB.  CMYK pixels can be
shun-iwasawa 82a8f5
   * reversibly transformed into YCCK, and as with YCbCr, the chrominance
shun-iwasawa 82a8f5
   * components in the YCCK pixels can be subsampled without incurring major
shun-iwasawa 82a8f5
   * perceptual loss.  YCCK JPEG images can only be compressed from and
shun-iwasawa 82a8f5
   * decompressed to CMYK pixels.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJCS_YCCK
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The uncompressed source/destination image is stored in bottom-up (Windows,
shun-iwasawa 82a8f5
 * OpenGL) order, not top-down (X11) order.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_BOTTOMUP  2
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * When decompressing an image that was compressed using chrominance
shun-iwasawa 82a8f5
 * subsampling, use the fastest chrominance upsampling algorithm available in
shun-iwasawa 82a8f5
 * the underlying codec.  The default is to use smooth upsampling, which
shun-iwasawa 82a8f5
 * creates a smooth transition between neighboring chrominance components in
shun-iwasawa 82a8f5
 * order to reduce upsampling artifacts in the decompressed image.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_FASTUPSAMPLE  256
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Disable buffer (re)allocation.  If passed to one of the JPEG compression or
shun-iwasawa 82a8f5
 * transform functions, this flag will cause those functions to generate an
shun-iwasawa 82a8f5
 * error if the JPEG image buffer is invalid or too small rather than
shun-iwasawa 82a8f5
 * attempting to allocate or reallocate that buffer.  This reproduces the
shun-iwasawa 82a8f5
 * behavior of earlier versions of TurboJPEG.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_NOREALLOC  1024
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Use the fastest DCT/IDCT algorithm available in the underlying codec.  The
shun-iwasawa 82a8f5
 * default if this flag is not specified is implementation-specific.  For
shun-iwasawa 82a8f5
 * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast
shun-iwasawa 82a8f5
 * algorithm by default when compressing, because this has been shown to have
shun-iwasawa 82a8f5
 * only a very slight effect on accuracy, but it uses the accurate algorithm
shun-iwasawa 82a8f5
 * when decompressing, because this has been shown to have a larger effect.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_FASTDCT  2048
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Use the most accurate DCT/IDCT algorithm available in the underlying codec.
shun-iwasawa 82a8f5
 * The default if this flag is not specified is implementation-specific.  For
shun-iwasawa 82a8f5
 * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast
shun-iwasawa 82a8f5
 * algorithm by default when compressing, because this has been shown to have
shun-iwasawa 82a8f5
 * only a very slight effect on accuracy, but it uses the accurate algorithm
shun-iwasawa 82a8f5
 * when decompressing, because this has been shown to have a larger effect.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_ACCURATEDCT  4096
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Immediately discontinue the current compression/decompression/transform
shun-iwasawa 82a8f5
 * operation if the underlying codec throws a warning (non-fatal error).  The
shun-iwasawa 82a8f5
 * default behavior is to allow the operation to complete unless a fatal error
shun-iwasawa 82a8f5
 * is encountered.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_STOPONWARNING  8192
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Use progressive entropy coding in JPEG images generated by the compression
shun-iwasawa 82a8f5
 * and transform functions.  Progressive entropy coding will generally improve
shun-iwasawa 82a8f5
 * compression relative to baseline entropy coding (the default), but it will
shun-iwasawa 82a8f5
 * reduce compression and decompression performance considerably.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJFLAG_PROGRESSIVE  16384
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The number of error codes
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJ_NUMERR  2
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Error codes
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
enum TJERR {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The error was non-fatal and recoverable, but the image may still be
shun-iwasawa 82a8f5
   * corrupt.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJERR_WARNING = 0,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The error was fatal and non-recoverable.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJERR_FATAL
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The number of transform operations
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJ_NUMXOP  8
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Transform operations for #tjTransform()
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
enum TJXOP {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Do not transform the position of the image pixels
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_NONE = 0,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Flip (mirror) image horizontally.  This transform is imperfect if there
shun-iwasawa 82a8f5
   * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_HFLIP,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Flip (mirror) image vertically.  This transform is imperfect if there are
shun-iwasawa 82a8f5
   * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_VFLIP,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Transpose image (flip/mirror along upper left to lower right axis.)  This
shun-iwasawa 82a8f5
   * transform is always perfect.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_TRANSPOSE,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Transverse transpose image (flip/mirror along upper right to lower left
shun-iwasawa 82a8f5
   * axis.)  This transform is imperfect if there are any partial MCU blocks in
shun-iwasawa 82a8f5
   * the image (see #TJXOPT_PERFECT.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_TRANSVERSE,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Rotate image clockwise by 90 degrees.  This transform is imperfect if
shun-iwasawa 82a8f5
   * there are any partial MCU blocks on the bottom edge (see
shun-iwasawa 82a8f5
   * #TJXOPT_PERFECT.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_ROT90,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Rotate image 180 degrees.  This transform is imperfect if there are any
shun-iwasawa 82a8f5
   * partial MCU blocks in the image (see #TJXOPT_PERFECT.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_ROT180,
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Rotate image counter-clockwise by 90 degrees.  This transform is imperfect
shun-iwasawa 82a8f5
   * if there are any partial MCU blocks on the right edge (see
shun-iwasawa 82a8f5
   * #TJXOPT_PERFECT.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  TJXOP_ROT270
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will cause #tjTransform() to return an error if the transform is
shun-iwasawa 82a8f5
 * not perfect.  Lossless transforms operate on MCU blocks, whose size depends
shun-iwasawa 82a8f5
 * on the level of chrominance subsampling used (see #tjMCUWidth
shun-iwasawa 82a8f5
 * and #tjMCUHeight.)  If the image's width or height is not evenly divisible
shun-iwasawa 82a8f5
 * by the MCU block size, then there will be partial MCU blocks on the right
shun-iwasawa 82a8f5
 * and/or bottom edges.  It is not possible to move these partial MCU blocks to
shun-iwasawa 82a8f5
 * the top or left of the image, so any transform that would require that is
shun-iwasawa 82a8f5
 * "imperfect."  If this option is not specified, then any partial MCU blocks
shun-iwasawa 82a8f5
 * that cannot be transformed will be left in place, which will create
shun-iwasawa 82a8f5
 * odd-looking strips on the right or bottom edge of the image.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_PERFECT  1
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will cause #tjTransform() to discard any partial MCU blocks that
shun-iwasawa 82a8f5
 * cannot be transformed.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_TRIM  2
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will enable lossless cropping.  See #tjTransform() for more
shun-iwasawa 82a8f5
 * information.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_CROP  4
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will discard the color data in the input image and produce
shun-iwasawa 82a8f5
 * a grayscale output image.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_GRAY  8
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will prevent #tjTransform() from outputting a JPEG image for
shun-iwasawa 82a8f5
 * this particular transform (this can be used in conjunction with a custom
shun-iwasawa 82a8f5
 * filter to capture the transformed DCT coefficients without transcoding
shun-iwasawa 82a8f5
 * them.)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_NOOUTPUT  16
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will enable progressive entropy coding in the output image
shun-iwasawa 82a8f5
 * generated by this particular transform.  Progressive entropy coding will
shun-iwasawa 82a8f5
 * generally improve compression relative to baseline entropy coding (the
shun-iwasawa 82a8f5
 * default), but it will reduce compression and decompression performance
shun-iwasawa 82a8f5
 * considerably.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_PROGRESSIVE  32
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * This option will prevent #tjTransform() from copying any extra markers
shun-iwasawa 82a8f5
 * (including EXIF and ICC profile data) from the source image to the output
shun-iwasawa 82a8f5
 * image.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJXOPT_COPYNONE  64
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Scaling factor
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
typedef struct {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Numerator
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int num;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Denominator
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int denom;
shun-iwasawa 82a8f5
} tjscalingfactor;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Cropping region
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
typedef struct {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The left boundary of the cropping region.  This must be evenly divisible
shun-iwasawa 82a8f5
   * by the MCU block width (see #tjMCUWidth.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int x;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The upper boundary of the cropping region.  This must be evenly divisible
shun-iwasawa 82a8f5
   * by the MCU block height (see #tjMCUHeight.)
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int y;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The width of the cropping region. Setting this to 0 is the equivalent of
shun-iwasawa 82a8f5
   * setting it to the width of the source JPEG image - x.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int w;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The height of the cropping region. Setting this to 0 is the equivalent of
shun-iwasawa 82a8f5
   * setting it to the height of the source JPEG image - y.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int h;
shun-iwasawa 82a8f5
} tjregion;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Lossless transform
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
typedef struct tjtransform {
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Cropping region
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  tjregion r;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * One of the @ref TJXOP "transform operations"
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int op;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options"
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int options;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * Arbitrary data that can be accessed within the body of the callback
shun-iwasawa 82a8f5
   * function
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  void *data;
shun-iwasawa 82a8f5
  /**
shun-iwasawa 82a8f5
   * A callback function that can be used to modify the DCT coefficients
shun-iwasawa 82a8f5
   * after they are losslessly transformed but before they are transcoded to a
shun-iwasawa 82a8f5
   * new JPEG image.  This allows for custom filters or other transformations
shun-iwasawa 82a8f5
   * to be applied in the frequency domain.
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @param coeffs pointer to an array of transformed DCT coefficients.  (NOTE:
shun-iwasawa 82a8f5
   * this pointer is not guaranteed to be valid once the callback returns, so
shun-iwasawa 82a8f5
   * applications wishing to hand off the DCT coefficients to another function
shun-iwasawa 82a8f5
   * or library should make a copy of them within the body of the callback.)
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @param arrayRegion #tjregion structure containing the width and height of
shun-iwasawa 82a8f5
   * the array pointed to by <tt>coeffs</tt> as well as its offset relative to
shun-iwasawa 82a8f5
   * the component plane.  TurboJPEG implementations may choose to split each
shun-iwasawa 82a8f5
   * component plane into multiple DCT coefficient arrays and call the callback
shun-iwasawa 82a8f5
   * function once for each array.
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @param planeRegion #tjregion structure containing the width and height of
shun-iwasawa 82a8f5
   * the component plane to which <tt>coeffs</tt> belongs
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @param componentID ID number of the component plane to which
shun-iwasawa 82a8f5
   * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1,
shun-iwasawa 82a8f5
   * and 2 in typical JPEG images.)
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @param transformID ID number of the transformed image to which
shun-iwasawa 82a8f5
   * <tt>coeffs</tt> belongs.  This is the same as the index of the transform
shun-iwasawa 82a8f5
   * in the <tt>transforms</tt> array that was passed to #tjTransform().
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @param transform a pointer to a #tjtransform structure that specifies the
shun-iwasawa 82a8f5
   * parameters and/or cropping region for this transform
shun-iwasawa 82a8f5
   *
shun-iwasawa 82a8f5
   * @return 0 if the callback was successful, or -1 if an error occurred.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  int (*customFilter) (short *coeffs, tjregion arrayRegion,
shun-iwasawa 82a8f5
                       tjregion planeRegion, int componentIndex,
shun-iwasawa 82a8f5
                       int transformIndex, struct tjtransform *transform);
shun-iwasawa 82a8f5
} tjtransform;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * TurboJPEG instance handle
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
typedef void *tjhandle;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Pad the given width to the nearest 32-bit boundary
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJPAD(width)  (((width) + 3) & (~3))
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Compute the scaled value of <tt>dimension</tt> using the given scaling
shun-iwasawa 82a8f5
 * factor.  This macro performs the integer equivalent of <tt>ceil(dimension *</tt>
shun-iwasawa 82a8f5
 * scalingFactor).
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
#define TJSCALED(dimension, scalingFactor) \
shun-iwasawa 82a8f5
  ((dimension * scalingFactor.num + scalingFactor.denom - 1) / \
shun-iwasawa 82a8f5
   scalingFactor.denom)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifdef __cplusplus
shun-iwasawa 82a8f5
extern "C" {
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Create a TurboJPEG compressor instance.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a handle to the newly-created instance, or NULL if an error
shun-iwasawa 82a8f5
 * occurred (see #tjGetErrorStr2().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT tjhandle tjInitCompress(void);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Compress an RGB, grayscale, or CMYK image into a JPEG image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcBuf pointer to an image buffer containing RGB, grayscale, or
shun-iwasawa 82a8f5
 * CMYK pixels to be compressed
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the source image.  Normally, this should be
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
shun-iwasawa 82a8f5
 * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
shun-iwasawa 82a8f5
 * is padded to the nearest 32-bit boundary, as is the case for Windows
shun-iwasawa 82a8f5
 * bitmaps.  You can also be clever and use this parameter to skip lines, etc.
shun-iwasawa 82a8f5
 * Setting this parameter to 0 is the equivalent of setting it to
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the source image (see @ref TJPF
shun-iwasawa 82a8f5
 * "Pixel formats".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf address of a pointer to an image buffer that will receive the
shun-iwasawa 82a8f5
 * JPEG image.  TurboJPEG has the ability to reallocate the JPEG buffer
shun-iwasawa 82a8f5
 * to accommodate the size of the JPEG image.  Thus, you can choose to:
shun-iwasawa 82a8f5
 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
shun-iwasawa 82a8f5
 * let TurboJPEG grow the buffer as needed,
shun-iwasawa 82a8f5
 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
shun-iwasawa 82a8f5
 * for you, or
shun-iwasawa 82a8f5
 * -# pre-allocate the buffer to a "worst case" size determined by calling
shun-iwasawa 82a8f5
 * #tjBufSize().  This should ensure that the buffer never has to be
shun-iwasawa 82a8f5
 * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.)
shun-iwasawa 82a8f5
 * .
shun-iwasawa 82a8f5
 * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
shun-iwasawa 82a8f5
 * pre-allocated buffer.  In any case, unless you have set #TJFLAG_NOREALLOC,
shun-iwasawa 82a8f5
 * you should always check <tt>*jpegBuf</tt> upon return from this function, as
shun-iwasawa 82a8f5
 * it may have changed.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize pointer to an unsigned long variable that holds the size of
shun-iwasawa 82a8f5
 * the JPEG image buffer.  If <tt>*jpegBuf</tt> points to a pre-allocated
shun-iwasawa 82a8f5
 * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
shun-iwasawa 82a8f5
 * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
shun-iwasawa 82a8f5
 * bytes.)  If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
shun-iwasawa 82a8f5
 * reused from a previous call to one of the JPEG compression functions, then
shun-iwasawa 82a8f5
 * <tt>*jpegSize</tt> is ignored.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSubsamp the level of chrominance subsampling to be used when
shun-iwasawa 82a8f5
 * generating the JPEG image (see @ref TJSAMP
shun-iwasawa 82a8f5
 * "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
shun-iwasawa 82a8f5
 * 100 = best)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf,
shun-iwasawa 82a8f5
                          int width, int pitch, int height, int pixelFormat,
shun-iwasawa 82a8f5
                          unsigned char **jpegBuf, unsigned long *jpegSize,
shun-iwasawa 82a8f5
                          int jpegSubsamp, int jpegQual, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Compress a YUV planar image into a JPEG image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcBuf pointer to an image buffer containing a YUV planar image to be
shun-iwasawa 82a8f5
 * compressed.  The size of this buffer should match the value returned by
shun-iwasawa 82a8f5
 * #tjBufSizeYUV2() for the given image width, height, padding, and level of
shun-iwasawa 82a8f5
 * chrominance subsampling.  The Y, U (Cb), and V (Cr) image planes should be
shun-iwasawa 82a8f5
 * stored sequentially in the source buffer (refer to @ref YUVnotes
shun-iwasawa 82a8f5
 * "YUV Image Format Notes".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source image.  If the width is not an
shun-iwasawa 82a8f5
 * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
shun-iwasawa 82a8f5
 * buffer copy will be performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pad the line padding used in the source image.  For instance, if each
shun-iwasawa 82a8f5
 * line in each plane of the YUV image is padded to the nearest multiple of 4
shun-iwasawa 82a8f5
 * bytes, then <tt>pad</tt> should be set to 4.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source image.  If the height is not
shun-iwasawa 82a8f5
 * an even multiple of the MCU block height (see #tjMCUHeight), then an
shun-iwasawa 82a8f5
 * intermediate buffer copy will be performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp the level of chrominance subsampling used in the source
shun-iwasawa 82a8f5
 * image (see @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf address of a pointer to an image buffer that will receive the
shun-iwasawa 82a8f5
 * JPEG image.  TurboJPEG has the ability to reallocate the JPEG buffer to
shun-iwasawa 82a8f5
 * accommodate the size of the JPEG image.  Thus, you can choose to:
shun-iwasawa 82a8f5
 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
shun-iwasawa 82a8f5
 * let TurboJPEG grow the buffer as needed,
shun-iwasawa 82a8f5
 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
shun-iwasawa 82a8f5
 * for you, or
shun-iwasawa 82a8f5
 * -# pre-allocate the buffer to a "worst case" size determined by calling
shun-iwasawa 82a8f5
 * #tjBufSize().  This should ensure that the buffer never has to be
shun-iwasawa 82a8f5
 * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.)
shun-iwasawa 82a8f5
 * .
shun-iwasawa 82a8f5
 * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
shun-iwasawa 82a8f5
 * pre-allocated buffer.  In any case, unless you have set #TJFLAG_NOREALLOC,
shun-iwasawa 82a8f5
 * you should always check <tt>*jpegBuf</tt> upon return from this function, as
shun-iwasawa 82a8f5
 * it may have changed.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize pointer to an unsigned long variable that holds the size of
shun-iwasawa 82a8f5
 * the JPEG image buffer.  If <tt>*jpegBuf</tt> points to a pre-allocated
shun-iwasawa 82a8f5
 * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
shun-iwasawa 82a8f5
 * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
shun-iwasawa 82a8f5
 * bytes.)  If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
shun-iwasawa 82a8f5
 * reused from a previous call to one of the JPEG compression functions, then
shun-iwasawa 82a8f5
 * <tt>*jpegSize</tt> is ignored.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
shun-iwasawa 82a8f5
 * 100 = best)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf,
shun-iwasawa 82a8f5
                                int width, int pad, int height, int subsamp,
shun-iwasawa 82a8f5
                                unsigned char **jpegBuf,
shun-iwasawa 82a8f5
                                unsigned long *jpegSize, int jpegQual,
shun-iwasawa 82a8f5
                                int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
shun-iwasawa 82a8f5
 * (or just a Y plane, if compressing a grayscale image) that contain a YUV
shun-iwasawa 82a8f5
 * image to be compressed.  These planes can be contiguous or non-contiguous in
shun-iwasawa 82a8f5
 * memory.  The size of each plane should match the value returned by
shun-iwasawa 82a8f5
 * #tjPlaneSizeYUV() for the given image width, height, strides, and level of
shun-iwasawa 82a8f5
 * chrominance subsampling.  Refer to @ref YUVnotes "YUV Image Format Notes"
shun-iwasawa 82a8f5
 * for more details.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source image.  If the width is not an
shun-iwasawa 82a8f5
 * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate
shun-iwasawa 82a8f5
 * buffer copy will be performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param strides an array of integers, each specifying the number of bytes per
shun-iwasawa 82a8f5
 * line in the corresponding plane of the YUV source image.  Setting the stride
shun-iwasawa 82a8f5
 * for any plane to 0 is the same as setting it to the plane width (see
shun-iwasawa 82a8f5
 * @ref YUVnotes "YUV Image Format Notes".)  If <tt>strides</tt> is NULL, then
shun-iwasawa 82a8f5
 * the strides for all planes will be set to their respective plane widths.
shun-iwasawa 82a8f5
 * You can adjust the strides in order to specify an arbitrary amount of line
shun-iwasawa 82a8f5
 * padding in each plane or to create a JPEG image from a subregion of a larger
shun-iwasawa 82a8f5
 * YUV planar image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source image.  If the height is not
shun-iwasawa 82a8f5
 * an even multiple of the MCU block height (see #tjMCUHeight), then an
shun-iwasawa 82a8f5
 * intermediate buffer copy will be performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp the level of chrominance subsampling used in the source
shun-iwasawa 82a8f5
 * image (see @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf address of a pointer to an image buffer that will receive the
shun-iwasawa 82a8f5
 * JPEG image.  TurboJPEG has the ability to reallocate the JPEG buffer to
shun-iwasawa 82a8f5
 * accommodate the size of the JPEG image.  Thus, you can choose to:
shun-iwasawa 82a8f5
 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
shun-iwasawa 82a8f5
 * let TurboJPEG grow the buffer as needed,
shun-iwasawa 82a8f5
 * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the buffer
shun-iwasawa 82a8f5
 * for you, or
shun-iwasawa 82a8f5
 * -# pre-allocate the buffer to a "worst case" size determined by calling
shun-iwasawa 82a8f5
 * #tjBufSize().  This should ensure that the buffer never has to be
shun-iwasawa 82a8f5
 * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.)
shun-iwasawa 82a8f5
 * .
shun-iwasawa 82a8f5
 * If you choose option 1, <tt>*jpegSize</tt> should be set to the size of your
shun-iwasawa 82a8f5
 * pre-allocated buffer.  In any case, unless you have set #TJFLAG_NOREALLOC,
shun-iwasawa 82a8f5
 * you should always check <tt>*jpegBuf</tt> upon return from this function, as
shun-iwasawa 82a8f5
 * it may have changed.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize pointer to an unsigned long variable that holds the size of
shun-iwasawa 82a8f5
 * the JPEG image buffer.  If <tt>*jpegBuf</tt> points to a pre-allocated
shun-iwasawa 82a8f5
 * buffer, then <tt>*jpegSize</tt> should be set to the size of the buffer.
shun-iwasawa 82a8f5
 * Upon return, <tt>*jpegSize</tt> will contain the size of the JPEG image (in
shun-iwasawa 82a8f5
 * bytes.)  If <tt>*jpegBuf</tt> points to a JPEG image buffer that is being
shun-iwasawa 82a8f5
 * reused from a previous call to one of the JPEG compression functions, then
shun-iwasawa 82a8f5
 * <tt>*jpegSize</tt> is ignored.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegQual the image quality of the generated JPEG image (1 = worst,
shun-iwasawa 82a8f5
 * 100 = best)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle,
shun-iwasawa 82a8f5
                                      const unsigned char **srcPlanes,
shun-iwasawa 82a8f5
                                      int width, const int *strides,
shun-iwasawa 82a8f5
                                      int height, int subsamp,
shun-iwasawa 82a8f5
                                      unsigned char **jpegBuf,
shun-iwasawa 82a8f5
                                      unsigned long *jpegSize, int jpegQual,
shun-iwasawa 82a8f5
                                      int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The maximum size of the buffer (in bytes) required to hold a JPEG image with
shun-iwasawa 82a8f5
 * the given parameters.  The number of bytes returned by this function is
shun-iwasawa 82a8f5
 * larger than the size of the uncompressed source image.  The reason for this
shun-iwasawa 82a8f5
 * is that the JPEG format uses 16-bit coefficients, and it is thus possible
shun-iwasawa 82a8f5
 * for a very high-quality JPEG image with very high-frequency content to
shun-iwasawa 82a8f5
 * expand rather than compress when converted to the JPEG format.  Such images
shun-iwasawa 82a8f5
 * represent a very rare corner case, but since there is no way to predict the
shun-iwasawa 82a8f5
 * size of a JPEG image prior to compression, the corner case has to be
shun-iwasawa 82a8f5
 * handled.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSubsamp the level of chrominance subsampling to be used when
shun-iwasawa 82a8f5
 * generating the JPEG image (see @ref TJSAMP
shun-iwasawa 82a8f5
 * "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return the maximum size of the buffer (in bytes) required to hold the
shun-iwasawa 82a8f5
 * image, or -1 if the arguments are out of bounds.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The size of the buffer (in bytes) required to hold a YUV planar image with
shun-iwasawa 82a8f5
 * the given parameters.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pad the width of each line in each plane of the image is padded to
shun-iwasawa 82a8f5
 * the nearest multiple of this number of bytes (must be a power of 2.)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp level of chrominance subsampling in the image (see
shun-iwasawa 82a8f5
 * @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return the size of the buffer (in bytes) required to hold the image, or
shun-iwasawa 82a8f5
 * -1 if the arguments are out of bounds.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT unsigned long tjBufSizeYUV2(int width, int pad, int height,
shun-iwasawa 82a8f5
                                      int subsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The size of the buffer (in bytes) required to hold a YUV image plane with
shun-iwasawa 82a8f5
 * the given parameters.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the YUV image.  NOTE: this is the width of
shun-iwasawa 82a8f5
 * the whole image, not the plane width.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param stride bytes per line in the image plane.  Setting this to 0 is the
shun-iwasawa 82a8f5
 * equivalent of setting it to the plane width.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the YUV image.  NOTE: this is the height
shun-iwasawa 82a8f5
 * of the whole image, not the plane height.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp level of chrominance subsampling in the image (see
shun-iwasawa 82a8f5
 * @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return the size of the buffer (in bytes) required to hold the YUV image
shun-iwasawa 82a8f5
 * plane, or -1 if the arguments are out of bounds.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride,
shun-iwasawa 82a8f5
                                       int height, int subsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The plane width of a YUV image plane with the given parameters.  Refer to
shun-iwasawa 82a8f5
 * @ref YUVnotes "YUV Image Format Notes" for a description of plane width.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the YUV image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp level of chrominance subsampling in the image (see
shun-iwasawa 82a8f5
 * @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return the plane width of a YUV image plane with the given parameters, or
shun-iwasawa 82a8f5
 * -1 if the arguments are out of bounds.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * The plane height of a YUV image plane with the given parameters.  Refer to
shun-iwasawa 82a8f5
 * @ref YUVnotes "YUV Image Format Notes" for a description of plane height.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the YUV image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp level of chrominance subsampling in the image (see
shun-iwasawa 82a8f5
 * @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return the plane height of a YUV image plane with the given parameters, or
shun-iwasawa 82a8f5
 * -1 if the arguments are out of bounds.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Encode an RGB or grayscale image into a YUV planar image.  This function
shun-iwasawa 82a8f5
 * uses the accelerated color conversion routines in the underlying
shun-iwasawa 82a8f5
 * codec but does not execute any of the other steps in the JPEG compression
shun-iwasawa 82a8f5
 * process.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
shun-iwasawa 82a8f5
 * to be encoded
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the source image.  Normally, this should be
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
shun-iwasawa 82a8f5
 * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
shun-iwasawa 82a8f5
 * is padded to the nearest 32-bit boundary, as is the case for Windows
shun-iwasawa 82a8f5
 * bitmaps.  You can also be clever and use this parameter to skip lines, etc.
shun-iwasawa 82a8f5
 * Setting this parameter to 0 is the equivalent of setting it to
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the source image (see @ref TJPF
shun-iwasawa 82a8f5
 * "Pixel formats".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstBuf pointer to an image buffer that will receive the YUV image.
shun-iwasawa 82a8f5
 * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based
shun-iwasawa 82a8f5
 * on the image width, height, padding, and level of chrominance subsampling.
shun-iwasawa 82a8f5
 * The Y, U (Cb), and V (Cr) image planes will be stored sequentially in the
shun-iwasawa 82a8f5
 * buffer (refer to @ref YUVnotes "YUV Image Format Notes".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pad the width of each line in each plane of the YUV image will be
shun-iwasawa 82a8f5
 * padded to the nearest multiple of this number of bytes (must be a power of
shun-iwasawa 82a8f5
 * 2.)  To generate images suitable for X Video, <tt>pad</tt> should be set to
shun-iwasawa 82a8f5
 * 4.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp the level of chrominance subsampling to be used when
shun-iwasawa 82a8f5
 * generating the YUV image (see @ref TJSAMP
shun-iwasawa 82a8f5
 * "Chrominance subsampling options".)  To generate images suitable for X
shun-iwasawa 82a8f5
 * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420.  This produces an
shun-iwasawa 82a8f5
 * image compatible with the I420 (AKA "YUV420P") format.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf,
shun-iwasawa 82a8f5
                           int width, int pitch, int height, int pixelFormat,
shun-iwasawa 82a8f5
                           unsigned char *dstBuf, int pad, int subsamp,
shun-iwasawa 82a8f5
                           int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Encode an RGB or grayscale image into separate Y, U (Cb), and V (Cr) image
shun-iwasawa 82a8f5
 * planes.  This function uses the accelerated color conversion routines in the
shun-iwasawa 82a8f5
 * underlying codec but does not execute any of the other steps in the JPEG
shun-iwasawa 82a8f5
 * compression process.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels
shun-iwasawa 82a8f5
 * to be encoded
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the source image.  Normally, this should be
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, or
shun-iwasawa 82a8f5
 * <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of the image
shun-iwasawa 82a8f5
 * is padded to the nearest 32-bit boundary, as is the case for Windows
shun-iwasawa 82a8f5
 * bitmaps.  You can also be clever and use this parameter to skip lines, etc.
shun-iwasawa 82a8f5
 * Setting this parameter to 0 is the equivalent of setting it to
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the source image (see @ref TJPF
shun-iwasawa 82a8f5
 * "Pixel formats".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
shun-iwasawa 82a8f5
 * (or just a Y plane, if generating a grayscale image) that will receive the
shun-iwasawa 82a8f5
 * encoded image.  These planes can be contiguous or non-contiguous in memory.
shun-iwasawa 82a8f5
 * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
shun-iwasawa 82a8f5
 * on the image width, height, strides, and level of chrominance subsampling.
shun-iwasawa 82a8f5
 * Refer to @ref YUVnotes "YUV Image Format Notes" for more details.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param strides an array of integers, each specifying the number of bytes per
shun-iwasawa 82a8f5
 * line in the corresponding plane of the output image.  Setting the stride for
shun-iwasawa 82a8f5
 * any plane to 0 is the same as setting it to the plane width (see
shun-iwasawa 82a8f5
 * @ref YUVnotes "YUV Image Format Notes".)  If <tt>strides</tt> is NULL, then
shun-iwasawa 82a8f5
 * the strides for all planes will be set to their respective plane widths.
shun-iwasawa 82a8f5
 * You can adjust the strides in order to add an arbitrary amount of line
shun-iwasawa 82a8f5
 * padding to each plane or to encode an RGB or grayscale image into a
shun-iwasawa 82a8f5
 * subregion of a larger YUV planar image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp the level of chrominance subsampling to be used when
shun-iwasawa 82a8f5
 * generating the YUV image (see @ref TJSAMP
shun-iwasawa 82a8f5
 * "Chrominance subsampling options".)  To generate images suitable for X
shun-iwasawa 82a8f5
 * Video, <tt>subsamp</tt> should be set to @ref TJSAMP_420.  This produces an
shun-iwasawa 82a8f5
 * image compatible with the I420 (AKA "YUV420P") format.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf,
shun-iwasawa 82a8f5
                                int width, int pitch, int height,
shun-iwasawa 82a8f5
                                int pixelFormat, unsigned char **dstPlanes,
shun-iwasawa 82a8f5
                                int *strides, int subsamp, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Create a TurboJPEG decompressor instance.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a handle to the newly-created instance, or NULL if an error
shun-iwasawa 82a8f5
 * occurred (see #tjGetErrorStr2().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT tjhandle tjInitDecompress(void);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Retrieve information about a JPEG image without decompressing it.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG decompressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf pointer to a buffer containing a JPEG image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize size of the JPEG image (in bytes)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width pointer to an integer variable that will receive the width (in
shun-iwasawa 82a8f5
 * pixels) of the JPEG image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height pointer to an integer variable that will receive the height
shun-iwasawa 82a8f5
 * (in pixels) of the JPEG image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSubsamp pointer to an integer variable that will receive the
shun-iwasawa 82a8f5
 * level of chrominance subsampling used when the JPEG image was compressed
shun-iwasawa 82a8f5
 * (see @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegColorspace pointer to an integer variable that will receive one
shun-iwasawa 82a8f5
 * of the JPEG colorspace constants, indicating the colorspace of the JPEG
shun-iwasawa 82a8f5
 * image (see @ref TJCS "JPEG colorspaces".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompressHeader3(tjhandle handle,
shun-iwasawa 82a8f5
                                  const unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                                  unsigned long jpegSize, int *width,
shun-iwasawa 82a8f5
                                  int *height, int *jpegSubsamp,
shun-iwasawa 82a8f5
                                  int *jpegColorspace);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Returns a list of fractional scaling factors that the JPEG decompressor in
shun-iwasawa 82a8f5
 * this implementation of TurboJPEG supports.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param numscalingfactors pointer to an integer variable that will receive
shun-iwasawa 82a8f5
 * the number of elements in the list
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a pointer to a list of fractional scaling factors, or NULL if an
shun-iwasawa 82a8f5
 * error is encountered (see #tjGetErrorStr2().)
shun-iwasawa 82a8f5
*/
shun-iwasawa 82a8f5
DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Decompress a JPEG image to an RGB, grayscale, or CMYK image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG decompressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize size of the JPEG image (in bytes)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstBuf pointer to an image buffer that will receive the decompressed
shun-iwasawa 82a8f5
 * image.  This buffer should normally be <tt>pitch * scaledHeight</tt> bytes
shun-iwasawa 82a8f5
 * in size, where <tt>scaledHeight</tt> can be determined by calling
shun-iwasawa 82a8f5
 * #TJSCALED() with the JPEG image height and one of the scaling factors
shun-iwasawa 82a8f5
 * returned by #tjGetScalingFactors().  The <tt>dstBuf</tt> pointer may also be
shun-iwasawa 82a8f5
 * used to decompress into a specific region of a larger buffer.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width desired width (in pixels) of the destination image.  If this is
shun-iwasawa 82a8f5
 * different than the width of the JPEG image being decompressed, then
shun-iwasawa 82a8f5
 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
shun-iwasawa 82a8f5
 * possible image that will fit within the desired width.  If <tt>width</tt> is
shun-iwasawa 82a8f5
 * set to 0, then only the height will be considered when determining the
shun-iwasawa 82a8f5
 * scaled image size.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the destination image.  Normally, this is
shun-iwasawa 82a8f5
 * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed image
shun-iwasawa 82a8f5
 * is unpadded, else <tt>#TJPAD(scaledWidth * #tjPixelSize[pixelFormat])</tt>
shun-iwasawa 82a8f5
 * if each line of the decompressed image is padded to the nearest 32-bit
shun-iwasawa 82a8f5
 * boundary, as is the case for Windows bitmaps.  (NOTE: <tt>scaledWidth</tt>
shun-iwasawa 82a8f5
 * can be determined by calling #TJSCALED() with the JPEG image width and one
shun-iwasawa 82a8f5
 * of the scaling factors returned by #tjGetScalingFactors().)  You can also be
shun-iwasawa 82a8f5
 * clever and use the pitch parameter to skip lines, etc.  Setting this
shun-iwasawa 82a8f5
 * parameter to 0 is the equivalent of setting it to
shun-iwasawa 82a8f5
 * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height desired height (in pixels) of the destination image.  If this
shun-iwasawa 82a8f5
 * is different than the height of the JPEG image being decompressed, then
shun-iwasawa 82a8f5
 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
shun-iwasawa 82a8f5
 * possible image that will fit within the desired height.  If <tt>height</tt>
shun-iwasawa 82a8f5
 * is set to 0, then only the width will be considered when determining the
shun-iwasawa 82a8f5
 * scaled image size.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the destination image (see @ref
shun-iwasawa 82a8f5
 * TJPF "Pixel formats".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompress2(tjhandle handle, const unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                            unsigned long jpegSize, unsigned char *dstBuf,
shun-iwasawa 82a8f5
                            int width, int pitch, int height, int pixelFormat,
shun-iwasawa 82a8f5
                            int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Decompress a JPEG image to a YUV planar image.  This function performs JPEG
shun-iwasawa 82a8f5
 * decompression but leaves out the color conversion step, so a planar YUV
shun-iwasawa 82a8f5
 * image is generated instead of an RGB image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG decompressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize size of the JPEG image (in bytes)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstBuf pointer to an image buffer that will receive the YUV image.
shun-iwasawa 82a8f5
 * Use #tjBufSizeYUV2() to determine the appropriate size for this buffer based
shun-iwasawa 82a8f5
 * on the image width, height, padding, and level of subsampling.  The Y,
shun-iwasawa 82a8f5
 * U (Cb), and V (Cr) image planes will be stored sequentially in the buffer
shun-iwasawa 82a8f5
 * (refer to @ref YUVnotes "YUV Image Format Notes".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width desired width (in pixels) of the YUV image.  If this is
shun-iwasawa 82a8f5
 * different than the width of the JPEG image being decompressed, then
shun-iwasawa 82a8f5
 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
shun-iwasawa 82a8f5
 * possible image that will fit within the desired width.  If <tt>width</tt> is
shun-iwasawa 82a8f5
 * set to 0, then only the height will be considered when determining the
shun-iwasawa 82a8f5
 * scaled image size.  If the scaled width is not an even multiple of the MCU
shun-iwasawa 82a8f5
 * block width (see #tjMCUWidth), then an intermediate buffer copy will be
shun-iwasawa 82a8f5
 * performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pad the width of each line in each plane of the YUV image will be
shun-iwasawa 82a8f5
 * padded to the nearest multiple of this number of bytes (must be a power of
shun-iwasawa 82a8f5
 * 2.)  To generate images suitable for X Video, <tt>pad</tt> should be set to
shun-iwasawa 82a8f5
 * 4.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height desired height (in pixels) of the YUV image.  If this is
shun-iwasawa 82a8f5
 * different than the height of the JPEG image being decompressed, then
shun-iwasawa 82a8f5
 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
shun-iwasawa 82a8f5
 * possible image that will fit within the desired height.  If <tt>height</tt>
shun-iwasawa 82a8f5
 * is set to 0, then only the width will be considered when determining the
shun-iwasawa 82a8f5
 * scaled image size.  If the scaled height is not an even multiple of the MCU
shun-iwasawa 82a8f5
 * block height (see #tjMCUHeight), then an intermediate buffer copy will be
shun-iwasawa 82a8f5
 * performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                                 unsigned long jpegSize, unsigned char *dstBuf,
shun-iwasawa 82a8f5
                                 int width, int pad, int height, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image
shun-iwasawa 82a8f5
 * planes.  This function performs JPEG decompression but leaves out the color
shun-iwasawa 82a8f5
 * conversion step, so a planar YUV image is generated instead of an RGB image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG decompressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf pointer to a buffer containing the JPEG image to decompress
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize size of the JPEG image (in bytes)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
shun-iwasawa 82a8f5
 * (or just a Y plane, if decompressing a grayscale image) that will receive
shun-iwasawa 82a8f5
 * the YUV image.  These planes can be contiguous or non-contiguous in memory.
shun-iwasawa 82a8f5
 * Use #tjPlaneSizeYUV() to determine the appropriate size for each plane based
shun-iwasawa 82a8f5
 * on the scaled image width, scaled image height, strides, and level of
shun-iwasawa 82a8f5
 * chrominance subsampling.  Refer to @ref YUVnotes "YUV Image Format Notes"
shun-iwasawa 82a8f5
 * for more details.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width desired width (in pixels) of the YUV image.  If this is
shun-iwasawa 82a8f5
 * different than the width of the JPEG image being decompressed, then
shun-iwasawa 82a8f5
 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
shun-iwasawa 82a8f5
 * possible image that will fit within the desired width.  If <tt>width</tt> is
shun-iwasawa 82a8f5
 * set to 0, then only the height will be considered when determining the
shun-iwasawa 82a8f5
 * scaled image size.  If the scaled width is not an even multiple of the MCU
shun-iwasawa 82a8f5
 * block width (see #tjMCUWidth), then an intermediate buffer copy will be
shun-iwasawa 82a8f5
 * performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param strides an array of integers, each specifying the number of bytes per
shun-iwasawa 82a8f5
 * line in the corresponding plane of the output image.  Setting the stride for
shun-iwasawa 82a8f5
 * any plane to 0 is the same as setting it to the scaled plane width (see
shun-iwasawa 82a8f5
 * @ref YUVnotes "YUV Image Format Notes".)  If <tt>strides</tt> is NULL, then
shun-iwasawa 82a8f5
 * the strides for all planes will be set to their respective scaled plane
shun-iwasawa 82a8f5
 * widths.  You can adjust the strides in order to add an arbitrary amount of
shun-iwasawa 82a8f5
 * line padding to each plane or to decompress the JPEG image into a subregion
shun-iwasawa 82a8f5
 * of a larger YUV planar image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height desired height (in pixels) of the YUV image.  If this is
shun-iwasawa 82a8f5
 * different than the height of the JPEG image being decompressed, then
shun-iwasawa 82a8f5
 * TurboJPEG will use scaling in the JPEG decompressor to generate the largest
shun-iwasawa 82a8f5
 * possible image that will fit within the desired height.  If <tt>height</tt>
shun-iwasawa 82a8f5
 * is set to 0, then only the width will be considered when determining the
shun-iwasawa 82a8f5
 * scaled image size.  If the scaled height is not an even multiple of the MCU
shun-iwasawa 82a8f5
 * block height (see #tjMCUHeight), then an intermediate buffer copy will be
shun-iwasawa 82a8f5
 * performed within TurboJPEG.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle,
shun-iwasawa 82a8f5
                                      const unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                                      unsigned long jpegSize,
shun-iwasawa 82a8f5
                                      unsigned char **dstPlanes, int width,
shun-iwasawa 82a8f5
                                      int *strides, int height, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Decode a YUV planar image into an RGB or grayscale image.  This function
shun-iwasawa 82a8f5
 * uses the accelerated color conversion routines in the underlying
shun-iwasawa 82a8f5
 * codec but does not execute any of the other steps in the JPEG decompression
shun-iwasawa 82a8f5
 * process.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG decompressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcBuf pointer to an image buffer containing a YUV planar image to be
shun-iwasawa 82a8f5
 * decoded.  The size of this buffer should match the value returned by
shun-iwasawa 82a8f5
 * #tjBufSizeYUV2() for the given image width, height, padding, and level of
shun-iwasawa 82a8f5
 * chrominance subsampling.  The Y, U (Cb), and V (Cr) image planes should be
shun-iwasawa 82a8f5
 * stored sequentially in the source buffer (refer to @ref YUVnotes
shun-iwasawa 82a8f5
 * "YUV Image Format Notes".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pad Use this parameter to specify that the width of each line in each
shun-iwasawa 82a8f5
 * plane of the YUV source image is padded to the nearest multiple of this
shun-iwasawa 82a8f5
 * number of bytes (must be a power of 2.)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp the level of chrominance subsampling used in the YUV source
shun-iwasawa 82a8f5
 * image (see @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstBuf pointer to an image buffer that will receive the decoded
shun-iwasawa 82a8f5
 * image.  This buffer should normally be <tt>pitch * height</tt> bytes in
shun-iwasawa 82a8f5
 * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a
shun-iwasawa 82a8f5
 * specific region of a larger buffer.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source and destination images
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the destination image.  Normally, this should
shun-iwasawa 82a8f5
 * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is
shun-iwasawa 82a8f5
 * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line
shun-iwasawa 82a8f5
 * of the destination image should be padded to the nearest 32-bit boundary, as
shun-iwasawa 82a8f5
 * is the case for Windows bitmaps.  You can also be clever and use the pitch
shun-iwasawa 82a8f5
 * parameter to skip lines, etc.  Setting this parameter to 0 is the equivalent
shun-iwasawa 82a8f5
 * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source and destination images
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the destination image (see @ref TJPF
shun-iwasawa 82a8f5
 * "Pixel formats".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
shun-iwasawa 82a8f5
                          int pad, int subsamp, unsigned char *dstBuf,
shun-iwasawa 82a8f5
                          int width, int pitch, int height, int pixelFormat,
shun-iwasawa 82a8f5
                          int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Decode a set of Y, U (Cb), and V (Cr) image planes into an RGB or grayscale
shun-iwasawa 82a8f5
 * image.  This function uses the accelerated color conversion routines in the
shun-iwasawa 82a8f5
 * underlying codec but does not execute any of the other steps in the JPEG
shun-iwasawa 82a8f5
 * decompression process.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG decompressor or transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes
shun-iwasawa 82a8f5
 * (or just a Y plane, if decoding a grayscale image) that contain a YUV image
shun-iwasawa 82a8f5
 * to be decoded.  These planes can be contiguous or non-contiguous in memory.
shun-iwasawa 82a8f5
 * The size of each plane should match the value returned by #tjPlaneSizeYUV()
shun-iwasawa 82a8f5
 * for the given image width, height, strides, and level of chrominance
shun-iwasawa 82a8f5
 * subsampling.  Refer to @ref YUVnotes "YUV Image Format Notes" for more
shun-iwasawa 82a8f5
 * details.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param strides an array of integers, each specifying the number of bytes per
shun-iwasawa 82a8f5
 * line in the corresponding plane of the YUV source image.  Setting the stride
shun-iwasawa 82a8f5
 * for any plane to 0 is the same as setting it to the plane width (see
shun-iwasawa 82a8f5
 * @ref YUVnotes "YUV Image Format Notes".)  If <tt>strides</tt> is NULL, then
shun-iwasawa 82a8f5
 * the strides for all planes will be set to their respective plane widths.
shun-iwasawa 82a8f5
 * You can adjust the strides in order to specify an arbitrary amount of line
shun-iwasawa 82a8f5
 * padding in each plane or to decode a subregion of a larger YUV planar image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param subsamp the level of chrominance subsampling used in the YUV source
shun-iwasawa 82a8f5
 * image (see @ref TJSAMP "Chrominance subsampling options".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstBuf pointer to an image buffer that will receive the decoded
shun-iwasawa 82a8f5
 * image.  This buffer should normally be <tt>pitch * height</tt> bytes in
shun-iwasawa 82a8f5
 * size, but the <tt>dstBuf</tt> pointer can also be used to decode into a
shun-iwasawa 82a8f5
 * specific region of a larger buffer.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the source and destination images
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the destination image.  Normally, this should
shun-iwasawa 82a8f5
 * be <tt>width * #tjPixelSize[pixelFormat]</tt> if the destination image is
shun-iwasawa 82a8f5
 * unpadded, or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line
shun-iwasawa 82a8f5
 * of the destination image should be padded to the nearest 32-bit boundary, as
shun-iwasawa 82a8f5
 * is the case for Windows bitmaps.  You can also be clever and use the pitch
shun-iwasawa 82a8f5
 * parameter to skip lines, etc.  Setting this parameter to 0 is the equivalent
shun-iwasawa 82a8f5
 * of setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the source and destination images
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the destination image (see @ref TJPF
shun-iwasawa 82a8f5
 * "Pixel formats".)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle,
shun-iwasawa 82a8f5
                                const unsigned char **srcPlanes,
shun-iwasawa 82a8f5
                                const int *strides, int subsamp,
shun-iwasawa 82a8f5
                                unsigned char *dstBuf, int width, int pitch,
shun-iwasawa 82a8f5
                                int height, int pixelFormat, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Create a new TurboJPEG transformer instance.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a handle to the newly-created instance, or NULL if an error
shun-iwasawa 82a8f5
 * occurred (see #tjGetErrorStr2().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT tjhandle tjInitTransform(void);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Losslessly transform a JPEG image into another JPEG image.  Lossless
shun-iwasawa 82a8f5
 * transforms work by moving the raw DCT coefficients from one JPEG image
shun-iwasawa 82a8f5
 * structure to another without altering the values of the coefficients.  While
shun-iwasawa 82a8f5
 * this is typically faster than decompressing the image, transforming it, and
shun-iwasawa 82a8f5
 * re-compressing it, lossless transforms are not free.  Each lossless
shun-iwasawa 82a8f5
 * transform requires reading and performing Huffman decoding on all of the
shun-iwasawa 82a8f5
 * coefficients in the source image, regardless of the size of the destination
shun-iwasawa 82a8f5
 * image.  Thus, this function provides a means of generating multiple
shun-iwasawa 82a8f5
 * transformed images from the same source or  applying multiple
shun-iwasawa 82a8f5
 * transformations simultaneously, in order to eliminate the need to read the
shun-iwasawa 82a8f5
 * source coefficients multiple times.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegBuf pointer to a buffer containing the JPEG source image to
shun-iwasawa 82a8f5
 * transform
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param jpegSize size of the JPEG source image (in bytes)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param n the number of transformed JPEG images to generate
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstBufs pointer to an array of n image buffers.  <tt>dstBufs[i]</tt>
shun-iwasawa 82a8f5
 * will receive a JPEG image that has been transformed using the parameters in
shun-iwasawa 82a8f5
 * <tt>transforms[i]</tt>.  TurboJPEG has the ability to reallocate the JPEG
shun-iwasawa 82a8f5
 * buffer to accommodate the size of the JPEG image.  Thus, you can choose to:
shun-iwasawa 82a8f5
 * -# pre-allocate the JPEG buffer with an arbitrary size using #tjAlloc() and
shun-iwasawa 82a8f5
 * let TurboJPEG grow the buffer as needed,
shun-iwasawa 82a8f5
 * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the buffer
shun-iwasawa 82a8f5
 * for you, or
shun-iwasawa 82a8f5
 * -# pre-allocate the buffer to a "worst case" size determined by calling
shun-iwasawa 82a8f5
 * #tjBufSize() with the transformed or cropped width and height.  Under normal
shun-iwasawa 82a8f5
 * circumstances, this should ensure that the buffer never has to be
shun-iwasawa 82a8f5
 * re-allocated (setting #TJFLAG_NOREALLOC guarantees that it won't be.)  Note,
shun-iwasawa 82a8f5
 * however, that there are some rare cases (such as transforming images with a
shun-iwasawa 82a8f5
 * large amount of embedded EXIF or ICC profile data) in which the output image
shun-iwasawa 82a8f5
 * will be larger than the worst-case size, and #TJFLAG_NOREALLOC cannot be
shun-iwasawa 82a8f5
 * used in those cases.
shun-iwasawa 82a8f5
 * .
shun-iwasawa 82a8f5
 * If you choose option 1, <tt>dstSizes[i]</tt> should be set to the size of
shun-iwasawa 82a8f5
 * your pre-allocated buffer.  In any case, unless you have set
shun-iwasawa 82a8f5
 * #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> upon return
shun-iwasawa 82a8f5
 * from this function, as it may have changed.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param dstSizes pointer to an array of n unsigned long variables that will
shun-iwasawa 82a8f5
 * receive the actual sizes (in bytes) of each transformed JPEG image.  If
shun-iwasawa 82a8f5
 * <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then
shun-iwasawa 82a8f5
 * <tt>dstSizes[i]</tt> should be set to the size of the buffer.  Upon return,
shun-iwasawa 82a8f5
 * <tt>dstSizes[i]</tt> will contain the size of the JPEG image (in bytes.)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param transforms pointer to an array of n #tjtransform structures, each of
shun-iwasawa 82a8f5
 * which specifies the transform parameters and/or cropping region for the
shun-iwasawa 82a8f5
 * corresponding transformed output image.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_ACCURATEDCT
shun-iwasawa 82a8f5
 * "flags"
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
shun-iwasawa 82a8f5
 * and #tjGetErrorCode().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                          unsigned long jpegSize, int n,
shun-iwasawa 82a8f5
                          unsigned char **dstBufs, unsigned long *dstSizes,
shun-iwasawa 82a8f5
                          tjtransform *transforms, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Destroy a TurboJPEG compressor, decompressor, or transformer instance.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor, decompressor or
shun-iwasawa 82a8f5
 * transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjDestroy(tjhandle handle);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Allocate an image buffer for use with TurboJPEG.  You should always use
shun-iwasawa 82a8f5
 * this function to allocate the JPEG destination buffer(s) for the compression
shun-iwasawa 82a8f5
 * and transform functions unless you are disabling automatic buffer
shun-iwasawa 82a8f5
 * (re)allocation (by setting #TJFLAG_NOREALLOC.)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param bytes the number of bytes to allocate
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a pointer to a newly-allocated buffer with the specified number of
shun-iwasawa 82a8f5
 * bytes.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @sa tjFree()
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT unsigned char *tjAlloc(int bytes);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Load an uncompressed image from disk into memory.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param filename name of a file containing an uncompressed image in Windows
shun-iwasawa 82a8f5
 * BMP or PBMPLUS (PPM/PGM) format
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width pointer to an integer variable that will receive the width (in
shun-iwasawa 82a8f5
 * pixels) of the uncompressed image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param align row alignment of the image buffer to be returned (must be a
shun-iwasawa 82a8f5
 * power of 2.)  For instance, setting this parameter to 4 will cause all rows
shun-iwasawa 82a8f5
 * in the image buffer to be padded to the nearest 32-bit boundary, and setting
shun-iwasawa 82a8f5
 * this parameter to 1 will cause all rows in the image buffer to be unpadded.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height pointer to an integer variable that will receive the height
shun-iwasawa 82a8f5
 * (in pixels) of the uncompressed image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pointer to an integer variable that specifies or will
shun-iwasawa 82a8f5
 * receive the pixel format of the uncompressed image buffer.  The behavior of
shun-iwasawa 82a8f5
 * #tjLoadImage() will vary depending on the value of <tt>*pixelFormat</tt>
shun-iwasawa 82a8f5
 * passed to the function:
shun-iwasawa 82a8f5
 * - @ref TJPF_UNKNOWN : The uncompressed image buffer returned by the function
shun-iwasawa 82a8f5
 * will use the most optimal pixel format for the file type, and
shun-iwasawa 82a8f5
 * <tt>*pixelFormat</tt> will contain the ID of this pixel format upon
shun-iwasawa 82a8f5
 * successful return from the function.
shun-iwasawa 82a8f5
 * - @ref TJPF_GRAY : Only PGM files and 8-bit BMP files with a grayscale
shun-iwasawa 82a8f5
 * colormap can be loaded.
shun-iwasawa 82a8f5
 * - @ref TJPF_CMYK : The RGB or grayscale pixels stored in the file will be
shun-iwasawa 82a8f5
 * converted using a quick & dirty algorithm that is suitable only for testing
shun-iwasawa 82a8f5
 * purposes (proper conversion between CMYK and other formats requires a color
shun-iwasawa 82a8f5
 * management system.)
shun-iwasawa 82a8f5
 * - Other @ref TJPF "pixel formats" : The uncompressed image buffer will use
shun-iwasawa 82a8f5
 * the specified pixel format, and pixel format conversion will be performed if
shun-iwasawa 82a8f5
 * necessary.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
shun-iwasawa 82a8f5
 * "flags".
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a pointer to a newly-allocated buffer containing the uncompressed
shun-iwasawa 82a8f5
 * image, converted to the chosen pixel format and with the chosen row
shun-iwasawa 82a8f5
 * alignment, or NULL if an error occurred (see #tjGetErrorStr2().)  This
shun-iwasawa 82a8f5
 * buffer should be freed using #tjFree().
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
shun-iwasawa 82a8f5
                                     int align, int *height, int *pixelFormat,
shun-iwasawa 82a8f5
                                     int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Save an uncompressed image from memory to disk.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param filename name of a file to which to save the uncompressed image.
shun-iwasawa 82a8f5
 * The image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format,
shun-iwasawa 82a8f5
 * depending on the file extension.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param buffer pointer to an image buffer containing RGB, grayscale, or
shun-iwasawa 82a8f5
 * CMYK pixels to be saved
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param width width (in pixels) of the uncompressed image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pitch bytes per line in the image buffer.  Setting this parameter to
shun-iwasawa 82a8f5
 * 0 is the equivalent of setting it to
shun-iwasawa 82a8f5
 * <tt>width * #tjPixelSize[pixelFormat]</tt>.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param height height (in pixels) of the uncompressed image
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param pixelFormat pixel format of the image buffer (see @ref TJPF
shun-iwasawa 82a8f5
 * "Pixel formats".)  If this parameter is set to @ref TJPF_GRAY, then the
shun-iwasawa 82a8f5
 * image will be stored in PGM or 8-bit (indexed color) BMP format.  Otherwise,
shun-iwasawa 82a8f5
 * the image will be stored in PPM or 24-bit BMP format.  If this parameter
shun-iwasawa 82a8f5
 * is set to @ref TJPF_CMYK, then the CMYK pixels will be converted to RGB
shun-iwasawa 82a8f5
 * using a quick & dirty algorithm that is suitable only for testing (proper
shun-iwasawa 82a8f5
 * conversion between CMYK and other formats requires a color management
shun-iwasawa 82a8f5
 * system.)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
shun-iwasawa 82a8f5
 * "flags".
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
shun-iwasawa 82a8f5
                          int width, int pitch, int height, int pixelFormat,
shun-iwasawa 82a8f5
                          int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Free an image buffer previously allocated by TurboJPEG.  You should always
shun-iwasawa 82a8f5
 * use this function to free JPEG destination buffer(s) that were automatically
shun-iwasawa 82a8f5
 * (re)allocated by the compression and transform functions or that were
shun-iwasawa 82a8f5
 * manually allocated using #tjAlloc().
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param buffer address of the buffer to free.  If the address is NULL, then
shun-iwasawa 82a8f5
 * this function has no effect.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @sa tjAlloc()
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT void tjFree(unsigned char *buffer);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Returns a descriptive error message explaining why the last command failed.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor, decompressor, or
shun-iwasawa 82a8f5
 * transformer instance, or NULL if the error was generated by a global
shun-iwasawa 82a8f5
 * function (but note that retrieving the error message for a global function
shun-iwasawa 82a8f5
 * is thread-safe only on platforms that support thread-local storage.)
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a descriptive error message explaining why the last command failed.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT char *tjGetErrorStr2(tjhandle handle);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * Returns a code indicating the severity of the last error.  See
shun-iwasawa 82a8f5
 * @ref TJERR "Error codes".
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @param handle a handle to a TurboJPEG compressor, decompressor or
shun-iwasawa 82a8f5
 * transformer instance
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * @return a code indicating the severity of the last error.  See
shun-iwasawa 82a8f5
 * @ref TJERR "Error codes".
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
DLLEXPORT int tjGetErrorCode(tjhandle handle);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Deprecated functions and macros */
shun-iwasawa 82a8f5
#define TJFLAG_FORCEMMX  8
shun-iwasawa 82a8f5
#define TJFLAG_FORCESSE  16
shun-iwasawa 82a8f5
#define TJFLAG_FORCESSE2  32
shun-iwasawa 82a8f5
#define TJFLAG_FORCESSE3  128
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Backward compatibility functions and macros (nothing to see here) */
shun-iwasawa 82a8f5
#define NUMSUBOPT  TJ_NUMSAMP
shun-iwasawa 82a8f5
#define TJ_444  TJSAMP_444
shun-iwasawa 82a8f5
#define TJ_422  TJSAMP_422
shun-iwasawa 82a8f5
#define TJ_420  TJSAMP_420
shun-iwasawa 82a8f5
#define TJ_411  TJSAMP_420
shun-iwasawa 82a8f5
#define TJ_GRAYSCALE  TJSAMP_GRAY
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define TJ_BGR  1
shun-iwasawa 82a8f5
#define TJ_BOTTOMUP  TJFLAG_BOTTOMUP
shun-iwasawa 82a8f5
#define TJ_FORCEMMX  TJFLAG_FORCEMMX
shun-iwasawa 82a8f5
#define TJ_FORCESSE  TJFLAG_FORCESSE
shun-iwasawa 82a8f5
#define TJ_FORCESSE2  TJFLAG_FORCESSE2
shun-iwasawa 82a8f5
#define TJ_ALPHAFIRST  64
shun-iwasawa 82a8f5
#define TJ_FORCESSE3  TJFLAG_FORCESSE3
shun-iwasawa 82a8f5
#define TJ_FASTUPSAMPLE  TJFLAG_FASTUPSAMPLE
shun-iwasawa 82a8f5
#define TJ_YUV  512
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT unsigned long TJBUFSIZE(int width, int height);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int jpegSubsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width,
shun-iwasawa 82a8f5
                         int pitch, int height, int pixelSize,
shun-iwasawa 82a8f5
                         unsigned char *dstBuf, unsigned long *compressedSize,
shun-iwasawa 82a8f5
                         int jpegSubsamp, int jpegQual, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width,
shun-iwasawa 82a8f5
                          int pitch, int height, int pixelSize,
shun-iwasawa 82a8f5
                          unsigned char *dstBuf, int subsamp, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width,
shun-iwasawa 82a8f5
                           int pitch, int height, int pixelFormat,
shun-iwasawa 82a8f5
                           unsigned char *dstBuf, int subsamp, int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                                 unsigned long jpegSize, int *width,
shun-iwasawa 82a8f5
                                 int *height);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                                  unsigned long jpegSize, int *width,
shun-iwasawa 82a8f5
                                  int *height, int *jpegSubsamp);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                           unsigned long jpegSize, unsigned char *dstBuf,
shun-iwasawa 82a8f5
                           int width, int pitch, int height, int pixelSize,
shun-iwasawa 82a8f5
                           int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf,
shun-iwasawa 82a8f5
                                unsigned long jpegSize, unsigned char *dstBuf,
shun-iwasawa 82a8f5
                                int flags);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
DLLEXPORT char *tjGetErrorStr(void);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/**
shun-iwasawa 82a8f5
 * @}
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifdef __cplusplus
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#endif