2 * Pixastic Lib - Histogram - v0.1.0
3 * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
4 * MIT License [http://www.opensource.org/licenses/mit-license.php]
7 Pixastic.Actions.histogram = {
8 process : function(params) {
10 var average = !!(params.options.average);
11 var paint = !!(params.options.paint);
12 var color = params.options.color || "rgba(255,255,255,0.5)";
14 if (typeof params.options.returnValue != "object") {
15 params.options.returnValue = {values:[]};
17 var returnValue = params.options.returnValue;
18 if (typeof returnValue.values != "array") {
19 returnValue.values = [];
21 values = returnValue.values;
23 if (Pixastic.Client.hasCanvasImageData()) {
24 var data = Pixastic.prepareData(params);
25 params.useData = false;
27 for (var i=0;i<256;i++) {
31 var rect = params.options.rect;
37 var offsetY = (y-1)*w4;
40 var offset = offsetY + (x*4-4);
41 var brightness = average ?
42 Math.round((data[offset]+data[offset+1]+data[offset+2])/3)
43 : Math.round(data[offset]*0.3 + data[offset+1]*0.59 + data[offset+2]*0.11);
51 for (var i=0;i<256;i++) {
52 if (values[i] > maxValue) {
56 var heightScale = params.height / maxValue;
57 var widthScale = params.width / 256;
58 var ctx = params.canvas.getContext("2d");
59 ctx.fillStyle = color;
60 for (var i=0;i<256;i++) {
62 i * widthScale, params.height - heightScale * values[i],
63 widthScale, values[i] * heightScale
68 returnValue.values = values;
73 checkSupport : function() {
74 return Pixastic.Client.hasCanvasImageData();