Ox.Image: correctly parse arguments of pixel method
This commit is contained in:
parent
c85d99202d
commit
703003bd2b
1 changed files with 19 additions and 6 deletions
|
@ -556,7 +556,8 @@ Ox.load.Image = function(options, callback) {
|
|||
/*@
|
||||
imageData <f> Get or set image data
|
||||
() -> <o> ImageData object
|
||||
data <a> CanvasPixelArray
|
||||
data <+> CanvasPixelArray
|
||||
see https://developer.mozilla.org/en/DOM/CanvasPixelArray
|
||||
height <n> Height in px
|
||||
width <n> Width in px
|
||||
(imageData) -> <o> Image object with new image data
|
||||
|
@ -598,7 +599,9 @@ Ox.load.Image = function(options, callback) {
|
|||
i <n> 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 <f> Get or set pixel values
|
||||
(xy) -> <[n]> RGBA values
|
||||
(x, y) -> <[n]> RGBA values
|
||||
(xy, val) -> <o> The image object
|
||||
(x, y, val) -> <o> The image object
|
||||
x <n> X coordinate
|
||||
y <n> 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 <f> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue