#ifdef _MSC_VER
#define _CRT_SECURE_NO_DEPRECATE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include "tjutil.h"
#include "turbojpeg.h"
#include "md5/md5.h"
#include "cmyk.h"
#ifdef _WIN32
#include <time.h>
#define random …
#else
#include <unistd.h>
#endif
#ifndef GTEST
static void usage(char *progName)
{
printf("\nUSAGE: %s [options]\n\n", progName);
printf("Options:\n");
printf("-yuv = test YUV encoding/compression/decompression/decoding\n");
printf("-noyuvpad = do not pad each row in each Y, U, and V plane to the nearest\n");
printf(" multiple of 4 bytes\n");
printf("-alloc = test automatic JPEG buffer allocation\n");
printf("-bmp = test packed-pixel image I/O\n");
exit(1);
}
#endif
#define THROW_TJ() …
#define TRY_TJ(f) …
#define THROW(m) …
#define THROW_MD5(filename, md5sum, ref) …
static const char *subNameLong[TJ_NUMSAMP] = …;
static const char *subName[TJ_NUMSAMP] = …;
static const char *pixFormatStr[TJ_NUMPF] = …;
static const int _3byteFormats[] = …;
static const int _4byteFormats[] = …;
static const int _onlyGray[] = …;
static const int _onlyRGB[] = …;
static int doYUV = …, alloc = …, yuvAlign = …;
static int exitStatus = …;
#define BAILOUT() …
static const size_t filePathSize = …;
static void initBuf(unsigned char *buf, int w, int h, int pf, int flags)
{ … }
#define CHECKVAL(v, cv) …
#define CHECKVAL0(v) …
#define CHECKVAL255(v) …
static int checkBuf(unsigned char *buf, int w, int h, int pf, int subsamp,
tjscalingfactor sf, int flags)
{ … }
#define PAD(v, p) …
static int checkBufYUV(unsigned char *buf, int w, int h, int subsamp,
tjscalingfactor sf)
{ … }
static void writeJPEG(unsigned char *jpegBuf, unsigned long jpegSize,
char *filename)
{ … }
static void compTest(tjhandle handle, unsigned char **dstBuf,
unsigned long *dstSize, int w, int h, int pf,
char *basename, int subsamp, int jpegQual, int flags)
{ … }
static void _decompTest(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, int w, int h, int pf,
char *basename, int subsamp, int flags,
tjscalingfactor sf)
{ … }
static void decompTest(tjhandle handle, unsigned char *jpegBuf,
unsigned long jpegSize, int w, int h, int pf,
char *basename, int subsamp, int flags)
{ … }
static void doTest(int w, int h, const int *formats, int nformats, int subsamp,
char *basename)
{ … }
#if SIZEOF_SIZE_T == 8
#define CHECKSIZE(function) …
#else
#define CHECKSIZE …
#endif
#define CHECKSIZEINT(function) …
#ifndef GTEST
static void overflowTest(void)
{
unsigned long size;
int intsize;
size = tjBufSize(26755, 26755, TJSAMP_444);
CHECKSIZE(tjBufSize());
size = TJBUFSIZE(26755, 26755);
CHECKSIZE(TJBUFSIZE());
size = tjBufSizeYUV2(37838, 1, 37838, TJSAMP_444);
CHECKSIZE(tjBufSizeYUV2());
size = tjBufSizeYUV2(37837, 3, 37837, TJSAMP_444);
CHECKSIZE(tjBufSizeYUV2());
size = tjBufSizeYUV2(37837, -1, 37837, TJSAMP_444);
CHECKSIZE(tjBufSizeYUV2());
size = TJBUFSIZEYUV(37838, 37838, TJSAMP_444);
CHECKSIZE(TJBUFSIZEYUV());
size = tjBufSizeYUV(37838, 37838, TJSAMP_444);
CHECKSIZE(tjBufSizeYUV());
size = tjPlaneSizeYUV(0, 65536, 0, 65536, TJSAMP_444);
CHECKSIZE(tjPlaneSizeYUV());
intsize = tjPlaneWidth(0, INT_MAX, TJSAMP_420);
CHECKSIZEINT(tjPlaneWidth());
intsize = tjPlaneHeight(0, INT_MAX, TJSAMP_420);
CHECKSIZEINT(tjPlaneHeight());
bailout:
return;
}
#endif
static void bufSizeTest(void)
{ … }
static void initBitmap(unsigned char *buf, int width, int pitch, int height,
int pf, int flags)
{ … }
static int cmpBitmap(unsigned char *buf, int width, int pitch, int height,
int pf, int flags, int gray2rgb)
{ … }
static int doBmpTest(const char *ext, int width, int align, int height, int pf,
int flags)
{ … }
static int bmpTest(void)
{ … }
#ifdef GTEST
static void initTJUnitTest(int yuv, int noyuvpad, int autoalloc)
{ … }
int testBmp(int yuv, int noyuvpad, int autoalloc)
{ … }
int testThreeByte444(int yuv, int noyuvpad, int autoalloc)
{ … }
int testFourByte444(int yuv, int noyuvpad, int autoalloc)
{ … }
int testThreeByte422(int yuv, int noyuvpad, int autoalloc)
{ … }
int testFourByte422(int yuv, int noyuvpad, int autoalloc)
{ … }
int testThreeByte420(int yuv, int noyuvpad, int autoalloc)
{ … }
int testFourByte420(int yuv, int noyuvpad, int autoalloc)
{ … }
int testThreeByte440(int yuv, int noyuvpad, int autoalloc)
{ … }
int testFourByte440(int yuv, int noyuvpad, int autoalloc)
{ … }
int testThreeByte411(int yuv, int noyuvpad, int autoalloc)
{ … }
int testFourByte411(int yuv, int noyuvpad, int autoalloc)
{ … }
int testOnlyGray(int yuv, int noyuvpad, int autoalloc)
{ … }
int testThreeByteGray(int yuv, int noyuvpad, int autoalloc)
{ … }
int testFourByteGray(int yuv, int noyuvpad, int autoalloc)
{ … }
int testBufSize(int yuv, int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyRGB444(int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyRGB422(int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyRGB420(int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyRGB440(int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyRGB411(int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyRGBGray(int noyuvpad, int autoalloc)
{ … }
int testYUVOnlyGrayGray(int noyuvpad, int autoalloc)
{ … }
#else
int main(int argc, char *argv[])
{
int i, num4bf = 5;
#ifdef _WIN32
srand((unsigned int)time(NULL));
#endif
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (!strcasecmp(argv[i], "-yuv")) doYUV = 1;
else if (!strcasecmp(argv[i], "-noyuvpad")) yuvAlign = 1;
else if (!strcasecmp(argv[i], "-alloc")) alloc = 1;
else if (!strcasecmp(argv[i], "-bmp")) return bmpTest();
else usage(argv[0]);
}
}
if (alloc) printf("Testing automatic buffer allocation\n");
if (doYUV) num4bf = 4;
overflowTest();
doTest(35, 39, _3byteFormats, 2, TJSAMP_444, "test");
doTest(39, 41, _4byteFormats, num4bf, TJSAMP_444, "test");
doTest(41, 35, _3byteFormats, 2, TJSAMP_422, "test");
doTest(35, 39, _4byteFormats, num4bf, TJSAMP_422, "test");
doTest(39, 41, _3byteFormats, 2, TJSAMP_420, "test");
doTest(41, 35, _4byteFormats, num4bf, TJSAMP_420, "test");
doTest(35, 39, _3byteFormats, 2, TJSAMP_440, "test");
doTest(39, 41, _4byteFormats, num4bf, TJSAMP_440, "test");
doTest(41, 35, _3byteFormats, 2, TJSAMP_411, "test");
doTest(35, 39, _4byteFormats, num4bf, TJSAMP_411, "test");
doTest(39, 41, _onlyGray, 1, TJSAMP_GRAY, "test");
doTest(41, 35, _3byteFormats, 2, TJSAMP_GRAY, "test");
doTest(35, 39, _4byteFormats, 4, TJSAMP_GRAY, "test");
bufSizeTest();
if (doYUV) {
printf("\n--------------------\n\n");
doTest(48, 48, _onlyRGB, 1, TJSAMP_444, "test_yuv0");
doTest(48, 48, _onlyRGB, 1, TJSAMP_422, "test_yuv0");
doTest(48, 48, _onlyRGB, 1, TJSAMP_420, "test_yuv0");
doTest(48, 48, _onlyRGB, 1, TJSAMP_440, "test_yuv0");
doTest(48, 48, _onlyRGB, 1, TJSAMP_411, "test_yuv0");
doTest(48, 48, _onlyRGB, 1, TJSAMP_GRAY, "test_yuv0");
doTest(48, 48, _onlyGray, 1, TJSAMP_GRAY, "test_yuv0");
}
return exitStatus;
}
#endif