# # gif2avt.icn # # Yosep Kim | 04.21.2005 # class gif2avt : Dialog(quit_button, ftext, picture, # .gif file to be processed img,win2,win3, xoffset, yoffset, isSelecting, result, PL, # list that saves all the points clicked count # number of points chosen ) method handle_undo1(ev) local i Zoom(img,cwin,0,0,WAttrib(img,"width"),WAttrib(img,"height"),200,200,128,128) count:=0 every i := !PL do { pull(PL) } end method handle_picture_entered(ev) local browser, temp browser:=FileDialog() browser.show_modal() picture:=ftext.set_contents(browser.get_result()) img:=WOpen("size=128,128", "canvas=hidden") temp:=WOpen("image="||picture, "canvas=hidden")|fail Zoom(temp,img,0,0,WAttrib(temp,"width"),WAttrib(temp,"height"),0,0,128,128) Zoom(img,cwin,0,0,WAttrib(img,"width"),WAttrib(img,"height"),200,200,128,128) WClose(temp) end method handle_tile (ev) local i Fg(cwin, "red") isSelecting:=1 Zoom(img,cwin,0,0,WAttrib(img,"width"),WAttrib(img,"height"),200,200,128,128) count:=0 every i := !PL do { pull(PL) } end method handle_tile_done(ev) local h1,w1,h2,w2,xdiff,ydiff, i, j isSelecting:=0 h1:=PL[*PL-3]-200 w1:=PL[*PL-2]-200 h2:=PL[*PL-1]-200 w2:=PL[*PL]-200 xdiff:=h2-h1 ydiff:=w2-w1 i:=0 j:=0 win3:=WOpen("size=256,256", "canvas=hidden")|stop("NO!!!!!") while i < 256 do { while j < 256 do { CopyArea(img,win3,h1,w1,h2,w2,i,j)|stop("too much!!!") j:=j+ydiff } j:=0 i:=i+xdiff } CopyArea(win3,cwin,0,0,WAttrib(win3, "width"), WAttrib(win3, "height"), 540,340) end method handle_face (ev) local i Fg(cwin, "green") isSelecting:=1 Zoom(img,cwin,0,0,WAttrib(img,"width"),WAttrib(img,"height"),200,200,128,128) count:=0 every i := !PL do { pull(PL) } end method handle_face_done(ev) local h1,w1,h2,w2,xdiff,ydiff h1:=PL[*PL-3]-200 w1:=PL[*PL-2]-200 h2:=PL[*PL-1]-200 w2:=PL[*PL]-200 xdiff:=h2-h1 ydiff:=w2-w1 win2:=WOpen("size="||xdiff||","||ydiff)#, "canvas=hidden") CopyArea(img,win2,h1,w1,h2,w2,0,0) xoffset:=(256-xdiff)/2 yoffset:=(256-ydiff)/2 CopyArea(win2,win,0,0,xdiff,ydiff,540+xoffset,340+yoffset) end method handle_done(ev) CopyArea(win2,win3,0,0,WAttrib(win2,"width"),WAttrib(win2,"height"),xoffset,yoffset) WriteImage(win3,output_path||username||"EH.GIF")|stop("failed") self.result:=output_path||username||"EH.GIF" WClose(win2) WClose(win3) WClose(img) dispose() end method get_result() return \self.result end method start_capturing (ev) if isSelecting = 1 then { Zoom(img,cwin,0,0,WAttrib(img,"width"),WAttrib(img,"height"),200,200,128,128) if count = 0 then { if *PL = 0 then { pull(PL) pull(PL) pull(PL) pull(PL) } put(PL,&x) put(PL,&y) put(PL,"-1") put(PL,"-1") } else { pull(PL) pull(PL) put(PL,&x) put(PL,&y) DrawLine(cwin, PL[*PL-1],PL[*PL],PL[*PL-1],PL[*PL-2]) DrawLine(cwin, PL[*PL-1],PL[*PL],PL[*PL-3],PL[*PL]) DrawLine(cwin, PL[*PL-1],PL[*PL-2],PL[*PL-3],PL[*PL-2]) DrawLine(cwin, PL[*PL-3],PL[*PL],PL[*PL-3],PL[*PL-2]) } count:=count+1 } end method stop_capturing(ev) count:=0 end method component_setup() local tab_set, tab_item_1, tab_item_2, tab_item_3 local txt1, txt2, txt3, tile1, tiledone1, capture_face local face_done, undo, done attrib("size=800,600", "font=sans", "bg=light gray","label=gif2avt", "resize=on") PL:=list() txt1:=Label("pos=10%,10%","label=Select your picture: ") add(txt1) ftext:=TextField("pos=10%,15%","size=170,","draw_border=t") add(ftext) h:= TextButton("label=Browse...", "pos=35%,15%") h.connect(self, "handle_picture_entered", ACTION_EVENT) add(h) connect(self, "start_capturing", MOUSE_DRAG_EVENT) connect(self, "stop_capturing", MOUSE_RELEASE_EVENT) txt2:=Label("pos=65%,20%","label=STEP 1: Caputre the tile area ") add(txt2) tile1:= TextButton("label=Capture", "pos=75%,25%") tile1.connect(self, "handle_tile", ACTION_EVENT) add(tile1) tiledone1:= TextButton("label=Finish", "pos=85%,25%") tiledone1.connect(self, "handle_tile_done", ACTION_EVENT) add(tiledone1) txt3:=Label("pos=65%,35%","label=STEP 2: Now select the face area ") add(txt3) capture_face:= TextButton("label=Capture", "pos=75%,40%") capture_face.connect(self, "handle_face", ACTION_EVENT) add(capture_face) face_done:= TextButton("label=Finish", "pos=85%,40%") face_done.connect(self, "handle_face_done", ACTION_EVENT) add(face_done) undo:= TextButton("label=Undo", "pos=75%,10%") undo.connect(self, "handle_undo1", ACTION_EVENT) add(undo) done:= TextButton("label=DONE", "pos=45%,85%") done.connect(self, "handle_done", ACTION_EVENT) add(done) connect(self, "dispose", CLOSE_BUTTON_EVENT) end initially(a[]) self.Dialog.initially() count:=0 isSelecting:=0 end