... | ... |
@@ -58,6 +58,7 @@ typedef struct TiffContext { |
58 | 58 |
int fax_opts; |
59 | 59 |
int predictor; |
60 | 60 |
int fill_order; |
61 |
+ uint32_t res[4]; |
|
61 | 62 |
|
62 | 63 |
int strips, rps, sstype; |
63 | 64 |
int sot; |
... | ... |
@@ -566,9 +567,19 @@ static int init_image(TiffContext *s, ThreadFrame *frame) |
566 | 566 |
return 0; |
567 | 567 |
} |
568 | 568 |
|
569 |
+static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den) |
|
570 |
+{ |
|
571 |
+ int offset = tag == TIFF_YRES ? 2 : 0; |
|
572 |
+ s->res[offset++] = num; |
|
573 |
+ s->res[offset] = den; |
|
574 |
+ if (s->res[0] && s->res[1] && s->res[2] && s->res[3]) |
|
575 |
+ av_reduce(&s->avctx->sample_aspect_ratio.num, &s->avctx->sample_aspect_ratio.den, |
|
576 |
+ s->res[2] * (uint64_t)s->res[1], s->res[0] * (uint64_t)s->res[3], INT32_MAX); |
|
577 |
+} |
|
578 |
+ |
|
569 | 579 |
static int tiff_decode_tag(TiffContext *s, AVFrame *frame) |
570 | 580 |
{ |
571 |
- unsigned tag, type, count, off, value = 0; |
|
581 |
+ unsigned tag, type, count, off, value = 0, value2 = 0; |
|
572 | 582 |
int i, j, k, pos, start; |
573 | 583 |
int ret; |
574 | 584 |
uint32_t *pal; |
... | ... |
@@ -587,6 +598,10 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) |
587 | 587 |
case TIFF_LONG: |
588 | 588 |
value = ff_tget(&s->gb, type, s->le); |
589 | 589 |
break; |
590 |
+ case TIFF_RATIONAL: |
|
591 |
+ value = ff_tget(&s->gb, TIFF_LONG, s->le); |
|
592 |
+ value2 = ff_tget(&s->gb, TIFF_LONG, s->le); |
|
593 |
+ break; |
|
590 | 594 |
case TIFF_STRING: |
591 | 595 |
if (count <= 4) { |
592 | 596 |
break; |
... | ... |
@@ -717,6 +732,10 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame) |
717 | 717 |
return AVERROR_INVALIDDATA; |
718 | 718 |
} |
719 | 719 |
break; |
720 |
+ case TIFF_XRES: |
|
721 |
+ case TIFF_YRES: |
|
722 |
+ set_sar(s, tag, value, value2); |
|
723 |
+ break; |
|
720 | 724 |
case TIFF_TILE_BYTE_COUNTS: |
721 | 725 |
case TIFF_TILE_LENGTH: |
722 | 726 |
case TIFF_TILE_OFFSETS: |