diff options
author | scuri <scuri> | 2009-08-18 02:21:01 +0000 |
---|---|---|
committer | scuri <scuri> | 2009-08-18 02:21:01 +0000 |
commit | 77a4608ee1f828ed70ec58588f0229cd57758148 (patch) | |
tree | b1550da93d53331715c200f1acf8a7c1b2ff7be9 /src/lua5/im_image.lua | |
parent | e2726d7bef3b0a1684011e558cb68ca99cfecd75 (diff) |
*** empty log message ***
Diffstat (limited to 'src/lua5/im_image.lua')
-rw-r--r-- | src/lua5/im_image.lua | 24 |
1 files changed, 24 insertions, 0 deletions
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 |