ext/rfreeimage/rfi_main.c in rfreeimage-0.1.9 vs ext/rfreeimage/rfi_main.c in rfreeimage-0.2.0
- old
+ new
@@ -696,12 +696,35 @@
}
return self;
}
+static VALUE Image_fill_rectangle(VALUE self, VALUE _x1, VALUE _y1,
+ VALUE _x2, VALUE _y2,
+ VALUE color)
+{
+ struct native_image* img;
+ int x1 = NUM2INT(_x1);
+ int y1 = NUM2INT(_y1);
+ int x2 = NUM2INT(_x2);
+ int y2 = NUM2INT(_y2);
+ unsigned int bgra = NUM2UINT(color);
+
+ Data_Get_Struct(self, struct native_image, img);
+ RFI_CHECK_IMG(img);
+ int i, j;
+ for(i = x1; i <= x2; i++) {
+ for(j = y1; j <= y2; j++) {
+ FreeImage_SetPixelColor(img->handle, i, img->h - j, (RGBQUAD*)&bgra);
+ }
+ }
+ return self;
+}
+
+
void Init_rfreeimage(void)
{
rb_mFI = rb_define_module("RFreeImage");
rb_define_module_function(rb_mFI, "freeimage_version", rb_rfi_version, 0);
rb_define_module_function(rb_mFI, "freeimage_string_version", rb_rfi_string_version, 0);
@@ -733,9 +756,10 @@
rb_define_method(Class_Image, "flip_vertical", Image_flip_vertical, 0);
/* draw */
rb_define_method(Class_Image, "draw_point", Image_draw_point, 4);
rb_define_method(Class_Image, "draw_rectangle", Image_draw_rectangle, 4 + 2);
+ rb_define_method(Class_Image, "fill_rectangle", Image_fill_rectangle, 4 + 1);
rb_define_singleton_method(Class_Image, "ping", Image_ping, 1);
rb_define_singleton_method(Class_Image, "from_blob", Image_from_blob, -1);
rb_define_singleton_method(Class_Image, "ping_blob", Image_ping_blob, 1);
rb_define_singleton_method(Class_Image, "from_bytes", Image_from_bytes, 5);