pan
pan copied to clipboard
Images
Possible API for this:
cat = pan.image("cat.png")
function render()
-- to blit the entire image at x=32 y=32
pan.blit(cat, 32, 32)
-- to blit the image at x=32 y=32 resized to 64×64 pixels
pan.blit(cat, 32, 32, 64, 64)
-- to blit a (16, 16, 16, 16) rectangle fragment of the image at x=32 y=32
-- resized to 64×64 pixels
pan.blit(cat, 32, 32, 64, 64, 16, 16, 16, 16)
end
Because cairo uses the same surface type both for drawing and images, here's another cool thing that could be done.
local s = pan.image(100, 100)
-- pan.switch switches rendering to a different image from the default and returns the previous image.
-- when called without parameters, it returns the current image.
local previous = pan.switch(s)
pan.clear(pan.paint(pan.hex"#212121"))
pan.rects(10, 10, 80, 80, pan.paint(pan.hex"#ffffff"))
pan.switch(previous)
Most of the API has now been implemented (commit 8f526fa
). Here are some notable things:
- every image gets its own cairo context, so state is not preserved when
switch
ing -
pan.image
got changed up a bit: it accepts a table after the height parameter- right now this table only has an option
filter
which specifies the filtering mode to use when upscaling - this table isn't easily accessible if you don't provide a width and a height right now, mainly because filtering is only really useful when the width and height is changed and the parameters default to the image's width and height so no upscaling is done by default
-
maybe future plans: integrate source clipping into this table. maybe something like
source = { x, y, w, h }
- right now this feature remains unimplemented as i'm yet to discover a use case for it (or find someone who needs it)
- right now this table only has an option