Archive for 11月 2010
夢の話
「ひた隠す」の「ひた」は「日田」から来ていて、
幕末に日田藩の人間が志士を匿ったことから来てるんだよ。
という夢を見た。
起きてから、日田は天領だったことに気が付いたorz
F#をいじってみた
2ちゃんねるで関数型言語のスレ見てたらなんか触ってみたくなったんで、
Visual StudioにくっついてるF#にしようと思い本を買ってきた。
3種類くらい本があったけど、とりあえずとっつきやすそうな本にしようと思って
F#入門という本にした。
で、読んでみたけど...
何が何やら、さっぱりわからんorz
とりあえず、ウインドウを作成するプログラムが書いてあるところを探して、
それのコピペから始めることにした。
まあ、単にウインドウ作成してもつまんないので、画像をいじって表示する
処理を追加してみた。
できたプログラムがこれ↓
//F# の詳細 (http://fsharp.net) open System open System.Windows.Forms open System.Drawing open Microsoft.FSharp.Control open Microsoft.FSharp.Control.CommonExtensions Application.EnableVisualStyles() // 画像ファイルを開いてバイナリデータを取り出す let pic1 = new System.Drawing.Bitmap("..\\..\\MiniIkamusume.png") let bitmap1 = pic1.LockBits(new Rectangle(0,0,pic1.Width,pic1.Height), Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format24bppRgb) let mutable ptr1 = bitmap1.Scan0 let elementNum = pic1.Width * pic1.Height let bytes = elementNum * 3 let rgbValues:byte[] = Array.create bytes 0uy System.Runtime.InteropServices.Marshal.Copy(ptr1,rgbValues,0,bytes) /// ウェーブレット変換 let Pn : float[] = [| 0.482962913; 0.836516304; 0.224143868;-0.129409523|] let Qn : float[] = [|-0.129409523;-0.224143868; 0.836516304;-0.482962913|] let d : int = 4 let halfWidth : int = pic1.Width / 2 let halfHeight : int = pic1.Height / 2 let mutable rgbTemp : float[] = Array.create bytes 0.0 let mutable rgbOutput : byte[] = Array.create bytes 0uy let mutable tmp_rgb : float[] = [|0.0;0.0;0.0|] let mutable curTable : float[] = null let mutable curPos : int = 0 let mutable i : int = 0 let mutable j : int = 0 /// 横 for y:int in 0 .. pic1.Height - 1 do for x:int in 0 .. pic1.Width - 1 do tmp_rgb <- [|0.0;0.0;0.0|] if x < halfWidth then i <- x curTable <- Pn else i <- x - halfWidth curTable <- Qn for n:int in 0 .. d - 1 do j <- ( n + 2 * i ) % pic1.Width curPos <- (y * pic1.Width + j) * 3 tmp_rgb <- [| tmp_rgb.[0] + curTable.[n] * float rgbValues.[curPos + 0]; tmp_rgb.[1] + curTable.[n] * float rgbValues.[curPos + 1]; tmp_rgb.[2] + curTable.[n] * float rgbValues.[curPos + 2] |] done curPos <- (y * pic1.Width + x)*3 rgbTemp.[curPos + 0] <- tmp_rgb.[0] rgbTemp.[curPos + 1] <- tmp_rgb.[1] rgbTemp.[curPos + 2] <- tmp_rgb.[2] done done /// 縦 for x : int in 0 .. pic1.Width - 1 do for y : int in 0 .. pic1.Height - 1 do tmp_rgb <- [|0.0;0.0;0.0|] if y < halfHeight then i <- y curTable <- Pn else i <- y - halfHeight curTable <- Qn for n:int in 0 .. d - 1 do j <- ( n + 2 * i ) % pic1.Height curPos <- ( j * pic1.Width + x ) * 3 tmp_rgb <- [| tmp_rgb.[0] + curTable.[n] * rgbTemp.[curPos + 0]; tmp_rgb.[1] + curTable.[n] * rgbTemp.[curPos + 1]; tmp_rgb.[2] + curTable.[n] * rgbTemp.[curPos + 2] |] done curPos <- (y * pic1.Width + x)*3 rgbOutput.[curPos+0] <- byte tmp_rgb.[0] rgbOutput.[curPos+1] <- byte tmp_rgb.[1] rgbOutput.[curPos+2] <- byte tmp_rgb.[2] done done // 変換後のデータを設定 System.Runtime.InteropServices.Marshal.Copy(rgbOutput,0,ptr1,bytes) pic1.UnlockBits(bitmap1) /// フォームの作成 let form = new Form(Text="Test",Visible=true,Size=pic1.Size) form.Paint.Add(fun e ->(e.Graphics.DrawImage(pic1,new Point(0,0))) ) [<STAThread>] do Application.Run(form)
お約束の2次元ウェーブレット変換(^^;
前に作ったプログラム(DirectComputeのhlsl)を横目に見ながら書いたんで
「これぞ関数型プログラミング」って感じにはなってないとは思う
あと、並列処理まで入れたかったけど、さすがに始めて1日だとちょっと難しかった。
#(ナンバー)と♯(シャープ)の区別つけなくてもいいのかな...
財布落とした
駅でpasmoを財布から出そうとしたら、財布がない。
かばんやポケットの中を探してみたが、見つからない。
もしかして、落とした?
ハロワに行ったときに暑かったので上着を脱いでかばんにしまった時に
落としてしまったのかと思い、ハロワに電話したが、なかったとの答え。
ちょっと、やばくない...?
どうしようかと考えていたら、何やら左手に違和感が...
袖の中に入ってたよ!!!
あー焦った