Hi people, after a rather long time without any patches from me, here's a small one from me (just to get warmed up :P). It adds a function called :insert() to image objects, which, as the name says, inserts one image into another. It takes three arguments:
1: The image to insert 2: (optional) The X offset of the upper left corner of the inserted image 3: (optional) The Y offset of the upper left corner of the inserted image The reason for me to implement this was a request by blaze-x in #awesome who wanted to create a FVWM-like pager widget (which shows the layout of windows on each tag and inserts application icons so you know which rectangle represents which application). -- GCS/IT/M d- s+:- a--- C++ UL+++ US UB++ P+++ L+++ E--- W+ N+ o-- K- w--- O M-- V PS+ PE- Y+ PGP+++ t+ 5 X+ R tv+ b++ DI+++ D+++ G+ e- h! r y+ Gregor Best
From 49282bb43a67446fe63f01d348d52181bb06333e Mon Sep 17 00:00:00 2001 From: Gregor Best <farha...@googlemail.com> Date: Wed, 27 May 2009 15:14:47 +0200 Subject: [PATCH] image: add insert function to combine two images Signed-off-by: Gregor Best <farha...@googlemail.com> --- image.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/image.c b/image.c index d36a74a..50ce009 100644 --- a/image.c +++ b/image.c @@ -510,6 +510,47 @@ luaA_image_save(lua_State *L) return 0; } +/** Insert one image into another + * \param L The Lua VM state. + * \return The number of elements pushed on stack + * \luastack + * \lvalue An image + * \lparam The image to insert + * \lparam The X offset of the image to insert (optional) + * \lparam The Y offset of the image to insert (optional) + */ + +static int +luaA_image_insert(lua_State *L) +{ + image_t *image_target = luaL_checkudata(L, 1, "image"); + image_t *image_source = luaL_checkudata(L, 2, "image"); + int xoff = luaL_optnumber(L, 3, 0); + int yoff = luaL_optnumber(L, 4, 0); + uint32_t *data_target; + uint32_t *data_source; + int x, y; + + imlib_context_set_image(image_target->image); + data_target = imlib_image_get_data_for_reading_only(); + + imlib_context_set_image(image_source->image); + data_source = imlib_image_get_data_for_reading_only(); + + for(y = (yoff < 0) ? -yoff : 0; ((y < image_source->height) && (y + yoff < image_target->height)); y++) + { + for(x = (xoff < 0) ? -xoff : 0; ((x < image_source->width) && (x + xoff < image_target->width)); x++) + { + data_target[x + xoff + ((y + yoff) * image_target->width)] = data_source[x + (y * image_source->width)]; + } + } + + image_target->image = imlib_create_image_using_copied_data(image_target->width, image_target->height, data_target); + image_compute(image_target); + + return 0; +} + /** Image object. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -563,6 +604,7 @@ const struct luaL_reg awesome_image_meta[] = { "crop", luaA_image_crop }, { "crop_and_scale", luaA_image_crop_and_scale }, { "save", luaA_image_save }, + { "insert", luaA_image_insert }, /* draw on images, whee! */ { "draw_pixel", luaA_image_draw_pixel }, { "draw_line", luaA_image_draw_line }, -- 1.6.3.1
signature.asc
Description: PGP signature