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

View File

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