multiframe: Tweaks around frame number handling

This commit is contained in:
Kim Woelders 2022-11-13 10:24:09 +01:00
parent 0071544859
commit 6df68e3e2e
10 changed files with 50 additions and 48 deletions

View File

@ -140,10 +140,10 @@ struct _ImlibImage {
char has_alpha; char has_alpha;
char rsvd[3]; char rsvd[3];
int frame;
int canvas_w; /* Canvas size */ int canvas_w; /* Canvas size */
int canvas_h; int canvas_h;
int frame_count; /* Number of frames */ int frame_count; /* Number of frames */
int frame_num; /* Current frame */
int frame_x; /* Frame origin */ int frame_x; /* Frame origin */
int frame_y; int frame_y;
int frame_flags; /* Frame flags */ int frame_flags; /* Frame flags */

View File

@ -683,7 +683,7 @@ imlib_image_get_frame_info(Imlib_Frame_Info * info)
info->loop_count = im->loop_count; info->loop_count = im->loop_count;
info->frame_count = im->frame_count; info->frame_count = im->frame_count;
info->frame_num = im->frame_num; info->frame_num = im->frame;
info->canvas_w = im->canvas_w ? im->canvas_w : im->w; info->canvas_w = im->canvas_w ? im->canvas_w : im->w;
info->canvas_h = im->canvas_h ? im->canvas_h : im->h; info->canvas_h = im->canvas_h ? im->canvas_h : im->h;
info->frame_x = im->frame_x; info->frame_x = im->frame_x;

View File

@ -220,19 +220,20 @@ __imlib_FindCachedImage(const char *file, int frame)
for (im = images, im_prev = NULL; im; im_prev = im, im = im->next) for (im = images, im_prev = NULL; im; im_prev = im, im = im->next)
{ {
/* if the filenames match and it's valid */ /* if the filenames match and it's valid */
if (!strcmp(file, im->file) && !IM_FLAG_ISSET(im, F_INVALID) && if (strcmp(file, im->file) || IM_FLAG_ISSET(im, F_INVALID))
frame == im->frame_num) continue;
if (frame != im->frame)
continue;
/* move the image to the head of the image list */
if (im_prev)
{ {
/* move the image to the head of the image list */ im_prev->next = im->next;
if (im_prev) im->next = images;
{ images = im;
im_prev->next = im->next;
im->next = images;
images = im;
}
DP(" got %p: '%s' frame %d\n", im, im->fi->name, im->frame_num);
return im;
} }
DP(" got %p: '%s' frame %d\n", im, im->fi->name, im->frame);
return im;
} }
DP(" got none\n"); DP(" got none\n");
return NULL; return NULL;
@ -242,7 +243,7 @@ __imlib_FindCachedImage(const char *file, int frame)
static void static void
__imlib_AddImageToCache(ImlibImage * im) __imlib_AddImageToCache(ImlibImage * im)
{ {
DP("%s: %p: '%s' frame %d\n", __func__, im, im->fi->name, im->frame_num); DP("%s: %p: '%s' frame %d\n", __func__, im, im->fi->name, im->frame);
im->next = images; im->next = images;
images = im; images = im;
} }
@ -254,7 +255,7 @@ __imlib_RemoveImageFromCache(ImlibImage * im_del)
ImlibImage *im, *im_prev; ImlibImage *im, *im_prev;
im = im_del; im = im_del;
DP("%s: %p: '%s' frame %d\n", __func__, im, im->fi->name, im->frame_num); DP("%s: %p: '%s' frame %d\n", __func__, im, im->fi->name, im->frame);
for (im = images, im_prev = NULL; im; im_prev = im, im = im->next) for (im = images, im_prev = NULL; im; im_prev = im, im = im->next)
{ {
@ -380,8 +381,8 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage * im, int load_data)
{ {
int rc; int rc;
DP("%s: fmt='%s' file='%s'(%s), imm=%d\n", __func__, DP("%s: fmt='%s' file='%s'(%s) frame=%d, imm=%d\n", __func__,
l->name, im->file, im->fi->name, load_data); l->name, im->file, im->fi->name, im->frame, load_data);
#if IMLIB2_DEBUG #if IMLIB2_DEBUG
unsigned int t0 = __imlib_time_us(); unsigned int t0 = __imlib_time_us();
@ -548,7 +549,7 @@ __imlib_LoadImage(const char *file, ImlibLoadArgs * ila)
im = __imlib_ProduceImage(); im = __imlib_ProduceImage();
im->file = strdup(file); im->file = strdup(file);
im->key = im_key; im->key = im_key;
im->frame_num = ila->frame; im->frame = ila->frame;
if (__imlib_ImageFileContextPush(im, true, im_file ? im_file : im->file) || if (__imlib_ImageFileContextPush(im, true, im_file ? im_file : im->file) ||
__imlib_FileContextOpen(im->fi, ila->fp, ila->fdata, st.st_size)) __imlib_FileContextOpen(im->fi, ila->fp, ila->fdata, st.st_size))

View File

@ -51,10 +51,10 @@ struct _ImlibImage {
char has_alpha; char has_alpha;
char rsvd[3]; char rsvd[3];
int frame;
int canvas_w; /* Canvas size */ int canvas_w; /* Canvas size */
int canvas_h; int canvas_h;
int frame_count; /* Number of frames */ int frame_count; /* Number of frames */
int frame_num; /* Current frame */
int frame_x; /* Frame origin */ int frame_x; /* Frame origin */
int frame_y; int frame_y;
int frame_flags; /* Frame flags */ int frame_flags; /* Frame flags */

View File

@ -84,10 +84,9 @@ _load(ImlibImage * im, int load_data)
transp = -1; transp = -1;
fcount = 0; fcount = 0;
frame = 1; frame = im->frame;
if (im->frame_num > 0) if (frame > 0)
{ {
frame = im->frame_num;
im->frame_count = gif->ImageCount; im->frame_count = gif->ImageCount;
im->loop_count = 0; /* Loop forever */ im->loop_count = 0; /* Loop forever */
if (im->frame_count > 1) if (im->frame_count > 1)
@ -137,7 +136,7 @@ _load(ImlibImage * im, int load_data)
fcount += 1; fcount += 1;
if (gif->ImageCount != frame) if (frame > 0 && gif->ImageCount != frame)
{ {
int size = 0; int size = 0;
GifByteType *data; GifByteType *data;
@ -204,7 +203,7 @@ _load(ImlibImage * im, int load_data)
} }
/* Break if no specific frame was requested */ /* Break if no specific frame was requested */
if (im->frame_num == 0) if (frame == 0)
break; break;
} }
else if (rec == EXTENSION_RECORD_TYPE) else if (rec == EXTENSION_RECORD_TYPE)

View File

@ -303,10 +303,9 @@ _load(ImlibImage * im, int load_data)
rc = LOAD_BADIMAGE; /* Format accepted */ rc = LOAD_BADIMAGE; /* Format accepted */
frame = 0; /* Select default */ frame = im->frame;
if (im->frame_num > 0) if (frame > 0)
{ {
frame = im->frame_num;
im->frame_count = ico.idir.icons; im->frame_count = ico.idir.icons;
if (frame > 1 && frame > im->frame_count) if (frame > 1 && frame > im->frame_count)

View File

@ -47,7 +47,7 @@ _load(ImlibImage * im, int load_data)
JxlDecoder *dec; JxlDecoder *dec;
JxlBasicInfo info; JxlBasicInfo info;
JxlFrameHeader fhdr; JxlFrameHeader fhdr;
int delay_unit; int frame, delay_unit;
#if MAX_RUNNERS > 0 #if MAX_RUNNERS > 0
size_t n_runners; size_t n_runners;
@ -99,6 +99,7 @@ _load(ImlibImage * im, int load_data)
if (jst != JXL_DEC_SUCCESS) if (jst != JXL_DEC_SUCCESS)
goto quit; goto quit;
frame = im->frame;
delay_unit = 0; delay_unit = 0;
for (;;) for (;;)
@ -136,12 +137,8 @@ _load(ImlibImage * im, int load_data)
im->h = info.ysize; im->h = info.ysize;
im->has_alpha = info.alpha_bits > 0; im->has_alpha = info.alpha_bits > 0;
int frame; if (frame > 0)
frame = 1;
if (im->frame_num > 0)
{ {
frame = im->frame_num;
if (info.have_animation) if (info.have_animation)
{ {
im->frame_count = 1234567890; // FIXME - Hack im->frame_count = 1234567890; // FIXME - Hack
@ -158,16 +155,16 @@ _load(ImlibImage * im, int load_data)
if (frame > 1 && im->frame_count > 0 if (frame > 1 && im->frame_count > 0
&& frame > im->frame_count) && frame > im->frame_count)
QUIT_WITH_RC(LOAD_BADFRAME); QUIT_WITH_RC(LOAD_BADFRAME);
if (frame > 1)
{
/* Fast forward to desired frame */
JxlDecoderSkipFrames(dec, frame - 1);
}
} }
if (!load_data) if (!load_data)
QUIT_WITH_RC(LOAD_SUCCESS); QUIT_WITH_RC(LOAD_SUCCESS);
if (frame > 1)
{
/* Fast forward to desired frame */
JxlDecoderSkipFrames(dec, frame - 1);
}
break; break;
case JXL_DEC_NEED_IMAGE_OUT_BUFFER: case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
@ -183,7 +180,7 @@ _load(ImlibImage * im, int load_data)
case JXL_DEC_FRAME: case JXL_DEC_FRAME:
JxlDecoderGetFrameHeader(dec, &fhdr); JxlDecoderGetFrameHeader(dec, &fhdr);
if (fhdr.is_last) if (fhdr.is_last)
im->frame_count = im->frame_num; im->frame_count = frame;
im->frame_delay = fhdr.duration * delay_unit; im->frame_delay = fhdr.duration * delay_unit;
D("Frame duration=%d tc=%08x nl=%d last=%d\n", D("Frame duration=%d tc=%08x nl=%d last=%d\n",
im->frame_delay, fhdr.timecode, fhdr.name_length, fhdr.is_last); im->frame_delay, fhdr.timecode, fhdr.name_length, fhdr.is_last);

View File

@ -337,8 +337,8 @@ _load(ImlibImage * im, int load_data)
png_set_progressive_read_fn(png_ptr, &ctx, png_set_progressive_read_fn(png_ptr, &ctx,
info_callback, row_callback, NULL); info_callback, row_callback, NULL);
frame = im->frame_num; frame = im->frame;
if (im->frame_num <= 0) if (frame <= 0)
goto scan_done; goto scan_done;
/* Animation info requested. Look it up to find the frame's /* Animation info requested. Look it up to find the frame's

View File

@ -46,16 +46,19 @@ _load(ImlibImage * im, int load_data)
rc = LOAD_BADIMAGE; /* Format accepted */ rc = LOAD_BADIMAGE; /* Format accepted */
frame = 1; frame = im->frame;
if (im->frame_num > 0) if (frame > 0)
{ {
frame = im->frame_num;
im->frame_count = spectre_document_get_n_pages(spdoc); im->frame_count = spectre_document_get_n_pages(spdoc);
D("Pages=%d\n", im->frame_count); D("Pages=%d\n", im->frame_count);
if (frame > 1 && frame > im->frame_count) if (frame > 1 && frame > im->frame_count)
QUIT_WITH_RC(LOAD_BADFRAME); QUIT_WITH_RC(LOAD_BADFRAME);
} }
else
{
frame = 1;
}
sppage = spectre_document_get_page(spdoc, frame - 1); sppage = spectre_document_get_page(spdoc, frame - 1);
spst = spectre_document_status(spdoc); spst = spectre_document_status(spdoc);

View File

@ -33,10 +33,9 @@ _load(ImlibImage * im, int load_data)
rc = LOAD_BADIMAGE; /* Format accepted */ rc = LOAD_BADIMAGE; /* Format accepted */
frame = 1; frame = im->frame;
if (im->frame_num > 0) if (frame > 0)
{ {
frame = im->frame_num;
im->frame_count = WebPDemuxGetI(demux, WEBP_FF_FRAME_COUNT); im->frame_count = WebPDemuxGetI(demux, WEBP_FF_FRAME_COUNT);
im->loop_count = WebPDemuxGetI(demux, WEBP_FF_LOOP_COUNT); im->loop_count = WebPDemuxGetI(demux, WEBP_FF_LOOP_COUNT);
if (im->frame_count > 1) if (im->frame_count > 1)
@ -50,6 +49,10 @@ _load(ImlibImage * im, int load_data)
if (frame > 1 && frame > im->frame_count) if (frame > 1 && frame > im->frame_count)
QUIT_WITH_RC(LOAD_BADFRAME); QUIT_WITH_RC(LOAD_BADFRAME);
} }
else
{
frame = 1;
}
if (!WebPDemuxGetFrame(demux, frame, &iter)) if (!WebPDemuxGetFrame(demux, frame, &iter))
goto quit; goto quit;