in turbojpeg.c [670:799]
DLLEXPORT int tj3Set(tjhandle handle, int param, int value)
{
static const char FUNCTION_NAME[] = "tj3Set";
int retval = 0;
GET_TJINSTANCE(handle, -1);
switch (param) {
case TJPARAM_STOPONWARNING:
SET_BOOL_PARAM(jerr.stopOnWarning);
break;
case TJPARAM_BOTTOMUP:
SET_BOOL_PARAM(bottomUp);
break;
case TJPARAM_NOREALLOC:
if (!(this->init & COMPRESS))
THROW("TJPARAM_NOREALLOC is not applicable to decompression instances.");
SET_BOOL_PARAM(noRealloc);
break;
case TJPARAM_QUALITY:
if (!(this->init & COMPRESS))
THROW("TJPARAM_QUALITY is not applicable to decompression instances.");
SET_PARAM(quality, 1, 100);
break;
case TJPARAM_SUBSAMP:
SET_PARAM(subsamp, 0, TJ_NUMSAMP - 1);
break;
case TJPARAM_JPEGWIDTH:
if (!(this->init & DECOMPRESS))
THROW("TJPARAM_JPEGWIDTH is not applicable to compression instances.");
THROW("TJPARAM_JPEGWIDTH is read-only in decompression instances.");
break;
case TJPARAM_JPEGHEIGHT:
if (!(this->init & DECOMPRESS))
THROW("TJPARAM_JPEGHEIGHT is not applicable to compression instances.");
THROW("TJPARAM_JPEGHEIGHT is read-only in decompression instances.");
break;
case TJPARAM_PRECISION:
if (!(this->init & DECOMPRESS))
THROW("TJPARAM_PRECISION is not applicable to compression instances.");
THROW("TJPARAM_PRECISION is read-only in decompression instances.");
break;
case TJPARAM_COLORSPACE:
if (!(this->init & COMPRESS))
THROW("TJPARAM_COLORSPACE is read-only in decompression instances.");
SET_PARAM(colorspace, 0, TJ_NUMCS - 1);
break;
case TJPARAM_FASTUPSAMPLE:
if (!(this->init & DECOMPRESS))
THROW("TJPARAM_FASTUPSAMPLE is not applicable to compression instances.");
SET_BOOL_PARAM(fastUpsample);
break;
case TJPARAM_FASTDCT:
SET_BOOL_PARAM(fastDCT);
break;
case TJPARAM_OPTIMIZE:
if (!(this->init & COMPRESS))
THROW("TJPARAM_OPTIMIZE is not applicable to decompression instances.");
SET_BOOL_PARAM(optimize);
break;
case TJPARAM_PROGRESSIVE:
if (!(this->init & COMPRESS))
THROW("TJPARAM_PROGRESSIVE is read-only in decompression instances.");
SET_BOOL_PARAM(progressive);
break;
case TJPARAM_SCANLIMIT:
if (!(this->init & DECOMPRESS))
THROW("TJPARAM_SCANLIMIT is not applicable to compression instances.");
SET_PARAM(scanLimit, 0, -1);
break;
case TJPARAM_ARITHMETIC:
if (!(this->init & COMPRESS))
THROW("TJPARAM_ARITHMETIC is read-only in decompression instances.");
SET_BOOL_PARAM(arithmetic);
break;
case TJPARAM_LOSSLESS:
if (!(this->init & COMPRESS))
THROW("TJPARAM_LOSSLESS is read-only in decompression instances.");
SET_BOOL_PARAM(lossless);
break;
case TJPARAM_LOSSLESSPSV:
if (!(this->init & COMPRESS))
THROW("TJPARAM_LOSSLESSPSV is read-only in decompression instances.");
SET_PARAM(losslessPSV, 1, 7);
break;
case TJPARAM_LOSSLESSPT:
if (!(this->init & COMPRESS))
THROW("TJPARAM_LOSSLESSPT is read-only in decompression instances.");
SET_PARAM(losslessPt, 0, 15);
break;
case TJPARAM_RESTARTBLOCKS:
if (!(this->init & COMPRESS))
THROW("TJPARAM_RESTARTBLOCKS is not applicable to decompression instances.");
SET_PARAM(restartIntervalBlocks, 0, 65535);
if (value != 0) this->restartIntervalRows = 0;
break;
case TJPARAM_RESTARTROWS:
if (!(this->init & COMPRESS))
THROW("TJPARAM_RESTARTROWS is not applicable to decompression instances.");
SET_PARAM(restartIntervalRows, 0, 65535);
if (value != 0) this->restartIntervalBlocks = 0;
break;
case TJPARAM_XDENSITY:
if (!(this->init & COMPRESS))
THROW("TJPARAM_XDENSITY is read-only in decompression instances.");
SET_PARAM(xDensity, 1, 65535);
break;
case TJPARAM_YDENSITY:
if (!(this->init & COMPRESS))
THROW("TJPARAM_YDENSITY is read-only in decompression instances.");
SET_PARAM(yDensity, 1, 65535);
break;
case TJPARAM_DENSITYUNITS:
if (!(this->init & COMPRESS))
THROW("TJPARAM_DENSITYUNITS is read-only in decompression instances.");
SET_PARAM(densityUnits, 0, 2);
break;
case TJPARAM_MAXMEMORY:
SET_PARAM(maxMemory, 0, (int)(min(LONG_MAX / 1048576L, (long)INT_MAX)));
break;
case TJPARAM_MAXPIXELS:
SET_PARAM(maxPixels, 0, -1);
break;
default:
THROW("Invalid parameter");
}
bailout:
return retval;
}