From 77a4608ee1f828ed70ec58588f0229cd57758148 Mon Sep 17 00:00:00 2001 From: scuri Date: Tue, 18 Aug 2009 02:21:01 +0000 Subject: *** empty log message *** --- src/lua5/im_image.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/lua5/im_image.lua (limited to 'src/lua5/im_image.lua') diff --git a/src/lua5/im_image.lua b/src/lua5/im_image.lua new file mode 100644 index 0000000..03e80f6 --- /dev/null +++ b/src/lua5/im_image.lua @@ -0,0 +1,24 @@ +-- If all parameteres, besides the image, are nil, this is equivalent to image:Clone. +-- If any parameter is not nil, then the value is used instead of the one from the source image. +-- If a parameter is a function, then the function is called, passing the source +-- image as parameter, to obtain the substituion value. + +function im.ImageCreateBased(image, width, height, color_space, data_type) + -- default values are those of the source image + width = width or image:Width() + height = height or image:Height() + color_space = color_space or image:ColorSpace() + data_type = data_type or image:DataType() + + -- callback to calculate parameters based on source image + if type(width) == "function" then width = width(image) end + if type(height) == "function" then height = height(image) end + if type(color_space) == "function" then color_space = color_space(image) end + if type(data_type) == "function" then data_type = data_type(image) end + + -- create a new image + new_image = im.ImageCreate(width, height, color_space, data_type) + image:CopyAttributes(new_image) + if (image:HasAlpha()) then new_image:AddAlpha() end + return new_image +end -- cgit v1.2.3