int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize, uint8_t *dst, int height, int stride, enum TiffCompr compr, int opts) { int j; BitstreamContext bc; int *runs, *ref = NULL, *runend; int ret; int runsize = avctx->width + 2; runs = av_malloc(runsize * sizeof(runs[0])); ref = av_malloc(runsize * sizeof(ref[0])); if (!runs || !ref) { ret = AVERROR(ENOMEM); goto fail; } ref[0] = avctx->width; ref[1] = 0; ref[2] = 0; bitstream_init(&bc, src, srcsize * 8); for (j = 0; j < height; j++) { runend = runs + runsize; if (compr == TIFF_G4) { ret = decode_group3_2d_line(avctx, &bc, avctx->width, runs, runend, ref); if (ret < 0) goto fail; } else { int g3d1 = (compr == TIFF_G3) && !(opts & 1); if (compr != TIFF_CCITT_RLE && find_group3_syncmarker(&bc, srcsize * 8) < 0) break; if (compr == TIFF_CCITT_RLE || g3d1 || bitstream_read_bit(&bc)) ret = decode_group3_1d_line(avctx, &bc, avctx->width, runs, runend); else ret = decode_group3_2d_line(avctx, &bc, avctx->width, runs, runend, ref); if (compr == TIFF_CCITT_RLE) bitstream_align(&bc); } if (avctx->err_recognition & AV_EF_EXPLODE && ret < 0) goto fail; if (ret < 0) { put_line(dst, stride, avctx->width, ref); } else { put_line(dst, stride, avctx->width, runs); FFSWAP(int *, runs, ref); } dst += stride; } ret = 0; fail: av_free(runs); av_free(ref); return ret; }
int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize, uint8_t *dst, int height, int stride, enum TiffCompr compr, int opts) { int j; GetBitContext gb; int *runs, *ref = NULL, *runend; int ret; int runsize= avctx->width + 2; int err = 0; int has_eol; runs = av_malloc(runsize * sizeof(runs[0])); ref = av_malloc(runsize * sizeof(ref[0])); if (!runs || ! ref) { err = AVERROR(ENOMEM); goto fail; } ref[0] = avctx->width; ref[1] = 0; ref[2] = 0; init_get_bits(&gb, src, srcsize*8); has_eol = show_bits(&gb, 12) == 1 || show_bits(&gb, 16) == 1; for(j = 0; j < height; j++){ runend = runs + runsize; if(compr == TIFF_G4){ ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref); if(ret < 0){ err = -1; goto fail; } }else{ int g3d1 = (compr == TIFF_G3) && !(opts & 1); if(compr!=TIFF_CCITT_RLE && has_eol && find_group3_syncmarker(&gb, srcsize*8) < 0) break; if(compr==TIFF_CCITT_RLE || g3d1 || get_bits1(&gb)) ret = decode_group3_1d_line(avctx, &gb, avctx->width, runs, runend); else ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref); if(compr==TIFF_CCITT_RLE) align_get_bits(&gb); } if(ret < 0){ put_line(dst, stride, avctx->width, ref); }else{ put_line(dst, stride, avctx->width, runs); FFSWAP(int*, runs, ref); } dst += stride; } fail: av_free(runs); av_free(ref); return err; }
int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize, uint8_t *dst, int height, int stride, enum TiffCompr compr) { int j; GetBitContext gb; int *runs, *ref, *runend; int ret; int runsize= avctx->width + 2; runs = av_malloc(runsize * sizeof(runs[0])); ref = av_malloc(runsize * sizeof(ref[0])); ref[0] = avctx->width; ref[1] = 0; ref[2] = 0; init_get_bits(&gb, src, srcsize*8); for(j = 0; j < height; j++){ runend = runs + runsize; if(compr == TIFF_G4){ ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref); if(ret < 0){ av_free(runs); av_free(ref); return -1; } }else{ if(find_group3_syncmarker(&gb, srcsize*8) < 0) break; if(compr==TIFF_CCITT_RLE || get_bits1(&gb)) ret = decode_group3_1d_line(avctx, &gb, avctx->width, runs, runend); else ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref); } if(ret < 0){ put_line(dst, stride, avctx->width, ref); }else{ put_line(dst, stride, avctx->width, runs); FFSWAP(int*, runs, ref); } dst += stride; } av_free(runs); av_free(ref); return 0; }