mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
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:
parent
cf560fce0f
commit
6c882928cc
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user