blob: 5f99c07697a7019199ab713b4af490ebefee4b6c [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 */
DRC8f0d62c2010-02-22 08:35:19 +000030#define TJ_BGR 1
31 /* The components of each pixel in the source/destination bitmap are stored
32 in B,G,R order, not R,G,B */
33#define TJ_BOTTOMUP 2
34 /* The source/destination bitmap is stored in bottom-up (Windows, OpenGL)
35 order, not top-down (X11) order */
36#define TJ_FORCEMMX 8
37 /* Turn off CPU auto-detection and force TurboJPEG to use MMX code
38 (IPP and 32-bit libjpeg-turbo versions only) */
39#define TJ_FORCESSE 16
40 /* Turn off CPU auto-detection and force TurboJPEG to use SSE code
41 (32-bit IPP and 32-bit libjpeg-turbo versions only) */
42#define TJ_FORCESSE2 32
43 /* Turn off CPU auto-detection and force TurboJPEG to use SSE2 code
44 (32-bit IPP and 32-bit libjpeg-turbo versions only) */
45#define TJ_ALPHAFIRST 64
46 /* If the source/destination bitmap is 32 bpp, assume that each pixel is
47 ARGB/XRGB (or ABGR/XBGR if TJ_BGR is also specified) */
48#define TJ_FORCESSE3 128
49 /* Turn off CPU auto-detection and force TurboJPEG to use SSE3 code
50 (64-bit IPP version only) */
51#define TJ_FASTUPSAMPLE 256
52 /* Use fast, inaccurate 4:2:2 and 4:2:0 YUV upsampling routines
53 (libjpeg version only) */
DRC2e7b76b2009-04-03 12:04:24 +000054typedef void* tjhandle;
55
56#define TJPAD(p) (((p)+3)&(~3))
57#ifndef max
58 #define max(a,b) ((a)>(b)?(a):(b))
59#endif
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/* API follows */
66
67
68/*
69 tjhandle tjInitCompress(void)
70
71 Creates a new JPEG compressor instance, allocates memory for the structures,
72 and returns a handle to the instance. Most applications will only
73 need to call this once at the beginning of the program or once for each
74 concurrent thread. Don't try to create a new instance every time you
75 compress an image, because this will cause performance to suffer.
76
77 RETURNS: NULL on error
78*/
79DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
80
81
82/*
83 int tjCompress(tjhandle j,
84 unsigned char *srcbuf, int width, int pitch, int height, int pixelsize,
85 unsigned char *dstbuf, unsigned long *size,
86 int jpegsubsamp, int jpegqual, int flags)
87
88 [INPUT] j = instance handle previously returned from a call to
89 tjInitCompress()
90 [INPUT] srcbuf = pointer to user-allocated image buffer containing pixels in
91 RGB(A) or BGR(A) form
92 [INPUT] width = width (in pixels) of the source image
93 [INPUT] pitch = bytes per line of the source image (width*pixelsize if the
94 bitmap is unpadded, else TJPAD(width*pixelsize) if each line of the bitmap
95 is padded to the nearest 32-bit boundary, such as is the case for Windows
96 bitmaps. You can also be clever and use this parameter to skip lines, etc.,
97 as long as the pitch is greater than 0.)
98 [INPUT] height = height (in pixels) of the source image
99 [INPUT] pixelsize = size (in bytes) of each pixel in the source image
100 RGBA and BGRA: 4, RGB and BGR: 3
101 [INPUT] dstbuf = pointer to user-allocated image buffer which will receive
102 the JPEG image. Use the macro TJBUFSIZE(width, height) to determine
103 the appropriate size for this buffer based on the image width and height.
104 [OUTPUT] size = pointer to unsigned long which receives the size (in bytes)
105 of the compressed image
DRC61e51f92009-04-05 21:53:20 +0000106 [INPUT] jpegsubsamp = Specifies either 4:2:0, 4:2:2, or 4:4:4 subsampling.
DRC2e7b76b2009-04-03 12:04:24 +0000107 When the image is converted from the RGB to YCbCr colorspace as part of the
108 JPEG compression process, every other Cb and Cr (chrominance) pixel can be
109 discarded to produce a smaller image with little perceptible loss of
110 image clarity (the human eye is more sensitive to small changes in
111 brightness than small changes in color.)
112
DRC61e51f92009-04-05 21:53:20 +0000113 TJ_420: 4:2:0 subsampling. Discards every other Cb, Cr pixel in both
DRC2e7b76b2009-04-03 12:04:24 +0000114 horizontal and vertical directions.
115 TJ_422: 4:2:2 subsampling. Discards every other Cb, Cr pixel only in
116 the horizontal direction.
117 TJ_444: no subsampling.
118 TJ_GRAYSCALE: Generate grayscale JPEG image
119
120 [INPUT] jpegqual = JPEG quality (an integer between 0 and 100 inclusive.)
DRC8f0d62c2010-02-22 08:35:19 +0000121 [INPUT] flags = the bitwise OR of one or more of the flags described in the
122 "Flags" section above.
DRC2e7b76b2009-04-03 12:04:24 +0000123
124 RETURNS: 0 on success, -1 on error
125*/
126DLLEXPORT int DLLCALL tjCompress(tjhandle j,
127 unsigned char *srcbuf, int width, int pitch, int height, int pixelsize,
128 unsigned char *dstbuf, unsigned long *size,
129 int jpegsubsamp, int jpegqual, int flags);
130
131DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height);
132
133/*
134 tjhandle tjInitDecompress(void)
135
136 Creates a new JPEG decompressor instance, allocates memory for the
137 structures, and returns a handle to the instance. Most applications will
138 only need to call this once at the beginning of the program or once for each
139 concurrent thread. Don't try to create a new instance every time you
140 decompress an image, because this will cause performance to suffer.
141
142 RETURNS: NULL on error
143*/
144DLLEXPORT tjhandle DLLCALL tjInitDecompress(void);
145
146
147/*
148 int tjDecompressHeader(tjhandle j,
149 unsigned char *srcbuf, unsigned long size,
150 int *width, int *height)
151
152 [INPUT] j = instance handle previously returned from a call to
153 tjInitDecompress()
154 [INPUT] srcbuf = pointer to a user-allocated buffer containing the JPEG image
155 to decompress
156 [INPUT] size = size of the JPEG image buffer (in bytes)
157 [OUTPUT] width = width (in pixels) of the JPEG image
158 [OUTPUT] height = height (in pixels) of the JPEG image
159
160 RETURNS: 0 on success, -1 on error
161*/
162DLLEXPORT int DLLCALL tjDecompressHeader(tjhandle j,
163 unsigned char *srcbuf, unsigned long size,
164 int *width, int *height);
165
166
167/*
168 int tjDecompress(tjhandle j,
169 unsigned char *srcbuf, unsigned long size,
170 unsigned char *dstbuf, int width, int pitch, int height, int pixelsize,
171 int flags)
172
173 [INPUT] j = instance handle previously returned from a call to
174 tjInitDecompress()
175 [INPUT] srcbuf = pointer to a user-allocated buffer containing the JPEG image
176 to decompress
177 [INPUT] size = size of the JPEG image buffer (in bytes)
178 [INPUT] dstbuf = pointer to user-allocated image buffer which will receive
179 the bitmap image. This buffer should normally be pitch*height
180 bytes in size, although this pointer may also be used to decompress into
181 a specific region of a larger buffer.
182 [INPUT] width = width (in pixels) of the destination image
183 [INPUT] pitch = bytes per line of the destination image (width*pixelsize if the
184 bitmap is unpadded, else TJPAD(width*pixelsize) if each line of the bitmap
185 is padded to the nearest 32-bit boundary, such as is the case for Windows
186 bitmaps. You can also be clever and use this parameter to skip lines, etc.,
187 as long as the pitch is greater than 0.)
188 [INPUT] height = height (in pixels) of the destination image
189 [INPUT] pixelsize = size (in bytes) of each pixel in the destination image
190 RGBA/RGBx and BGRA/BGRx: 4, RGB and BGR: 3
DRC8f0d62c2010-02-22 08:35:19 +0000191 [INPUT] flags = the bitwise OR of one or more of the flags described in the
192 "Flags" section above.
DRC2e7b76b2009-04-03 12:04:24 +0000193
194 RETURNS: 0 on success, -1 on error
195*/
196DLLEXPORT int DLLCALL tjDecompress(tjhandle j,
197 unsigned char *srcbuf, unsigned long size,
198 unsigned char *dstbuf, int width, int pitch, int height, int pixelsize,
199 int flags);
200
201
202/*
203 int tjDestroy(tjhandle h)
204
205 Frees structures associated with a compression or decompression instance
206
207 [INPUT] h = instance handle (returned from a previous call to
208 tjInitCompress() or tjInitDecompress()
209
210 RETURNS: 0 on success, -1 on error
211*/
212DLLEXPORT int DLLCALL tjDestroy(tjhandle h);
213
214
215/*
216 char *tjGetErrorStr(void)
217
218 Returns a descriptive error message explaining why the last command failed
219*/
220DLLEXPORT char* DLLCALL tjGetErrorStr(void);
221
222#ifdef __cplusplus
223}
224#endif