-
Notifications
You must be signed in to change notification settings - Fork 19
feat: updated imageCodec #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
You should maintained the loop and instead added the validation for milliseconds. |
Hello @fernan542, Just revisiting this, do you know exactly what the loop does? and is this your suggestion? if(duration>0){
for (int sec = 1; sec <= duration; sec++) {
infos.add(ImageInfo(image: frameInfo.image));
}
}else{
infos.add(ImageInfo(image: frameInfo.image));
} |
Hey @diegogarciar.
I encountered a problem where the The goal of this package is to render each frame per second
824E
that's why I've added a loop in order to correctly render each frame per second, not per Formula from GPT: Time Interval (in milliseconds)=1/FPS×1000 Given your requirement of 15 to 30 frames per second (fps), you would have: For 15 fps: For 30 fps: So, you would need to increment by approximately 66.67 milliseconds for 15 fps and 33.33 milliseconds for 30 fps. Now to apply that in your code (P.S: I didn't test this code, but you get the point) const _fps15 = 66.67;
const _fps30 = 33.33; final buffer = await ImmutableBuffer.fromUint8List(bytes);
ui.Codec codec = await PaintingBinding.instance.instantiateImageCodecWithSize(buffer);
infos = [];
// Log how many frames are decoded by codec.
print('frames: ${codec.frameCount}');
for (int i = 0; i < codec.frameCount; i++) {
final frameInfo = await codec.getNextFrame();
// Use milliseconds.
final duration = frameInfo.duration.inMilliseconds;
// Means the GIF duration is shorter than a single fps.
// Either throw an error or early return.
if (duration <= _fps15 ) {
infos.add(ImageInfo(image: frameInfo.image));
// Exit the loop immediately since there's no other frame left.
break;
}
// Loop through each rate. Each rate is incremented by the computation previously.
for (int rate = 1; rate <= duration; rate+=_fps15 ) {
infos.add(ImageInfo(image: frameInfo.image));
}
}
GifImage.cache.caches.putIfAbsent(key, () => infos);
return infos; If this does not work, I think you may want to read the (FrameInfo docs)[https://api.flutter.dev/flutter/dart-ui/FrameInfo-class.html] because AFAIK the rate is limited to second. One thing that I'm wrong about is deleting the cache of GIF. I didn't notice that I'd pushed my version for cacheing; I intended to remove it because it causes a problem with my dynamic image cacheing. |
I updated the image codec to support flutter3.16, I also had to revert this change because it doesn't support frames with duration below 1 second
#3