mirror of
https://github.com/danbulant/pngjs
synced 2026-05-27 05:41:47 +00:00
bitblt
This commit is contained in:
parent
66c0a34c7a
commit
2fe6c8805a
1 changed files with 22 additions and 0 deletions
22
lib/png.js
22
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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue