TurboJPEG: Clean up/repurpose THROWI() macro

We already had a use case for two integer arguments, and the new use
cases benefit from two integer arguments as well.
This commit is contained in:
DRC
2023-01-27 12:31:44 -06:00
parent 8c57aad0a3
commit 54f571f8fb
2 changed files with 23 additions and 19 deletions

View File

@@ -197,11 +197,13 @@ DLLEXPORT int GET_NAME(tj3Decompress, BITS_IN_JSAMPLE)
_jpeg_crop_scanline(dinfo, &crop_x, &crop_w);
if ((int)crop_x != this->croppingRegion.x)
THROWI("Unexplained mismatch between specified and actual (%d) cropping region left boundary",
(int)crop_x);
THROWI("Unexplained mismatch between specified (%d) and\n"
"actual (%d) cropping region left boundary",
this->croppingRegion.x, (int)crop_x);
if ((int)crop_w != this->croppingRegion.w)
THROWI("Unexplained mismatch between specified and actual (%d) cropping region width",
(int)crop_w);
THROWI("Unexplained mismatch between specified (%d) and\n"
"actual (%d) cropping region width",
this->croppingRegion.w, (int)crop_w);
}
#endif
@@ -232,8 +234,9 @@ DLLEXPORT int GET_NAME(tj3Decompress, BITS_IN_JSAMPLE)
JDIMENSION lines = _jpeg_skip_scanlines(dinfo, this->croppingRegion.y);
if ((int)lines != this->croppingRegion.y)
THROWI("Unexplained mismatch between specified and actual (%d) cropping region upper boundary",
(int)lines);
THROWI("Unexplained mismatch between specified (%d) and\n"
"actual (%d) cropping region upper boundary",
this->croppingRegion.y, (int)lines);
}
while ((int)dinfo->output_scanline <
this->croppingRegion.y + this->croppingRegion.h)
@@ -249,7 +252,9 @@ DLLEXPORT int GET_NAME(tj3Decompress, BITS_IN_JSAMPLE)
if (lines != dinfo->output_height - this->croppingRegion.y -
this->croppingRegion.h)
THROWI("Unexplained mismatch between specified and actual (%d) cropping region lower boundary",
THROWI("Unexplained mismatch between specified (%d) and\n"
"actual (%d) cropping region lower boundary",
this->croppingRegion.y + this->croppingRegion.h,
(int)(dinfo->output_height - lines));
}
} else

View File

@@ -249,11 +249,12 @@ static int cs2pf[JPEG_NUMCS] = {
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s", FUNCTION_NAME, m); \
this->isInstanceError = TRUE; THROWG(m, -1) \
}
#define THROWI(format, val) { \
#define THROWI(format, val1, val2) { \
SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): " format, FUNCTION_NAME, \
val); \
val1, val2); \
this->isInstanceError = TRUE; \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): " format, FUNCTION_NAME, val); \
SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): " format, FUNCTION_NAME, val1, \
val2); \
retval = -1; goto bailout; \
}
@@ -1911,7 +1912,9 @@ DLLEXPORT int tj3SetCroppingRegion(tjhandle handle, tjregion croppingRegion)
if (croppingRegion.x %
TJSCALED(tjMCUWidth[this->subsamp], this->scalingFactor) != 0)
THROWI("The left boundary of the cropping region is not divisible by the scaled MCU width (%d)",
THROWI("The left boundary of the cropping region (%d) is not\n"
"divisible by the scaled MCU width (%d)",
croppingRegion.x,
TJSCALED(tjMCUWidth[this->subsamp], this->scalingFactor));
if (croppingRegion.w == 0)
croppingRegion.w = scaledWidth - croppingRegion.x;
@@ -2685,14 +2688,10 @@ DLLEXPORT int tj3Transform(tjhandle handle, const unsigned char *jpegBuf,
if (this->subsamp == TJSAMP_UNKNOWN)
THROW("Could not determine subsampling level of JPEG image");
if ((t[i].r.x % tjMCUWidth[this->subsamp]) != 0 ||
(t[i].r.y % tjMCUHeight[this->subsamp]) != 0) {
SNPRINTF(this->errStr, JMSG_LENGTH_MAX,
"To crop this JPEG image, x must be a multiple of %d\n"
"and y must be a multiple of %d.\n",
tjMCUWidth[this->subsamp], tjMCUHeight[this->subsamp]);
this->isInstanceError = TRUE;
retval = -1; goto bailout;
}
(t[i].r.y % tjMCUHeight[this->subsamp]) != 0)
THROWI("To crop this JPEG image, x must be a multiple of %d\n"
"and y must be a multiple of %d.", tjMCUWidth[this->subsamp],
tjMCUHeight[this->subsamp]);
}
}