consolidated js into color-thief.js

This commit is contained in:
Lokesh Dhakar
2011-11-03 15:43:04 -04:00
parent 16894c23f4
commit a32716930d
4 changed files with 94 additions and 86 deletions

View File

@@ -7,14 +7,57 @@
* The median cut palette function uses quantize.js which is written by Nick Rabinowitz
* and licensed under the MIT license. Big props to Nick as this is where the magic happens.
*
* == Classes
* CanvasImage
* == Functions
* getDominantColor()
* createPalette()
* getAverageRGB()
* createAreaBasedPalette()
*
* Requires jquery and quantize.js.
*/
/*
CanvasImage Class
Class that wraps the html image element and canvas.
It also simplifies some of the canvas context manipulation
with a set of helper functions.
*/
var CanvasImage = function(image){
// If jquery object is passed in, get html element
this.imgEl = (image.jquery)? image[0]: image;
this.canvas = document.createElement('canvas'),
this.context = this.canvas.getContext('2d');
document.body.appendChild(this.canvas);
this.width = this.canvas.width = $(this.imgEl).width(),
this.height = this.canvas.height = $(this.imgEl).height();
this.context.drawImage(this.imgEl, 0, 0);
}
CanvasImage.prototype.clear = function() {
this.context.clearRect(0, 0, this.width, this.height);
}
CanvasImage.prototype.update = function(imageData) {
console.log('worked');
this.context.putImageData(imageData, 0, 0);
}
CanvasImage.prototype.getPixelCount = function() {
return this.width * this.height;
}
CanvasImage.prototype.getImageData = function() {
return this.context.getImageData(0, 0, this.width, this.height);
}
/*
* getDominantColor(sourceImage)
* returns {r: num, g: num, b: num}