Merge pull request #150 from lokesh/dont-append-dom

refactor: Dont append canvas tag to DOM
This commit is contained in:
Lokesh Dhakar
2019-05-26 20:34:15 -07:00
committed by GitHub
2 changed files with 0 additions and 19 deletions

View File

@@ -45,7 +45,6 @@ const showColorsForImage = function(image, section) {
let start = Date.now(); let start = Date.now();
let result = colorThief.getPalette(image, count); let result = colorThief.getPalette(image, count);
let elapsedTime = Date.now() - start; let elapsedTime = Date.now() - start;
console.log('palette()', count, result.length)
paletteHTML += Mustache.to_html(document.getElementById('palette-tpl').innerHTML, { paletteHTML += Mustache.to_html(document.getElementById('palette-tpl').innerHTML, {
count, count,
palette: result, palette: result,

View File

@@ -28,22 +28,12 @@ var CanvasImage = function (image) {
this.canvas = document.createElement('canvas'); this.canvas = document.createElement('canvas');
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
document.body.appendChild(this.canvas);
this.width = this.canvas.width = image.width; this.width = this.canvas.width = image.width;
this.height = this.canvas.height = image.height; this.height = this.canvas.height = image.height;
this.context.drawImage(image, 0, 0, this.width, this.height); this.context.drawImage(image, 0, 0, this.width, this.height);
}; };
CanvasImage.prototype.clear = function () {
this.context.clearRect(0, 0, this.width, this.height);
};
CanvasImage.prototype.update = function (imageData) {
this.context.putImageData(imageData, 0, 0);
};
CanvasImage.prototype.getPixelCount = function () { CanvasImage.prototype.getPixelCount = function () {
return this.width * this.height; return this.width * this.height;
}; };
@@ -52,11 +42,6 @@ CanvasImage.prototype.getImageData = function () {
return this.context.getImageData(0, 0, this.width, this.height); return this.context.getImageData(0, 0, this.width, this.height);
}; };
CanvasImage.prototype.removeCanvas = function () {
this.canvas.parentNode.removeChild(this.canvas);
};
var ColorThief = function () {}; var ColorThief = function () {};
/* /*
@@ -132,9 +117,6 @@ ColorThief.prototype.getPalette = function(sourceImage, colorCount, quality) {
var cmap = MMCQ.quantize(pixelArray, colorCount); var cmap = MMCQ.quantize(pixelArray, colorCount);
var palette = cmap? cmap.palette() : null; var palette = cmap? cmap.palette() : null;
// Clean up
image.removeCanvas();
return palette; return palette;
}; };