#ifndef __TURBOJPEG_H__
#define __TURBOJPEG_H__
#include <stddef.h>
#if defined(_WIN32) && defined(DLLDEFINE)
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#define DLLCALL
#define TJ_NUMINIT 3
enum TJINIT {
TJINIT_COMPRESS,
TJINIT_DECOMPRESS,
TJINIT_TRANSFORM
};
#define TJ_NUMSAMP 7
enum TJSAMP {
TJSAMP_444,
TJSAMP_422,
TJSAMP_420,
TJSAMP_GRAY,
TJSAMP_440,
TJSAMP_411,
TJSAMP_441,
TJSAMP_UNKNOWN = -1
};
static const int tjMCUWidth[TJ_NUMSAMP] = { 8, 16, 16, 8, 8, 32, 8 };
static const int tjMCUHeight[TJ_NUMSAMP] = { 8, 8, 16, 8, 16, 8, 32 };
#define TJ_NUMPF 12
enum TJPF {
TJPF_RGB,
TJPF_BGR,
TJPF_RGBX,
TJPF_BGRX,
TJPF_XBGR,
TJPF_XRGB,
TJPF_GRAY,
TJPF_RGBA,
TJPF_BGRA,
TJPF_ABGR,
TJPF_ARGB,
TJPF_CMYK,
TJPF_UNKNOWN = -1
};
static const int tjRedOffset[TJ_NUMPF] = {
0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
};
static const int tjGreenOffset[TJ_NUMPF] = {
1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
};
static const int tjBlueOffset[TJ_NUMPF] = {
2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
};
static const int tjAlphaOffset[TJ_NUMPF] = {
-1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
};
static const int tjPixelSize[TJ_NUMPF] = {
3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
};
#define TJ_NUMCS 5
enum TJCS {
TJCS_RGB,
TJCS_YCbCr,
TJCS_GRAY,
TJCS_CMYK,
TJCS_YCCK
};
enum TJPARAM {
TJPARAM_STOPONWARNING,
TJPARAM_BOTTOMUP,
TJPARAM_NOREALLOC,
TJPARAM_QUALITY,
TJPARAM_SUBSAMP,
TJPARAM_JPEGWIDTH,
TJPARAM_JPEGHEIGHT,
TJPARAM_PRECISION,
TJPARAM_COLORSPACE,
TJPARAM_FASTUPSAMPLE,
TJPARAM_FASTDCT,
TJPARAM_OPTIMIZE,
TJPARAM_PROGRESSIVE,
TJPARAM_SCANLIMIT,
TJPARAM_ARITHMETIC,
TJPARAM_LOSSLESS,
TJPARAM_LOSSLESSPSV,
TJPARAM_LOSSLESSPT,
TJPARAM_RESTARTBLOCKS,
TJPARAM_RESTARTROWS,
TJPARAM_XDENSITY,
TJPARAM_YDENSITY,
TJPARAM_DENSITYUNITS,
TJPARAM_MAXMEMORY,
TJPARAM_MAXPIXELS,
TJPARAM_SAVEMARKERS
};
#define TJ_NUMERR 2
enum TJERR {
TJERR_WARNING,
TJERR_FATAL
};
#define TJ_NUMXOP 8
enum TJXOP {
TJXOP_NONE,
TJXOP_HFLIP,
TJXOP_VFLIP,
TJXOP_TRANSPOSE,
TJXOP_TRANSVERSE,
TJXOP_ROT90,
TJXOP_ROT180,
TJXOP_ROT270
};
#define TJXOPT_PERFECT (1 << 0)
#define TJXOPT_TRIM (1 << 1)
#define TJXOPT_CROP (1 << 2)
#define TJXOPT_GRAY (1 << 3)
#define TJXOPT_NOOUTPUT (1 << 4)
#define TJXOPT_PROGRESSIVE (1 << 5)
#define TJXOPT_COPYNONE (1 << 6)
#define TJXOPT_ARITHMETIC (1 << 7)
#define TJXOPT_OPTIMIZE (1 << 8)
typedef struct {
int num;
int denom;
} tjscalingfactor;
typedef struct {
int x;
int y;
int w;
int h;
} tjregion;
static const tjregion TJUNCROPPED = { 0, 0, 0, 0 };
typedef struct tjtransform {
tjregion r;
int op;
int options;
void *data;
int (*customFilter) (short *coeffs, tjregion arrayRegion,
tjregion planeRegion, int componentID, int transformID,
struct tjtransform *transform);
} tjtransform;
typedef void *tjhandle;
#define TJSCALED(dimension, scalingFactor) \
(((dimension) * scalingFactor.num + scalingFactor.denom - 1) / \
scalingFactor.denom)
static const tjscalingfactor TJUNSCALED = { 1, 1 };
#ifdef __cplusplus
extern "C" {
#endif
DLLEXPORT tjhandle tj3Init(int initType);
DLLEXPORT void tj3Destroy(tjhandle handle);
DLLEXPORT char *tj3GetErrorStr(tjhandle handle);
DLLEXPORT int tj3GetErrorCode(tjhandle handle);
DLLEXPORT int tj3Set(tjhandle handle, int param, int value);
DLLEXPORT int tj3Get(tjhandle handle, int param);
DLLEXPORT void *tj3Alloc(size_t bytes);
DLLEXPORT void tj3Free(void *buffer);
DLLEXPORT size_t tj3JPEGBufSize(int width, int height, int jpegSubsamp);
DLLEXPORT size_t tj3YUVBufSize(int width, int align, int height, int subsamp);
DLLEXPORT size_t tj3YUVPlaneSize(int componentID, int width, int stride,
int height, int subsamp);
DLLEXPORT int tj3YUVPlaneWidth(int componentID, int width, int subsamp);
DLLEXPORT int tj3YUVPlaneHeight(int componentID, int height, int subsamp);
DLLEXPORT int tj3SetICCProfile(tjhandle handle, unsigned char *iccBuf,
size_t iccSize);
DLLEXPORT int tj3Compress8(tjhandle handle, const unsigned char *srcBuf,
int width, int pitch, int height, int pixelFormat,
unsigned char **jpegBuf, size_t *jpegSize);
DLLEXPORT int tj3Compress12(tjhandle handle, const short *srcBuf, int width,
int pitch, int height, int pixelFormat,
unsigned char **jpegBuf, size_t *jpegSize);
DLLEXPORT int tj3Compress16(tjhandle handle, const unsigned short *srcBuf,
int width, int pitch, int height, int pixelFormat,
unsigned char **jpegBuf, size_t *jpegSize);
DLLEXPORT int tj3CompressFromYUVPlanes8(tjhandle handle,
const unsigned char * const *srcPlanes,
int width, const int *strides,
int height, unsigned char **jpegBuf,
size_t *jpegSize);
DLLEXPORT int tj3CompressFromYUV8(tjhandle handle,
const unsigned char *srcBuf, int width,
int align, int height,
unsigned char **jpegBuf, size_t *jpegSize);
DLLEXPORT int tj3EncodeYUVPlanes8(tjhandle handle, const unsigned char *srcBuf,
int width, int pitch, int height,
int pixelFormat, unsigned char **dstPlanes,
int *strides);
DLLEXPORT int tj3EncodeYUV8(tjhandle handle, const unsigned char *srcBuf,
int width, int pitch, int height, int pixelFormat,
unsigned char *dstBuf, int align);
DLLEXPORT int tj3DecompressHeader(tjhandle handle,
const unsigned char *jpegBuf,
size_t jpegSize);
DLLEXPORT int tj3GetICCProfile(tjhandle handle, unsigned char **iccBuf,
size_t *iccSize);
DLLEXPORT tjscalingfactor *tj3GetScalingFactors(int *numScalingFactors);
DLLEXPORT int tj3SetScalingFactor(tjhandle handle,
tjscalingfactor scalingFactor);
DLLEXPORT int tj3SetCroppingRegion(tjhandle handle, tjregion croppingRegion);
DLLEXPORT int tj3Decompress8(tjhandle handle, const unsigned char *jpegBuf,
size_t jpegSize, unsigned char *dstBuf, int pitch,
int pixelFormat);
DLLEXPORT int tj3Decompress12(tjhandle handle, const unsigned char *jpegBuf,
size_t jpegSize, short *dstBuf, int pitch,
int pixelFormat);
DLLEXPORT int tj3Decompress16(tjhandle handle, const unsigned char *jpegBuf,
size_t jpegSize, unsigned short *dstBuf,
int pitch, int pixelFormat);
DLLEXPORT int tj3DecompressToYUVPlanes8(tjhandle handle,
const unsigned char *jpegBuf,
size_t jpegSize,
unsigned char **dstPlanes,
int *strides);
DLLEXPORT int tj3DecompressToYUV8(tjhandle handle,
const unsigned char *jpegBuf,
size_t jpegSize,
unsigned char *dstBuf, int align);
DLLEXPORT int tj3DecodeYUVPlanes8(tjhandle handle,
const unsigned char * const *srcPlanes,
const int *strides, unsigned char *dstBuf,
int width, int pitch, int height,
int pixelFormat);
DLLEXPORT int tj3DecodeYUV8(tjhandle handle, const unsigned char *srcBuf,
int align, unsigned char *dstBuf, int width,
int pitch, int height, int pixelFormat);
DLLEXPORT size_t tj3TransformBufSize(tjhandle handle,
const tjtransform *transform);
DLLEXPORT int tj3Transform(tjhandle handle, const unsigned char *jpegBuf,
size_t jpegSize, int n, unsigned char **dstBufs,
size_t *dstSizes, const tjtransform *transforms);
DLLEXPORT unsigned char *tj3LoadImage8(tjhandle handle, const char *filename,
int *width, int align, int *height,
int *pixelFormat);
DLLEXPORT short *tj3LoadImage12(tjhandle handle, const char *filename,
int *width, int align, int *height,
int *pixelFormat);
DLLEXPORT unsigned short *tj3LoadImage16(tjhandle handle, const char *filename,
int *width, int align, int *height,
int *pixelFormat);
DLLEXPORT int tj3SaveImage8(tjhandle handle, const char *filename,
const unsigned char *buffer, int width, int pitch,
int height, int pixelFormat);
DLLEXPORT int tj3SaveImage12(tjhandle handle, const char *filename,
const short *buffer, int width, int pitch,
int height, int pixelFormat);
DLLEXPORT int tj3SaveImage16(tjhandle handle, const char *filename,
const unsigned short *buffer, int width,
int pitch, int height, int pixelFormat);
#define NUMSUBOPT TJ_NUMSAMP
#define TJ_444 TJSAMP_444
#define TJ_422 TJSAMP_422
#define TJ_420 TJSAMP_420
#define TJ_411 TJSAMP_420
#define TJ_GRAYSCALE TJSAMP_GRAY
#define TJ_BGR 1
#define TJ_BOTTOMUP TJFLAG_BOTTOMUP
#define TJ_FORCEMMX TJFLAG_FORCEMMX
#define TJ_FORCESSE TJFLAG_FORCESSE
#define TJ_FORCESSE2 TJFLAG_FORCESSE2
#define TJ_ALPHAFIRST 64
#define TJ_FORCESSE3 TJFLAG_FORCESSE3
#define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE
#define TJPAD(width) (((width) + 3) & (~3))
DLLEXPORT unsigned long TJBUFSIZE(int width, int height);
DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width,
int pitch, int height, int pixelSize,
unsigned char *dstBuf, unsigned long *compressedSize,
int jpegSubsamp, int jpegQual, int flags);
DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, unsigned char *dstBuf,
int width, int pitch, int height, int pixelSize,
int flags);
DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, int *width,
int *height);
DLLEXPORT int tjDestroy(tjhandle handle);
DLLEXPORT char *tjGetErrorStr(void);
DLLEXPORT tjhandle tjInitCompress(void);
DLLEXPORT tjhandle tjInitDecompress(void);
#define TJ_YUV 512
DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int jpegSubsamp);
DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, int *width,
int *height, int *jpegSubsamp);
DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, unsigned char *dstBuf,
int flags);
DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width,
int pitch, int height, int pixelSize,
unsigned char *dstBuf, int subsamp, int flags);
#define TJFLAG_BOTTOMUP 2
#define TJFLAG_FORCEMMX 8
#define TJFLAG_FORCESSE 16
#define TJFLAG_FORCESSE2 32
#define TJFLAG_FORCESSE3 128
#define TJFLAG_FASTUPSAMPLE 256
#define TJFLAG_NOREALLOC 1024
DLLEXPORT unsigned char *tjAlloc(int bytes);
DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp);
DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp);
DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf,
int width, int pitch, int height, int pixelFormat,
unsigned char **jpegBuf, unsigned long *jpegSize,
int jpegSubsamp, int jpegQual, int flags);
DLLEXPORT int tjDecompress2(tjhandle handle, const unsigned char *jpegBuf,
unsigned long jpegSize, unsigned char *dstBuf,
int width, int pitch, int height, int pixelFormat,
int flags);
DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width,
int pitch, int height, int pixelFormat,
unsigned char *dstBuf, int subsamp, int flags);
DLLEXPORT void tjFree(unsigned char *buffer);
DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors);
DLLEXPORT tjhandle tjInitTransform(void);
DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
unsigned long jpegSize, int n,
unsigned char **dstBufs, unsigned long *dstSizes,
tjtransform *transforms, int flags);
#define TJFLAG_FASTDCT 2048
#define TJFLAG_ACCURATEDCT 4096
DLLEXPORT unsigned long tjBufSizeYUV2(int width, int align, int height,
int subsamp);
DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf,
int width, int align, int height, int subsamp,
unsigned char **jpegBuf,
unsigned long *jpegSize, int jpegQual,
int flags);
DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle,
const unsigned char **srcPlanes,
int width, const int *strides,
int height, int subsamp,
unsigned char **jpegBuf,
unsigned long *jpegSize, int jpegQual,
int flags);
DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
int align, int subsamp, unsigned char *dstBuf,
int width, int pitch, int height, int pixelFormat,
int flags);
DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle,
const unsigned char **srcPlanes,
const int *strides, int subsamp,
unsigned char *dstBuf, int width, int pitch,
int height, int pixelFormat, int flags);
DLLEXPORT int tjDecompressHeader3(tjhandle handle,
const unsigned char *jpegBuf,
unsigned long jpegSize, int *width,
int *height, int *jpegSubsamp,
int *jpegColorspace);
DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf,
unsigned long jpegSize, unsigned char *dstBuf,
int width, int align, int height, int flags);
DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle,
const unsigned char *jpegBuf,
unsigned long jpegSize,
unsigned char **dstPlanes, int width,
int *strides, int height, int flags);
DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf,
int width, int pitch, int height, int pixelFormat,
unsigned char *dstBuf, int align, int subsamp,
int flags);
DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf,
int width, int pitch, int height,
int pixelFormat, unsigned char **dstPlanes,
int *strides, int subsamp, int flags);
DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp);
DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride,
int height, int subsamp);
DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp);
#define TJFLAG_STOPONWARNING 8192
#define TJFLAG_PROGRESSIVE 16384
DLLEXPORT int tjGetErrorCode(tjhandle handle);
DLLEXPORT char *tjGetErrorStr2(tjhandle handle);
DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
int align, int *height, int *pixelFormat,
int flags);
DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
int width, int pitch, int height, int pixelFormat,
int flags);
#define TJFLAG_LIMITSCANS 32768
#ifdef __cplusplus
}
#endif
#endif