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 /html | |
parent | e2726d7bef3b0a1684011e558cb68ca99cfecd75 (diff) |
*** empty log message ***
Diffstat (limited to 'html')
-rw-r--r-- | html/en/history.html | 5 | ||||
-rw-r--r-- | html/examples/animate_gif.wlua | 90 | ||||
-rw-r--r-- | html/examples/combine9.wlua (renamed from html/examples/combine9.lua) | 0 | ||||
-rw-r--r-- | html/examples/combine9view.wlua | 125 | ||||
-rw-r--r-- | html/examples/multimorpho.lua | 2 | ||||
-rw-r--r-- | html/examples/view_image.wlua | 76 |
6 files changed, 295 insertions, 3 deletions
diff --git a/html/en/history.html b/html/en/history.html index 93cf1c4..528f656 100644 --- a/html/en/history.html +++ b/html/en/history.html @@ -12,7 +12,7 @@ <h1>History of Changes</h1> <h3 dir="ltr"> - CVS (11/Aug/2009)</h3> + CVS (17/Aug/2009)</h3> <ul> <li><span style="color: #0000FF">New:</span> function <strong> imImageGetOpenGLData</strong>.</li> @@ -20,7 +20,8 @@ 1.2.37. Removed changes to the library that made it incompatible with other libPNG distributions.</li> <li><span style="color: #008000">Changed: <span - style="color: #000000"> <strong>imImageCreateBased</strong> now also + style="color: #000000"> <strong>imImageCreateBased</strong> and + <strong>imConvertColorSpace</strong> now also consider the alpha plane.</span></span></li> <li><span style="color: #008000"><span style="color: #ff0000">Fixed:</span><span style="color: #000000"> PNG attribute TransparencyIndex. new PNG diff --git a/html/examples/animate_gif.wlua b/html/examples/animate_gif.wlua new file mode 100644 index 0000000..de96d48 --- /dev/null +++ b/html/examples/animate_gif.wlua @@ -0,0 +1,90 @@ +require"imlua" +require"cdlua" +require"cdluaim" +require"iuplua" +require"iupluacd" + +gimgs={} +gimgs.delays={} + +ggif=im.FileOpen(iup.GetFile("*.*")) + +for i=1, select(3,ggif:GetInfo()) do + gimgs[i]=ggif:LoadImage(i-1) + err, gimgs[i] = im.ConvertColorSpaceNew(gimgs[i], im.RGB, true) + local delay=gimgs[i]:GetAttribute "Delay" + if delay then + gimgs.delays[i]=delay[1]*10 + else + gimgs.delays[i]=10 + end +end + +ggif:Close() + +function gifanimator(gimgs, behavior, start, final, runyn, initial) + + start=start or 1 + final=final or #gimgs + local increment=1 + local frame=initial or start + + --hack to get data to canvas action + anii=frame + return iup.timer{ + time=gimgs.delays[frame], + run=runyn or "YES", + action_cb=function(self) + self.run="NO" + if frame==final then + if behavior=="LOOP" then + frame=start + elseif behavior=="BOUNCE" then + increment=-1 + frame=frame+increment + else + return nil + end + elseif frame==start and behavior=="BOUNCE" then + increment=1 + frame=frame+increment + else + frame=frame+increment + end + self.time=gimgs.delays[frame] + self.run="YES" + + --for the canvas redrawing function + anii=frame + --redraw the canvas. yeah, it's a bit of a hack. + cnv.action() + end} +end + +anit=gifanimator(gimgs,"LOOP")--,"BOUNCE",3,20) + +cnv = iup.canvas{rastersize = gimgs[1]:Width().."x"..gimgs[1]:Height(), + border = "NO", + expand = "YES"} + +function cnv:map_cb()-- the CD canvas can only be created when the IUP canvas is mapped + cdanvas = cd.CreateCanvas(cd.IUP, self) +end + +function cnv:action()-- called everytime the IUP canvas needs to be repainted + cdanvas:Activate() + gimgs[anii]:cdCanvasPutImageRect(cdanvas, 0, 0, 0, 0, 0, 0, 0, 0) -- use default values +end + +dlg = iup.dialog{cnv,title="Animated Gif Player"} + +function dlg:close_cb() + iup.Destroy(anit) + gimgs=nil --Destroys will be called by the garbage collector + cdanvas:Kill() + self:destroy() + return iup.IGNORE -- because we destroy the dialog +end + +dlg:show() +iup.MainLoop() diff --git a/html/examples/combine9.lua b/html/examples/combine9.wlua index 0bc1b17..0bc1b17 100644 --- a/html/examples/combine9.lua +++ b/html/examples/combine9.wlua diff --git a/html/examples/combine9view.wlua b/html/examples/combine9view.wlua new file mode 100644 index 0000000..d606355 --- /dev/null +++ b/html/examples/combine9view.wlua @@ -0,0 +1,125 @@ +--A script to compose 9 photos, with 4/6 aspect ratio + +require"imlua" +require"imlua_process" +require"iuplua" +require"view_image" + +err_msg = { + "No error.", + "Error while opening the file.", + "Error while accessing the file.", + "Invalid or unrecognized file format.", + "Invalid or unsupported data.", + "Invalid or unsupported compression.", + "Insufficient memory", + "Interrupted by the counter", +} + +function Confirm(title,msg) + if continue then + b=iup.Alarm(title, msg ,"Continue" ,"Exit") + if b==2 then continue=false print("Script Aborted!") end + end +end + +function Create_Host_Image() + if continue then + local screenx=1024*3 screeny=684*3 + dst_photo = im.ImageCreate(screenx, screeny, im.RGB, im.BYTE) + resize_photo = im.ImageCreate(1024, 684, im.RGB, im.BYTE) -- for resize + end +end + +function Create_Host_Name(name) + if continue then + i=0 + repeat + i=i+1 + num=1000+i + numstr=string.sub(tostring(num),-3) +-- path="D:/Composite/" +-- path="D:/Downloads/Test/" + path = "./" + ext=".jpg" + Result=path..name..numstr..ext + res,msg=io.open(Result) + io.close() + until not res + end +end + +function Get_Source_Photo() + if continue then +-- path="D:/MyPictures/" + path="test/*.jpg" + Source, err = iup.GetFile(path) + print("Source: ", Source) + if err<0 then continue=false end + end +end + +function Insert_Photo(num) + if continue then + title="Photo "..num.." of 9" --msg=Source Confirm(title,msg) + wd=dst_photo:Width() + hd=dst_photo:Height() + --print("Dst Size:",wd,hd) + src_photo, err=im.FileImageLoadBitmap(Source) + if (err and err ~= im.ERR_NONE) then + error(err_msg[err+1]) + end + if (not View_Image(src_photo, title)) then continue = false return end + valuex=src_photo:Width() + valuey=src_photo:Height() + --print("Source Size:",valuex,valuey) + panex={0,1024,2048,0,1024,2048,0,1024,2048} + paney={0,0,0,684,684,684,1368,1368,1368} + Xd=panex[num] + Yd=paney[num] + Wd=1024 Hd=684 + -- extract a proportional rectangle from the source image + if 1.5*valuey>valuex then + Ws=valuex + Xs=0 + Hs=math.floor(valuex/1.5) + Ys=math.floor((valuey-Hs)/2) + else + Hs=valuey + Ys=0 + Ws=math.floor(1.5*Hs) + Xs=math.floor((valuex-Ws)/2) + end + + --print("Crop Size:",Ws, Hs) + --print("Crop Shift:",Xs,Ys) + crop_photo = im.ImageCreate(Ws, Hs, im.RGB, im.BYTE) + im.ProcessCrop(src_photo, crop_photo, Xs,Ys) + im.ProcessResize(crop_photo, resize_photo, 1) -- do bilinear interpolation + im.ProcessInsert(dst_photo, resize_photo, dst_photo, Xd, Yd) -- insert resize in dst and place the result in dst + crop_photo:Destroy() + + if num==9 then src_photo:CopyAttributes(dst_photo) end + end +end + +function Save_Composite_Photo() + if continue then + name="Composite" + Create_Host_Name(name) + if (not View_Image(dst_photo, "Composite")) then continue = false return end + dst_photo:Save(Result, "JPEG") + --os.execute(Result) + end +end + +--Script Starts +continue=true +title="9 Panel Composite" msg="Photos can be anysize." Confirm(title,msg) +Create_Host_Image() +for i=1,9 do + num=i + Get_Source_Photo() + Insert_Photo(num) + end +Save_Composite_Photo() diff --git a/html/examples/multimorpho.lua b/html/examples/multimorpho.lua index be612c6..742d713 100644 --- a/html/examples/multimorpho.lua +++ b/html/examples/multimorpho.lua @@ -16,7 +16,7 @@ err_msg = { "Invalid or unrecognized file format.", "Invalid or unsupported data.", "Invalid or unsupported compression.", - "Insuficient memory", + "Insufficient memory", "Interrupted by the counter", } diff --git a/html/examples/view_image.wlua b/html/examples/view_image.wlua new file mode 100644 index 0000000..c156bd3 --- /dev/null +++ b/html/examples/view_image.wlua @@ -0,0 +1,76 @@ +require"imlua" +require"cdlua" +require"cdluaim" +require"iuplua" +require"iupluacd" + +iup.key_open() + +function View_Image(image, title) + ret = false + + cnv = iup.canvas{} + + function cnv:action() + local canvas = dlg.canvas + local image = dlg.image + + if (not canvas) then return end + + canvas:Activate() + cw, ch = canvas:GetSize() + iw = image:Width() + ih = image:Height() + + if (iw > ih) then + h = iw/iw * ch + y = (ch-h)/2 + x = 0 + w = cw + else + w = iw/ih * ch + x = (cw-w)/2 + y = 0 + h = ch + end + + canvas:Clear() + image:cdCanvasPutImageRect(canvas, x, y, w, h, 0, 0, 0, 0) + end + + function cnv:button_cb() + dlg:close_cb() + ret = true + return iup.CLOSE + end + + dlg = iup.dialog{iup.vbox{cnv, iup.label{title="Click to accept or press Esc to abort."}}} + dlg.placement="maximized" + dlg.title = title + dlg.cnv = cnv + dlg.image = image + + function dlg:k_any(c) + print("K_any("..c..")") + if (c == iup.K_ESC) then + dlg:close_cb() + return iup.CLOSE + end + end + + function dlg:close_cb() + local canvas = self.canvas + if canvas then canvas:Kill() end + end + + function dlg:map_cb() + canvas = cd.CreateCanvas(cd.IUP, self.cnv) + self.canvas = canvas + end + + dlg:show() + iup.MainLoop() + dlg:destroy() + + return ret +end |