From 9434c60b531a710f7f4061db69f3456e7bd5f7a0 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 4 Jun 2012 18:35:55 +0200 Subject: [PATCH] fix bugs in Image module --- source/Ox.Image/Ox.Image.js | 52 +++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/source/Ox.Image/Ox.Image.js b/source/Ox.Image/Ox.Image.js index 047d712e..5eafb283 100644 --- a/source/Ox.Image/Ox.Image.js +++ b/source/Ox.Image/Ox.Image.js @@ -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) -> undefined - (width, height, callback) -> undefined - (width, height, background, callback) -> undefined - src Image source (local, remote or data URL) - width Width in px - image Height in px - background <[n]> Background color (RGB or RGBA) + (width, height[, background], callback) -> undefined + src Image source (local, remote or data URL) + width Width in px + height Height in px + background <[n]> Background color (RGB or RGBA) + callback Callback function + image 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 Canvas element + /*@ channel Reduce the image to one channel (channel) -> 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);