blob: 808e2f30a73becfad7e891ed1fac5f31bff2188b [file] [log] [blame]
DRC2e7b76b2009-04-03 12:04:24 +00001/* Copyright (C)2004 Landmark Graphics Corporation
2 * Copyright (C)2005, 2006 Sun Microsystems, Inc.
DRC61e51f92009-04-05 21:53:20 +00003 * Copyright (C)2009 D. R. Commander
DRC2e7b76b2009-04-03 12:04:24 +00004 *
5 * This library is free software and may be redistributed and/or modified under
6 * the terms of the wxWindows Library License, Version 3.1 or (at your option)
7 * any later version. The full license is in the LICENSE.txt file included
8 * with this distribution.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * wxWindows Library License for more details.
14 */
15
16#if (defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__)) && defined(_WIN32) && defined(DLLDEFINE)
17#define DLLEXPORT __declspec(dllexport)
18#else
19#define DLLEXPORT
20#endif
21
22#define DLLCALL
23
24/* Subsampling */
25#define NUMSUBOPT 4
26
DRC61e51f92009-04-05 21:53:20 +000027enum {TJ_444=0, TJ_422, TJ_420, TJ_GRAYSCALE};
DRC2e7b76b2009-04-03 12:04:24 +000028
29/* Flags */
30#define TJ_BGR 1
31#define TJ_BOTTOMUP 2
32#define TJ_FORCEMMX 8 /* Force IPP to use MMX code even if SSE available */
33#define TJ_FORCESSE 16 /* Force IPP to use SSE1 code even if SSE2 available */
34#define TJ_FORCESSE2 32 /* Force IPP to use SSE2 code (useful if auto-detect is not working properly) */
35#define TJ_ALPHAFIRST 64 /* BGR buffer is ABGR and RGB buffer is ARGB */
36#define TJ_FORCESSE3 128 /* Force IPP to use SSE3 code (useful if auto-detect is not working properly) */
DRC61e51f92009-04-05 21:53:20 +000037#define TJ_FASTUPSAMPLE 256 /* Use fast, inaccurate 4:2:2 and 4:2:0 YUV upsampling routines in libjpeg decompressor */
DRC2e7b76b2009-04-03 12:04:24 +000038
39typedef void* tjhandle;
40
41#define TJPAD(p) (((p)+3)&(~3))
42#ifndef max
43 #define max(a,b) ((a)>(b)?(a):(b))
44#endif
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/* API follows */
51
52
53/*
54 tjhandle tjInitCompress(void)
55
56 Creates a new JPEG compressor instance, allocates memory for the structures,
57 and returns a handle to the instance. Most applications will only
58 need to call this once at the beginning of the program or once for each
59 concurrent thread. Don't try to create a new instance every time you
60 compress an image, because this will cause performance to suffer.
61
62 RETURNS: NULL on error
63*/
64DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
65
66
67/*
68 int tjCompress(tjhandle j,
69 unsigned char *srcbuf, int width, int pitch, int height, int pixelsize,
70 unsigned char *dstbuf, unsigned long *size,
71 int jpegsubsamp, int jpegqual, int flags)
72
73 [INPUT] j = instance handle previously returned from a call to
74 tjInitCompress()
75 [INPUT] srcbuf = pointer to user-allocated image buffer containing pixels in
76 RGB(A) or BGR(A) form
77 [INPUT] width = width (in pixels) of the source image
78 [INPUT] pitch = bytes per line of the source image (width*pixelsize if the
79 bitmap is unpadded, else TJPAD(width*pixelsize) if each line of the bitmap
80 is padded to the nearest 32-bit boundary, such as is the case for Windows
81 bitmaps. You can also be clever and use this parameter to skip lines, etc.,
82 as long as the pitch is greater than 0.)
83 [INPUT] height = height (in pixels) of the source image
84 [INPUT] pixelsize = size (in bytes) of each pixel in the source image
85 RGBA and BGRA: 4, RGB and BGR: 3
86 [INPUT] dstbuf = pointer to user-allocated image buffer which will receive
87 the JPEG image. Use the macro TJBUFSIZE(width, height) to determine
88 the appropriate size for this buffer based on the image width and height.
89 [OUTPUT] size = pointer to unsigned long which receives the size (in bytes)
90 of the compressed image
DRC61e51f92009-04-05 21:53:20 +000091 [INPUT] jpegsubsamp = Specifies either 4:2:0, 4:2:2, or 4:4:4 subsampling.
DRC2e7b76b2009-04-03 12:04:24 +000092 When the image is converted from the RGB to YCbCr colorspace as part of the
93 JPEG compression process, every other Cb and Cr (chrominance) pixel can be
94 discarded to produce a smaller image with little perceptible loss of
95 image clarity (the human eye is more sensitive to small changes in
96 brightness than small changes in color.)
97
DRC61e51f92009-04-05 21:53:20 +000098 TJ_420: 4:2:0 subsampling. Discards every other Cb, Cr pixel in both
DRC2e7b76b2009-04-03 12:04:24 +000099 horizontal and vertical directions.
100 TJ_422: 4:2:2 subsampling. Discards every other Cb, Cr pixel only in
101 the horizontal direction.
102 TJ_444: no subsampling.
103 TJ_GRAYSCALE: Generate grayscale JPEG image
104
105 [INPUT] jpegqual = JPEG quality (an integer between 0 and 100 inclusive.)
106 [INPUT] flags = the bitwise OR of one or more of the following
107
108 TJ_BGR: The components of each pixel in the source image are stored in
109 B,G,R order, not R,G,B
110 TJ_BOTTOMUP: The source image is stored in bottom-up (Windows) order,
111 not top-down
112 TJ_FORCEMMX: Valid only for the Intel Performance Primitives implementation
113 of this codec-- force IPP to use MMX code (bypass CPU auto-detection)
114 TJ_FORCESSE: Valid only for the Intel Performance Primitives implementation
115 of this codec-- force IPP to use SSE code (bypass CPU auto-detection)
116 TJ_FORCESSE2: Valid only for the Intel Performance Primitives implementation
117 of this codec-- force IPP to use SSE2 code (bypass CPU auto-detection)
118 TJ_FORCESSE3: Valid only for the Intel Performance Primitives implementation
119 of this codec-- force IPP to use SSE3 code (bypass CPU auto-detection)
120
121 RETURNS: 0 on success, -1 on error
122*/
123DLLEXPORT int DLLCALL tjCompress(tjhandle j,
124 unsigned char *srcbuf, int width, int pitch, int height, int pixelsize,
125 unsigned char *dstbuf, unsigned long *size,
126 int jpegsubsamp, int jpegqual, int flags);
127
128DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height);
129
130/*
131 tjhandle tjInitDecompress(void)
132
133 Creates a new JPEG decompressor instance, allocates memory for the
134 structures, and returns a handle to the instance. Most applications will
135 only need to call this once at the beginning of the program or once for each
136 concurrent thread. Don't try to create a new instance every time you
137 decompress an image, because this will cause performance to suffer.
138
139 RETURNS: NULL on error
140*/
141DLLEXPORT tjhandle DLLCALL tjInitDecompress(void);
142
143
144/*
145 int tjDecompressHeader(tjhandle j,
146 unsigned char *srcbuf, unsigned long size,
147 int *width, int *height)
148
149 [INPUT] j = instance handle previously returned from a call to
150 tjInitDecompress()
151 [INPUT] srcbuf = pointer to a user-allocated buffer containing the JPEG image
152 to decompress
153 [INPUT] size = size of the JPEG image buffer (in bytes)
154 [OUTPUT] width = width (in pixels) of the JPEG image
155 [OUTPUT] height = height (in pixels) of the JPEG image
156
157 RETURNS: 0 on success, -1 on error
158*/
159DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle j,
160 unsigned char *srcbuf, unsigned long size,
161 int *width, int *height);
162
163
164/*
165 int tjDecompress(tjhandle j,
166 unsigned char *srcbuf, unsigned long size,
167 unsigned char *dstbuf, int width, int pitch, int height, int pixelsize,
168 int flags)
169
170 [INPUT] j = instance handle previously returned from a call to
171 tjInitDecompress()
172 [INPUT] srcbuf = pointer to a user-allocated buffer containing the JPEG image
173 to decompress
174 [INPUT] size = size of the JPEG image buffer (in bytes)
175 [INPUT] dstbuf = pointer to user-allocated image buffer which will receive
176 the bitmap image. This buffer should normally be pitch*height
177 bytes in size, although this pointer may also be used to decompress into
178 a specific region of a larger buffer.
179 [INPUT] width = width (in pixels) of the destination image
180 [INPUT] pitch = bytes per line of the destination image (width*pixelsize if the
181 bitmap is unpadded, else TJPAD(width*pixelsize) if each line of the bitmap
182 is padded to the nearest 32-bit boundary, such as is the case for Windows
183 bitmaps. You can also be clever and use this parameter to skip lines, etc.,
184 as long as the pitch is greater than 0.)
185 [INPUT] height = height (in pixels) of the destination image
186 [INPUT] pixelsize = size (in bytes) of each pixel in the destination image
187 RGBA/RGBx and BGRA/BGRx: 4, RGB and BGR: 3
188 [INPUT] flags = the bitwise OR of one or more of the following
189
190 TJ_BGR: The components of each pixel in the destination image should be
191 written in B,G,R order, not R,G,B
192 TJ_BOTTOMUP: The destination image should be stored in bottom-up
193 (Windows) order, not top-down
194 TJ_FORCEMMX: Valid only for the Intel Performance Primitives implementation
195 of this codec-- force IPP to use MMX code (bypass CPU auto-detection)
196 TJ_FORCESSE: Valid only for the Intel Performance Primitives implementation
197 of this codec-- force IPP to use SSE code (bypass CPU auto-detection)
198 TJ_FORCESSE2: Valid only for the Intel Performance Primitives implementation
199 of this codec-- force IPP to use SSE2 code (bypass CPU auto-detection)
200
201 RETURNS: 0 on success, -1 on error
202*/
203DLLEXPORT int DLLCALL tjDecompress(tjhandle j,
204 unsigned char *srcbuf, unsigned long size,
205 unsigned char *dstbuf, int width, int pitch, int height, int pixelsize,
206 int flags);
207
208
209/*
210 int tjDestroy(tjhandle h)
211
212 Frees structures associated with a compression or decompression instance
213
214 [INPUT] h = instance handle (returned from a previous call to
215 tjInitCompress() or tjInitDecompress()
216
217 RETURNS: 0 on success, -1 on error
218*/
219DLLEXPORT int DLLCALL tjDestroy(tjhandle h);
220
221
222/*
223 char *tjGetErrorStr(void)
224
225 Returns a descriptive error message explaining why the last command failed
226*/
227DLLEXPORT char* DLLCALL tjGetErrorStr(void);
228
229#ifdef __cplusplus
230}
231#endif