Skip to content

Commit

Permalink
"DCT coefficient out of range" fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakurdyukov authored Aug 18, 2023
1 parent 6b83337 commit 87accb6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions quantsmooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,29 @@ JPEGQS_ATTR int QS_NAME(j_decompress_ptr srcinfo, jvirt_barray_ptr *coef_arrays,
#endif
} // iter

// fix a rare JERR_BAD_DCT_COEF ("DCT coefficient out of range") error
// it doesn't take much time
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)
#endif
for (blk_y = 0; blk_y < comp_height; blk_y++) {
JDIMENSION blk_x;
JBLOCKARRAY buffer = (*srcinfo->mem->access_virt_barray)
((j_common_ptr)srcinfo, coef_arrays[ci], blk_y, 1, TRUE);

for (blk_x = 0; blk_x < comp_width; blk_x++) {
JCOEFPTR coef = buffer[0][blk_x]; int i;
for (i = 0; i < DCTSIZE2; i++) {
// MAX_COEF_BITS = BITS_IN_JSAMPLE + 2
int lim = (4 << BITS_IN_JSAMPLE) - 1;
int a = coef[i];
if (a > lim) a = lim;
if (a < -lim) a = -lim;
coef[i] = a;
}
}
}

if (!stop && image1) {
JSAMPLE *mem; int st, w1, h1, h2, ws, hs, ww, hh;
compptr = srcinfo->comp_info;
Expand Down

0 comments on commit 87accb6

Please sign in to comment.