- if (img->flags & FLAG_RAW)
- return read_raw_frame(img, frame);
-
- if ((img->flags & FLAG_OVERWRITE)
- || (pub->chunk && !(frame % pub->chunk))) {
- /* Clear the slate. */
- img->currentframe = -1;
- memset(img->framedata[0], 0, pub->width * pub->height);
- memset(img->mask[0], 0, pub->width * pub->height);
- } else {
- /* Start over if we are backtracking. */
- if (img->currentframe > frame) {
- memset(img->mask[0], 0, pub->width * pub->height);
- img->currentframe = -1;
- }
-
- /* We must have previous frame decoded to continue. */
- if (frame > img->currentframe + 1) {
- if (!lbx_img_getframe(pub, frame-1))
- return NULL;
- }
+ if (img->fops->read(buf, img->currentn, img->f) != img->currentn) {
+ if (img->fops->eof(img->f))
+ lbx_error_raise(LBX_EEOF);
+ return -1;