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