Option "-page N" (page index N starts from 1) can now be used to specify which TIFF page/subfile to decode.
Signed-off-by: Nick Renieris <velocityra@gmail.com>
@ -1364,6 +1372,7 @@ static int decode_frame(AVCodecContext *avctx,
uint8_t*dst;
GetByteContextstripsizes;
GetByteContextstripdata;
intretry_for_subifd,retry_for_page;
bytestream2_init(&s->gb,avpkt->data,avpkt->size);
@ -1384,6 +1393,7 @@ again:
s->fill_order=0;
s->white_level=0;
s->is_bayer=0;
s->cur_page=0;
free_geotags(s);
// Reset these offsets so we can tell if they were set this frame
@ -1398,8 +1408,20 @@ again:
returnret;
}
if(s->sub_ifd&&s->get_subimage){
/** 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 */
retry_for_page=s->get_page&&s->cur_page+1<s->get_page;// get_page is 1-indexed
if(retry_for_page){
// set offset to the next IFD
off=ff_tget_long(&s->gb,le);
}elseif(retry_for_subifd){
// set offset to the SubIFD
off=s->sub_ifd;
}
if(retry_for_subifd||retry_for_page){
if(off>=UINT_MAX-14||avpkt->size<off+14){
av_log(avctx,AV_LOG_ERROR,"IFD offset is greater than image size\n");
returnAVERROR_INVALIDDATA;
@ -1648,6 +1670,7 @@ static av_cold int tiff_end(AVCodecContext *avctx)
#define OFFSET(x) offsetof(TiffContext, x)
staticconstAVOptiontiff_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},
{"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},