|
|
@ -122,6 +122,77 @@ av_cold void ff_ccitt_unpack_init(void) |
|
|
|
initialized = 1; |
|
|
|
initialized = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int decode_uncompressed(AVCodecContext *avctx, GetBitContext *gb, |
|
|
|
|
|
|
|
unsigned int *pix_left, int **runs, |
|
|
|
|
|
|
|
const int *runend, int *mode) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int eob = 0; |
|
|
|
|
|
|
|
int newmode; |
|
|
|
|
|
|
|
int saved_run = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
int cwi, k; |
|
|
|
|
|
|
|
int cw = 0; |
|
|
|
|
|
|
|
int codes[2]; |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
cwi = show_bits(gb, 11); |
|
|
|
|
|
|
|
if (!cwi) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid uncompressed codeword\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cwi = 10 - av_log2(cwi); |
|
|
|
|
|
|
|
skip_bits(gb, cwi + 1); |
|
|
|
|
|
|
|
if (cwi > 5) { |
|
|
|
|
|
|
|
newmode = get_bits1(gb); |
|
|
|
|
|
|
|
eob = 1; |
|
|
|
|
|
|
|
cwi -= 6; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cw += cwi; |
|
|
|
|
|
|
|
} while(cwi == 5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codes[0] = cw; |
|
|
|
|
|
|
|
codes[1] = !eob; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (k = 0; k < 2; k++) { |
|
|
|
|
|
|
|
if (codes[k]) { |
|
|
|
|
|
|
|
if (*mode == k) { |
|
|
|
|
|
|
|
*(*runs)++ = saved_run; |
|
|
|
|
|
|
|
if (*runs >= runend) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (*pix_left <= saved_run) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of bounds\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*pix_left -= saved_run; |
|
|
|
|
|
|
|
saved_run = 0; |
|
|
|
|
|
|
|
*mode = !*mode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saved_run += codes[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (!eob); |
|
|
|
|
|
|
|
*(*runs)++ = saved_run; |
|
|
|
|
|
|
|
if (*runs >= runend) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (*pix_left <= saved_run) { |
|
|
|
|
|
|
|
if (*pix_left == saved_run) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of boundsE\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*pix_left -= saved_run; |
|
|
|
|
|
|
|
saved_run = 0; |
|
|
|
|
|
|
|
*mode = !*mode; |
|
|
|
|
|
|
|
if (newmode != *mode) { //FIXME CHECK
|
|
|
|
|
|
|
|
*(*runs)++ = 0; |
|
|
|
|
|
|
|
*mode = newmode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb, |
|
|
|
static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb, |
|
|
|
unsigned int pix_left, int *runs, |
|
|
|
unsigned int pix_left, int *runs, |
|
|
@ -150,72 +221,13 @@ static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb, |
|
|
|
mode = !mode; |
|
|
|
mode = !mode; |
|
|
|
} else if ((int)t == -1) { |
|
|
|
} else if ((int)t == -1) { |
|
|
|
if (show_bits(gb, 12) == 15) { |
|
|
|
if (show_bits(gb, 12) == 15) { |
|
|
|
int eob = 0; |
|
|
|
int ret; |
|
|
|
int newmode; |
|
|
|
|
|
|
|
int saved_run = 0; |
|
|
|
|
|
|
|
skip_bits(gb, 12); |
|
|
|
skip_bits(gb, 12); |
|
|
|
|
|
|
|
ret = decode_uncompressed(avctx, gb, &pix_left, &runs, runend, &mode); |
|
|
|
do { |
|
|
|
if (ret < 0) { |
|
|
|
int cwi, k; |
|
|
|
return ret; |
|
|
|
int cw = 0; |
|
|
|
} else if (ret) |
|
|
|
int codes[2]; |
|
|
|
break; |
|
|
|
do { |
|
|
|
|
|
|
|
cwi = show_bits(gb, 11); |
|
|
|
|
|
|
|
if (!cwi) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid uncompressed codeword\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cwi = 10 - av_log2(cwi); |
|
|
|
|
|
|
|
skip_bits(gb, cwi + 1); |
|
|
|
|
|
|
|
if (cwi > 5) { |
|
|
|
|
|
|
|
newmode = get_bits1(gb); |
|
|
|
|
|
|
|
eob = 1; |
|
|
|
|
|
|
|
cwi -= 6; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cw += cwi; |
|
|
|
|
|
|
|
} while(cwi == 5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codes[0] = cw; |
|
|
|
|
|
|
|
codes[1] = !eob; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (k = 0; k < 2; k++) { |
|
|
|
|
|
|
|
if (codes[k]) { |
|
|
|
|
|
|
|
if (mode == k) { |
|
|
|
|
|
|
|
*runs++ = saved_run; |
|
|
|
|
|
|
|
if (runs >= runend) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pix_left <= saved_run) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of bounds\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pix_left -= saved_run; |
|
|
|
|
|
|
|
saved_run = 0; |
|
|
|
|
|
|
|
mode = !mode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saved_run += codes[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (!eob); |
|
|
|
|
|
|
|
*runs++ = saved_run; |
|
|
|
|
|
|
|
if (runs >= runend) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pix_left <= saved_run) { |
|
|
|
|
|
|
|
if (pix_left == saved_run) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of boundsE\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pix_left -= saved_run; |
|
|
|
|
|
|
|
saved_run = 0; |
|
|
|
|
|
|
|
mode = !mode; |
|
|
|
|
|
|
|
if (newmode != mode) { //FIXME CHECK
|
|
|
|
|
|
|
|
*runs++ = 0; |
|
|
|
|
|
|
|
mode = newmode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Incorrect code\n"); |
|
|
|
av_log(avctx, AV_LOG_ERROR, "Incorrect code\n"); |
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
return AVERROR_INVALIDDATA; |
|
|
@ -282,73 +294,19 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb, |
|
|
|
} else if (cmode == 9 || cmode == 10) { |
|
|
|
} else if (cmode == 9 || cmode == 10) { |
|
|
|
int xxx = get_bits(gb, 3); |
|
|
|
int xxx = get_bits(gb, 3); |
|
|
|
if (cmode == 9 && xxx == 7) { |
|
|
|
if (cmode == 9 && xxx == 7) { |
|
|
|
int eob = 0; |
|
|
|
int ret; |
|
|
|
int newmode; |
|
|
|
int pix_left = width - offs; |
|
|
|
|
|
|
|
|
|
|
|
if (saved_run) { |
|
|
|
if (saved_run) { |
|
|
|
av_log(avctx, AV_LOG_ERROR, "saved run %d on entering uncompressed mode\n", saved_run); |
|
|
|
av_log(avctx, AV_LOG_ERROR, "saved run %d on entering uncompressed mode\n", saved_run); |
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ret = decode_uncompressed(avctx, gb, &pix_left, &runs, runend, &mode); |
|
|
|
do { |
|
|
|
offs = width - pix_left; |
|
|
|
int cwi, k; |
|
|
|
if (ret < 0) { |
|
|
|
int cw = 0; |
|
|
|
return ret; |
|
|
|
int codes[2]; |
|
|
|
} else if (ret) |
|
|
|
do { |
|
|
|
break; |
|
|
|
cwi = show_bits(gb, 11); |
|
|
|
|
|
|
|
if (!cwi) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid uncompressed codeword\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cwi = 10 - av_log2(cwi); |
|
|
|
|
|
|
|
skip_bits(gb, cwi + 1); |
|
|
|
|
|
|
|
if (cwi > 5) { |
|
|
|
|
|
|
|
newmode = get_bits1(gb); |
|
|
|
|
|
|
|
eob = 1; |
|
|
|
|
|
|
|
cwi -= 6; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cw += cwi; |
|
|
|
|
|
|
|
} while(cwi == 5); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codes[0] = cw; |
|
|
|
|
|
|
|
codes[1] = !eob; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (k = 0; k < 2; k++) { |
|
|
|
|
|
|
|
if (codes[k]) { |
|
|
|
|
|
|
|
if (mode == k) { |
|
|
|
|
|
|
|
*runs++ = saved_run; |
|
|
|
|
|
|
|
if (runs >= runend) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
offs += saved_run; |
|
|
|
|
|
|
|
if (offs > width || run > width) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of bounds\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saved_run = 0; |
|
|
|
|
|
|
|
mode = !mode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saved_run += codes[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} while (!eob); |
|
|
|
|
|
|
|
*runs++ = saved_run; |
|
|
|
|
|
|
|
if (runs >= runend) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run overrun\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
offs += saved_run; |
|
|
|
|
|
|
|
if (offs > width || run > width) { |
|
|
|
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "uncompressed run went out of bounds\n"); |
|
|
|
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
saved_run = 0; |
|
|
|
|
|
|
|
mode = !mode; |
|
|
|
|
|
|
|
if (newmode != mode) { //FIXME CHECK
|
|
|
|
|
|
|
|
*runs++ = 0; |
|
|
|
|
|
|
|
mode = newmode; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
avpriv_report_missing_feature(avctx, "Special mode %d xxx=%d support", cmode, xxx); |
|
|
|
avpriv_report_missing_feature(avctx, "Special mode %d xxx=%d support", cmode, xxx); |
|
|
|
return AVERROR_PATCHWELCOME; |
|
|
|
return AVERROR_PATCHWELCOME; |
|
|
|