Skip to content

Commit

Permalink
fix: only restore background when dispose is 2 or 3
Browse files Browse the repository at this point in the history
Signed-off-by: Cocoa <[email protected]>
  • Loading branch information
cocoa-xu committed Oct 8, 2024
1 parent 5f9c9c6 commit b22dcdc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions 3rd_party/stb/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -6840,8 +6840,10 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
// 0: not specified.
}

// background is what out is after the undoing of the previou frame;
memcpy( g->background, g->out, 4 * g->w * g->h );
if (dispose == 2 || dispose == 3) {
// background is what out is after the undoing of the previou frame;
memcpy( g->background, g->out, 4 * g->w * g->h );
}
}

// clear my history;
Expand Down
Binary file added test/stb-issue-1688-expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/stb-issue-1688-horse.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions test/stb_image_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,23 @@ defmodule StbImageTest do
end
end
end

describe "GIF" do
test "only restores background when dispose is 2 or 3" do
file = Path.join(__DIR__, "stb-issue-1688-horse.gif")
binary = File.read!(file)

{:ok, frames, _} = StbImage.read_gif_binary(binary)
assert 34 == Enum.count(frames)

decoded = Enum.at(frames, 5)
# StbImage.write_file!(decoded, Path.join(__DIR__, "stb-issue-1688-horse-5.png"))
decoded = StbImage.to_binary(decoded, :png)

{:ok, expected_img} = StbImage.read_file(Path.join(__DIR__, "stb-issue-1688-expected.png"))
expected = StbImage.to_binary(expected_img, :png)

assert decoded == expected
end
end
end

0 comments on commit b22dcdc

Please sign in to comment.