1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
-- Contribution by Gustavo Lyrio
require"imlua"
require"imlua_process"
require"cdlua"
require"cdluaim"
require"iuplua"
require"iupluacd"
--IupCanvas Example in IupLua
cv = iup.canvas {rastersize="640x480"}
dg = iup.dialog{iup.frame{cv}; title="Rotate Test"}
-- Simple parameters
width = 640
height = 480
screen_width = 1024
screen_height = 768
image = im.FileImageLoad("flower.jpg")
Timage = {}
--Timage.x0 = (width/2) - (image:Width()/2)
--Timage.y0 = (height/2) - (image:Height()/2)
Timage.x0 = 0
Timage.y0 = 0
function cv:action()
canvas:Activate()
canvas:Clear()
if (image2) then
image2:cdCanvasPutImageRect(canvas, Timage.x0, Timage.y0, image2:Width(), image2:Height(), 0,0,0,0)
end
return iup.DEFAULT
end
function cv:motion_cb(x, y, status)
cd.Activate(canvas)
y = cd.UpdateYAxis(y)
if iup.isbutton1(status) == true then
end
return iup.DEFAULT
end
function cv:button_cb(but, pressed, x, y, status)
if iup.isbutton1(status) == false then
end
return iup.DEFAULT
end
dg:map()
canvas = cd.CreateCanvas(cd.IUP, cv.handle)
dg:showxy(iup.CENTER, iup.CENTER)
-- Rotation Test
image:AddAlpha() -- option 1: to avoid a black background
image:SetAlpha(255)
local w, h = im.ProcessCalcRotateSize(image:Width(), image:Height(), math.cos(math.pi/4), math.sin(math.pi/4))
image2 = im.ImageCreateBased(image, w, h)
--image2 = im.ImageCreate(w, h, im.RGB, im.BYTE) -- option 2: to avoid a black background
--im.ProcessRenderConstant(image2, {255, 255, 255})
im.ProcessRotate(image, image2, math.cos(math.pi/4), math.sin(math.pi/4), 1)
--image2 = image:Clone() -- rotate and preserve size
--im.ProcessRotateRef(image, image2, math.cos(math.pi/4), math.sin(math.pi/4), image:Width()/2, image:Height()/2, false, 1)
canvas:Activate()
canvas:Clear()
--original
--image:cdCanvasPutImageRect(canvas, Timage.x0, Timage.y0, image:Width(), image:Height(), 0,0,0,0)
--processed
image2:cdCanvasPutImageRect(canvas, Timage.x0, Timage.y0, image2:Width(), image2:Height(), 0,0,0,0)
if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
iup.MainLoop()
end
|