summaryrefslogtreecommitdiff
path: root/libavcodec/tiff.c
diff options
context:
space:
mode:
authorNick Renieris <velocityra@gmail.com>2019-05-30 13:42:40 +0300
committerPaul B Mahol <onemda@gmail.com>2019-05-30 19:27:05 +0200
commita7e018b05e0ec99a466b20c797785620645e5d3a (patch)
treee38b0de1a1b14d447ddb491c4bae83fea5ab8f1f /libavcodec/tiff.c
parent6895b350c31d8fda5bd9e4285c52de6e391e7ff4 (diff)
avcodec/tiff: Option to decode embedded thumbnail
Adds the "-thumbnail" option, that works like the current "-subifd" option, but only for non-full-sized images. This is particularly useful for DNG images (see next commit) that have SubIFDs that are not necessarily thumbnails. Signed-off-by: Nick Renieris <velocityra@gmail.com>
Diffstat (limited to 'libavcodec/tiff.c')
-rw-r--r--libavcodec/tiff.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 79e6242549..6e15d00310 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -56,6 +56,7 @@ typedef struct TiffContext {
int get_subimage;
uint16_t get_page;
+ int get_thumbnail;
int width, height;
unsigned int bpp, bppcount;
@@ -70,6 +71,7 @@ typedef struct TiffContext {
int predictor;
int fill_order;
uint32_t res[4];
+ int is_thumbnail;
int is_bayer;
uint8_t pattern[4];
@@ -948,6 +950,8 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
}
switch (tag) {
+ case TIFF_SUBFILE:
+ s->is_thumbnail = (value != 0);
case TIFF_WIDTH:
s->width = value;
break;
@@ -1387,6 +1391,7 @@ static int decode_frame(AVCodecContext *avctx,
s->le = le;
// TIFF_BPP is not a required tag and defaults to 1
again:
+ s->is_thumbnail = 0;
s->bppcount = s->bpp = 1;
s->photometric = TIFF_PHOTOMETRIC_NONE;
s->compr = TIFF_RAW;
@@ -1408,9 +1413,14 @@ again:
return ret;
}
- /** whether we should look for this IFD's SubIFD */
- retry_for_subifd = s->sub_ifd && s->get_subimage;
- /** whether we should look for this multi-page IFD's next page */
+ if (s->get_thumbnail && !s->is_thumbnail) {
+ av_log(avctx, AV_LOG_INFO, "No embedded thumbnail present\n");
+ return AVERROR_EOF;
+ }
+
+ /** whether we should process this IFD's SubIFD */
+ retry_for_subifd = s->sub_ifd && (s->get_subimage || (!s->get_thumbnail && s->is_thumbnail));
+ /** whether we should process this multi-page IFD's next page */
retry_for_page = s->get_page && s->cur_page + 1 < s->get_page; // get_page is 1-indexed
if (retry_for_page) {
@@ -1670,6 +1680,7 @@ static av_cold int tiff_end(AVCodecContext *avctx)
#define OFFSET(x) offsetof(TiffContext, x)
static const AVOption tiff_options[] = {
{ "subimage", "decode subimage instead if available", OFFSET(get_subimage), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
+ { "thumbnail", "decode embedded thumbnail subimage instead if available", OFFSET(get_thumbnail), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
{ "page", "page number of multi-page image to decode (starting from 1)", OFFSET(get_page), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
{ NULL },
};