Skip to content
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

refactor: add frame info duration loop that checks the number of image info to add #3

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

fernan542
Copy link

I noticed that if the current frame contains the same image info, they are only considered as one frame which makes the actual gif unable to play the complete gif frame/duration.

To make things clear, here's an example gif:
rendered_preview_15

The first( image with #1) frame's duration is 4 seconds but when played, it only shows 1 frame since they're all the same. Then the rest is fine since they're all playing at 1 sec, meaning 1 frame.

So to fix that, I added a validator that loop and checks whether the actual duration/frame was added to the list of ImageInfos.

    for (int sec = 1; sec <= duration; sec++) {
      infos.add(ImageInfo(image: frameInfo.image));
    }

Another thing, I replaced this deprecated method:

ui.Codec codec = await PaintingBinding.instance.instantiateImageCodec(bytes);

'instantiateImageCodec' is deprecated and shouldn't be used. Use instantiateImageCodecFromBuffer with an ImmutableBuffer instance instead. This feature was deprecated after v2.13.0-1.0.pre..

by using the suggested:

  final buffer = await ImmutableBuffer.fromUint8List(bytes);
  ui.Codec codec =
      await PaintingBinding.instance.instantiateImageCodecFromBuffer(buffer);

@saytoonz saytoonz merged commit f6ad76c into saytoonz:main Feb 9, 2023
@diegogarciar
Copy link

this doesn't work if the duration of a frame is <0 as the loop conditions never met

@sipanpetrosyan
Copy link

final buffer = await ImmutableBuffer.fromUint8List(bytes); ui.Codec codec = await PaintingBinding.instance.instantiateImageCodecFromBuffer(buffer);

  I approve these changes. This will help to avoid the `instantiateImageCodec()` deprecation issue. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants