Fix image cropping/enlarging

Function imlib_create_cropped_image() from imlib2 doesn't initialize
buffer for new image, so if we use crop bounds bigger than original ones
we need to erase garbage from derived image.
This bug produced colorful pressed buttons (FS#516, FS#822).

Signed-off-by: Roman Kosenko <madkite@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Roman Kosenko 2010-09-18 23:08:20 +03:00 committed by Uli Schlachter
parent 825efd21b3
commit dd656f514a
1 changed files with 13 additions and 0 deletions

View File

@ -415,7 +415,20 @@ luaA_image_crop(lua_State *L)
new = image_new(L);
imlib_context_set_image(image->image);
int ow = imlib_image_get_width(), oh = imlib_image_get_height();
new->image = imlib_create_cropped_image(x, y, w, h);
imlib_context_set_image(new->image);
imlib_context_set_color(0, 0, 0, 0);
imlib_context_set_blend(0);
if(x < 0)
imlib_image_fill_rectangle(0, 0, -x, h);
if(y < 0)
imlib_image_fill_rectangle(x < 0 ? -x : 0, 0, w, -y);
if(x + w > ow)
imlib_image_fill_rectangle(ow - x, y < 0 ? -y : 0, x + w - ow, h);
if(y + h > oh)
imlib_image_fill_rectangle(x < 0 ? -x : 0, oh - y, x + w > ow ? ow - x : w, y + h - oh);
imlib_context_set_blend(1);
return 1;
}