Permalink
Browse files

Cleaned up code a bit, and finally added licensing information. Also …

…added a minified version, only 12.7KB!
  • Loading branch information...
1 parent 973e344 commit 7f88b03a36987e15b9470fb19316bf1f54cab2dc @meltingice committed Jan 12, 2011
Showing with 123 additions and 29 deletions.
  1. +10 −0 LICENSE
  2. +44 −29 caman.js
  3. +69 −0 caman.min.js
View
10 LICENSE
@@ -0,0 +1,10 @@
+Copyright (c) 2010, Ryan LeFevre
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of Ryan LeFevre nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,3 +1,12 @@
+/*!
+ * CamanJS - Image Manipulation Library
+ * http://camanjs.com/
+ *
+ * Copyright 2011, Ryan LeFevre
+ * Licensed under the new BSD License.
+ * See LICENSE for more info.
+ */
+
(function () {
var forEach = Array.prototype.forEach,
@@ -766,22 +775,25 @@ Caman.manip.processNext = function (finishedFn) {
this.executeFilter(next.adjust, next.processFn);
};
-// Basic library of effects/filters that is always loaded
+// Expose Caman to the world!
+window.Caman = Caman;
+
+/****************************************************************************
+ * Below are a basic library of filters that are always loaded with CamanJS *
+ ****************************************************************************/
(function(Caman) {
Caman.manip.brightness = function(adjust) {
adjust = Math.floor(255 * (adjust / 100));
- // Note that process has 2 args now
return this.process( adjust, function brightness(adjust, rgba) {
- // also pass the adjustment to the process callback
- rgba.r += adjust;
- rgba.g += adjust;
- rgba.b += adjust;
-
- return rgba;
- });
+ rgba.r += adjust;
+ rgba.g += adjust;
+ rgba.b += adjust;
+
+ return rgba;
+ });
};
Caman.manip.saturation = function(adjust) {
@@ -794,11 +806,11 @@ Caman.manip.processNext = function (finishedFn) {
for (chan in rgba) {
if (rgba.hasOwnProperty(chan)) {
if (rgba[chan] === max || chan === "a") {
- continue;
- }
+ continue;
+ }
- diff = max - rgba[chan];
- rgba[chan] += Math.ceil(diff * (adjust / 100));
+ diff = max - rgba[chan];
+ rgba[chan] += Math.ceil(diff * (adjust / 100));
}
}
@@ -833,13 +845,18 @@ Caman.manip.processNext = function (finishedFn) {
var chan;
for (chan in rgba) {
if (rgba.hasOwnProperty(chan)) {
+ // skip the alpha channel
if (chan === 'a') { continue; }
+
rgba[chan] /= 255;
rgba[chan] -= 0.5;
rgba[chan] *= adjust;
rgba[chan] += 0.5;
rgba[chan] *= 255;
+ // While uglier, I found that using if statements are
+ // faster than calling Math.max() and Math.min() to bound
+ // the numbers.
if (rgba[chan] > 255) {
rgba[chan] = 255;
} else if (rgba[chan] < 0) {
@@ -853,18 +870,19 @@ Caman.manip.processNext = function (finishedFn) {
};
Caman.manip.hue = function(adjust) {
- var hsv, h;
+ var hsv, h;
+
return this.process( adjust, function hue(adjust, rgba) {
- hsv = Caman.rgb_to_hsv(rgba.r, rgba.g, rgba.b);
- h = hsv.h * 100;
- h += Math.abs(adjust);
- h = h % 100;
- h /= 100;
- hsv.h = h;
-
- rgb = Caman.hsv_to_rgb(hsv.h, hsv.s, hsv.v);
-
- return {r: rgb.r, g: rgb.g, b: rgb.b, a: rgba.a};
+ hsv = Caman.rgb_to_hsv(rgba.r, rgba.g, rgba.b);
+ h = hsv.h * 100;
+ h += Math.abs(adjust);
+ h = h % 100;
+ h /= 100;
+ hsv.h = h;
+
+ rgb = Caman.hsv_to_rgb(hsv.h, hsv.s, hsv.v);
+
+ return {r: rgb.r, g: rgb.g, b: rgb.b, a: rgba.a};
});
};
@@ -873,20 +891,19 @@ Caman.manip.processNext = function (finishedFn) {
if (arguments.length === 2) {
rgb = Caman.hex_to_rgb(arguments[0]);
-
level = arguments[1];
} else if (arguments.length === 4) {
rgb = {
r: arguments[0],
g: arguments[1],
b: arguments[2]
- }
+ };
level = arguments[3];
}
return this.process( [ level, rgb ], function colorize( adjust, rgba) {
-
+ // adjust[0] == level; adjust[1] == rgb;
rgba.r -= (rgba.r - adjust[1].r) * (adjust[0] / 100);
rgba.g -= (rgba.g - adjust[1].g) * (adjust[0] / 100);
rgba.b -= (rgba.b - adjust[1].b) * (adjust[0] / 100);
@@ -1045,6 +1062,4 @@ Caman.manip.processNext = function (finishedFn) {
}(Caman));
-window.Caman = Caman;
-
}());
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 7f88b03

Please sign in to comment.