From 703003bd2b0b8a87f89c5d897376634726b9228e Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 25 Jun 2012 16:42:30 +0200 Subject: [PATCH] Ox.Image: correctly parse arguments of pixel method --- source/Ox.Image/Ox.Image.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/source/Ox.Image/Ox.Image.js b/source/Ox.Image/Ox.Image.js index 0e438f19..1994b527 100644 --- a/source/Ox.Image/Ox.Image.js +++ b/source/Ox.Image/Ox.Image.js @@ -556,7 +556,8 @@ Ox.load.Image = function(options, callback) { /*@ imageData Get or set image data () -> ImageData object - data CanvasPixelArray + data <+> CanvasPixelArray + see https://developer.mozilla.org/en/DOM/CanvasPixelArray height Height in px width Width in px (imageData) -> Image object with new image data @@ -598,7 +599,9 @@ Ox.load.Image = function(options, callback) { i Pixel index @*/ 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; that.forEach(function(rgba, xy, i) { fn(rgba, xy, i).forEach(function(val, c) { @@ -669,14 +672,22 @@ Ox.load.Image = function(options, callback) { /*@ pixel Get or set pixel values + (xy) -> <[n]> RGBA values (x, y) -> <[n]> RGBA values + (xy, val) -> The image object (x, y, val) -> The image object x X coordinate y Y coordinate + xy <[n]> XY coordinates ([x, y]) val <[n]> RGBA values @*/ - that.pixel = function(xy, val) { - var i = getIndex(xy), ret; + that.pixel = function() { + 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) { ret = Ox.range(4).map(function(c) { return self.data[i + c]; @@ -689,7 +700,7 @@ Ox.load.Image = function(options, callback) { ret = that; } return ret; - } + }; /*@ posterize Apply posterize filter @@ -773,7 +784,9 @@ Ox.load.Image = function(options, callback) { height: self.height }); 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; callback && callback(that); }