From 702db380c501481499f816f2ecc8aa27fe2161f5 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 15 Nov 2010 10:14:32 -0800 Subject: [PATCH] Added PixelArray#inspect() --- lib/canvas.js | 6 ++++++ lib/pixelarray.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 lib/pixelarray.js diff --git a/lib/canvas.js b/lib/canvas.js index 339d4e6..89fe55a 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -55,6 +55,12 @@ require('./context2d'); require('./image'); +/** + * PixelArray implementation. + */ + +require('./pixelarray'); + /** * Inspect canvas. * diff --git a/lib/pixelarray.js b/lib/pixelarray.js new file mode 100644 index 0000000..0a5b1ce --- /dev/null +++ b/lib/pixelarray.js @@ -0,0 +1,29 @@ + +/*! + * Canvas - PixelArray + * Copyright (c) 2010 LearnBoost + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Canvas = require('../build/default/canvas') + , PixelArray = Canvas.CanvasPixelArray; + +/** + * Custom inspect. + */ + +PixelArray.prototype.inspect = function(){ + var buf = '[PixelArray '; + for (var i = 0, len = this.length; i < len; ++i) { + buf += '\n ' + i + ': rgba(' + + this[i++] + ',' + + this[i++] + ',' + + this[i++] + ',' + + this[i] + ')'; + } + return buf + '\n]'; +};