* commit '016c5b066de08a93a5f6b5beb0ef377356b35cde':
tiff: refactor fax support in a separate function
Conflicts:
libavcodec/tiff.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -470,6 +470,44 @@ static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride, |
470 | 470 |
} |
471 | 471 |
#endif |
472 | 472 |
|
473 |
+ |
|
474 |
+static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, |
|
475 |
+ const uint8_t *src, int size, int width, int lines) |
|
476 |
+{ |
|
477 |
+ int i, ret = 0; |
|
478 |
+ int line; |
|
479 |
+ uint8_t *src2 = av_malloc((unsigned)size + |
|
480 |
+ FF_INPUT_BUFFER_PADDING_SIZE); |
|
481 |
+ |
|
482 |
+ if (!src2) { |
|
483 |
+ av_log(s->avctx, AV_LOG_ERROR, |
|
484 |
+ "Error allocating temporary buffer\n"); |
|
485 |
+ return AVERROR(ENOMEM); |
|
486 |
+ } |
|
487 |
+ if (s->fax_opts & 2) { |
|
488 |
+ av_log(s->avctx, AV_LOG_ERROR, |
|
489 |
+ "Uncompressed fax mode is not supported (yet)\n"); |
|
490 |
+ av_free(src2); |
|
491 |
+ return AVERROR_INVALIDDATA; |
|
492 |
+ } |
|
493 |
+ if (!s->fill_order) { |
|
494 |
+ memcpy(src2, src, size); |
|
495 |
+ } else { |
|
496 |
+ for (i = 0; i < size; i++) |
|
497 |
+ src2[i] = ff_reverse[src[i]]; |
|
498 |
+ } |
|
499 |
+ memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
|
500 |
+ ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, |
|
501 |
+ s->compr, s->fax_opts); |
|
502 |
+ if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) |
|
503 |
+ for (line = 0; line < lines; line++) { |
|
504 |
+ horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0); |
|
505 |
+ dst += stride; |
|
506 |
+ } |
|
507 |
+ av_free(src2); |
|
508 |
+ return ret; |
|
509 |
+} |
|
510 |
+ |
|
473 | 511 |
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
474 | 512 |
const uint8_t *src, int size, int lines) |
475 | 513 |
{ |
... | ... |
@@ -510,43 +548,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
510 | 510 |
if (s->compr == TIFF_CCITT_RLE || |
511 | 511 |
s->compr == TIFF_G3 || |
512 | 512 |
s->compr == TIFF_G4) { |
513 |
- int i, ret = 0; |
|
514 |
- uint8_t *src2 = av_malloc((unsigned)size + |
|
515 |
- FF_INPUT_BUFFER_PADDING_SIZE); |
|
516 |
- |
|
517 |
- if (!src2) { |
|
518 |
- av_log(s->avctx, AV_LOG_ERROR, |
|
519 |
- "Error allocating temporary buffer\n"); |
|
520 |
- return AVERROR(ENOMEM); |
|
521 |
- } |
|
522 |
- if (s->fax_opts & 2) { |
|
523 |
- av_log(s->avctx, AV_LOG_ERROR, |
|
524 |
- "Uncompressed fax mode is not supported (yet)\n"); |
|
525 |
- av_free(src2); |
|
526 |
- return AVERROR_INVALIDDATA; |
|
527 |
- } |
|
528 |
- if (!s->fill_order) { |
|
529 |
- memcpy(src2, src, size); |
|
530 |
- } else { |
|
531 |
- for (i = 0; i < size; i++) |
|
532 |
- src2[i] = ff_reverse[src[i]]; |
|
533 |
- } |
|
534 |
- memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
|
535 |
- switch (s->compr) { |
|
536 |
- case TIFF_CCITT_RLE: |
|
537 |
- case TIFF_G3: |
|
538 |
- case TIFF_G4: |
|
539 |
- ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, |
|
540 |
- s->compr, s->fax_opts); |
|
541 |
- break; |
|
542 |
- } |
|
543 |
- if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) |
|
544 |
- for (line = 0; line < lines; line++) { |
|
545 |
- horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0); |
|
546 |
- dst += stride; |
|
547 |
- } |
|
548 |
- av_free(src2); |
|
549 |
- return ret; |
|
513 |
+ return tiff_unpack_fax(s, dst, stride, src, size, width, lines); |
|
550 | 514 |
} |
551 | 515 |
for (line = 0; line < lines; line++) { |
552 | 516 |
if (src - ssrc > size) { |