Permalink
Browse files

Fix merge

  • Loading branch information...
2 parents 4465720 + d5ee508 commit f156873868e163c007cbb8abdb42404e05418248 @meltingice committed Jun 22, 2013
View
@@ -47,7 +47,7 @@ coffeeFiles = [
"core/io"
"core/layer"
"core/logger"
- "core/pixelinfo"
+ "core/pixel"
"core/plugin"
"core/renderer"
"core/store"
View
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.2
(function() {
- var $, Analyze, Blender, Calculate, Caman, CamanParser, Canvas, Convert, Event, Fiber, Filter, IO, Image, Layer, Log, Logger, Module, PixelInfo, Plugin, Renderer, Root, Store, Util, fs, moduleKeywords, slice, vignetteFilters,
+ var $, Analyze, Blender, Calculate, Caman, CamanParser, Canvas, Convert, Event, Fiber, Filter, IO, Image, Layer, Log, Logger, Module, Pixel, Plugin, Renderer, Root, Store, Util, fs, moduleKeywords, slice, vignetteFilters,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
@@ -181,9 +181,9 @@
Caman = (function(_super) {
__extends(Caman, _super);
- Caman["extends"](IO.ClassMethods);
+ Caman["extends"](IO.prototype.ClassMethods);
- Caman.includes(IO.InstanceMethods);
+ Caman.includes(IO.prototype.InstanceMethods);
Caman.version = {
release: "4.1.1",
@@ -669,7 +669,7 @@
width = this.originalWidth;
}
for (i = _j = 0, _ref1 = pixelData.length; _j < _ref1; i = _j += 4) {
- coord = PixelInfo.locationToCoordinates(i, width);
+ coord = Pixel.locationToCoordinates(i, width);
if (((startX <= (_ref2 = coord.x) && _ref2 < endX)) && ((startY <= (_ref3 = coord.y) && _ref3 < endY))) {
pixels.push(pixelData[i], pixelData[i + 1], pixelData[i + 2], pixelData[i + 3]);
}
@@ -1736,12 +1736,12 @@
Log = new Logger();
- PixelInfo = (function() {
- PixelInfo.coordinatesToLocation = function(x, y, width) {
+ Pixel = (function() {
+ Pixel.coordinatesToLocation = function(x, y, width) {
return (y * width + x) * 4;
};
- PixelInfo.locationToCoordinates = function(loc, width) {
+ Pixel.locationToCoordinates = function(loc, width) {
var x, y;
y = Math.floor(loc / (width * 4));
@@ -1752,14 +1752,25 @@
};
};
- function PixelInfo(c) {
- this.c = c;
+ function Pixel(r, g, b, a, c) {
+ this.r = r != null ? r : 0;
+ this.g = g != null ? g : 0;
+ this.b = b != null ? b : 0;
+ this.a = a != null ? a : 255;
+ this.c = c != null ? c : null;
this.loc = 0;
}
- PixelInfo.prototype.locationXY = function() {
+ Pixel.prototype.setContext = function(c) {
+ return this.c = c;
+ };
+
+ Pixel.prototype.locationXY = function() {
var x, y;
+ if (this.c == null) {
+ throw "Requires a CamanJS context";
+ }
y = this.c.dimensions.height - Math.floor(this.loc / (this.c.dimensions.width * 4));
x = (this.loc % (this.c.dimensions.width * 4)) / 4;
return {
@@ -1768,29 +1779,32 @@
};
};
- PixelInfo.prototype.getPixelRelative = function(horiz, vert) {
+ Pixel.prototype.pixelAtLocation = function(loc) {
+ if (this.c == null) {
+ throw "Requires a CamanJS context";
+ }
+ return new Pixel(this.c.pixelData[loc], this.c.pixelData[loc + 1], this.c.pixelData[loc + 2], this.c.pixelData[loc + 3], this.c);
+ };
+
+ Pixel.prototype.getPixelRelative = function(horiz, vert) {
var newLoc;
+ if (this.c == null) {
+ throw "Requires a CamanJS context";
+ }
newLoc = this.loc + (this.c.dimensions.width * 4 * (vert * -1)) + (4 * horiz);
if (newLoc > this.c.pixelData.length || newLoc < 0) {
- return {
- r: 0,
- g: 0,
- b: 0,
- a: 0
- };
+ return new Pixel(0, 0, 0, 255, this.c);
}
- return {
- r: this.c.pixelData[newLoc],
- g: this.c.pixelData[newLoc + 1],
- b: this.c.pixelData[newLoc + 2],
- a: this.c.pixelData[newLoc + 3]
- };
+ return this.pixelAtLocation(newLoc);
};
- PixelInfo.prototype.putPixelRelative = function(horiz, vert, rgba) {
+ Pixel.prototype.putPixelRelative = function(horiz, vert, rgba) {
var nowLoc;
+ if (this.c == null) {
+ throw "Requires a CamanJS context";
+ }
nowLoc = this.loc + (this.c.dimensions.width * 4 * (vert * -1)) + (4 * horiz);
if (newLoc > this.c.pixelData.length || newLoc < 0) {
return;
@@ -1802,32 +1816,53 @@
return true;
};
- PixelInfo.prototype.getPixel = function(x, y) {
+ Pixel.prototype.getPixel = function(x, y) {
var loc;
+ if (this.c == null) {
+ throw "Requires a CamanJS context";
+ }
loc = this.coordinatesToLocation(x, y, this.width);
- return {
- r: this.c.pixelData[loc],
- g: this.c.pixelData[loc + 1],
- b: this.c.pixelData[loc + 2],
- a: this.c.pixelData[loc + 3]
- };
+ return this.pixelAtLocation(loc);
};
- PixelInfo.prototype.putPixel = function(x, y, rgba) {
+ Pixel.prototype.putPixel = function(x, y, rgba) {
var loc;
+ if (this.c == null) {
+ throw "Requires a CamanJS context";
+ }
loc = this.coordinatesToLocation(x, y, this.width);
this.c.pixelData[loc] = rgba.r;
this.c.pixelData[loc + 1] = rgba.g;
this.c.pixelData[loc + 2] = rgba.b;
return this.c.pixelData[loc + 3] = rgba.a;
};
- return PixelInfo;
+ Pixel.prototype.toString = function() {
+ return this.toKey();
+ };
+
+ Pixel.prototype.toHex = function(includeAlpha) {
+ var hex;
+
+ if (includeAlpha == null) {
+ includeAlpha = false;
+ }
+ hex = '#' + this.r.toString(16) + this.g.toString(16) + this.b.toString(16);
+ if (includeAlpha) {
+ return hex + this.a.toString(16);
+ } else {
+ return hex;
+ }
+ };
+
+ return Pixel;
})();
+ Caman.Pixel = Pixel;
+
Plugin = (function() {
function Plugin() {}
@@ -1946,7 +1981,7 @@
};
Renderer.prototype.renderBlock = function(bnum, start, end) {
- var data, i, pixelInfo, res, _i;
+ var i, pixel, _i;
Log.debug("Block #" + bnum + " - Filter: " + this.currentJob.name + ", Start: " + start + ", End: " + end);
Event.trigger(this.c, "blockStarted", {
@@ -1955,27 +1990,19 @@
startPixel: start,
endPixel: end
});
- data = {
- r: 0,
- g: 0,
- b: 0,
- a: 0
- };
- pixelInfo = new PixelInfo(this.c);
+ pixel = new Pixel();
+ pixel.setContext(this.c);
for (i = _i = start; _i < end; i = _i += 4) {
- pixelInfo.loc = i;
- data.r = this.c.pixelData[i];
- data.g = this.c.pixelData[i + 1];
- data.b = this.c.pixelData[i + 2];
- data.a = this.c.pixelData[i + 3];
- res = this.currentJob.processFn.call(pixelInfo, data);
- if (res.a == null) {
- res.a = data.a;
- }
- this.c.pixelData[i] = Util.clampRGB(res.r);
- this.c.pixelData[i + 1] = Util.clampRGB(res.g);
- this.c.pixelData[i + 2] = Util.clampRGB(res.b);
- this.c.pixelData[i + 3] = Util.clampRGB(res.a);
+ pixel.loc = i;
+ pixel.r = this.c.pixelData[i];
+ pixel.g = this.c.pixelData[i + 1];
+ pixel.b = this.c.pixelData[i + 2];
+ pixel.a = this.c.pixelData[i + 3];
+ this.currentJob.processFn.call(pixel, pixel);
+ this.c.pixelData[i] = Util.clampRGB(pixel.r);
+ this.c.pixelData[i + 1] = Util.clampRGB(pixel.g);
+ this.c.pixelData[i + 2] = Util.clampRGB(pixel.b);
+ this.c.pixelData[i + 3] = Util.clampRGB(pixel.a);
}
if (Caman.NodeJS) {
return Fiber["yield"](bnum);
@@ -1985,7 +2012,7 @@
};
Renderer.prototype.renderKernel = function(bnum, start, end) {
- var adjust, adjustSize, bias, builder, builderIndex, divisor, i, j, k, kernel, n, name, pixel, pixelInfo, res, _i, _j, _k;
+ var adjust, adjustSize, bias, builder, builderIndex, divisor, i, j, k, kernel, n, name, p, pixel, res, _i, _j, _k;
name = this.currentJob.name;
bias = this.currentJob.bias;
@@ -1998,16 +2025,17 @@
start = Math.max(start, this.c.dimensions.width * 4 * ((adjustSize - 1) / 2));
end = Math.min(end, n - (this.c.dimensions.width * 4 * ((adjustSize - 1) / 2)));
builder = (adjustSize - 1) / 2;
- pixelInfo = new PixelInfo(this.c);
+ pixel = new Pixel();
+ pixel.setContext(this.c);
for (i = _i = start; _i < end; i = _i += 4) {
- pixelInfo.loc = i;
+ pixel.loc = i;
builderIndex = 0;
for (j = _j = -builder; -builder <= builder ? _j <= builder : _j >= builder; j = -builder <= builder ? ++_j : --_j) {
for (k = _k = builder; builder <= -builder ? _k <= -builder : _k >= -builder; k = builder <= -builder ? ++_k : --_k) {
- pixel = pixelInfo.getPixelRelative(j, k);
- kernel[builderIndex * 3] = pixel.r;
- kernel[builderIndex * 3 + 1] = pixel.g;
- kernel[builderIndex * 3 + 2] = pixel.b;
+ p = pixel.getPixelRelative(j, k);
+ kernel[builderIndex * 3] = p.r;
+ kernel[builderIndex * 3 + 1] = p.g;
+ kernel[builderIndex * 3 + 2] = p.b;
builderIndex++;
}
}
Oops, something went wrong.

0 comments on commit f156873

Please sign in to comment.