//bmpをPotraceで指定サイズにsvg出力、Inkscapeで開いて線画と彩色範囲を //それぞれOutline,Baseレイヤーに振り分けて合成. public potrace,inkscape,outptdir,outline,innerfill,fullpath,reduction,filetype,resolution potrace="C:\potrace" inkscape="C:\Program Files\Inkscape" i_view32="C:\Program Files\IrfanView" temp="C:\Temp" ifb (FOPEN(potrace+"\potrace.exe",F_EXISTS)=False) or (FOPEN(inkscape+"\inkscape.exe",F_EXISTS)=False) or (FOPEN(i_view32+"\i_view32.exe",F_EXISTS)=False) or (FOPEN(temp+"\",F_EXISTS)=False) MsgBox("指定したパスにアプリケーションまたはディレクトリが見つかりません<#cr>このuwsファイルの5〜8行目を修正してください<#cr>パス設定は現在以下のように設定されています<#cr><#cr>Potraceのパス="+potrace+"<#cr>Inkscapeのパス="+inkscape+"<#cr>IrfanViewのパス="+i_view32+"<#cr>%TEMPDIR%="+temp,BTN_ABORT) Sleep(0.2) Exit endif While True Scale=input("ビットマップファイルのフルパス<半角spc>に続けて縮小率を入力<#cr>等倍(スケール=100%)で出力する場合はフルパスのみでもokです。<#cr><#cr>eg.) D:\MY_CG\2007\09\15\senga.bmp 25%<#cr>") if Scale=EMPTY then Exit outptdir=Copy(Scale,1,Val(pos("\",Scale,-1))-1) outline=outptdir+"\outline.svg" if pos(" ",outline)>1 then outline="<#dbl>"+outline+"<#dbl>" innerfill=outptdir+"\innerfill.svg" if pos(" ",innerfill)>1 then innerfill="<#dbl>"+innerfill+"<#dbl>" ifb pos(" ",Scale)>pos("p",Scale,-1) fullpath=Copy(Scale,1,Val(pos(" ",Scale,-1))-1) if pos(" ",fullpath)>1 then fullpath="<#dbl>"+fullpath+"<#dbl>" filetype=Copy(Scale,Val(pos(" ",Scale,-1))-3,3) else fullpath=Copy(Scale,1,Val(pos(".",Scale,-1))+3) if pos(" ",fullpath)>1 then fullpath="<#dbl>"+fullpath+"<#dbl>" filetype=Copy(Scale,Val(pos(".",Scale,-1))+1,3) endif ifb !(filetype="bmp") and !(filetype="pbm") and !(filetype="pgm") and !(filetype="ppm") ifb MsgBox("ファイル形式を確認してください。使用できるのは*.bmp;*.pbm;*.pgm;*.ppmだけです<#cr>参照されたファイルのフルパス : <#cr>"+fullpath,BTN_ABORT or BTN_RETRY,G_MOUSE_X-282,G_MOUSE_Y-96,BTN_RETRY)=BTN_RETRY Continue else Exit endif elseif FOPEN(fullpath,F_Exists)=False ifb MsgBox("ファイルが存在しないか、タイプミスがあります<#cr>参照されたファイルのフルパス : <#cr>"+fullpath,BTN_ABORT or BTN_RETRY,G_MOUSE_X-180,G_MOUSE_Y-90,BTN_RETRY)=BTN_RETRY Continue else Exit endif elseif (FOPEN(outline,F_EXISTS)=True) or (FOPEN(innerfill,F_EXISTS)=True) button=MsgBox(outptdir+" には outline.svg または innerfill.svg が既に存在します。<#cr>続行すると同名のファイルは上書きされます。本当に宜しいですか?",BTN_YES or BTN_ABORT or BTN_RETRY,G_MOUSE_X-246,G_MOUSE_Y-82,BTN_ABORT) ifb button=BTN_ABORT Exit elseif button=BTN_YES break else Continue endif else break endif Sleep(0.2) Wend ifb pos(" ",Scale)>pos("p",Scale,-1) reduction=Copy(Scale,Val(pos(" ",Scale,-1))+1,(Val(length(Scale)))-(Val(pos(" ",Scale,-1))+1)) else reduction=100 endif image_info=temp+"\info.txt" Doscmd(i_view32+"\i_view32 "+fullpath+" /info="+image_info) info=FOPEN(image_info,F_read) image_dim=FGET(info,6) dim_x=Val(Copy(image_dim,20,Val(pos(" x",image_dim))-20))*(Val(reduction)/100) dim_y=Val(Copy(image_dim,Val(pos("x ",image_dim))+2,(pos(" P",image_dim))-(Val(pos("x ",image_dim))+2)))*(Val(reduction)/100) FCLOSE(info) Doscmd("del /q "+image_info) ifb (pos(".",Val(dim_x)/4)=0) and (pos(".",Val(dim_y)/4)=0) resolution=90*(100/Val(reduction)) if resolution=0 then resolution=90 if pos(".",resolution)>1 then resolution=Round(Val(resolution)) potrace() inkscape() else resolution=72*(100/Val(reduction)) if resolution=0 then resolution=72 if pos(".",resolution)>1 then resolution=Round(Val(resolution)) potrace() replace() inkscape() endif procedure potrace() resolution="-r"+resolution+" " Doscmd(potrace+"\potrace -s "+resolution+fullpath+" -o "+outline) Doscmd(potrace+"\potrace -s "+resolution+fullpath+" -i -C#FAF2DF -o "+innerfill) fend procedure replace() rep_o=FOPEN(outline,F_read or F_write8) FPUT(rep_o,ChgMoj(FGET(rep_o,5),"pt","px"),5) FCLOSE(rep_o) Sleep(0.2) rep_i=FOPEN(innerfill,F_read or F_write8) FPUT(rep_i,ChgMoj(FGET(rep_i,5),"pt","px"),5) FCLOSE(rep_i) fend procedure inkscape() setpath="set PATH="+inkscape+";"+inkscape+"\python;"+potrace+"<#cr>" settmp="set TEMP=C:\TEMP<#cr>" //setlang="set LANG=en<#cr>" cd="cd /d "+inkscape+"<#cr>inkscape "+outline+"<#cr>" SendStr(0,setpath+settmp+cd) //SendStr(0,setpath+settmp+setlang+cd) prompt=exec("cmd") Sleep(0.2) SCKEY(prompt,VK_ALT,VK_SPACE,E,P) KBD(VK_ALT,2,20) CtrlWin(prompt,CLOSE) Repeat INK_ID=GETID("outline.svg - Inkscape","gdkWindowToplevel",0.1) Sleep(1) Until STATUS(INK_ID,ST_ACTIVE) Sleep(0.5) LockHard(True) CtrlWin(INK_ID,ACTIVATE) //rootの線画オブジェクトをOutlineレイヤーに移動 SCKEY(INK_ID,VK_ALT,L) KBD(VK_ALT,2,40) KBD(VK_RETURN,0,40) SendStr(0,"Outline") Sleep(0.2) Add_Layer=GETID("レイヤーを追加","gdkWindowToplevel") //Add_Layer=GETID("Add Layer","gdkWindowToplevel") CtrlWin(Add_Layer,ACTIVATE) SCKEY(Add_Layer,VK_CTRL,V) KBD(VK_CTRL,2,40) Sleep(0.2) KBD(VK_RETURN,0,40) Sleep(0.2) CtrlWin(INK_ID,ACTIVATE) SCKEY(INK_ID,VK_CTRL,VK_ALT,A) KBD(VK_CTRL,2,40) KBD(VK_ALT,2,40) Sleep(0.5) SCKEY(INK_ID,VK_SHIFT,VK_NEXT) KBD(VK_SHIFT,2,40) Sleep(0.2) //Outlineレイヤーをロック SCKEY(INK_ID,VK_SHIFT,VK_CTRL,L) KBD(VK_SHIFT,2,40) KBD(VK_CTRL,2,40) Layers=GETID("レイヤー(S) (Shift+Ctrl+L)","gdkWindowToplevel") //Layers=GETID("Layers (Shift+Ctrl+L)","gdkWindowToplevel") CtrlWin(Layers,ACTIVATE) KBD(VK_LEFT,0,40) KBD(VK_LEFT,0,40) KBD(VK_RIGHT,0,40) KBD(VK_SPACE,0,40) Sleep(0.2) //innerfill.svgをBase_Paintレイヤーにインポート CtrlWin(INK_ID,ACTIVATE) SCKEY(INK_ID,VK_ALT,L) KBD(VK_ALT,2,40) KBD(VK_RETURN,0,40) SendStr(0,"Base_Paint") Sleep(0.2) Add_Layer=GETID("レイヤーを追加","gdkWindowToplevel") //Add_Layer=GETID("Add Layer","gdkWindowToplevel") CtrlWin(Add_Layer,ACTIVATE) SCKEY(Add_Layer,VK_CTRL,V) KBD(VK_CTRL,2,40) Sleep(0.2) KBD(VK_TAB,0,40) KBD(VK_DOWN,0,40) KBD(VK_ALT,1,40) KBD(VK_A,0,40) KBD(VK_ALT,2,40) Sleep(0.2) CtrlWin(INK_ID,ACTIVATE) DROPFILE(INK_ID,outptdir,"innerfill.svg") Sleep(1) //念のため座標修正 SCKEY(INK_ID,VK_ALT,X) KBD(VK_ALT,2,40) KBD(VK_0,0,40) KBD(VK_TAB,0,40) KBD(VK_0,0,40) KBD(VK_RETURN,0,40) Sleep(0.2) SCKEY(INK_ID,VK_SHIFT,VK_CTRL,G) KBD(VK_SHIFT,2,40) KBD(VK_CTRL,2,40) LockHard(False) SCKEY(INK_ID,VK_SHIFT,VK_CTRL,S) KBD(VK_SHIFT,2,40) KBD(VK_CTRL,2,40) Save_as=GETID("保存するファイルを選択","gdkWindowToplevel",-1) //Save_as=GETID("Select file to save to","gdkWindowToplevel",-1) SendStr(0,outptdir+"\") //Doscmd("md "+outptdir+"\svg") //SendStr(0,outptdir+"\svg") Sleep(0.2) SCKEY(Save_as,VK_CTRL,V) KBD(VK_CTRL,2,40) KBD(VK_RETURN,0,40) ExitExit fend