Enhancement : Lossless GIF encoding

If there are less than 256 colors in the piskel, do not perform anycolor
quantization, just reuse the colors from the piskel.

Added preserveColorsParameter to gif.js library.

If nb colors>256, fallback to the previous behavior. This could be
improved by checking the number of colors for each frame. The palette is
defined independantly for each frame, so as long as a frame is <256
colors, we could reuse the original colors.

I also believe that images with more colors would get a better quality if
we could use a single color sample for all frames. This would avoid color
'gaps' as we can experience today. In any case, for piskel, < 256 is a
reasonable assumption
This commit is contained in:
jdescottes 2014-05-12 01:06:37 +02:00
parent cf560fce0f
commit 6c882928cc
2 changed files with 11 additions and 2 deletions

View File

@ -10,6 +10,8 @@
// I apologize to my future self for this one.
var NO_SCROLL_MAX_COLORS = 20;
var MAX_COLORS = 100;
ns.PalettesListController = function (paletteController, usedColorService) {
this.usedColorService = usedColorService;
this.paletteController = paletteController;
@ -77,6 +79,11 @@
colors = palette.colors;
}
}
if (colors.length > MAX_COLORS) {
colors = colors.slice(0, MAX_COLORS);
}
return colors;
};

View File

@ -115,12 +115,14 @@
};
ns.GifExportController.prototype.renderAsImageDataAnimatedGIF = function(zoom, fps, cb) {
var preserveColors = pskl.app.currentColorsService.getCurrentColors().length < MAX_GIF_COLORS;
var colorCount = pskl.app.currentColorsService.getCurrentColors().length;
var preserveColors = colorCount < MAX_GIF_COLORS;
var gif = new window.GIF({
workers: 2,
quality: 1,
width: this.piskelController.getWidth()*zoom,
height: this.piskelController.getHeight()*zoom
height: this.piskelController.getHeight()*zoom,
preserveColors : preserveColors
});
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {