Merge pull request #182 from juliandescottes/enhancement-gif-encoding

Enhancement gif encoding
This commit is contained in:
Julian Descottes
2014-05-16 08:25:01 +02:00
4 changed files with 17 additions and 4 deletions

View File

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

View File

@@ -2,6 +2,7 @@
var ns = $.namespace("pskl.controller.settings"); var ns = $.namespace("pskl.controller.settings");
var URL_MAX_LENGTH = 60; var URL_MAX_LENGTH = 60;
var MAX_GIF_COLORS = 256;
ns.GifExportController = function (piskelController) { ns.GifExportController = function (piskelController) {
this.piskelController = piskelController; this.piskelController = piskelController;
@@ -114,11 +115,14 @@
}; };
ns.GifExportController.prototype.renderAsImageDataAnimatedGIF = function(zoom, fps, cb) { ns.GifExportController.prototype.renderAsImageDataAnimatedGIF = function(zoom, fps, cb) {
var colorCount = pskl.app.currentColorsService.getCurrentColors().length;
var preserveColors = colorCount < MAX_GIF_COLORS;
var gif = new window.GIF({ var gif = new window.GIF({
workers: 2, workers: 2,
quality: 10, quality: 1,
width: this.piskelController.getWidth()*zoom, 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++) { for (var i = 0; i < this.piskelController.getFrameCount(); i++) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long