Ox.Image: correctly parse arguments of pixel method

This commit is contained in:
rolux 2012-06-25 16:42:30 +02:00
parent c85d99202d
commit 703003bd2b

View file

@ -556,7 +556,8 @@ Ox.load.Image = function(options, callback) {
/*@ /*@
imageData <f> Get or set image data imageData <f> Get or set image data
() -> <o> ImageData object () -> <o> ImageData object
data <a> CanvasPixelArray data <+> CanvasPixelArray
see https://developer.mozilla.org/en/DOM/CanvasPixelArray
height <n> Height in px height <n> Height in px
width <n> Width in px width <n> Width in px
(imageData) -> <o> Image object with new image data (imageData) -> <o> Image object with new image data
@ -598,7 +599,9 @@ Ox.load.Image = function(options, callback) {
i <n> Pixel index i <n> Pixel index
@*/ @*/
that.map = function(fn, callback) { that.map = function(fn, callback) {
self.imageData = that.context.getImageData(0, 0, self.width, self.height); self.imageData = that.context.getImageData(
0, 0, self.width, self.height
);
self.data = self.imageData.data; self.data = self.imageData.data;
that.forEach(function(rgba, xy, i) { that.forEach(function(rgba, xy, i) {
fn(rgba, xy, i).forEach(function(val, c) { fn(rgba, xy, i).forEach(function(val, c) {
@ -669,14 +672,22 @@ Ox.load.Image = function(options, callback) {
/*@ /*@
pixel <f> Get or set pixel values pixel <f> Get or set pixel values
(xy) -> <[n]> RGBA values
(x, y) -> <[n]> RGBA values (x, y) -> <[n]> RGBA values
(xy, val) -> <o> The image object
(x, y, val) -> <o> The image object (x, y, val) -> <o> The image object
x <n> X coordinate x <n> X coordinate
y <n> Y coordinate y <n> Y coordinate
xy <[n]> XY coordinates ([x, y])
val <[n]> RGBA values val <[n]> RGBA values
@*/ @*/
that.pixel = function(xy, val) { that.pixel = function() {
var i = getIndex(xy), ret; var xy = arguments.length == 1 || Ox.isArray(arguments[1])
? arguments[0] : [arguments[0], arguments[1]],
val = Ox.isArray(Ox.last(arguments))
? Ox.last(arguments) : null,
i = getIndex(xy),
ret;
if (!val) { if (!val) {
ret = Ox.range(4).map(function(c) { ret = Ox.range(4).map(function(c) {
return self.data[i + c]; return self.data[i + c];
@ -689,7 +700,7 @@ Ox.load.Image = function(options, callback) {
ret = that; ret = that;
} }
return ret; return ret;
} };
/*@ /*@
posterize <f> Apply posterize filter posterize <f> Apply posterize filter
@ -773,7 +784,9 @@ Ox.load.Image = function(options, callback) {
height: self.height height: self.height
}); });
that.context.drawImage(self.image, 0, 0); that.context.drawImage(self.image, 0, 0);
self.imageData = that.context.getImageData(0, 0, self.width, self.height); self.imageData = that.context.getImageData(
0, 0, self.width, self.height
);
self.data = self.imageData.data; self.data = self.imageData.data;
callback && callback(that); callback && callback(that);
} }