Browse files

fix crlf

  • Loading branch information...
1 parent 9d47c17 commit 0845d479b3b0a1215581c331ffd2a3ee550375e7 Jacob committed Feb 11, 2010
View
1,014 actions/blend.js
@@ -1,508 +1,508 @@
-/*
- * Pixastic Lib - Blend - v0.1.1
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.blend = {
-
- process : function(params) {
- var amount = parseFloat(params.options.amount);
- var mode = (params.options.mode || "normal").toLowerCase();
- var image = params.options.image;
-
- amount = Math.max(0,Math.min(1,amount));
-
- if (!image) return false;
-
- if (Pixastic.Client.hasCanvasImageData()) {
-
- var rect = params.options.rect;
- var data = Pixastic.prepareData(params);
- var w = rect.width;
- var h = rect.height;
-
- params.useData = false;
-
- var otherCanvas = document.createElement("canvas");
- otherCanvas.width = params.canvas.width;
- otherCanvas.height = params.canvas.height;
- var otherCtx = otherCanvas.getContext("2d");
- otherCtx.drawImage(image,0,0);
-
- var params2 = {canvas:otherCanvas,options:params.options};
- var data2 = Pixastic.prepareData(params2);
- var dataDesc2 = params2.canvasData;
-
- var p = w*h;
- var pix = p*4;
- var pix1, pix2;
- var r1, g1, b1;
- var r2, g2, b2;
- var r3, g3, b3;
- var r4, g4, b4;
-
- var dataChanged = false;
-
- switch (mode) {
- case "normal" :
- //while (p--) {
- // data2[pix-=4] = data2[pix];
- // data2[pix1=pix+1] = data2[pix1];
- // data2[pix2=pix+2] = data2[pix2];
- //}
- break;
-
- case "multiply" :
- while (p--) {
- data2[pix-=4] = data[pix] * data2[pix] / 255;
- data2[pix1=pix+1] = data[pix1] * data2[pix1] / 255;
- data2[pix2=pix+2] = data[pix2] * data2[pix2] / 255;
- }
- dataChanged = true;
- break;
-
- case "lighten" :
- while (p--) {
- if ((r1 = data[pix-=4]) > data2[pix])
- data2[pix] = r1;
- if ((g1 = data[pix1=pix+1]) > data2[pix1])
- data2[pix1] = g1;
- if ((b1 = data[pix2=pix+2]) > data2[pix2])
- data2[pix2] = b1;
- }
- dataChanged = true;
- break;
-
- case "darken" :
- while (p--) {
- if ((r1 = data[pix-=4]) < data2[pix])
- data2[pix] = r1;
- if ((g1 = data[pix1=pix+1]) < data2[pix1])
- data2[pix1] = g1;
- if ((b1 = data[pix2=pix+2]) < data2[pix2])
- data2[pix2] = b1;
-
- }
- dataChanged = true;
- break;
-
- case "darkercolor" :
- while (p--) {
- if (((r1 = data[pix-=4])*0.3+(g1 = data[pix1=pix+1])*0.59+(b1 = data[pix2=pix+2])*0.11) <= (data2[pix]*0.3+data2[pix1]*0.59+data2[pix2]*0.11)) {
- data2[pix] = r1;
- data2[pix1] = g1;
- data2[pix2] = b1;
- }
- }
- dataChanged = true;
- break;
-
- case "lightercolor" :
- while (p--) {
- if (((r1 = data[pix-=4])*0.3+(g1 = data[pix1=pix+1])*0.59+(b1 = data[pix2=pix+2])*0.11) > (data2[pix]*0.3+data2[pix1]*0.59+data2[pix2]*0.11)) {
- data2[pix] = r1;
- data2[pix1] = g1;
- data2[pix2] = b1;
- }
- }
- dataChanged = true;
- break;
-
- case "lineardodge" :
- /*
- otherCtx.globalCompositeOperation = "source-over";
- otherCtx.drawImage(params.canvas, 0, 0);
- otherCtx.globalCompositeOperation = "lighter";
- otherCtx.drawImage(image, 0, 0);
- */
-
- while (p--) {
- if ((r3 = data[pix-=4] + data2[pix]) > 255)
- data2[pix] = 255;
- else
- data2[pix] = r3;
- if ((g3 = data[pix1=pix+1] + data2[pix1]) > 255)
- data2[pix1] = 255;
- else
- data2[pix1] = g3;
- if ((b3 = data[pix2=pix+2] + data2[pix2]) > 255)
- data2[pix2] = 255;
- else
- data2[pix2] = b3;
- }
- dataChanged = true;
-
- break;
-
- case "linearburn" :
- while (p--) {
- if ((r3 = data[pix-=4] + data2[pix]) < 255)
- data2[pix] = 0;
- else
- data2[pix] = (r3 - 255);
- if ((g3 = data[pix1=pix+1] + data2[pix1]) < 255)
- data2[pix1] = 0;
- else
- data2[pix1] = (g3 - 255);
- if ((b3 = data[pix2=pix+2] + data2[pix2]) < 255)
- data2[pix2] = 0;
- else
- data2[pix2] = (b3 - 255);
- }
- dataChanged = true;
- break;
-
- case "difference" :
- while (p--) {
- if ((r3 = data[pix-=4] - data2[pix]) < 0)
- data2[pix] = -r3;
- else
- data2[pix] = r3;
- if ((g3 = data[pix1=pix+1] - data2[pix1]) < 0)
- data2[pix1] = -g3;
- else
- data2[pix1] = g3;
- if ((b3 = data[pix2=pix+2] - data2[pix2]) < 0)
- data2[pix2] = -b3;
- else
- data2[pix2] = b3;
- }
- dataChanged = true;
- break;
-
- case "screen" :
- while (p--) {
- data2[pix-=4] = (255 - ( ((255-data2[pix])*(255-data[pix])) >> 8));
- data2[pix1=pix+1] = (255 - ( ((255-data2[pix1])*(255-data[pix1])) >> 8));
- data2[pix2=pix+2] = (255 - ( ((255-data2[pix2])*(255-data[pix2])) >> 8));
- }
- dataChanged = true;
- break;
-
- case "exclusion" :
- var div_2_255 = 2 / 255;
- while (p--) {
- data2[pix-=4] = (r1 = data[pix]) - (r1 * div_2_255 - 1) * data2[pix];
- data2[pix1=pix+1] = (g1 = data[pix1]) - (g1 * div_2_255 - 1) * data2[pix1];
- data2[pix2=pix+2] = (b1 = data[pix2]) - (b1 * div_2_255 - 1) * data2[pix2];
- }
- dataChanged = true;
- break;
-
- case "overlay" :
- var div_2_255 = 2 / 255;
- while (p--) {
- if ((r1 = data[pix-=4]) < 128)
- data2[pix] = data2[pix]*r1*div_2_255;
- else
- data2[pix] = 255 - (255-data2[pix])*(255-r1)*div_2_255;
-
- if ((g1 = data[pix1=pix+1]) < 128)
- data2[pix1] = data2[pix1]*g1*div_2_255;
- else
- data2[pix1] = 255 - (255-data2[pix1])*(255-g1)*div_2_255;
-
- if ((b1 = data[pix2=pix+2]) < 128)
- data2[pix2] = data2[pix2]*b1*div_2_255;
- else
- data2[pix2] = 255 - (255-data2[pix2])*(255-b1)*div_2_255;
-
- }
- dataChanged = true;
- break;
-
- case "softlight" :
- var div_2_255 = 2 / 255;
- while (p--) {
- if ((r1 = data[pix-=4]) < 128)
- data2[pix] = ((data2[pix]>>1) + 64) * r1 * div_2_255;
- else
- data2[pix] = 255 - (191 - (data2[pix]>>1)) * (255-r1) * div_2_255;
-
- if ((g1 = data[pix1=pix+1]) < 128)
- data2[pix1] = ((data2[pix1]>>1)+64) * g1 * div_2_255;
- else
- data2[pix1] = 255 - (191 - (data2[pix1]>>1)) * (255-g1) * div_2_255;
-
- if ((b1 = data[pix2=pix+2]) < 128)
- data2[pix2] = ((data2[pix2]>>1)+64) * b1 * div_2_255;
- else
- data2[pix2] = 255 - (191 - (data2[pix2]>>1)) * (255-b1) * div_2_255;
-
- }
- dataChanged = true;
- break;
-
- case "hardlight" :
- var div_2_255 = 2 / 255;
- while (p--) {
- if ((r2 = data2[pix-=4]) < 128)
- data2[pix] = data[pix] * r2 * div_2_255;
- else
- data2[pix] = 255 - (255-data[pix]) * (255-r2) * div_2_255;
-
- if ((g2 = data2[pix1=pix+1]) < 128)
- data2[pix1] = data[pix1] * g2 * div_2_255;
- else
- data2[pix1] = 255 - (255-data[pix1]) * (255-g2) * div_2_255;
-
- if ((b2 = data2[pix2=pix+2]) < 128)
- data2[pix2] = data[pix2] * b2 * div_2_255;
- else
- data2[pix2] = 255 - (255-data[pix2]) * (255-b2) * div_2_255;
-
- }
- dataChanged = true;
- break;
-
- case "colordodge" :
- while (p--) {
- if ((r3 = (data[pix-=4]<<8)/(255-(r2 = data2[pix]))) > 255 || r2 == 255)
- data2[pix] = 255;
- else
- data2[pix] = r3;
-
- if ((g3 = (data[pix1=pix+1]<<8)/(255-(g2 = data2[pix1]))) > 255 || g2 == 255)
- data2[pix1] = 255;
- else
- data2[pix1] = g3;
-
- if ((b3 = (data[pix2=pix+2]<<8)/(255-(b2 = data2[pix2]))) > 255 || b2 == 255)
- data2[pix2] = 255;
- else
- data2[pix2] = b3;
- }
- dataChanged = true;
- break;
-
- case "colorburn" :
- while (p--) {
- if ((r3 = 255-((255-data[pix-=4])<<8)/data2[pix]) < 0 || data2[pix] == 0)
- data2[pix] = 0;
- else
- data2[pix] = r3;
-
- if ((g3 = 255-((255-data[pix1=pix+1])<<8)/data2[pix1]) < 0 || data2[pix1] == 0)
- data2[pix1] = 0;
- else
- data2[pix1] = g3;
-
- if ((b3 = 255-((255-data[pix2=pix+2])<<8)/data2[pix2]) < 0 || data2[pix2] == 0)
- data2[pix2] = 0;
- else
- data2[pix2] = b3;
- }
- dataChanged = true;
- break;
-
- case "linearlight" :
- while (p--) {
- if ( ((r3 = 2*(r2=data2[pix-=4])+data[pix]-256) < 0) || (r2 < 128 && r3 < 0)) {
- data2[pix] = 0
- } else {
- if (r3 > 255)
- data2[pix] = 255;
- else
- data2[pix] = r3;
- }
- if ( ((g3 = 2*(g2=data2[pix1=pix+1])+data[pix1]-256) < 0) || (g2 < 128 && g3 < 0)) {
- data2[pix1] = 0
- } else {
- if (g3 > 255)
- data2[pix1] = 255;
- else
- data2[pix1] = g3;
- }
- if ( ((b3 = 2*(b2=data2[pix2=pix+2])+data[pix2]-256) < 0) || (b2 < 128 && b3 < 0)) {
- data2[pix2] = 0
- } else {
- if (b3 > 255)
- data2[pix2] = 255;
- else
- data2[pix2] = b3;
- }
- }
- dataChanged = true;
- break;
-
- case "vividlight" :
- while (p--) {
- if ((r2=data2[pix-=4]) < 128) {
- if (r2) {
- if ((r3 = 255 - ((255-data[pix])<<8) / (2*r2)) < 0)
- data2[pix] = 0;
- else
- data2[pix] = r3
- } else {
- data2[pix] = 0;
- }
- } else if ((r3 = (r4=2*r2-256)) < 255) {
- if ((r3 = (data[pix]<<8)/(255-r4)) > 255)
- data2[pix] = 255;
- else
- data2[pix] = r3;
- } else {
- if (r3 < 0)
- data2[pix] = 0;
- else
- data2[pix] = r3
- }
-
- if ((g2=data2[pix1=pix+1]) < 128) {
- if (g2) {
- if ((g3 = 255 - ((255-data[pix1])<<8) / (2*g2)) < 0)
- data2[pix1] = 0;
- else
- data2[pix1] = g3;
- } else {
- data2[pix1] = 0;
- }
- } else if ((g3 = (g4=2*g2-256)) < 255) {
- if ((g3 = (data[pix1]<<8)/(255-g4)) > 255)
- data2[pix1] = 255;
- else
- data2[pix1] = g3;
- } else {
- if (g3 < 0)
- data2[pix1] = 0;
- else
- data2[pix1] = g3;
- }
-
- if ((b2=data2[pix2=pix+2]) < 128) {
- if (b2) {
- if ((b3 = 255 - ((255-data[pix2])<<8) / (2*b2)) < 0)
- data2[pix2] = 0;
- else
- data2[pix2] = b3;
- } else {
- data2[pix2] = 0;
- }
- } else if ((b3 = (b4=2*b2-256)) < 255) {
- if ((b3 = (data[pix2]<<8)/(255-b4)) > 255)
- data2[pix2] = 255;
- else
- data2[pix2] = b3;
- } else {
- if (b3 < 0)
- data2[pix2] = 0;
- else
- data2[pix2] = b3;
- }
- }
- dataChanged = true;
- break;
-
- case "pinlight" :
- while (p--) {
- if ((r2=data2[pix-=4]) < 128)
- if ((r1=data[pix]) < (r4=2*r2))
- data2[pix] = r1;
- else
- data2[pix] = r4;
- else
- if ((r1=data[pix]) > (r4=2*r2-256))
- data2[pix] = r1;
- else
- data2[pix] = r4;
-
- if ((g2=data2[pix1=pix+1]) < 128)
- if ((g1=data[pix1]) < (g4=2*g2))
- data2[pix1] = g1;
- else
- data2[pix1] = g4;
- else
- if ((g1=data[pix1]) > (g4=2*g2-256))
- data2[pix1] = g1;
- else
- data2[pix1] = g4;
-
- if ((r2=data2[pix2=pix+2]) < 128)
- if ((r1=data[pix2]) < (r4=2*r2))
- data2[pix2] = r1;
- else
- data2[pix2] = r4;
- else
- if ((r1=data[pix2]) > (r4=2*r2-256))
- data2[pix2] = r1;
- else
- data2[pix2] = r4;
- }
- dataChanged = true;
- break;
-
- case "hardmix" :
- while (p--) {
- if ((r2 = data2[pix-=4]) < 128)
- if (255 - ((255-data[pix])<<8)/(2*r2) < 128 || r2 == 0)
- data2[pix] = 0;
- else
- data2[pix] = 255;
- else if ((r4=2*r2-256) < 255 && (data[pix]<<8)/(255-r4) < 128)
- data2[pix] = 0;
- else
- data2[pix] = 255;
-
- if ((g2 = data2[pix1=pix+1]) < 128)
- if (255 - ((255-data[pix1])<<8)/(2*g2) < 128 || g2 == 0)
- data2[pix1] = 0;
- else
- data2[pix1] = 255;
- else if ((g4=2*g2-256) < 255 && (data[pix1]<<8)/(255-g4) < 128)
- data2[pix1] = 0;
- else
- data2[pix1] = 255;
-
- if ((b2 = data2[pix2=pix+2]) < 128)
- if (255 - ((255-data[pix2])<<8)/(2*b2) < 128 || b2 == 0)
- data2[pix2] = 0;
- else
- data2[pix2] = 255;
- else if ((b4=2*b2-256) < 255 && (data[pix2]<<8)/(255-b4) < 128)
- data2[pix2] = 0;
- else
- data2[pix2] = 255;
- }
- dataChanged = true;
- break;
- }
-
- if (dataChanged)
- otherCtx.putImageData(dataDesc2,0,0);
-
- if (amount != 1 && !Pixastic.Client.hasGlobalAlpha()) {
- var p = w*h;
- var amount2 = amount;
- var amount1 = 1 - amount;
- while (p--) {
- var pix = p*4;
- var r = (data[pix] * amount1 + data2[pix] * amount2)>>0;
- var g = (data[pix+1] * amount1 + data2[pix+1] * amount2)>>0;
- var b = (data[pix+2] * amount1 + data2[pix+2] * amount2)>>0;
-
- data[pix] = r;
- data[pix+1] = g;
- data[pix+2] = b;
- }
- params.useData = true;
- } else {
- var ctx = params.canvas.getContext("2d");
- ctx.save();
- ctx.globalAlpha = amount;
- ctx.drawImage(
- otherCanvas,
- 0,0,rect.width,rect.height,
- rect.left,rect.top,rect.width,rect.height
- );
- ctx.globalAlpha = 1;
- ctx.restore();
- }
-
- return true;
- }
- },
- checkSupport : function() {
- return Pixastic.Client.hasCanvasImageData();
- }
+/*
+ * Pixastic Lib - Blend - v0.1.1
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.blend = {
+
+ process : function(params) {
+ var amount = parseFloat(params.options.amount);
+ var mode = (params.options.mode || "normal").toLowerCase();
+ var image = params.options.image;
+
+ amount = Math.max(0,Math.min(1,amount));
+
+ if (!image) return false;
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+
+ var rect = params.options.rect;
+ var data = Pixastic.prepareData(params);
+ var w = rect.width;
+ var h = rect.height;
+
+ params.useData = false;
+
+ var otherCanvas = document.createElement("canvas");
+ otherCanvas.width = params.canvas.width;
+ otherCanvas.height = params.canvas.height;
+ var otherCtx = otherCanvas.getContext("2d");
+ otherCtx.drawImage(image,0,0);
+
+ var params2 = {canvas:otherCanvas,options:params.options};
+ var data2 = Pixastic.prepareData(params2);
+ var dataDesc2 = params2.canvasData;
+
+ var p = w*h;
+ var pix = p*4;
+ var pix1, pix2;
+ var r1, g1, b1;
+ var r2, g2, b2;
+ var r3, g3, b3;
+ var r4, g4, b4;
+
+ var dataChanged = false;
+
+ switch (mode) {
+ case "normal" :
+ //while (p--) {
+ // data2[pix-=4] = data2[pix];
+ // data2[pix1=pix+1] = data2[pix1];
+ // data2[pix2=pix+2] = data2[pix2];
+ //}
+ break;
+
+ case "multiply" :
+ while (p--) {
+ data2[pix-=4] = data[pix] * data2[pix] / 255;
+ data2[pix1=pix+1] = data[pix1] * data2[pix1] / 255;
+ data2[pix2=pix+2] = data[pix2] * data2[pix2] / 255;
+ }
+ dataChanged = true;
+ break;
+
+ case "lighten" :
+ while (p--) {
+ if ((r1 = data[pix-=4]) > data2[pix])
+ data2[pix] = r1;
+ if ((g1 = data[pix1=pix+1]) > data2[pix1])
+ data2[pix1] = g1;
+ if ((b1 = data[pix2=pix+2]) > data2[pix2])
+ data2[pix2] = b1;
+ }
+ dataChanged = true;
+ break;
+
+ case "darken" :
+ while (p--) {
+ if ((r1 = data[pix-=4]) < data2[pix])
+ data2[pix] = r1;
+ if ((g1 = data[pix1=pix+1]) < data2[pix1])
+ data2[pix1] = g1;
+ if ((b1 = data[pix2=pix+2]) < data2[pix2])
+ data2[pix2] = b1;
+
+ }
+ dataChanged = true;
+ break;
+
+ case "darkercolor" :
+ while (p--) {
+ if (((r1 = data[pix-=4])*0.3+(g1 = data[pix1=pix+1])*0.59+(b1 = data[pix2=pix+2])*0.11) <= (data2[pix]*0.3+data2[pix1]*0.59+data2[pix2]*0.11)) {
+ data2[pix] = r1;
+ data2[pix1] = g1;
+ data2[pix2] = b1;
+ }
+ }
+ dataChanged = true;
+ break;
+
+ case "lightercolor" :
+ while (p--) {
+ if (((r1 = data[pix-=4])*0.3+(g1 = data[pix1=pix+1])*0.59+(b1 = data[pix2=pix+2])*0.11) > (data2[pix]*0.3+data2[pix1]*0.59+data2[pix2]*0.11)) {
+ data2[pix] = r1;
+ data2[pix1] = g1;
+ data2[pix2] = b1;
+ }
+ }
+ dataChanged = true;
+ break;
+
+ case "lineardodge" :
+ /*
+ otherCtx.globalCompositeOperation = "source-over";
+ otherCtx.drawImage(params.canvas, 0, 0);
+ otherCtx.globalCompositeOperation = "lighter";
+ otherCtx.drawImage(image, 0, 0);
+ */
+
+ while (p--) {
+ if ((r3 = data[pix-=4] + data2[pix]) > 255)
+ data2[pix] = 255;
+ else
+ data2[pix] = r3;
+ if ((g3 = data[pix1=pix+1] + data2[pix1]) > 255)
+ data2[pix1] = 255;
+ else
+ data2[pix1] = g3;
+ if ((b3 = data[pix2=pix+2] + data2[pix2]) > 255)
+ data2[pix2] = 255;
+ else
+ data2[pix2] = b3;
+ }
+ dataChanged = true;
+
+ break;
+
+ case "linearburn" :
+ while (p--) {
+ if ((r3 = data[pix-=4] + data2[pix]) < 255)
+ data2[pix] = 0;
+ else
+ data2[pix] = (r3 - 255);
+ if ((g3 = data[pix1=pix+1] + data2[pix1]) < 255)
+ data2[pix1] = 0;
+ else
+ data2[pix1] = (g3 - 255);
+ if ((b3 = data[pix2=pix+2] + data2[pix2]) < 255)
+ data2[pix2] = 0;
+ else
+ data2[pix2] = (b3 - 255);
+ }
+ dataChanged = true;
+ break;
+
+ case "difference" :
+ while (p--) {
+ if ((r3 = data[pix-=4] - data2[pix]) < 0)
+ data2[pix] = -r3;
+ else
+ data2[pix] = r3;
+ if ((g3 = data[pix1=pix+1] - data2[pix1]) < 0)
+ data2[pix1] = -g3;
+ else
+ data2[pix1] = g3;
+ if ((b3 = data[pix2=pix+2] - data2[pix2]) < 0)
+ data2[pix2] = -b3;
+ else
+ data2[pix2] = b3;
+ }
+ dataChanged = true;
+ break;
+
+ case "screen" :
+ while (p--) {
+ data2[pix-=4] = (255 - ( ((255-data2[pix])*(255-data[pix])) >> 8));
+ data2[pix1=pix+1] = (255 - ( ((255-data2[pix1])*(255-data[pix1])) >> 8));
+ data2[pix2=pix+2] = (255 - ( ((255-data2[pix2])*(255-data[pix2])) >> 8));
+ }
+ dataChanged = true;
+ break;
+
+ case "exclusion" :
+ var div_2_255 = 2 / 255;
+ while (p--) {
+ data2[pix-=4] = (r1 = data[pix]) - (r1 * div_2_255 - 1) * data2[pix];
+ data2[pix1=pix+1] = (g1 = data[pix1]) - (g1 * div_2_255 - 1) * data2[pix1];
+ data2[pix2=pix+2] = (b1 = data[pix2]) - (b1 * div_2_255 - 1) * data2[pix2];
+ }
+ dataChanged = true;
+ break;
+
+ case "overlay" :
+ var div_2_255 = 2 / 255;
+ while (p--) {
+ if ((r1 = data[pix-=4]) < 128)
+ data2[pix] = data2[pix]*r1*div_2_255;
+ else
+ data2[pix] = 255 - (255-data2[pix])*(255-r1)*div_2_255;
+
+ if ((g1 = data[pix1=pix+1]) < 128)
+ data2[pix1] = data2[pix1]*g1*div_2_255;
+ else
+ data2[pix1] = 255 - (255-data2[pix1])*(255-g1)*div_2_255;
+
+ if ((b1 = data[pix2=pix+2]) < 128)
+ data2[pix2] = data2[pix2]*b1*div_2_255;
+ else
+ data2[pix2] = 255 - (255-data2[pix2])*(255-b1)*div_2_255;
+
+ }
+ dataChanged = true;
+ break;
+
+ case "softlight" :
+ var div_2_255 = 2 / 255;
+ while (p--) {
+ if ((r1 = data[pix-=4]) < 128)
+ data2[pix] = ((data2[pix]>>1) + 64) * r1 * div_2_255;
+ else
+ data2[pix] = 255 - (191 - (data2[pix]>>1)) * (255-r1) * div_2_255;
+
+ if ((g1 = data[pix1=pix+1]) < 128)
+ data2[pix1] = ((data2[pix1]>>1)+64) * g1 * div_2_255;
+ else
+ data2[pix1] = 255 - (191 - (data2[pix1]>>1)) * (255-g1) * div_2_255;
+
+ if ((b1 = data[pix2=pix+2]) < 128)
+ data2[pix2] = ((data2[pix2]>>1)+64) * b1 * div_2_255;
+ else
+ data2[pix2] = 255 - (191 - (data2[pix2]>>1)) * (255-b1) * div_2_255;
+
+ }
+ dataChanged = true;
+ break;
+
+ case "hardlight" :
+ var div_2_255 = 2 / 255;
+ while (p--) {
+ if ((r2 = data2[pix-=4]) < 128)
+ data2[pix] = data[pix] * r2 * div_2_255;
+ else
+ data2[pix] = 255 - (255-data[pix]) * (255-r2) * div_2_255;
+
+ if ((g2 = data2[pix1=pix+1]) < 128)
+ data2[pix1] = data[pix1] * g2 * div_2_255;
+ else
+ data2[pix1] = 255 - (255-data[pix1]) * (255-g2) * div_2_255;
+
+ if ((b2 = data2[pix2=pix+2]) < 128)
+ data2[pix2] = data[pix2] * b2 * div_2_255;
+ else
+ data2[pix2] = 255 - (255-data[pix2]) * (255-b2) * div_2_255;
+
+ }
+ dataChanged = true;
+ break;
+
+ case "colordodge" :
+ while (p--) {
+ if ((r3 = (data[pix-=4]<<8)/(255-(r2 = data2[pix]))) > 255 || r2 == 255)
+ data2[pix] = 255;
+ else
+ data2[pix] = r3;
+
+ if ((g3 = (data[pix1=pix+1]<<8)/(255-(g2 = data2[pix1]))) > 255 || g2 == 255)
+ data2[pix1] = 255;
+ else
+ data2[pix1] = g3;
+
+ if ((b3 = (data[pix2=pix+2]<<8)/(255-(b2 = data2[pix2]))) > 255 || b2 == 255)
+ data2[pix2] = 255;
+ else
+ data2[pix2] = b3;
+ }
+ dataChanged = true;
+ break;
+
+ case "colorburn" :
+ while (p--) {
+ if ((r3 = 255-((255-data[pix-=4])<<8)/data2[pix]) < 0 || data2[pix] == 0)
+ data2[pix] = 0;
+ else
+ data2[pix] = r3;
+
+ if ((g3 = 255-((255-data[pix1=pix+1])<<8)/data2[pix1]) < 0 || data2[pix1] == 0)
+ data2[pix1] = 0;
+ else
+ data2[pix1] = g3;
+
+ if ((b3 = 255-((255-data[pix2=pix+2])<<8)/data2[pix2]) < 0 || data2[pix2] == 0)
+ data2[pix2] = 0;
+ else
+ data2[pix2] = b3;
+ }
+ dataChanged = true;
+ break;
+
+ case "linearlight" :
+ while (p--) {
+ if ( ((r3 = 2*(r2=data2[pix-=4])+data[pix]-256) < 0) || (r2 < 128 && r3 < 0)) {
+ data2[pix] = 0
+ } else {
+ if (r3 > 255)
+ data2[pix] = 255;
+ else
+ data2[pix] = r3;
+ }
+ if ( ((g3 = 2*(g2=data2[pix1=pix+1])+data[pix1]-256) < 0) || (g2 < 128 && g3 < 0)) {
+ data2[pix1] = 0
+ } else {
+ if (g3 > 255)
+ data2[pix1] = 255;
+ else
+ data2[pix1] = g3;
+ }
+ if ( ((b3 = 2*(b2=data2[pix2=pix+2])+data[pix2]-256) < 0) || (b2 < 128 && b3 < 0)) {
+ data2[pix2] = 0
+ } else {
+ if (b3 > 255)
+ data2[pix2] = 255;
+ else
+ data2[pix2] = b3;
+ }
+ }
+ dataChanged = true;
+ break;
+
+ case "vividlight" :
+ while (p--) {
+ if ((r2=data2[pix-=4]) < 128) {
+ if (r2) {
+ if ((r3 = 255 - ((255-data[pix])<<8) / (2*r2)) < 0)
+ data2[pix] = 0;
+ else
+ data2[pix] = r3
+ } else {
+ data2[pix] = 0;
+ }
+ } else if ((r3 = (r4=2*r2-256)) < 255) {
+ if ((r3 = (data[pix]<<8)/(255-r4)) > 255)
+ data2[pix] = 255;
+ else
+ data2[pix] = r3;
+ } else {
+ if (r3 < 0)
+ data2[pix] = 0;
+ else
+ data2[pix] = r3
+ }
+
+ if ((g2=data2[pix1=pix+1]) < 128) {
+ if (g2) {
+ if ((g3 = 255 - ((255-data[pix1])<<8) / (2*g2)) < 0)
+ data2[pix1] = 0;
+ else
+ data2[pix1] = g3;
+ } else {
+ data2[pix1] = 0;
+ }
+ } else if ((g3 = (g4=2*g2-256)) < 255) {
+ if ((g3 = (data[pix1]<<8)/(255-g4)) > 255)
+ data2[pix1] = 255;
+ else
+ data2[pix1] = g3;
+ } else {
+ if (g3 < 0)
+ data2[pix1] = 0;
+ else
+ data2[pix1] = g3;
+ }
+
+ if ((b2=data2[pix2=pix+2]) < 128) {
+ if (b2) {
+ if ((b3 = 255 - ((255-data[pix2])<<8) / (2*b2)) < 0)
+ data2[pix2] = 0;
+ else
+ data2[pix2] = b3;
+ } else {
+ data2[pix2] = 0;
+ }
+ } else if ((b3 = (b4=2*b2-256)) < 255) {
+ if ((b3 = (data[pix2]<<8)/(255-b4)) > 255)
+ data2[pix2] = 255;
+ else
+ data2[pix2] = b3;
+ } else {
+ if (b3 < 0)
+ data2[pix2] = 0;
+ else
+ data2[pix2] = b3;
+ }
+ }
+ dataChanged = true;
+ break;
+
+ case "pinlight" :
+ while (p--) {
+ if ((r2=data2[pix-=4]) < 128)
+ if ((r1=data[pix]) < (r4=2*r2))
+ data2[pix] = r1;
+ else
+ data2[pix] = r4;
+ else
+ if ((r1=data[pix]) > (r4=2*r2-256))
+ data2[pix] = r1;
+ else
+ data2[pix] = r4;
+
+ if ((g2=data2[pix1=pix+1]) < 128)
+ if ((g1=data[pix1]) < (g4=2*g2))
+ data2[pix1] = g1;
+ else
+ data2[pix1] = g4;
+ else
+ if ((g1=data[pix1]) > (g4=2*g2-256))
+ data2[pix1] = g1;
+ else
+ data2[pix1] = g4;
+
+ if ((r2=data2[pix2=pix+2]) < 128)
+ if ((r1=data[pix2]) < (r4=2*r2))
+ data2[pix2] = r1;
+ else
+ data2[pix2] = r4;
+ else
+ if ((r1=data[pix2]) > (r4=2*r2-256))
+ data2[pix2] = r1;
+ else
+ data2[pix2] = r4;
+ }
+ dataChanged = true;
+ break;
+
+ case "hardmix" :
+ while (p--) {
+ if ((r2 = data2[pix-=4]) < 128)
+ if (255 - ((255-data[pix])<<8)/(2*r2) < 128 || r2 == 0)
+ data2[pix] = 0;
+ else
+ data2[pix] = 255;
+ else if ((r4=2*r2-256) < 255 && (data[pix]<<8)/(255-r4) < 128)
+ data2[pix] = 0;
+ else
+ data2[pix] = 255;
+
+ if ((g2 = data2[pix1=pix+1]) < 128)
+ if (255 - ((255-data[pix1])<<8)/(2*g2) < 128 || g2 == 0)
+ data2[pix1] = 0;
+ else
+ data2[pix1] = 255;
+ else if ((g4=2*g2-256) < 255 && (data[pix1]<<8)/(255-g4) < 128)
+ data2[pix1] = 0;
+ else
+ data2[pix1] = 255;
+
+ if ((b2 = data2[pix2=pix+2]) < 128)
+ if (255 - ((255-data[pix2])<<8)/(2*b2) < 128 || b2 == 0)
+ data2[pix2] = 0;
+ else
+ data2[pix2] = 255;
+ else if ((b4=2*b2-256) < 255 && (data[pix2]<<8)/(255-b4) < 128)
+ data2[pix2] = 0;
+ else
+ data2[pix2] = 255;
+ }
+ dataChanged = true;
+ break;
+ }
+
+ if (dataChanged)
+ otherCtx.putImageData(dataDesc2,0,0);
+
+ if (amount != 1 && !Pixastic.Client.hasGlobalAlpha()) {
+ var p = w*h;
+ var amount2 = amount;
+ var amount1 = 1 - amount;
+ while (p--) {
+ var pix = p*4;
+ var r = (data[pix] * amount1 + data2[pix] * amount2)>>0;
+ var g = (data[pix+1] * amount1 + data2[pix+1] * amount2)>>0;
+ var b = (data[pix+2] * amount1 + data2[pix+2] * amount2)>>0;
+
+ data[pix] = r;
+ data[pix+1] = g;
+ data[pix+2] = b;
+ }
+ params.useData = true;
+ } else {
+ var ctx = params.canvas.getContext("2d");
+ ctx.save();
+ ctx.globalAlpha = amount;
+ ctx.drawImage(
+ otherCanvas,
+ 0,0,rect.width,rect.height,
+ rect.left,rect.top,rect.width,rect.height
+ );
+ ctx.globalAlpha = 1;
+ ctx.restore();
+ }
+
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return Pixastic.Client.hasCanvasImageData();
+ }
}
View
250 actions/blur.js
@@ -1,126 +1,126 @@
-/*
- * Pixastic Lib - Blur filter - v0.1.0
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.blur = {
- process : function(params) {
-
- if (typeof params.options.fixMargin == "undefined")
- params.options.fixMargin = true;
-
- if (Pixastic.Client.hasCanvasImageData()) {
- var data = Pixastic.prepareData(params);
- var dataCopy = Pixastic.prepareData(params, true)
-
- /*
- var kernel = [
- [0.5, 1, 0.5],
- [1, 2, 1],
- [0.5, 1, 0.5]
- ];
- */
-
- var kernel = [
- [0, 1, 0],
- [1, 2, 1],
- [0, 1, 0]
- ];
-
- var weight = 0;
- for (var i=0;i<3;i++) {
- for (var j=0;j<3;j++) {
- weight += kernel[i][j];
- }
- }
-
- weight = 1 / (weight*2);
-
- var rect = params.options.rect;
- var w = rect.width;
- var h = rect.height;
-
- var w4 = w*4;
- var y = h;
- do {
- var offsetY = (y-1)*w4;
-
- var prevY = (y == 1) ? 0 : y-2;
- var nextY = (y == h) ? y - 1 : y;
-
- var offsetYPrev = prevY*w*4;
- var offsetYNext = nextY*w*4;
-
- var x = w;
- do {
- var offset = offsetY + (x*4-4);
-
- var offsetPrev = offsetYPrev + ((x == 1) ? 0 : x-2) * 4;
- var offsetNext = offsetYNext + ((x == w) ? x-1 : x) * 4;
-
- data[offset] = (
- /*
- dataCopy[offsetPrev - 4]
- + dataCopy[offsetPrev+4]
- + dataCopy[offsetNext - 4]
- + dataCopy[offsetNext+4]
- +
- */
- (dataCopy[offsetPrev]
- + dataCopy[offset-4]
- + dataCopy[offset+4]
- + dataCopy[offsetNext]) * 2
- + dataCopy[offset] * 4
- ) * weight;
-
- data[offset+1] = (
- /*
- dataCopy[offsetPrev - 3]
- + dataCopy[offsetPrev+5]
- + dataCopy[offsetNext - 3]
- + dataCopy[offsetNext+5]
- +
- */
- (dataCopy[offsetPrev+1]
- + dataCopy[offset-3]
- + dataCopy[offset+5]
- + dataCopy[offsetNext+1]) * 2
- + dataCopy[offset+1] * 4
- ) * weight;
-
- data[offset+2] = (
- /*
- dataCopy[offsetPrev - 2]
- + dataCopy[offsetPrev+6]
- + dataCopy[offsetNext - 2]
- + dataCopy[offsetNext+6]
- +
- */
- (dataCopy[offsetPrev+2]
- + dataCopy[offset-2]
- + dataCopy[offset+6]
- + dataCopy[offsetNext+2]) * 2
- + dataCopy[offset+2] * 4
- ) * weight;
-
- } while (--x);
- } while (--y);
-
- return true;
-
- } else if (Pixastic.Client.isIE()) {
- params.image.style.filter += " progid:DXImageTransform.Microsoft.Blur(pixelradius=1.5)";
-
- if (params.options.fixMargin) {
- params.image.style.marginLeft = (parseInt(params.image.style.marginLeft,10)||0) - 2 + "px";
- params.image.style.marginTop = (parseInt(params.image.style.marginTop,10)||0) - 2 + "px";
- }
-
- return true;
- }
- },
- checkSupport : function() {
- return (Pixastic.Client.hasCanvasImageData() || Pixastic.Client.isIE());
- }
+/*
+ * Pixastic Lib - Blur filter - v0.1.0
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.blur = {
+ process : function(params) {
+
+ if (typeof params.options.fixMargin == "undefined")
+ params.options.fixMargin = true;
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+ var data = Pixastic.prepareData(params);
+ var dataCopy = Pixastic.prepareData(params, true)
+
+ /*
+ var kernel = [
+ [0.5, 1, 0.5],
+ [1, 2, 1],
+ [0.5, 1, 0.5]
+ ];
+ */
+
+ var kernel = [
+ [0, 1, 0],
+ [1, 2, 1],
+ [0, 1, 0]
+ ];
+
+ var weight = 0;
+ for (var i=0;i<3;i++) {
+ for (var j=0;j<3;j++) {
+ weight += kernel[i][j];
+ }
+ }
+
+ weight = 1 / (weight*2);
+
+ var rect = params.options.rect;
+ var w = rect.width;
+ var h = rect.height;
+
+ var w4 = w*4;
+ var y = h;
+ do {
+ var offsetY = (y-1)*w4;
+
+ var prevY = (y == 1) ? 0 : y-2;
+ var nextY = (y == h) ? y - 1 : y;
+
+ var offsetYPrev = prevY*w*4;
+ var offsetYNext = nextY*w*4;
+
+ var x = w;
+ do {
+ var offset = offsetY + (x*4-4);
+
+ var offsetPrev = offsetYPrev + ((x == 1) ? 0 : x-2) * 4;
+ var offsetNext = offsetYNext + ((x == w) ? x-1 : x) * 4;
+
+ data[offset] = (
+ /*
+ dataCopy[offsetPrev - 4]
+ + dataCopy[offsetPrev+4]
+ + dataCopy[offsetNext - 4]
+ + dataCopy[offsetNext+4]
+ +
+ */
+ (dataCopy[offsetPrev]
+ + dataCopy[offset-4]
+ + dataCopy[offset+4]
+ + dataCopy[offsetNext]) * 2
+ + dataCopy[offset] * 4
+ ) * weight;
+
+ data[offset+1] = (
+ /*
+ dataCopy[offsetPrev - 3]
+ + dataCopy[offsetPrev+5]
+ + dataCopy[offsetNext - 3]
+ + dataCopy[offsetNext+5]
+ +
+ */
+ (dataCopy[offsetPrev+1]
+ + dataCopy[offset-3]
+ + dataCopy[offset+5]
+ + dataCopy[offsetNext+1]) * 2
+ + dataCopy[offset+1] * 4
+ ) * weight;
+
+ data[offset+2] = (
+ /*
+ dataCopy[offsetPrev - 2]
+ + dataCopy[offsetPrev+6]
+ + dataCopy[offsetNext - 2]
+ + dataCopy[offsetNext+6]
+ +
+ */
+ (dataCopy[offsetPrev+2]
+ + dataCopy[offset-2]
+ + dataCopy[offset+6]
+ + dataCopy[offsetNext+2]) * 2
+ + dataCopy[offset+2] * 4
+ ) * weight;
+
+ } while (--x);
+ } while (--y);
+
+ return true;
+
+ } else if (Pixastic.Client.isIE()) {
+ params.image.style.filter += " progid:DXImageTransform.Microsoft.Blur(pixelradius=1.5)";
+
+ if (params.options.fixMargin) {
+ params.image.style.marginLeft = (parseInt(params.image.style.marginLeft,10)||0) - 2 + "px";
+ params.image.style.marginTop = (parseInt(params.image.style.marginTop,10)||0) - 2 + "px";
+ }
+
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return (Pixastic.Client.hasCanvasImageData() || Pixastic.Client.isIE());
+ }
}
View
154 actions/blurfast.js
@@ -1,77 +1,77 @@
-/*
- * Pixastic Lib - Blur Fast - v0.1.1
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.blurfast = {
- process : function(params) {
-
- var amount = parseFloat(params.options.amount)||0;
- var clear = !!(params.options.clear && params.options.clear != "false");
-
- amount = Math.max(0,Math.min(5,amount));
-
- if (Pixastic.Client.hasCanvas()) {
- var rect = params.options.rect;
-
- var ctx = params.canvas.getContext("2d");
- ctx.save();
- ctx.beginPath();
- ctx.rect(rect.left, rect.top, rect.width, rect.height);
- ctx.clip();
-
- var scale = 2;
- var smallWidth = Math.round(params.width / scale);
- var smallHeight = Math.round(params.height / scale);
-
- var copy = document.createElement("canvas");
- copy.width = smallWidth;
- copy.height = smallHeight;
-
- var clear = false;
- var steps = Math.round(amount * 20);
-
- var copyCtx = copy.getContext("2d");
- for (var i=0;i<steps;i++) {
- var scaledWidth = Math.max(1,Math.round(smallWidth - i));
- var scaledHeight = Math.max(1,Math.round(smallHeight - i));
-
- copyCtx.clearRect(0,0,smallWidth,smallHeight);
-
- copyCtx.drawImage(
- params.canvas,
- 0,0,params.width,params.height,
- 0,0,scaledWidth,scaledHeight
- );
-
- if (clear)
- ctx.clearRect(rect.left,rect.top,rect.width,rect.height);
-
- ctx.drawImage(
- copy,
- 0,0,scaledWidth,scaledHeight,
- 0,0,params.width,params.height
- );
- }
-
- ctx.restore();
-
- params.useData = false;
- return true;
- } else if (Pixastic.Client.isIE()) {
- var radius = 10 * amount;
- params.image.style.filter += " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + radius + ")";
-
- if (params.options.fixMargin || 1) {
- params.image.style.marginLeft = (parseInt(params.image.style.marginLeft,10)||0) - Math.round(radius) + "px";
- params.image.style.marginTop = (parseInt(params.image.style.marginTop,10)||0) - Math.round(radius) + "px";
- }
-
- return true;
- }
- },
- checkSupport : function() {
- return (Pixastic.Client.hasCanvas() || Pixastic.Client.isIE());
- }
-}
+/*
+ * Pixastic Lib - Blur Fast - v0.1.1
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.blurfast = {
+ process : function(params) {
+
+ var amount = parseFloat(params.options.amount)||0;
+ var clear = !!(params.options.clear && params.options.clear != "false");
+
+ amount = Math.max(0,Math.min(5,amount));
+
+ if (Pixastic.Client.hasCanvas()) {
+ var rect = params.options.rect;
+
+ var ctx = params.canvas.getContext("2d");
+ ctx.save();
+ ctx.beginPath();
+ ctx.rect(rect.left, rect.top, rect.width, rect.height);
+ ctx.clip();
+
+ var scale = 2;
+ var smallWidth = Math.round(params.width / scale);
+ var smallHeight = Math.round(params.height / scale);
+
+ var copy = document.createElement("canvas");
+ copy.width = smallWidth;
+ copy.height = smallHeight;
+
+ var clear = false;
+ var steps = Math.round(amount * 20);
+
+ var copyCtx = copy.getContext("2d");
+ for (var i=0;i<steps;i++) {
+ var scaledWidth = Math.max(1,Math.round(smallWidth - i));
+ var scaledHeight = Math.max(1,Math.round(smallHeight - i));
+
+ copyCtx.clearRect(0,0,smallWidth,smallHeight);
+
+ copyCtx.drawImage(
+ params.canvas,
+ 0,0,params.width,params.height,
+ 0,0,scaledWidth,scaledHeight
+ );
+
+ if (clear)
+ ctx.clearRect(rect.left,rect.top,rect.width,rect.height);
+
+ ctx.drawImage(
+ copy,
+ 0,0,scaledWidth,scaledHeight,
+ 0,0,params.width,params.height
+ );
+ }
+
+ ctx.restore();
+
+ params.useData = false;
+ return true;
+ } else if (Pixastic.Client.isIE()) {
+ var radius = 10 * amount;
+ params.image.style.filter += " progid:DXImageTransform.Microsoft.Blur(pixelradius=" + radius + ")";
+
+ if (params.options.fixMargin || 1) {
+ params.image.style.marginLeft = (parseInt(params.image.style.marginLeft,10)||0) - Math.round(radius) + "px";
+ params.image.style.marginTop = (parseInt(params.image.style.marginTop,10)||0) - Math.round(radius) + "px";
+ }
+
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return (Pixastic.Client.hasCanvas() || Pixastic.Client.isIE());
+ }
+}
View
158 actions/brightness.js
@@ -1,79 +1,79 @@
-/*
- * Pixastic Lib - Brightness/Contrast filter - v0.1.1
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.brightness = {
-
- process : function(params) {
-
- var brightness = parseInt(params.options.brightness,10) || 0;
- var contrast = parseFloat(params.options.contrast)||0;
- var legacy = !!(params.options.legacy && params.options.legacy != "false");
-
- if (legacy) {
- brightness = Math.min(150,Math.max(-150,brightness));
- } else {
- var brightMul = 1 + Math.min(150,Math.max(-150,brightness)) / 150;
- }
- contrast = Math.max(0,contrast+1);
-
- if (Pixastic.Client.hasCanvasImageData()) {
- var data = Pixastic.prepareData(params);
- var rect = params.options.rect;
- var w = rect.width;
- var h = rect.height;
-
- var p = w*h;
- var pix = p*4, pix1, pix2;
-
- var mul, add;
- if (contrast != 1) {
- if (legacy) {
- mul = contrast;
- add = (brightness - 128) * contrast + 128;
- } else {
- mul = brightMul * contrast;
- add = - contrast * 128 + 128;
- }
- } else { // this if-then is not necessary anymore, is it?
- if (legacy) {
- mul = 1;
- add = brightness;
- } else {
- mul = brightMul;
- add = 0;
- }
- }
- var r, g, b;
- while (p--) {
- if ((r = data[pix-=4] * mul + add) > 255 )
- data[pix] = 255;
- else if (r < 0)
- data[pix] = 0;
- else
- data[pix] = r;
-
- if ((g = data[pix1=pix+1] * mul + add) > 255 )
- data[pix1] = 255;
- else if (g < 0)
- data[pix1] = 0;
- else
- data[pix1] = g;
-
- if ((b = data[pix2=pix+2] * mul + add) > 255 )
- data[pix2] = 255;
- else if (b < 0)
- data[pix2] = 0;
- else
- data[pix2] = b;
- }
- return true;
- }
- },
- checkSupport : function() {
- return Pixastic.Client.hasCanvasImageData();
- }
-}
-
+/*
+ * Pixastic Lib - Brightness/Contrast filter - v0.1.1
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.brightness = {
+
+ process : function(params) {
+
+ var brightness = parseInt(params.options.brightness,10) || 0;
+ var contrast = parseFloat(params.options.contrast)||0;
+ var legacy = !!(params.options.legacy && params.options.legacy != "false");
+
+ if (legacy) {
+ brightness = Math.min(150,Math.max(-150,brightness));
+ } else {
+ var brightMul = 1 + Math.min(150,Math.max(-150,brightness)) / 150;
+ }
+ contrast = Math.max(0,contrast+1);
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+ var data = Pixastic.prepareData(params);
+ var rect = params.options.rect;
+ var w = rect.width;
+ var h = rect.height;
+
+ var p = w*h;
+ var pix = p*4, pix1, pix2;
+
+ var mul, add;
+ if (contrast != 1) {
+ if (legacy) {
+ mul = contrast;
+ add = (brightness - 128) * contrast + 128;
+ } else {
+ mul = brightMul * contrast;
+ add = - contrast * 128 + 128;
+ }
+ } else { // this if-then is not necessary anymore, is it?
+ if (legacy) {
+ mul = 1;
+ add = brightness;
+ } else {
+ mul = brightMul;
+ add = 0;
+ }
+ }
+ var r, g, b;
+ while (p--) {
+ if ((r = data[pix-=4] * mul + add) > 255 )
+ data[pix] = 255;
+ else if (r < 0)
+ data[pix] = 0;
+ else
+ data[pix] = r;
+
+ if ((g = data[pix1=pix+1] * mul + add) > 255 )
+ data[pix1] = 255;
+ else if (g < 0)
+ data[pix1] = 0;
+ else
+ data[pix1] = g;
+
+ if ((b = data[pix2=pix+2] * mul + add) > 255 )
+ data[pix2] = 255;
+ else if (b < 0)
+ data[pix2] = 0;
+ else
+ data[pix2] = b;
+ }
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return Pixastic.Client.hasCanvasImageData();
+ }
+}
+
View
124 actions/coloradjust.js
@@ -1,62 +1,62 @@
-/*
- * Pixastic Lib - Color adjust filter - v0.1.1
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.coloradjust = {
-
- process : function(params) {
- var red = parseFloat(params.options.red) || 0;
- var green = parseFloat(params.options.green) || 0;
- var blue = parseFloat(params.options.blue) || 0;
-
- red = Math.round(red*255);
- green = Math.round(green*255);
- blue = Math.round(blue*255);
-
- if (Pixastic.Client.hasCanvasImageData()) {
- var data = Pixastic.prepareData(params);
- var rect = params.options.rect;
-
- var p = rect.width*rect.height;
- var pix = p*4, pix1, pix2;
-
- var r, g, b;
- while (p--) {
- pix -= 4;
-
- if (red) {
- if ((r = data[pix] + red) < 0 )
- data[pix] = 0;
- else if (r > 255 )
- data[pix] = 255;
- else
- data[pix] = r;
- }
-
- if (green) {
- if ((g = data[pix1=pix+1] + green) < 0 )
- data[pix1] = 0;
- else if (g > 255 )
- data[pix1] = 255;
- else
- data[pix1] = g;
- }
-
- if (blue) {
- if ((b = data[pix2=pix+2] + blue) < 0 )
- data[pix2] = 0;
- else if (b > 255 )
- data[pix2] = 255;
- else
- data[pix2] = b;
- }
- }
- return true;
- }
- },
- checkSupport : function() {
- return (Pixastic.Client.hasCanvasImageData());
- }
-}
+/*
+ * Pixastic Lib - Color adjust filter - v0.1.1
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.coloradjust = {
+
+ process : function(params) {
+ var red = parseFloat(params.options.red) || 0;
+ var green = parseFloat(params.options.green) || 0;
+ var blue = parseFloat(params.options.blue) || 0;
+
+ red = Math.round(red*255);
+ green = Math.round(green*255);
+ blue = Math.round(blue*255);
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+ var data = Pixastic.prepareData(params);
+ var rect = params.options.rect;
+
+ var p = rect.width*rect.height;
+ var pix = p*4, pix1, pix2;
+
+ var r, g, b;
+ while (p--) {
+ pix -= 4;
+
+ if (red) {
+ if ((r = data[pix] + red) < 0 )
+ data[pix] = 0;
+ else if (r > 255 )
+ data[pix] = 255;
+ else
+ data[pix] = r;
+ }
+
+ if (green) {
+ if ((g = data[pix1=pix+1] + green) < 0 )
+ data[pix1] = 0;
+ else if (g > 255 )
+ data[pix1] = 255;
+ else
+ data[pix1] = g;
+ }
+
+ if (blue) {
+ if ((b = data[pix2=pix+2] + blue) < 0 )
+ data[pix2] = 0;
+ else if (b > 255 )
+ data[pix2] = 255;
+ else
+ data[pix2] = b;
+ }
+ }
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return (Pixastic.Client.hasCanvasImageData());
+ }
+}
View
162 actions/colorhistogram.js
@@ -1,82 +1,82 @@
-/*
- * Pixastic Lib - Histogram - v0.1.0
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-
-Pixastic.Actions.colorhistogram = {
-
- array256 : function(default_value) {
- arr = [];
- for (var i=0; i<256; i++) { arr[i] = default_value; }
- return arr
- },
-
- process : function(params) {
- var values = [];
- if (typeof params.options.returnValue != "object") {
- params.options.returnValue = {rvals:[], gvals:[], bvals:[]};
- }
- var paint = !!(params.options.paint);
-
- var returnValue = params.options.returnValue;
- if (typeof returnValue.values != "array") {
- returnValue.rvals = [];
- returnValue.gvals = [];
- returnValue.bvals = [];
- }
-
- if (Pixastic.Client.hasCanvasImageData()) {
- var data = Pixastic.prepareData(params);
- params.useData = false;
-
- var rvals = this.array256(0);
- var gvals = this.array256(0);
- var bvals = this.array256(0);
-
- var rect = params.options.rect;
-
- var p = rect.width*rect.height;
- var pix = p*4;
- while (p--) {
- rvals[data[pix-=4]]++;
- gvals[data[pix+1]]++;
- bvals[data[pix+2]]++;
- }
-
- returnValue.rvals = rvals;
- returnValue.gvals = gvals;
- returnValue.bvals = bvals;
-
- if (paint) {
- var ctx = params.canvas.getContext("2d");
- var vals = [rvals, gvals, bvals];
- for (var v=0;v<3;v++) {
- var yoff = (v+1) * params.height / 3;
- var maxValue = 0;
- for (var i=0;i<256;i++) {
- if (vals[v][i] > maxValue)
- maxValue = vals[v][i];
- }
- var heightScale = params.height / 3 / maxValue;
- var widthScale = params.width / 256;
- if (v==0) ctx.fillStyle = "rgba(255,0,0,0.5)";
- else if (v==1) ctx.fillStyle = "rgba(0,255,0,0.5)";
- else if (v==2) ctx.fillStyle = "rgba(0,0,255,0.5)";
- for (var i=0;i<256;i++) {
- ctx.fillRect(
- i * widthScale, params.height - heightScale * vals[v][i] - params.height + yoff,
- widthScale, vals[v][i] * heightScale
- );
- }
- }
- }
- return true;
- }
- },
-
- checkSupport : function() {
- return Pixastic.Client.hasCanvasImageData();
- }
+/*
+ * Pixastic Lib - Histogram - v0.1.0
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+
+Pixastic.Actions.colorhistogram = {
+
+ array256 : function(default_value) {
+ arr = [];
+ for (var i=0; i<256; i++) { arr[i] = default_value; }
+ return arr
+ },
+
+ process : function(params) {
+ var values = [];
+ if (typeof params.options.returnValue != "object") {
+ params.options.returnValue = {rvals:[], gvals:[], bvals:[]};
+ }
+ var paint = !!(params.options.paint);
+
+ var returnValue = params.options.returnValue;
+ if (typeof returnValue.values != "array") {
+ returnValue.rvals = [];
+ returnValue.gvals = [];
+ returnValue.bvals = [];
+ }
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+ var data = Pixastic.prepareData(params);
+ params.useData = false;
+
+ var rvals = this.array256(0);
+ var gvals = this.array256(0);
+ var bvals = this.array256(0);
+
+ var rect = params.options.rect;
+
+ var p = rect.width*rect.height;
+ var pix = p*4;
+ while (p--) {
+ rvals[data[pix-=4]]++;
+ gvals[data[pix+1]]++;
+ bvals[data[pix+2]]++;
+ }
+
+ returnValue.rvals = rvals;
+ returnValue.gvals = gvals;
+ returnValue.bvals = bvals;
+
+ if (paint) {
+ var ctx = params.canvas.getContext("2d");
+ var vals = [rvals, gvals, bvals];
+ for (var v=0;v<3;v++) {
+ var yoff = (v+1) * params.height / 3;
+ var maxValue = 0;
+ for (var i=0;i<256;i++) {
+ if (vals[v][i] > maxValue)
+ maxValue = vals[v][i];
+ }
+ var heightScale = params.height / 3 / maxValue;
+ var widthScale = params.width / 256;
+ if (v==0) ctx.fillStyle = "rgba(255,0,0,0.5)";
+ else if (v==1) ctx.fillStyle = "rgba(0,255,0,0.5)";
+ else if (v==2) ctx.fillStyle = "rgba(0,0,255,0.5)";
+ for (var i=0;i<256;i++) {
+ ctx.fillRect(
+ i * widthScale, params.height - heightScale * vals[v][i] - params.height + yoff,
+ widthScale, vals[v][i] * heightScale
+ );
+ }
+ }
+ }
+ return true;
+ }
+ },
+
+ checkSupport : function() {
+ return Pixastic.Client.hasCanvasImageData();
+ }
}
View
126 actions/crop.js
@@ -1,63 +1,63 @@
-/*
- * Pixastic Lib - Crop - v0.1.1
- * Copyright (c) 2008-2009 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.crop = {
- process : function(params) {
- if (Pixastic.Client.hasCanvas()) {
- var rect = params.options.rect;
-
- var width = rect.width;
- var height = rect.height;
- var top = rect.top;
- var left = rect.left;
-
- if (typeof params.options.left != "undefined")
- left = parseInt(params.options.left,10);
- if (typeof params.options.top != "undefined")
- top = parseInt(params.options.top,10);
- if (typeof params.options.height != "undefined")
- width = parseInt(params.options.width,10);
- if (typeof params.options.height != "undefined")
- height = parseInt(params.options.height,10);
-
- if (left < 0) left = 0;
- if (left > params.width-1) left = params.width-1;
-
- if (top < 0) top = 0;
- if (top > params.height-1) top = params.height-1;
-
- if (width < 1) width = 1;
- if (left + width > params.width)
- width = params.width - left;
-
- if (height < 1) height = 1;
- if (top + height > params.height)
- height = params.height - top;
-
- var copy = document.createElement("canvas");
- copy.width = params.width;
- copy.height = params.height;
- copy.getContext("2d").drawImage(params.canvas,0,0);
-
- params.canvas.width = width;
- params.canvas.height = height;
- params.canvas.getContext("2d").clearRect(0,0,width,height);
-
- params.canvas.getContext("2d").drawImage(copy,
- left,top,width,height,
- 0,0,width,height
- );
-
- params.useData = false;
- return true;
- }
- },
- checkSupport : function() {
- return Pixastic.Client.hasCanvas();
- }
-}
-
-
+/*
+ * Pixastic Lib - Crop - v0.1.1
+ * Copyright (c) 2008-2009 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.crop = {
+ process : function(params) {
+ if (Pixastic.Client.hasCanvas()) {
+ var rect = params.options.rect;
+
+ var width = rect.width;
+ var height = rect.height;
+ var top = rect.top;
+ var left = rect.left;
+
+ if (typeof params.options.left != "undefined")
+ left = parseInt(params.options.left,10);
+ if (typeof params.options.top != "undefined")
+ top = parseInt(params.options.top,10);
+ if (typeof params.options.height != "undefined")
+ width = parseInt(params.options.width,10);
+ if (typeof params.options.height != "undefined")
+ height = parseInt(params.options.height,10);
+
+ if (left < 0) left = 0;
+ if (left > params.width-1) left = params.width-1;
+
+ if (top < 0) top = 0;
+ if (top > params.height-1) top = params.height-1;
+
+ if (width < 1) width = 1;
+ if (left + width > params.width)
+ width = params.width - left;
+
+ if (height < 1) height = 1;
+ if (top + height > params.height)
+ height = params.height - top;
+
+ var copy = document.createElement("canvas");
+ copy.width = params.width;
+ copy.height = params.height;
+ copy.getContext("2d").drawImage(params.canvas,0,0);
+
+ params.canvas.width = width;
+ params.canvas.height = height;
+ params.canvas.getContext("2d").clearRect(0,0,width,height);
+
+ params.canvas.getContext("2d").drawImage(copy,
+ left,top,width,height,
+ 0,0,width,height
+ );
+
+ params.useData = false;
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return Pixastic.Client.hasCanvas();
+ }
+}
+
+
View
72 actions/desaturate.js
@@ -1,37 +1,37 @@
-/*
- * Pixastic Lib - Desaturation filter - v0.1.1
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.desaturate = {
-
- process : function(params) {
- var useAverage = !!(params.options.average && params.options.average != "false");
-
- if (Pixastic.Client.hasCanvasImageData()) {
- var data = Pixastic.prepareData(params);
- var rect = params.options.rect;
- var w = rect.width;
- var h = rect.height;
-
- var p = w*h;
- var pix = p*4, pix1, pix2;
-
- if (useAverage) {
- while (p--)
- data[pix-=4] = data[pix1=pix+1] = data[pix2=pix+2] = (data[pix]+data[pix1]+data[pix2])/3
- } else {
- while (p--)
- data[pix-=4] = data[pix1=pix+1] = data[pix2=pix+2] = (data[pix]*0.3 + data[pix1]*0.59 + data[pix2]*0.11);
- }
- return true;
- } else if (Pixastic.Client.isIE()) {
- params.image.style.filter += " gray";
- return true;
- }
- },
- checkSupport : function() {
- return (Pixastic.Client.hasCanvasImageData() || Pixastic.Client.isIE());
- }
+/*
+ * Pixastic Lib - Desaturation filter - v0.1.1
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.desaturate = {
+
+ process : function(params) {
+ var useAverage = !!(params.options.average && params.options.average != "false");
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+ var data = Pixastic.prepareData(params);
+ var rect = params.options.rect;
+ var w = rect.width;
+ var h = rect.height;
+
+ var p = w*h;
+ var pix = p*4, pix1, pix2;
+
+ if (useAverage) {
+ while (p--)
+ data[pix-=4] = data[pix1=pix+1] = data[pix2=pix+2] = (data[pix]+data[pix1]+data[pix2])/3
+ } else {
+ while (p--)
+ data[pix-=4] = data[pix1=pix+1] = data[pix2=pix+2] = (data[pix]*0.3 + data[pix1]*0.59 + data[pix2]*0.11);
+ }
+ return true;
+ } else if (Pixastic.Client.isIE()) {
+ params.image.style.filter += " gray";
+ return true;
+ }
+ },
+ checkSupport : function() {
+ return (Pixastic.Client.hasCanvasImageData() || Pixastic.Client.isIE());
+ }
}
View
228 actions/edges.js
@@ -1,115 +1,115 @@
-/*
- * Pixastic Lib - Edge detection filter - v0.1.1
- * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
- * License: [http://www.pixastic.com/lib/license.txt]
- */
-
-Pixastic.Actions.edges = {
- process : function(params) {
-
- var mono = !!(params.options.mono && params.options.mono != "false");
- var invert = !!(params.options.invert && params.options.invert != "false");
-
- if (Pixastic.Client.hasCanvasImageData()) {
- var data = Pixastic.prepareData(params);
- var dataCopy = Pixastic.prepareData(params, true)
-
- var c = -1/8;
- var kernel = [
- [c, c, c],
- [c, 1, c],
- [c, c, c]
- ];
-
- weight = 1/c;
-
- var rect = params.options.rect;
- var w = rect.width;
- var h = rect.height;
-
- var w4 = w*4;
- var y = h;
- do {
- var offsetY = (y-1)*w4;
-
- var nextY = (y == h) ? y - 1 : y;
- var prevY = (y == 1) ? 0 : y-2;
-
- var offsetYPrev = prevY*w*4;
- var offsetYNext = nextY*w*4;
-
- var x = w;
- do {
- var offset = offsetY + (x*4-4);
-
- var offsetPrev = offsetYPrev + ((x == 1) ? 0 : x-2) * 4;
- var offsetNext = offsetYNext + ((x == w) ? x-1 : x) * 4;
-
- var r = ((dataCopy[offsetPrev-4]
- + dataCopy[offsetPrev]
- + dataCopy[offsetPrev+4]
- + dataCopy[offset-4]
- + dataCopy[offset+4]
- + dataCopy[offsetNext-4]
- + dataCopy[offsetNext]
- + dataCopy[offsetNext+4]) * c
- + dataCopy[offset]
- )
- * weight;
-
- var g = ((dataCopy[offsetPrev-3]
- + dataCopy[offsetPrev+1]
- + dataCopy[offsetPrev+5]
- + dataCopy[offset-3]
- + dataCopy[offset+5]
- + dataCopy[offsetNext-3]
- + dataCopy[offsetNext+1]
- + dataCopy[offsetNext+5]) * c
- + dataCopy[offset+1])
- * weight;
-
- var b = ((dataCopy[offsetPrev-2]
- + dataCopy[offsetPrev+2]
- + dataCopy[offsetPrev+6]
- + dataCopy[offset-2]
- + dataCopy[offset+6]
- + dataCopy[offsetNext-2]
- + dataCopy[offsetNext+2]
- + dataCopy[offsetNext+6]) * c
- + dataCopy[offset+2])
- * weight;
-
- if (mono) {
- var brightness = (r*0.3 + g*0.59 + b*0.11)||0;
- if (invert) brightness = 255 - brightness;
- if (brightness < 0 ) brightness = 0;
- if (brightness > 255 ) brightness = 255;
- r = g = b = brightness;
- } else {
- if (invert) {
- r = 255 - r;
- g = 255 - g;
- b = 255 - b;
- }
- if (r < 0 ) r = 0;
- if (g < 0 ) g = 0;
- if (b < 0 ) b = 0;
- if (r > 255 ) r = 255;
- if (g > 255 ) g = 255;
- if (b > 255 ) b = 255;
- }
-
- data[offset] = r;
- data[offset+1] = g;
- data[offset+2] = b;
-
- } while (--x);
- } while (--y);
-
- return true;
- }
- },
- checkSupport : function() {
- return Pixastic.Client.hasCanvasImageData();
- }
+/*
+ * Pixastic Lib - Edge detection filter - v0.1.1
+ * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
+ * License: [http://www.pixastic.com/lib/license.txt]
+ */
+
+Pixastic.Actions.edges = {
+ process : function(params) {
+
+ var mono = !!(params.options.mono && params.options.mono != "false");
+ var invert = !!(params.options.invert && params.options.invert != "false");
+
+ if (Pixastic.Client.hasCanvasImageData()) {
+ var data = Pixastic.prepareData(params);
+ var dataCopy = Pixastic.prepareData(params, true)
+
+ var c = -1/8;
+ var kernel = [
+ [c, c, c],
+ [c, 1, c],
+ [c, c, c]
+ ];
+
+ weight = 1/c;
+
+ var rect = params.options.rect;
+ var w = rect.width;
+ var h = rect.height;
+
+ var w4 = w*4;
+ var y = h;
+ do {
+ var offsetY = (y-1)*w4;
+
+ var nextY = (y == h) ? y - 1 : y;
+ var prevY = (y == 1) ? 0 : y-2;
+
+ var offsetYPrev = prevY*w*4;
+ var offsetYNext = nextY*w*4;
+
+ var x = w;
+ do {
+ var offset = offsetY + (x*4-4);
+
+ var offsetPrev = offsetYPrev + ((x == 1) ? 0 : x-2) * 4;
+ var offsetNext = offsetYNext + ((x == w) ? x-1 : x) * 4;
+
+ var r = ((dataCopy[offsetPrev-4]
+ + dataCopy[offsetPrev]
+ + dataCopy[offsetPrev+4]
+ + dataCopy[offset-4]
+ + dataCopy[offset+4]
+ + dataCopy[offsetNext-4]
+ + dataCopy[offsetNext]
+ + dataCopy[offsetNext+4]) * c
+ + dataCopy[offset]
+ )
+ * weight;
+
+ var g = ((dataCopy[offsetPrev-3]
+ + dataCopy[offsetPrev+1]
+ + dataCopy[offsetPrev+5]
+ + dataCopy[offset-3]
+ + dataCopy[offset+5]
+ + dataCopy[offsetNext-3]
+ + dataCopy[offsetNext+1]
+ + dataCopy[offsetNext+5]) * c
+ + dataCopy[offset+1])
+ * weight;
+
+ var b = ((dataCopy[offsetPrev-2]
+ + dataCopy[offsetPrev+2]
+ + dataCopy[offsetPrev+6]
+ + dataCopy[offset-2]
+ + dataCopy[offset+6]
+ + dataCopy[offsetNext-2]
+ + dataCopy[offsetNext+2]
+ + dataCopy[offsetNext+6]) * c
+ + dataCopy[offset+2])
+ * weight;
+
+ if (mono) {