19862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/* 23395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * Copyright (C)2009-2013 D. R. Commander. All Rights Reserved. 39862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 49862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Redistribution and use in source and binary forms, with or without 59862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * modification, are permitted provided that the following conditions are met: 6f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org * 79862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - Redistributions of source code must retain the above copyright notice, 89862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * this list of conditions and the following disclaimer. 99862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - Redistributions in binary form must reproduce the above copyright notice, 109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * this list of conditions and the following disclaimer in the documentation 119862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * and/or other materials provided with the distribution. 129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - Neither the name of the libjpeg-turbo Project nor the names of its 139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * contributors may be used to endorse or promote products derived from this 149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * software without specific prior written permission. 15f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org * 169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", 179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * POSSIBILITY OF SUCH DAMAGE. 27f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org */ 28f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#ifndef __TURBOJPEG_H__ 309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define __TURBOJPEG_H__ 319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#if defined(_WIN32) && defined(DLLDEFINE) 33f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#define DLLEXPORT __declspec(dllexport) 34f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#else 35f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#define DLLEXPORT 36f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#endif 37f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#define DLLCALL 38f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @addtogroup TurboJPEG 429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * TurboJPEG API. This API provides an interface for generating, decoding, and 439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * transforming planar YUV and JPEG images in memory. 449862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @{ 469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 499862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 509862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The number of chrominance subsampling options 519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_NUMSAMP 5 539862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 549862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 559862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Chrominance subsampling options. 569862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * When an image is converted from the RGB to the YCbCr colorspace as part of 579862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the JPEG compression process, some of the Cb and Cr (chrominance) components 589862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * can be discarded or averaged together to produce a smaller image with little 599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * perceptible loss of image clarity (the human eye is more sensitive to small 609862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * changes in brightness than small changes in color.) This is called 619862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "chrominance subsampling". 623395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * <p> 633395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the 643395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * convention of the digital video community, the TurboJPEG API uses "YUV" to 653395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * refer to an image format consisting of Y, Cb, and Cr image planes. 669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgenum TJSAMP 689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org{ 699862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or 719862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * YUV image will contain one chrominance component for every pixel in the 729862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * source image. 739862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 749862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJSAMP_444=0, 759862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 769862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one 779862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * chrominance component for every 2x1 block of pixels in the source image. 789862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJSAMP_422, 809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one 829862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * chrominance component for every 2x2 block of pixels in the source image. 839862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 849862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJSAMP_420, 859862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Grayscale. The JPEG or YUV image will contain no chrominance components. 879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJSAMP_GRAY, 899862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 909862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one 919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * chrominance component for every 1x2 block of pixels in the source image. 923395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo. 939862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJSAMP_440 959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org}; 969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * MCU block width (in pixels) for a given level of chrominance subsampling. 999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * MCU block sizes: 1009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 8x8 for no subsampling or grayscale 1019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 16x8 for 4:2:2 1029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 8x16 for 4:4:0 1039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 16x16 for 4:2:0 1049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgstatic const int tjMCUWidth[TJ_NUMSAMP] = {8, 16, 16, 8, 8}; 1069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 1079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 1089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * MCU block height (in pixels) for a given level of chrominance subsampling. 1099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * MCU block sizes: 1109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 8x8 for no subsampling or grayscale 1119862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 16x8 for 4:2:2 1129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 8x16 for 4:4:0 1139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * - 16x16 for 4:2:0 1149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgstatic const int tjMCUHeight[TJ_NUMSAMP] = {8, 8, 16, 8, 16}; 1169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 1179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 1189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 1199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The number of pixel formats 1209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1210ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org#define TJ_NUMPF 11 1229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 1239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 1249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Pixel formats 1259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgenum TJPF 1279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org{ 1289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * RGB pixel format. The red, green, and blue components in the image are 1309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * stored in 3-byte pixels in the order R, G, B from lowest to highest byte 1319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * address within each pixel. 1329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJPF_RGB=0, 1349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1359862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * BGR pixel format. The red, green, and blue components in the image are 1369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * stored in 3-byte pixels in the order B, G, R from lowest to highest byte 1379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * address within each pixel. 1389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJPF_BGR, 1409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * RGBX pixel format. The red, green, and blue components in the image are 1429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * stored in 4-byte pixels in the order R, G, B from lowest to highest byte 1430ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * address within each pixel. The X component is ignored when compressing 1440ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * and undefined when decompressing. 1459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJPF_RGBX, 1479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * BGRX pixel format. The red, green, and blue components in the image are 1499862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * stored in 4-byte pixels in the order B, G, R from lowest to highest byte 1500ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * address within each pixel. The X component is ignored when compressing 1510ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * and undefined when decompressing. 1529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1539862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJPF_BGRX, 1549862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1559862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * XBGR pixel format. The red, green, and blue components in the image are 1569862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * stored in 4-byte pixels in the order R, G, B from highest to lowest byte 1570ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * address within each pixel. The X component is ignored when compressing 1580ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * and undefined when decompressing. 1599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1609862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJPF_XBGR, 1619862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1629862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * XRGB pixel format. The red, green, and blue components in the image are 1639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * stored in 4-byte pixels in the order B, G, R from highest to lowest byte 1640ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * address within each pixel. The X component is ignored when compressing 1650ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * and undefined when decompressing. 1669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJPF_XRGB, 1689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 1699862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Grayscale pixel format. Each 1-byte pixel represents a luminance 1709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * (brightness) level from 0 to 255. 1719862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 1720ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org TJPF_GRAY, 1730ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org /** 1740ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when 1750ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * decompressing, the X component is guaranteed to be 0xFF, which can be 1760ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * interpreted as an opaque alpha channel. 1770ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org */ 1780ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org TJPF_RGBA, 1790ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org /** 1800ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when 1810ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * decompressing, the X component is guaranteed to be 0xFF, which can be 1820ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * interpreted as an opaque alpha channel. 1830ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org */ 1840ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org TJPF_BGRA, 1850ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org /** 1860ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when 1870ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * decompressing, the X component is guaranteed to be 0xFF, which can be 1880ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * interpreted as an opaque alpha channel. 1890ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org */ 1900ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org TJPF_ABGR, 1910ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org /** 1920ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when 1930ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * decompressing, the X component is guaranteed to be 0xFF, which can be 1940ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * interpreted as an opaque alpha channel. 1950ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org */ 1960ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org TJPF_ARGB 1979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org}; 1989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 1999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Red offset (in bytes) for a given pixel format. This specifies the number 2019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * of bytes that the red component is offset from the start of the pixel. For 2029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, 2039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * then the red component will be <tt>pixel[tjRedOffset[TJ_BGRX]]</tt>. 2049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2050ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.orgstatic const int tjRedOffset[TJ_NUMPF] = {0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1}; 2069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Green offset (in bytes) for a given pixel format. This specifies the number 2089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * of bytes that the green component is offset from the start of the pixel. 2099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * For instance, if a pixel of format TJ_BGRX is stored in 2109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * <tt>char pixel[]</tt>, then the green component will be 2119862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * <tt>pixel[tjGreenOffset[TJ_BGRX]]</tt>. 2129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2130ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.orgstatic const int tjGreenOffset[TJ_NUMPF] = {1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2}; 2149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Blue offset (in bytes) for a given pixel format. This specifies the number 2169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * of bytes that the Blue component is offset from the start of the pixel. For 2179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * instance, if a pixel of format TJ_BGRX is stored in <tt>char pixel[]</tt>, 2189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * then the blue component will be <tt>pixel[tjBlueOffset[TJ_BGRX]]</tt>. 2199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2200ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.orgstatic const int tjBlueOffset[TJ_NUMPF] = {2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3}; 2219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 2229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Pixel size (in bytes) for a given pixel format. 2249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2250ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.orgstatic const int tjPixelSize[TJ_NUMPF] = {3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4}; 2269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 2279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 2289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The uncompressed source/destination image is stored in bottom-up (Windows, 2309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * OpenGL) order, not top-down (X11) order. 2319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_BOTTOMUP 2 2339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 23411e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * Turn off CPU auto-detection and force TurboJPEG to use MMX code (if the 23511e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * underlying codec supports it.) 2369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_FORCEMMX 8 2389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 23911e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * Turn off CPU auto-detection and force TurboJPEG to use SSE code (if the 24011e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * underlying codec supports it.) 2419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_FORCESSE 16 2439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 24411e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * Turn off CPU auto-detection and force TurboJPEG to use SSE2 code (if the 24511e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * underlying codec supports it.) 2469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_FORCESSE2 32 2489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 24911e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * Turn off CPU auto-detection and force TurboJPEG to use SSE3 code (if the 25011e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * underlying codec supports it.) 2519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_FORCESSE3 128 2539862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2543395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * When decompressing an image that was compressed using chrominance 2553395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * subsampling, use the fastest chrominance upsampling algorithm available in 2563395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * the underlying codec. The default is to use smooth upsampling, which 2573395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * creates a smooth transition between neighboring chrominance components in 2583395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * order to reduce upsampling artifacts in the decompressed image. 2599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2609862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_FASTUPSAMPLE 256 2619862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2629862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Disable buffer (re)allocation. If passed to #tjCompress2() or 2639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * #tjTransform(), this flag will cause those functions to generate an error if 2649862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the JPEG image buffer is invalid or too small rather than attempting to 2659862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * allocate or reallocate that buffer. This reproduces the behavior of earlier 2669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * versions of TurboJPEG. 2679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJFLAG_NOREALLOC 1024 26911e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org/** 27011e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * Use the fastest DCT/IDCT algorithm available in the underlying codec. The 2713395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * default if this flag is not specified is implementation-specific. For 2723395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast 2733395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * algorithm by default when compressing, because this has been shown to have 2743395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * only a very slight effect on accuracy, but it uses the accurate algorithm 2753395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * when decompressing, because this has been shown to have a larger effect. 27611e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org */ 27711e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org#define TJFLAG_FASTDCT 2048 27811e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org/** 27911e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org * Use the most accurate DCT/IDCT algorithm available in the underlying codec. 2803395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * The default if this flag is not specified is implementation-specific. For 2813395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast 2823395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * algorithm by default when compressing, because this has been shown to have 2833395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * only a very slight effect on accuracy, but it uses the accurate algorithm 2843395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * when decompressing, because this has been shown to have a larger effect. 28511e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org */ 28611e6ee95ca9a40fe6b86a1cd23a9fbfd7d19c2bdhbono@chromium.org#define TJFLAG_ACCURATEDCT 4096 2879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 2889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 2899862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2903395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * The number of transform operations 2919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2929862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_NUMXOP 8 2939862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 2949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 2959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Transform operations for #tjTransform() 2969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 2979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgenum TJXOP 2989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org{ 2999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Do not transform the position of the image pixels 3019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_NONE=0, 3039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Flip (mirror) image horizontally. This transform is imperfect if there 3059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.) 3069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_HFLIP, 3089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Flip (mirror) image vertically. This transform is imperfect if there are 3109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.) 3119862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_VFLIP, 3139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Transpose image (flip/mirror along upper left to lower right axis.) This 3159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * transform is always perfect. 3169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_TRANSPOSE, 3189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Transverse transpose image (flip/mirror along upper right to lower left 3209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * axis.) This transform is imperfect if there are any partial MCU blocks in 3219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the image (see #TJXOPT_PERFECT.) 3229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_TRANSVERSE, 3249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Rotate image clockwise by 90 degrees. This transform is imperfect if 3269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * there are any partial MCU blocks on the bottom edge (see 3279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * #TJXOPT_PERFECT.) 3289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_ROT90, 3309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Rotate image 180 degrees. This transform is imperfect if there are any 3329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * partial MCU blocks in the image (see #TJXOPT_PERFECT.) 3339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_ROT180, 3359862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Rotate image counter-clockwise by 90 degrees. This transform is imperfect 3379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * if there are any partial MCU blocks on the right edge (see 3389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * #TJXOPT_PERFECT.) 3399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org TJXOP_ROT270 3419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org}; 3429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 3439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 3449862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 3459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * This option will cause #tjTransform() to return an error if the transform is 3469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * not perfect. Lossless transforms operate on MCU blocks, whose size depends 3479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * on the level of chrominance subsampling used (see #tjMCUWidth 3489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * and #tjMCUHeight.) If the image's width or height is not evenly divisible 3499862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * by the MCU block size, then there will be partial MCU blocks on the right 3509862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * and/or bottom edges. It is not possible to move these partial MCU blocks to 3519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the top or left of the image, so any transform that would require that is 3529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "imperfect." If this option is not specified, then any partial MCU blocks 3539862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * that cannot be transformed will be left in place, which will create 3549862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * odd-looking strips on the right or bottom edge of the image. 3559862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3569862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJXOPT_PERFECT 1 3579862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 3589862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * This option will cause #tjTransform() to discard any partial MCU blocks that 3599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * cannot be transformed. 3609862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3619862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJXOPT_TRIM 2 3629862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 3639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * This option will enable lossless cropping. See #tjTransform() for more 3649862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * information. 3659862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJXOPT_CROP 4 3679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 3689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * This option will discard the color data in the input image and produce 3699862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * a grayscale output image. 3709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3719862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJXOPT_GRAY 8 372c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org/** 373c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * This option will prevent #tjTransform() from outputting a JPEG image for 374c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * this particular transform (this can be used in conjunction with a custom 375c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * filter to capture the transformed DCT coefficients without transcoding 376c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * them.) 377c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org */ 378c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org#define TJXOPT_NOOUTPUT 16 3799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 3809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 3819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 3829862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Scaling factor 3839862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3849862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgtypedef struct 3859862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org{ 3869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Numerator 3889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3899862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int num; 3909862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 3919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Denominator 3929862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3939862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int denom; 3949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org} tjscalingfactor; 3959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 3969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 3979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Cropping region 3989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 3999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgtypedef struct 4009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org{ 4019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The left boundary of the cropping region. This must be evenly divisible 4039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * by the MCU block width (see #tjMCUWidth.) 4049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int x; 4069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The upper boundary of the cropping region. This must be evenly divisible 4089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * by the MCU block height (see #tjMCUHeight.) 4099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int y; 4119862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The width of the cropping region. Setting this to 0 is the equivalent of 4139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * setting it to the width of the source JPEG image - x. 4149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int w; 4169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The height of the cropping region. Setting this to 0 is the equivalent of 4189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * setting it to the height of the source JPEG image - y. 4199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int h; 4219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org} tjregion; 4229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 4239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 4249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Lossless transform 4259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 426c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.orgtypedef struct tjtransform 4279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org{ 4289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Cropping region 4309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org tjregion r; 4329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * One of the @ref TJXOP "transform operations" 4349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4359862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int op; 4369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org /** 4379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options" 4389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int options; 440c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org /** 441c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * Arbitrary data that can be accessed within the body of the callback 442c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * function 443c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org */ 444c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org void *data; 445c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org /** 446c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * A callback function that can be used to modify the DCT coefficients 447c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * after they are losslessly transformed but before they are transcoded to a 4483395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * new JPEG image. This allows for custom filters or other transformations 4493395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * to be applied in the frequency domain. 450c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * 451c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE: 452c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * this pointer is not guaranteed to be valid once the callback 453c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * returns, so applications wishing to hand off the DCT coefficients 454c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * to another function or library should make a copy of them within 455c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * the body of the callback.) 456c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @param arrayRegion #tjregion structure containing the width and height of 457c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * the array pointed to by <tt>coeffs</tt> as well as its offset 458c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * relative to the component plane. TurboJPEG implementations may 459c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * choose to split each component plane into multiple DCT coefficient 460c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * arrays and call the callback function once for each array. 461c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @param planeRegion #tjregion structure containing the width and height of 462c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * the component plane to which <tt>coeffs</tt> belongs 463c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @param componentID ID number of the component plane to which 464c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 465c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * 0, 1, and 2 in typical JPEG images.) 466c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @param transformID ID number of the transformed image to which 467c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * <tt>coeffs</tt> belongs. This is the same as the index of the 4683395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * transform in the <tt>transforms</tt> array that was passed to 469c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * #tjTransform(). 470c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @param transform a pointer to a #tjtransform structure that specifies the 471c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * parameters and/or cropping region for this transform 472c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * 473c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org * @return 0 if the callback was successful, or -1 if an error occurred. 474c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org */ 475c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org int (*customFilter)(short *coeffs, tjregion arrayRegion, 476c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org tjregion planeRegion, int componentIndex, int transformIndex, 477c6beb74efd1b43982a5b6c957c57426442359c17hbono@chromium.org struct tjtransform *transform); 4789862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org} tjtransform; 4799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 4809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 4819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * TurboJPEG instance handle 4829862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 483f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.orgtypedef void* tjhandle; 484f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 485f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 4869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 4879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Pad the given width to the nearest 32-bit boundary 4889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4899862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJPAD(width) (((width)+3)&(~3)) 490f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 4919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 4929862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Compute the scaled value of <tt>dimension</tt> using the given scaling 4939862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * factor. This macro performs the integer equivalent of <tt>ceil(dimension * 4949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * scalingFactor)</tt>. 4959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 4969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJSCALED(dimension, scalingFactor) ((dimension * scalingFactor.num \ 4979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org + scalingFactor.denom - 1) / scalingFactor.denom) 498f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 499f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 5009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#ifdef __cplusplus 5019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgextern "C" { 5029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#endif 503f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 504f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 5059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 5069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Create a TurboJPEG compressor instance. 5079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return a handle to the newly-created instance, or NULL if an error 5099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * occurred (see #tjGetErrorStr().) 5109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 511f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.orgDLLEXPORT tjhandle DLLCALL tjInitCompress(void); 512f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 513f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 5149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 5159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Compress an RGB or grayscale image into a JPEG image. 5169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG compressor or transformer instance 5189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels 5199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to be compressed 5209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param width width (in pixels) of the source image 5219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param pitch bytes per line of the source image. Normally, this should be 5229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, 5239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of 5249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the image is padded to the nearest 32-bit boundary, as is the case 5259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * for Windows bitmaps. You can also be clever and use this parameter 5269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to skip lines, etc. Setting this parameter to 0 is the equivalent of 5279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. 5289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param height height (in pixels) of the source image 5299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param pixelFormat pixel format of the source image (see @ref TJPF 5309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "Pixel formats".) 5319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegBuf address of a pointer to an image buffer that will receive the 5329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer 5339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to accommodate the size of the JPEG image. Thus, you can choose to: 5349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -# pre-allocate the JPEG buffer with an arbitrary size using 5359862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * #tjAlloc() and let TurboJPEG grow the buffer as needed, 5369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -# set <tt>*jpegBuf</tt> to NULL to tell TurboJPEG to allocate the 5379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * buffer for you, or 5389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -# pre-allocate the buffer to a "worst case" size determined by 5399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * calling #tjBufSize(). This should ensure that the buffer never has 5409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to be re-allocated (setting #TJFLAG_NOREALLOC guarantees this.) 5419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * . 5429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * If you choose option 1, <tt>*jpegSize</tt> should be set to the 5439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * size of your pre-allocated buffer. In any case, unless you have 5449862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * set #TJFLAG_NOREALLOC, you should always check <tt>*jpegBuf</tt> upon 5459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * return from this function, as it may have changed. 5460ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param jpegSize pointer to an unsigned long variable that holds the size of 5479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the JPEG image buffer. If <tt>*jpegBuf</tt> points to a 5489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * pre-allocated buffer, then <tt>*jpegSize</tt> should be set to the 5499862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * size of the buffer. Upon return, <tt>*jpegSize</tt> will contain the 5509862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * size of the JPEG image (in bytes.) 5519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegSubsamp the level of chrominance subsampling to be used when 5529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * generating the JPEG image (see @ref TJSAMP 5539862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "Chrominance subsampling options".) 5549862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegQual the image quality of the generated JPEG image (1 = worst, 5559862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 100 = best) 5569862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 5579862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "flags". 5589862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 560f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org*/ 5619862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, 5629862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf, 5639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned long *jpegSize, int jpegSubsamp, int jpegQual, int flags); 5649862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 5659862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 5669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 5679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The maximum size of the buffer (in bytes) required to hold a JPEG image with 5689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the given parameters. The number of bytes returned by this function is 5699862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * larger than the size of the uncompressed source image. The reason for this 5709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * is that the JPEG format uses 16-bit coefficients, and it is thus possible 5713395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * for a very high-quality JPEG image with very high-frequency content to 5729862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * expand rather than compress when converted to the JPEG format. Such images 5739862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * represent a very rare corner case, but since there is no way to predict the 5749862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * size of a JPEG image prior to compression, the corner case has to be 5759862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * handled. 5769862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5779862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param width width of the image (in pixels) 5789862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param height height of the image (in pixels) 5799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegSubsamp the level of chrominance subsampling to be used when 5809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * generating the JPEG image (see @ref TJSAMP 5819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "Chrominance subsampling options".) 5829862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5839862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return the maximum size of the buffer (in bytes) required to hold the 5849862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * image, or -1 if the arguments are out of bounds. 5859862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 5869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, 5879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int jpegSubsamp); 588f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 589f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 5909862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 5919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * The size of the buffer (in bytes) required to hold a YUV planar image with 5929862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the given parameters. 5939862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param width width of the image (in pixels) 5959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param height height of the image (in pixels) 5969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param subsamp level of chrominance subsampling in the image (see 5979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @ref TJSAMP "Chrominance subsampling options".) 5989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 5999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return the size of the buffer (in bytes) required to hold the image, or 6009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -1 if the arguments are out of bounds. 6019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 6029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT unsigned long DLLCALL tjBufSizeYUV(int width, int height, 6039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int subsamp); 6049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 6059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 6069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 6079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Encode an RGB or grayscale image into a YUV planar image. This function 6089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * uses the accelerated color conversion routines in TurboJPEG's underlying 6099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * codec to produce a planar YUV image that is suitable for X Video. 6109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Specifically, if the chrominance components are subsampled along the 6113395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * horizontal dimension, then the width of the luminance plane is padded to the 6123395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * nearest multiple of 2 in the output image (same goes for the height of the 6133395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * luminance plane, if the chrominance components are subsampled along the 6143395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * vertical dimension.) Also, each line of each plane in the output image is 6153395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * padded to 4 bytes. Although this will work with any subsampling option, it 6163395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * is really only useful in combination with TJ_420, which produces an image 6173395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * compatible with the I420 (AKA "YUV420P") format. 6183395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * <p> 6193395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the 6203395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * convention of the digital video community, the TurboJPEG API uses "YUV" to 6213395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * refer to an image format consisting of Y, Cb, and Cr image planes. 6229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG compressor or transformer instance 6249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param srcBuf pointer to an image buffer containing RGB or grayscale pixels 6259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to be encoded 6269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param width width (in pixels) of the source image 6279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param pitch bytes per line of the source image. Normally, this should be 6289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * <tt>width * #tjPixelSize[pixelFormat]</tt> if the image is unpadded, 6299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * or <tt>#TJPAD(width * #tjPixelSize[pixelFormat])</tt> if each line of 6309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the image is padded to the nearest 32-bit boundary, as is the case 6319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * for Windows bitmaps. You can also be clever and use this parameter 6329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to skip lines, etc. Setting this parameter to 0 is the equivalent of 6339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * setting it to <tt>width * #tjPixelSize[pixelFormat]</tt>. 6349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param height height (in pixels) of the source image 6359862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param pixelFormat pixel format of the source image (see @ref TJPF 6369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "Pixel formats".) 6370ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param dstBuf pointer to an image buffer that will receive the YUV image. 6389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Use #tjBufSizeYUV() to determine the appropriate size for this buffer 6399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * based on the image width, height, and level of chrominance 6409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * subsampling. 6419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param subsamp the level of chrominance subsampling to be used when 6429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * generating the YUV image (see @ref TJSAMP 6439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "Chrominance subsampling options".) 6449862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 6459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "flags". 6469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 6489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org*/ 6499862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjEncodeYUV2(tjhandle handle, 6509862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *srcBuf, int width, int pitch, int height, int pixelFormat, 6519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *dstBuf, int subsamp, int flags); 652f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 653f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 6549862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 6559862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Create a TurboJPEG decompressor instance. 6569862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6579862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return a handle to the newly-created instance, or NULL if an error 6589862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * occurred (see #tjGetErrorStr().) 659f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org*/ 660f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.orgDLLEXPORT tjhandle DLLCALL tjInitDecompress(void); 661f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 662f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 6639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 6649862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Retrieve information about a JPEG image without decompressing it. 6659862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG decompressor or transformer instance 6679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegBuf pointer to a buffer containing a JPEG image 6689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegSize size of the JPEG image (in bytes) 6690ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param width pointer to an integer variable that will receive the width (in 6709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * pixels) of the JPEG image 6710ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param height pointer to an integer variable that will receive the height 6729862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * (in pixels) of the JPEG image 6730ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param jpegSubsamp pointer to an integer variable that will receive the 6749862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * level of chrominance subsampling used when compressing the JPEG image 6759862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * (see @ref TJSAMP "Chrominance subsampling options".) 6769862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6779862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 678f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org*/ 6799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjDecompressHeader2(tjhandle handle, 6809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height, 6819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int *jpegSubsamp); 682f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 683f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 6849862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 6859862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Returns a list of fractional scaling factors that the JPEG decompressor in 6869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * this implementation of TurboJPEG supports. 6879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param numscalingfactors pointer to an integer variable that will receive 6899862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the number of elements in the list 6909862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 6919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return a pointer to a list of fractional scaling factors, or NULL if an 6929862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * error is encountered (see #tjGetErrorStr().) 693f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org*/ 6949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors); 695f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 696f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 6979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 6989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Decompress a JPEG image to an RGB or grayscale image. 6999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 7009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG decompressor or transformer instance 7019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegBuf pointer to a buffer containing the JPEG image to decompress 7029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegSize size of the JPEG image (in bytes) 7030ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param dstBuf pointer to an image buffer that will receive the decompressed 7049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * image. This buffer should normally be <tt>pitch * scaledHeight</tt> 7059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * bytes in size, where <tt>scaledHeight</tt> can be determined by 7069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * calling #TJSCALED() with the JPEG image height and one of the scaling 7073395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * factors returned by #tjGetScalingFactors(). The <tt>dstBuf</tt> 7083395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * pointer may also be used to decompress into a specific region of a 7093395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * larger buffer. 7109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param width desired width (in pixels) of the destination image. If this is 7113395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * different than the width of the JPEG image being decompressed, then 7129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * TurboJPEG will use scaling in the JPEG decompressor to generate the 7139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * largest possible image that will fit within the desired width. If 7143395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * <tt>width</tt> is set to 0, then only the height will be considered 7153395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * when determining the scaled image size. 7169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param pitch bytes per line of the destination image. Normally, this is 7179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * <tt>scaledWidth * #tjPixelSize[pixelFormat]</tt> if the decompressed 7189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * image is unpadded, else <tt>#TJPAD(scaledWidth * 7199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * #tjPixelSize[pixelFormat])</tt> if each line of the decompressed 7209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * image is padded to the nearest 32-bit boundary, as is the case for 7219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Windows bitmaps. (NOTE: <tt>scaledWidth</tt> can be determined by 7229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * calling #TJSCALED() with the JPEG image width and one of the scaling 7239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * factors returned by #tjGetScalingFactors().) You can also be clever 7249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * and use the pitch parameter to skip lines, etc. Setting this 7259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * parameter to 0 is the equivalent of setting it to <tt>scaledWidth 7269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * * #tjPixelSize[pixelFormat]</tt>. 7279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param height desired height (in pixels) of the destination image. If this 7283395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * is different than the height of the JPEG image being decompressed, 7293395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * then TurboJPEG will use scaling in the JPEG decompressor to generate 7303395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * the largest possible image that will fit within the desired height. 7313395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * If <tt>height</tt> is set to 0, then only the width will be 7323395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * considered when determining the scaled image size. 7339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param pixelFormat pixel format of the destination image (see @ref 7349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * TJPF "Pixel formats".) 7359862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 7369862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "flags". 7379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 7389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 7399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 7409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, 7419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, 7429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int width, int pitch, int height, int pixelFormat, int flags); 7439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 7449862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 7459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 7469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Decompress a JPEG image to a YUV planar image. This function performs JPEG 7479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * decompression but leaves out the color conversion step, so a planar YUV 7489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * image is generated instead of an RGB image. The padding of the planes in 7493395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * this image is the same as in the images generated by #tjEncodeYUV2(). Note 7509862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * that, if the width or height of the image is not an even multiple of the MCU 7519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * block size (see #tjMCUWidth and #tjMCUHeight), then an intermediate buffer 7529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * copy will be performed within TurboJPEG. 7533395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * <p> 7543395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the 7553395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * convention of the digital video community, the TurboJPEG API uses "YUV" to 7563395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * refer to an image format consisting of Y, Cb, and Cr image planes. 7579862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 7589862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG decompressor or transformer instance 7599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegBuf pointer to a buffer containing the JPEG image to decompress 7609862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegSize size of the JPEG image (in bytes) 7610ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param dstBuf pointer to an image buffer that will receive the YUV image. 7623395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * Use #tjBufSizeYUV() to determine the appropriate size for this buffer 7639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * based on the image width, height, and level of subsampling. 7649862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 7659862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "flags". 7669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 7679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 7689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 7699862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjDecompressToYUV(tjhandle handle, 7709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, 7719862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int flags); 772f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 773f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 7749862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 7759862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Create a new TurboJPEG transformer instance. 7769862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 7779862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return a handle to the newly-created instance, or NULL if an error 7789862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * occurred (see #tjGetErrorStr().) 7799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 7809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT tjhandle DLLCALL tjInitTransform(void); 7819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 7829862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 7839862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 7849862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Losslessly transform a JPEG image into another JPEG image. Lossless 7859862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * transforms work by moving the raw coefficients from one JPEG image structure 7869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * to another without altering the values of the coefficients. While this is 7879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * typically faster than decompressing the image, transforming it, and 7889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * re-compressing it, lossless transforms are not free. Each lossless 7893395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * transform requires reading and performing Huffman decoding on all of the 7903395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * coefficients in the source image, regardless of the size of the destination 7913395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * image. Thus, this function provides a means of generating multiple 7923395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * transformed images from the same source or applying multiple 7933395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * transformations simultaneously, in order to eliminate the need to read the 7943395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * source coefficients multiple times. 7959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 7969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG transformer instance 7979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegBuf pointer to a buffer containing the JPEG image to transform 7989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param jpegSize size of the JPEG image (in bytes) 7999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param n the number of transformed JPEG images to generate 8009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param dstBufs pointer to an array of n image buffers. <tt>dstBufs[i]</tt> 8019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * will receive a JPEG image that has been transformed using the 8029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * parameters in <tt>transforms[i]</tt>. TurboJPEG has the ability to 8039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * reallocate the JPEG buffer to accommodate the size of the JPEG image. 8049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Thus, you can choose to: 8059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -# pre-allocate the JPEG buffer with an arbitrary size using 8069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * #tjAlloc() and let TurboJPEG grow the buffer as needed, 8079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -# set <tt>dstBufs[i]</tt> to NULL to tell TurboJPEG to allocate the 8089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * buffer for you, or 8099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * -# pre-allocate the buffer to a "worst case" size determined by 8103395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * calling #tjBufSize() with the transformed or cropped width and 8113395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * height. This should ensure that the buffer never has to be 8123395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * re-allocated (setting #TJFLAG_NOREALLOC guarantees this.) 8139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * . 8149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * If you choose option 1, <tt>dstSizes[i]</tt> should be set to 8159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the size of your pre-allocated buffer. In any case, unless you have 8169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * set #TJFLAG_NOREALLOC, you should always check <tt>dstBufs[i]</tt> 8179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * upon return from this function, as it may have changed. 8180ec930ec950c94f0319d5b94a201b7e61ef15130hbono@chromium.org * @param dstSizes pointer to an array of n unsigned long variables that will 8199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * receive the actual sizes (in bytes) of each transformed JPEG image. 8209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * If <tt>dstBufs[i]</tt> points to a pre-allocated buffer, then 8219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * <tt>dstSizes[i]</tt> should be set to the size of the buffer. Upon 8229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * return, <tt>dstSizes[i]</tt> will contain the size of the JPEG image 8239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * (in bytes.) 8243395bcc26e390d2960d15020d4a4d27ae0c122fenoel@chromium.org * @param transforms pointer to an array of n #tjtransform structures, each of 8259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * which specifies the transform parameters and/or cropping region for 8269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * the corresponding transformed output image. 8279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP 8289862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * "flags". 8299862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8309862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 8319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 8329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjTransform(tjhandle handle, unsigned char *jpegBuf, 8339862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned long jpegSize, int n, unsigned char **dstBufs, 8349862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned long *dstSizes, tjtransform *transforms, int flags); 835f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 836f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 8379862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 8389862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Destroy a TurboJPEG compressor, decompressor, or transformer instance. 8399862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8409862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param handle a handle to a TurboJPEG compressor, decompressor or 8419862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * transformer instance 8429862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8439862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) 8449862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 8459862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjDestroy(tjhandle handle); 8469862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8479862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8489862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 8499862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Allocate an image buffer for use with TurboJPEG. You should always use 8509862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * this function to allocate the JPEG destination buffer(s) for #tjCompress2() 8519862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * and #tjTransform() unless you are disabling automatic buffer 8529862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * (re)allocation (by setting #TJFLAG_NOREALLOC.) 8539862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8549862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param bytes the number of bytes to allocate 8559862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8569862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return a pointer to a newly-allocated buffer with the specified number of 8579862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * bytes 8589862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8599862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @sa tjFree() 8609862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 8619862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT unsigned char* DLLCALL tjAlloc(int bytes); 8629862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8639862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8649862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 8659862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Free an image buffer previously allocated by TurboJPEG. You should always 8669862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * use this function to free JPEG destination buffer(s) that were automatically 8679862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * (re)allocated by #tjCompress2() or #tjTransform() or that were manually 8689862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * allocated using #tjAlloc(). 8699862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8709862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @param buffer address of the buffer to free 8719862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8729862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @sa tjAlloc() 8739862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 8749862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT void DLLCALL tjFree(unsigned char *buffer); 8759862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8769862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8779862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 8789862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * Returns a descriptive error message explaining why the last command failed. 8799862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * 8809862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @return a descriptive error message explaining why the last command failed. 8819862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 882f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.orgDLLEXPORT char* DLLCALL tjGetErrorStr(void); 883f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org 8849862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8859862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/* Backward compatibility functions and macros (nothing to see here) */ 8869862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define NUMSUBOPT TJ_NUMSAMP 8879862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_444 TJSAMP_444 8889862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_422 TJSAMP_422 8899862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_420 TJSAMP_420 8909862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_411 TJSAMP_420 8919862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_GRAYSCALE TJSAMP_GRAY 8929862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 8939862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_BGR 1 8949862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_BOTTOMUP TJFLAG_BOTTOMUP 8959862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_FORCEMMX TJFLAG_FORCEMMX 8969862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_FORCESSE TJFLAG_FORCESSE 8979862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_FORCESSE2 TJFLAG_FORCESSE2 8989862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_ALPHAFIRST 64 8999862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_FORCESSE3 TJFLAG_FORCESSE3 9009862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE 9019862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#define TJ_YUV 512 9029862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9039862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height); 9049862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9059862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height, 9069862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int jpegSubsamp); 9079862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9089862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjCompress(tjhandle handle, unsigned char *srcBuf, 9099862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int width, int pitch, int height, int pixelSize, unsigned char *dstBuf, 9109862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned long *compressedSize, int jpegSubsamp, int jpegQual, int flags); 9119862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9129862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjEncodeYUV(tjhandle handle, 9139862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *srcBuf, int width, int pitch, int height, int pixelSize, 9149862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *dstBuf, int subsamp, int flags); 9159862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9169862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjDecompressHeader(tjhandle handle, 9179862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *jpegBuf, unsigned long jpegSize, int *width, int *height); 9189862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9199862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.orgDLLEXPORT int DLLCALL tjDecompress(tjhandle handle, 9209862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, 9219862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org int width, int pitch, int height, int pixelSize, int flags); 9229862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9239862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9249862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org/** 9259862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org * @} 9269862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org */ 9279862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 928f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#ifdef __cplusplus 929f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org} 930f0c4f33a4aa0760ba0e12a254b69d996442c9c5hbono@chromium.org#endif 9319862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org 9329862697206250265c6bb37a4186b0a411c78de3bhbono@chromium.org#endif 933