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; +};