Browse Source

Fix tests "putImageData() 8" and "putImageData() 9".

Negative arguments were causing source image data to be painted wrapped-around the other side of the canvas.
v1.x
Zach Bjornson 9 years ago
parent
commit
11f0709ec6
  1. 7
      src/CanvasRenderingContext2d.cc

7
src/CanvasRenderingContext2d.cc

@ -605,14 +605,21 @@ NAN_METHOD(Context2d::PutImageData) {
sy = args[4]->Int32Value();
sw = args[5]->Int32Value();
sh = args[6]->Int32Value();
// fix up negative height, width
if (sw < 0) sx += sw, sw = -sw;
if (sh < 0) sy += sh, sh = -sh;
// clamp the left edge
if (sx < 0) sw += sx, sx = 0;
if (sy < 0) sh += sy, sy = 0;
// clamp the right edge
if (sx + sw > imageData->width()) sw = imageData->width() - sx;
if (sy + sh > imageData->height()) sh = imageData->height() - sy;
// start destination at source offset
dx += sx;
dy += sy;
// chop off outlying source data
if (dx < 0) sw += dx, sx -= dx, dx = 0;
if (dy < 0) sh += dy, sy -= dy, dy = 0;
// clamp width at canvas size
cols = std::min(sw, context->canvas()->width - dx);
rows = std::min(sh, context->canvas()->height - dy);

Loading…
Cancel
Save