ext/psd_native/mask.c in psd_native-1.1.0 vs ext/psd_native/mask.c in psd_native-1.1.1
- old
+ new
@@ -14,10 +14,12 @@
int mask_height = FIX2INT(rb_funcall(mask, rb_intern("height"), 0));
int mask_width = FIX2INT(rb_funcall(mask, rb_intern("width"), 0));
int mask_left = FIX2INT(rb_funcall(mask, rb_intern("left"), 0));
int mask_top = FIX2INT(rb_funcall(mask, rb_intern("top"), 0));
+ int layer_height = FIX2INT(rb_funcall(layer, rb_intern("height"), 0));
+ int layer_width = FIX2INT(rb_funcall(layer, rb_intern("width"), 0));
int layer_left = FIX2INT(rb_funcall(layer, rb_intern("left"), 0));
int layer_top = FIX2INT(rb_funcall(layer, rb_intern("top"), 0));
PIXEL color;
int x, y, doc_x, doc_y, layer_x, layer_y, alpha;
@@ -27,9 +29,11 @@
doc_x = mask_left + x;
doc_y = mask_top + y;
layer_x = doc_x - layer_left;
layer_y = doc_y - layer_top;
+ if (layer_x < 0 || layer_x > layer_width || layer_y < 0 || layer_y > layer_height) continue;
+
color = FIX2UINT(rb_funcall(canvas, rb_intern("[]"), 2, INT2FIX(layer_x), INT2FIX(layer_y)));
if (doc_x < 0 || doc_x >= doc_width || doc_y < 0 || doc_y > doc_height) {
alpha = 0;
} else {
\ No newline at end of file