fix bugs in Image module

This commit is contained in:
rolux 2012-06-04 18:35:55 +02:00
parent 20b3508f86
commit 9434c60b53

View file

@ -9,12 +9,15 @@ Ox.load.Image = function(options, callback) {
To render the image as an image element, use its `src()` method, to
render it as a canvas, use its `canvas` property.
(src, callback) -> <u> undefined
(width, height, callback) -> <u> undefined
(width, height, background, callback) -> <u> undefined
src <s> Image source (local, remote or data URL)
width <n> Width in px
image <n> Height in px
background <[n]> Background color (RGB or RGBA)
(width, height[, background], callback) -> <u> undefined
src <s> Image source (local, remote or data URL)
width <n> Width in px
height <n> Height in px
background <[n]> Background color (RGB or RGBA)
callback <f> Callback function
image <o> Image object
> Ox.Image(1, 1, [255, 0, 0], function(i) { Ox.test(i.pixel([0, 0]), [255, 0, 0, 255]); })
undefined
> Ox.Image(Ox.UI.PATH + 'themes/classic/png/icon16.png', function(i) { i.encode('foo', function(i) { i.decode(function(s) { Ox.test(s, 'foo'); })})})
undefined
@*/
@ -23,20 +26,6 @@ Ox.load.Image = function(options, callback) {
var self = {},
that = {};
self.callback = arguments[arguments.length - 1];
if (arguments.length == 2) {
self.src = arguments[0];
self.image = new Image();
self.image.onload = init;
self.image.src = self.src;
} else {
self.width = arguments[0];
self.height = arguments[1];
self.background = arguments.length == 4
? arguments[2] : [0, 0, 0, 0];
init();
}
function error(mode) {
throw new RangeError('PNG codec can\'t ' + mode + ' ' + (
mode == 'encode' ? 'data' : 'image'
@ -75,8 +64,11 @@ Ox.load.Image = function(options, callback) {
that.context = that.canvas[0].getContext('2d');
if (self.image) {
that.context.drawImage(self.image, 0, 0);
} else if (Ox.sum(self.background)) {
that.context.fillStyle(self.background);
} else if (!Ox.isEqual(self.background, [0, 0, 0, 0])) {
that.context.fillStyle = (
self.background.length == 3 ? 'rgb' : 'rgba'
) + '(' + self.background.join(', ') + ')';
Ox.print('----------------------------------', self.width, self.height, that.context.fillStyle)
that.context.fillRect(0, 0, self.width, self.height);
}
self.imageData = that.context.getImageData(
@ -128,6 +120,8 @@ Ox.load.Image = function(options, callback) {
return that.filter(filter);
};
//@ canvas <o> Canvas element
/*@
channel <f> Reduce the image to one channel
(channel) -> <o> The image object
@ -790,6 +784,20 @@ Ox.load.Image = function(options, callback) {
return ret;
};
self.callback = arguments[arguments.length - 1];
if (arguments.length == 2) {
self.src = arguments[0];
self.image = new Image();
self.image.onload = init;
self.image.src = self.src;
} else {
self.width = arguments[0];
self.height = arguments[1];
self.background = arguments.length == 4
? arguments[2] : [0, 0, 0, 0];
init();
}
};
callback(true);