Skip to content

Commit

Permalink
Fix gif animated decoder for dispose:2 frames
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed Dec 15, 2024
1 parent 1d2cdae commit a595a4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions lib/src/formats/gif_decoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,22 @@ class GifDecoder extends Decoder {
if (frame.disposal == 2) {
nextImage.clear(colorMap.color(info!.backgroundColor!.r as int));
} else if (frame.disposal != 3) {
if (frame.x != 0 ||
frame.y != 0 ||
frame.width != lastImage.width ||
frame.height != lastImage.height) {
if (frame.colorMap != null) {
final lp = lastImage.palette!;
final remapColors = <int, int>{};
for (var ci = 0; ci < colorMap.numColors; ++ci) {
final nc = colorMap.findColor(lp.getRed(ci), lp.getGreen(ci),
lp.getBlue(ci), lp.getAlpha(ci));
remapColors[ci] = nc;
}
if (frame.colorMap != null) {
final lp = lastImage.palette!;
final remapColors = <int, int>{};
for (var ci = 0; ci < colorMap.numColors; ++ci) {
final nc = colorMap.findColor(lp.getRed(ci), lp.getGreen(ci),
lp.getBlue(ci), lp.getAlpha(ci));
remapColors[ci] = nc;
}

final nextBytes = nextImage.toUint8List();
final lastBytes = lastImage.toUint8List();
for (var i = 0, l = nextBytes.length; i < l; ++i) {
final lc = lastBytes[i];
final nc = remapColors[lc];
if (nc != -1) {
nextBytes[i] = nc!;
}
final nextBytes = nextImage.toUint8List();
final lastBytes = lastImage.toUint8List();
for (var i = 0, l = nextBytes.length; i < l; ++i) {
final lc = lastBytes[i];
final nc = remapColors[lc];
if (nc != -1) {
nextBytes[i] = nc!;
}
}
}
Expand Down
Binary file added test/_data/gif/lighthouse.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a595a4c

Please sign in to comment.