pixelmatix / AnimatedGIFs

MIT License
62 stars 34 forks source link

Improve calculation of frame rate delay #35

Open embedded-creations opened 5 years ago

embedded-creations commented 5 years ago
    // wait until time to display next frame
    while(nextFrameTime_ms > millis());

    // calculate time to display next frame
    nextFrameTime_ms = millis() + (10 * frameDelay);
    if(updateScreenCallback)
        (*updateScreenCallback)();

Ideally we want nextFrameTime_ms to be exactly equal to millis() when we calculate the time for next frame. If however it's taken longer, and now nextFrameTime_ms is less than millis(), we update the frame late, and extend that delay into the nextFrameTime_ms calculation, so a late frame makes the next frame even later, instead of trying to make up the delay. The nextFrameTime_ms calculation should take this into account.

Potentially if keeping the pacing of the GIF is important and we get behind we may want to skip frames