Skip to content

Commit

Permalink
fix: Gif parsing did not work with certain formats (#3173)
Browse files Browse the repository at this point in the history
Closes #3172

This PR fixes GIF parsing for certain gif formats. Leverages the documentation provided by GIFLib https://giflib.sourceforge.net/whatsinagif/index.html

## Changes:

- Tweak the image generation algorithm to be more efficient
- Support Local Color Table in image generation
- Support Disposal Method to allow frame to frame persistence
  • Loading branch information
eonarheim authored Aug 9, 2024
1 parent 76f65bd commit 0d6ea12
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 110 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Breaking Changes

- `ex.Gif` transparent color constructor arg is removed in favor of the built in Gif file mechanism
- Remove core-js dependency, it is no longer necessary in modern browsers. Technically a breaking change for older browsers
- `ex.Particle` and `ex.ParticleEmitter` now have an API that looks like modern Excalibur APIs
* `particleSprite` is renamed to `graphic`
Expand Down Expand Up @@ -47,6 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Deprecated


- `Vector.size` is deprecated, use `Vector.magnitude` instead
- `ScreenShader` v_texcoord is deprecated, use v_uv. This is changed to match the materials shader API
- `actor.getGlobalPos()` - use `actor.globalPos` instead
Expand All @@ -55,6 +57,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Added

- `ex.Gif` can now handle default embedded GIF frame timings
- New `ex.Screen.worldToPagePixelRatio` API that will return the ratio between excalibur pixels and the HTML pixels.
* Additionally excalibur will now decorate the document root with this same value as a CSS variable `--ex-pixel-ratio`
* Useful for scaling HTML UIs to match your game
Expand Down Expand Up @@ -90,6 +93,7 @@ are doing mtv adjustments during precollision.

### Fixed

- Fixed issue where `ex.Gif` was not parsing certain binary formats correctly
- Fixed issue where the boot `ex.Loader` was removing pixelRatio override
- Fixed `ex.RasterOptions`, it now extends `ex.GraphicsOptions` which is the underlying truth
- Fixed issue where rayCast `filter` would not be called in hit order
Expand Down
35 changes: 30 additions & 5 deletions sandbox/tests/gif/animatedGif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,35 @@ var game = new ex.Engine({

game.currentScene.camera.zoom = 2;

var gif: ex.Gif = new ex.Gif('./sword.gif', ex.Color.Black);
var loader = new ex.Loader([gif]);
var gif: ex.Gif = new ex.Gif('./loading-screen.gif');
var gif2: ex.Gif = new ex.Gif('./sword.gif');
var gif3: ex.Gif = new ex.Gif('./stoplight.gif');
var loader = new ex.Loader([gif, gif2, gif3]);
game.start(loader).then(() => {
var actor = new ex.Actor({ x: game.currentScene.camera.x, y: game.currentScene.camera.y, width: gif.width, height: gif.height });
actor.graphics.add(gif.toAnimation(500));
game.add(actor);
var stoplight = new ex.Actor({
x: game.currentScene.camera.x + 120,
y: game.currentScene.camera.y,
width: gif3.width,
height: gif3.height
});
stoplight.graphics.add(gif3.toAnimation());
game.add(stoplight);

var sword = new ex.Actor({
x: game.currentScene.camera.x - 120,
y: game.currentScene.camera.y,
width: gif2.width,
height: gif2.height
});
sword.graphics.add(gif2.toAnimation());
game.add(sword);

var loading = new ex.Actor({
x: game.currentScene.camera.x,
y: game.currentScene.camera.y,
width: gif2.width,
height: gif2.height
});
loading.graphics.add(gif.toAnimation());
game.add(loading);
});
Binary file added sandbox/tests/gif/loading-screen.gif
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 sandbox/tests/gif/stoplight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0d6ea12

Please sign in to comment.