ext/rfreeimage/rfi_main.c in rfreeimage-0.2.0 vs ext/rfreeimage/rfi_main.c in rfreeimage-0.2.1

- old
+ new

@@ -14,10 +14,19 @@ __attribute__((destructor)) static void __rfi_module_uninit() { FreeImage_DeInitialise(); } +static void try_sort(int *x, int *y) +{ + if(*y < *x ){ + int tmp = *x; + *x = *y; + *y = tmp; + } +} + static VALUE rb_rfi_version(VALUE self) { return rb_ary_new3(3, INT2NUM(FREEIMAGE_MAJOR_VERSION), INT2NUM(FREEIMAGE_MINOR_VERSION), INT2NUM(FREEIMAGE_RELEASE_SERIAL)); } @@ -679,10 +688,13 @@ if (size < 0) rb_raise(rb_eArgError, "Invalid line width: %d", size); Data_Get_Struct(self, struct native_image, img); RFI_CHECK_IMG(img); + try_sort(&x1, &x2); + try_sort(&y1, &y2); + for(i = -hs; i <= hs; i++) { for(j = x1; j <= x2; j++) { FreeImage_SetPixelColor(img->handle, j, img->h - (y1 + i) - 1, (RGBQUAD*)&bgra); FreeImage_SetPixelColor(img->handle, j, img->h - (y2 + i) - 1, (RGBQUAD*)&bgra); } @@ -706,14 +718,17 @@ int x1 = NUM2INT(_x1); int y1 = NUM2INT(_y1); int x2 = NUM2INT(_x2); int y2 = NUM2INT(_y2); unsigned int bgra = NUM2UINT(color); + int i, j; Data_Get_Struct(self, struct native_image, img); RFI_CHECK_IMG(img); - int i, j; + try_sort(&x1, &x2); + try_sort(&y1, &y2); + for(i = x1; i <= x2; i++) { for(j = y1; j <= y2; j++) { FreeImage_SetPixelColor(img->handle, i, img->h - j, (RGBQUAD*)&bgra); } }