From 2fe6c8805adb166cf4ccd9eff8df154f1d3fd7a6 Mon Sep 17 00:00:00 2001 From: Kuba Niegowski Date: Sun, 19 Aug 2012 23:36:53 +0200 Subject: [PATCH] bitblt --- lib/png.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/png.js b/lib/png.js index 0d1e624..00cf3d1 100644 --- a/lib/png.js +++ b/lib/png.js @@ -92,3 +92,25 @@ PNG.prototype._metadata = function(width, height) { this.height = height; this.data = null; }; + +PNG.prototype.bitblt = function(dst, sx, sy, w, h, dx, dy) { + + var src = this; + + if (sx > src.width || sy > src.height + || sx + w > src.width || sy + h > src.height) + throw new Error('bitblt reading outside image'); + if (dy > dst.width || dy > dst.height + || dx + w > dst.width || dy + h > dst.height) + throw new Error('bitblt writing outside image'); + + for (var y = 0; y < h; y++) { + src.data.copy(dst.data, + ((dy + y) * dst.width + dx) << 2, + ((sy + y) * src.width + sx) << 2, + ((sy + y) * src.width + sx + w) << 2 + ); + } + + return this; +};