Permalink
Browse files

clamp image bounds in PixelArray::PixelArray() [marcello3d]

  • Loading branch information...
1 parent f870032 commit 7da4a3689353ce4481d186ed6f652fa331c2e50d @tj tj committed Apr 11, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/PixelArray.cc
View
@@ -98,6 +98,12 @@ PixelArray::PixelArray(Canvas *canvas, int sx, int sy, int width, int height):
int srcStride = canvas->stride()
, dstStride = stride();
+ if (sx < 0) width += sx, sx = 0;
+ if (sy < 0) height += sy, sy = 0;
+ if (sx + width > canvas->width) width = canvas->width - sx;
+ if (sy + height > canvas->height) height = canvas->height - sy;
+ if (width <= 0 || height <= 0) return;
+
// Normalize data (argb -> rgba)
for (int y = 0; y < height; ++y) {
uint32_t *row = (uint32_t *)(src + srcStride * (y + sy));

0 comments on commit 7da4a36

Please sign in to comment.