tag:blogger.com,1999:blog-69961684699653130232023-11-15T23:44:38.183+08:00F6FAnonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-6996168469965313023.post-60686718527431505722013-10-14T02:46:00.002+08:002013-10-14T02:46:38.394+08:00看不到圖我發現 blog 有一些圖都失效了…<br />
<br />
因為前幾個月在整理 Google+ 的相簿,全部刪光光了 Orz<br />
<br />
之後再來重弄回來吧Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com0tag:blogger.com,1999:blog-6996168469965313023.post-69438846778009171402012-10-30T00:47:00.002+08:002012-10-30T11:49:31.893+08:00Funtoo Linux and Intel Rapid Start Technology<div>
Recently I got myself a new laptop of <b>NEC's Lavie Z (LZ550/H)</b>. It's really a nice laptop, weights only 875g in its 13.3" size. NEC said it is the world's most lightweight 13.3" laptop ever been.</div>
<div>
<br /></div>
<div>
The laptop encompasses an Intel 7 series chipset UM77 which supports Intel Rapid Start, a technology let the laptop goes into the deeper ACPI S4 (hibernate) from ACPI S3 (standby) after some periods of time.</div>
<div>
<br /></div>
<div>
It differs from that the hibernation is <b>directly supported in the hardware</b>, so that you will not see any traditional boot sequences during waking up from a hibernated machine as before, just a flash. It seems Apple implements Safe Sleep by the use of it in their Macs.</div>
<div>
<br /></div>
<div>
The laptop runs linux (Funtoo Linux) and I found out no instructions about how to setup Intel Rapid Start up with linux. But it ends up being not too complicated:</div>
<div>
<ul>
<li>an SSD</li>
<li>an BIOS supports Intel Rapid Start Technology</li>
<li>a partition equal or greater than the laptop's physical memory</li>
</ul>
<div>
I use <b>gdisk</b> to create an extra 4GB partition since the laptop is 4GB model, and then you must give the partition a specified id as to be recognized by the hardware. According to Intel and Gigabyte's manuals, it must be:</div>
</div>
<div>
<ul>
<li>in diskpart, id: <b>84</b>, or</li>
<li>in gdisk, guid: <b>D3BFE2DE-3DAF-11DF-BA40-E3A556D89593</b></li>
</ul>
<div>
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-0O5jUewiWSU/UI6x_TqH3eI/AAAAAAAALAE/CLiAJ1QL0VE/s1600/DSCN3123.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-0O5jUewiWSU/UI6x_TqH3eI/AAAAAAAALAE/CLiAJ1QL0VE/s1600/DSCN3123.JPG" /></a></div>
<div>
<br /></div>
<div>
After that you can reboot the machine into BIOS and check whether the Intel Rapid Start Technology options is on. <b>If you see something like "No valid IFFS partition found" then there must be something wrong in the previous partitioning step</b>.</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-gAjrm1xwXAA/UI6yInesRFI/AAAAAAAALAM/aLv1MIrxYJM/s1600/DSCN3124.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-gAjrm1xwXAA/UI6yInesRFI/AAAAAAAALAM/aLv1MIrxYJM/s1600/DSCN3124.JPG" /></a></div>
<div>
<br /></div>
<div>
Now you can see in the BIOS there are additional options can be configured the Rapid Start. Since Intel releases no software for Linux currently, you can only configure it via BIOS.</div>
<div>
<br /></div>
<div>
To test if it works, configure it to "<b>Entry Imemediately</b>", and make your latop go into S3 standby:</div>
<div>
<br /></div>
<div>
<pre># echo -n mem > /sys/power/state</pre>
</div>
<div>
<ol>
<li>it goes into standby.</li>
<li>it wake up immediately after standby.</li>
<li>then it will flush memory contents into the partition.</li>
<li>goes into hibernation.</li>
<li>you can only wake it up by pressing the power button.</li>
<li>after powering up again, you are now at where you were as if it had never powered down.</li>
</ol>
<div>
<a href="http://www.intel.com/support/motherboards/desktop/sb/CS-033637.htm">The Intel's manual can be found at Intel's with a keyword search of Rapid Start</a>.</div>
</div>
<div>
<br /></div>
<div>
I've just set it up for hours, don't know whether it is stable yet, but it did work. I'm at vanilla-sources-3.6.3 with CK patches. <br />
<br />
There are some times that it goes into hibernation immediately while I setup up a 5 mins period, and there are some times that it wake up from first S3 but not going to hibernation anymore..., since I just got my Funtoo prototype without any further settings for ACPI/laptop, I cannot make sure it's my problem or not.</div>
Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com1tag:blogger.com,1999:blog-6996168469965313023.post-60210492617152614682012-08-16T13:03:00.001+08:002012-08-16T15:05:01.078+08:00Build A Live Audio Streaming System這是一個手工打造串流音樂台的記錄,source 是以 ffmpeg 擷取 foobar2000 的音源,轉檔並傳送到 server 那邊的 ffserver,<br />
<ul>
<li>source: Intel Core 2 Duo E6850, 8GB ram, Windows 7 64bit.</li>
<li>server: Intel Atom D510, 4GB ram, FreeBSD 9.0 amd64.</li>
</ul>
<div>
Server 端只負責對外的服務,不需要特別強悍的效能。</div>
<div class="separator" style="clear: both; text-align: center;">
<img src="http://3.bp.blogspot.com/-dbCsjfsNqko/UCxVvPURwXI/AAAAAAAAKmk/BempaA4LefU/s1600/Untitled.png" style="border: none; box-shadow: none;" /></div>
這個串流系統總共用到這些東西,<br />
<ul>
<li>ffmpeg:@source,擷取音源</li>
<li>foobar2000:@source,播音樂,並且將現在播放的資訊丟到遠方的節目表 service</li>
<li>ffserver :@server,接收 ffmpeg 來源,並提供對外的 streaming</li>
<li>socket.io:@server,接收 foobar2000 現在播放的資訊,推播到網頁上</li>
<li>nginx :@web,網頁介面</li>
<li>jPlayer:@web,HTML5 audio library</li>
</ul>
<div>
<br /></div>
<h4>
ffmpeg & ffserver</h4>
<div>
<br /></div>
<div>
<a href="http://blog.adios.tw/2012/07/ffserver-mp3-stream-doesnt-work-with.html">關於 ffmpeg 的指令使用,虛擬裝置的安裝,ffserver 端的問題,已經寫在前些日子那</a>。實際上這裡設定了兩個 stream,</div>
<div>
<ul>
<li>ogg in webm, 192kb for Firefox, Chrome.</li>
<li>mp3, 256kb for Chrome, Internet Explorer, Safari.</li>
</ul>
<div>
因此 <a href="http://www.youtube.com/watch?v=jVZLhKzMZ1Y">ffmpeg 跑起來的時候就會將同一個音源轉壓成兩條 stream 丟到 ffmpeg</a>。</div>
<br />
<pre><stream mu.webm="mu.webm">
Feed mu.ffm
Format webm
AudioCodec libvorbis
AVOptionAudio flags +global_header
AudioBitRate 192
AudioChannels 2
AudioSampleRate 44100
NoVideo
</stream>
<stream mu.mp3="mu.mp3">
Feed mu.ffm
Format mp3
AudioCodec libmp3lame
AVOptionAudio flags +global_header
AudioBitRate 256
AudioChannels 2
AudioSampleRate 44100
NoVideo
</stream></pre>
</div>
<div>
<br />
只要這邊設定好了,就已經能用常用的 player 打開 URL 聽串流。<br />
<br />
<h4>
foobar2000</h4>
</div>
<div>
<br /></div>
<div>
因為是採用 ffmpeg 直接擷取整台電腦的音源,沒辦法直接將 foobar2000 的 meta informations 串流在一起,meta informations 必須另外自己處理,所以 foobar2000 這邊除了播音樂,還要負責將現在播放的資訊丟到遠方的節目表服務,<a href="http://www.foobar2000.org/SDK">這邊是以 foobar SDK 弄了一個 </a></div>
<div>
<ul>
<li><a href="https://github.com/Adios/foo_http_now_playing">https://github.com/Adios/foo_http_now_playing</a> (<a href="https://github.com/Adios/foo_http_now_playing/downloads">download</a>)</li>
</ul>
<div>
它能將現在播放的資訊以 HTTP POST 傳到設定頁中指定的 URL,傳送的動作會在「歌曲變更」時觸發。<br />
<br />
<h4>
socket.io</h4>
</div>
</div>
<div>
<br /></div>
<div>
<a href="http://socket.io/">socket.io 是 node 上非常方便的 Web Socket implementation</a>,對於支援的的 browser,會直接以 WebSocket 溝通,否則會降回到傳統的幾個 long-pulling 機制。這邊以 node 與 socket.io 弄出一個節目表的服務,它的功用在</div>
<div>
<ul>
<li>接收 foobar2000 的 HTTP POST</li>
<li>將 HTTP POST 的資訊後處理,轉換成方便瀏覽器使用的 JSON string</li>
<li>推播到現存的 client</li>
<li><a href="https://github.com/Adios/muuun/blob/master/muuun.js">https://github.com/Adios/muuun/blob/master/muuun.js</a></li>
</ul>
<div>
<br /></div>
</div>
<div>
<h4>
nginx</h4>
</div>
<div>
<br /></div>
<div>
一者是想讓對外的服務介面一致,一者是 node 不花心思寫的話,serving static files 效能不彰。這裡實際上我讓 foobar2000 的 HTTP POST 與 browser client 的推播導向跑在 localhost 的節目表 service。<br />
<br /></div>
<pre> server {
server_name mu.adios.tw;
location / {
root /home/www/adios.tw/mu;
index mu.html;
try_files $uri $uri/ @home;
}
location ~ /\.git {
deny all;
}
location ~ ^/foo {
proxy_pass http://127.0.0.1:2000;
}
location ~ ^/muuun {
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:2000;
}
location @home {
proxy_pass http://127.0.0.1;
}
}</pre>
<div>
<br /></div>
<div>
<h4>
網頁介面</h4>
</div>
<div>
<br />
網頁介面包括使用了現成的 jPlayer & CirclePlayer,與修改後的版本<br />
<ul>
<li><a href="https://github.com/Adios/circleplayer">https://github.com/Adios/circleplayer</a><br />將 CirclePlayer 的圈圈功能改成音量調整</li>
<li><a href="https://github.com/Adios/mu">https://github.com/Adios/mu</a><br />整份網頁介面</li>
</ul>
<div>
這邊使用到的技術有 HTML5 Audio, Socket.io, <a href="http://blog.adios.tw/2012/08/css3-web-font.html">CSS 3 WebFont</a>。<br />
<br />
整個系統之後可以朝向多人 hosters 的目標發展,也就是由聽眾決定,要不要繼續聽目前的曲子,還是要直接跳至 foobar2000 清單中的下一首。這個過程能經過投票決定。這部份會是 foobar2000 與 socket.io 的相關設計。<br />
<br /></div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="http://2.bp.blogspot.com/-9z4v2eNuwK0/UCx6jZqt0KI/AAAAAAAAKm4/nV4VD0keWfA/s1600/Untitled.png" /></div>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="http://4.bp.blogspot.com/-NZDmrvG5MQQ/UCx9CeZ37hI/AAAAAAAAKnM/RBZdsBc12vw/s1600/Untitled.png" /></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com0tag:blogger.com,1999:blog-6996168469965313023.post-44684643026566993182012-08-15T23:18:00.000+08:002012-08-16T13:03:43.680+08:00在 Windows 用 ffmpeg 錄桌面比較新版本的 ffmpeg 支援 dshow input,在 Windows 下能直接使用 DirectShow 相容的裝置 (webcam, mic) 當輸入源,<br />
<br />
<pre>ffmpeg -f dshow -list_devices true -i dummy</pre>
<br />
會列出所有它能認出的 dshow devices。接著安裝虛擬的 dshow 裝置,視需求安裝,<br />
<ul>
<li><a href="https://github.com/rdp/screen-capture-recorder-to-video-windows-free">https://github.com/rdp/screen-capture-recorder-to-video-windows-free</a> (錄桌面)</li>
<li><a href="https://github.com/rdp/virtual-audio-capture-grabber-device">https://github.com/rdp/virtual-audio-capture-grabber-device</a> (錄電腦音源)</li>
</ul>
<div>
如果要擷取整台電腦的音源(想錄一般麥克風、或是列出的名稱是亂碼的音源裝置),第二項是必須要裝的。注意要用這兩個 virtual device <a href="http://ffmpeg.zeranoe.com/builds/">需要 32bit 的 ffmpeg</a>。<br />
<br />
<pre>ffmpeg -rtbufsize 512000k -f dshow -i video=screen-capture-recorder:audio=virtual-audio-capturer
-vcodec libx264 -preset fast -tune stillimage -x264opts crf=26
-acodec libvorbis -aq 3
screencast.mkv</pre>
<br /></div>
<div>
這樣會將現在看到的桌面與任何動作以 x264 壓縮到 screencast.mkv 這個影片中,就算是在被遠端桌面的狀況下,也能正常錄製;當下桌面的解析度就會是影片壓製的解析度。<br />
<br />
最近版本這樣壓出來的影片會是 4:4:4 的,若要丟到 Youtube 上,必須是 yuv420p,所以要指定,<br />
<br />
<pre>ffmpeg -rtbufsize 512000k -f dshow -i video=screen-capture-recorder:audio=virtual-audio-capturer
-vcodec libx264 -preset fast -tune stillimage -x264opts crf=26
-acodec libvorbis -aq 3
<span style="color: red;">-pix_fmt yuv420p</span>
<span style="color: lime;">-sws_flags lanczos</span>
<span style="color: lime;">-vf crop=1440:810:0:0,scale=1280:720</span>
screencast.mkv</pre>
<br />
假設你的螢幕解析度是 1440x900,為了上傳 youtube 方便,想弄成 720p 的 16:9,可以先 crop 成 16:9 的 1440x810,然後再 scale 成 1280x720,如上的綠字部份。<a href="http://www.youtube.com/watch?v=jVZLhKzMZ1Y">像是這個測試</a>就是從 1024x640 crop and scale to 1280x720。<br />
<br />
如果要流暢一點,還能指定 input 的 framerate (defaults to 25fps),詳細請看 ffmpeg 的 man pages。
<br />
<br />
<h4>
記得,如果是在 mac 下…</h4>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" src="http://3.bp.blogspot.com/-gE7-q1wprTA/UCu7zV49w-I/AAAAAAAAKmQ/fY-Z1JC7uxo/s1600/%25E5%2590%258D%25E7%25A7%25B0%25E6%259C%25AA%25E8%25A8%25AD%25E5%25AE%259A.png" /></div>
<div>
<br /></div>
<div>
可以直接用 QuickTime Player 錄桌面!</div>
Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com0tag:blogger.com,1999:blog-6996168469965313023.post-23454620064682144232012-08-14T01:59:00.002+08:002012-08-14T02:51:20.878+08:00試試 CSS3 Web Font如果只是想要好看的英文字型,<a href="http://www.google.com/webfonts/">Google Web Font</a> 提供非常方便的服務:<br />
<ul>
<li>能選擇多組字型</li>
<li>能預覽這些字型在不同樣式、位置的搭配效果</li>
<li>字型是公開授權過的</li>
<li>不用擔心 @font-face 的多平台多字型問題</li>
</ul>
<div>
可惜沒有提供中文、日文字型,畢竟這些字型的檔案都太大(2MB+)。</div>
<br />
<h4>
TO HOST FONT</h4>
<br />
把字型檔案擺在正確的位置,並多加一行 @font-face 在 CSS 前面,就能讓 font-family 使用自已放在 server 上的字體:<br />
<br />
<pre class="html"><span class="htmlTag"><</span><span class="Statement">style</span><span class="htmlTag"> </span><span class="htmlArg">type</span><span class="htmlTag">=</span><span class="Constant">"text/css"</span><span class="htmlTag">></span>
<span class="Special">@font-face</span> <span class="Identifier">{</span>
<span class="Type">font-family</span>: 'mikachan';
<span class="Type">src</span>: <span class="Identifier">url(</span><span class="Constant">'/fonts/mikachan.otf'</span><span class="Identifier">)</span>;
<span class="Identifier">}</span>
<span class="Comment">/* some elsewhere ... */</span>
<span class="Statement">body</span> <span class="Identifier">{</span>
<span class="Type">font-family</span>: 'mikachan', <span class="Type">sans-serif</span>;
<span class="Identifier">}</span>
<span class="htmlEndTag"></</span><span class="Statement">style</span><span class="htmlEndTag">></span></pre>
<br />
在最簡單的情況下,用 Chrome 與 Firefox 能正常下載和顯示這字型。若字型要讓<br />
<ul>
<li>老版本的 Internet Explorer 使用 (eot)</li>
<li>其它平台的瀏覽器使用 (svg, ttf)</li>
<li>讓它遵循規範</li>
</ul>
<div>
那麼 @font-face 這邊就必須加上多種格式:<br />
<br /></div>
<pre class="html"><span class="htmlTag"><</span><span class="Statement">style</span><span class="htmlTag"> </span><span class="htmlArg">type</span><span class="htmlTag">=</span><span class="Constant">"text/css"</span><span class="htmlTag">></span>
<span class="Special">@font-face</span> <span class="Identifier">{</span>
<span class="Type">font-family</span>: <span class="Constant">'mikachan'</span>;
<span class="Type">src</span>: <span class="Identifier">url(</span><span class="Constant">'/fonts/mikachan.eot'</span><span class="Identifier">)</span>;
<span class="Type">src</span>: <span class="Identifier">url(</span><span class="Constant">'/fonts/mikachan.eot?#iefix'</span><span class="Identifier">)</span> <span class="Identifier">format(</span><span class="Constant">'embedded-opentype'</span><span class="Identifier">)</span>,
<span class="Identifier">url(</span><span class="Constant">'/fonts/mikachan.woff'</span><span class="Identifier">)</span> <span class="Identifier">format(</span><span class="Constant">'woff'</span><span class="Identifier">)</span>,
<span class="Identifier">url(</span><span class="Constant">'/fonts/mikachan.ttf'</span><span class="Identifier">)</span> <span class="Identifier">format(</span><span class="Constant">'truetype'</span><span class="Identifier">)</span>,
<span class="Identifier">url(</span><span class="Constant">'/fonts/mikachan.svg#mikachan'</span><span class="Identifier">)</span> <span class="Identifier">format(</span><span class="Constant">'svg'</span><span class="Identifier">)</span>;
<span class="Type">font-weight</span>: <span class="Type">normal</span>;
<span class="Type">font-style</span>: <span class="Type">normal</span>;
<span class="Identifier">}</span>
<span class="htmlEndTag"></</span><span class="Statement">style</span><span class="htmlEndTag">></span></pre>
<br />
當中的數個 src properties 是必要的,<a href="http://nicewebtype.com/notes/2009/10/30/how-to-use-css-font-face/">Nice Web Type 這邊記錄和說明每一行必須存在的原因</a>,也詳列數年來各種不同的 bullet-proof 技巧。<br />
<br />
不同字型格式的轉換可以用 <a href="http://www.freshports.org/www/ttf2eot">www/ttf2eot</a> 和 <a href="http://www.freshports.org/www/sfnt2woff">www/sfnt2woff</a>,或是直接用線上的轉換服務:<br />
<ul>
<li><a href="http://www.fontsquirrel.com/fontface/generator/">http://www.fontsquirrel.com/fontface/generator/</a> # 轉字型的龍頭,有檔案大小限制</li>
<li><a href="http://fontface.codeandmore.com/">http://fontface.codeandmore.com/</a> # 能轉亞洲語系這類超過 2<b>MB</b> 的檔案</li>
</ul>
<div>
它們會同時幫你產生對應的 @font-face CSS 和 demo page。<br />
<br />
如果要 host 的字型變多了,可以寫一個產生 CSS @font-face 的 handler:
<br />
<br />
<pre class="php"><span class="Special"><?php</span>
<span class="Identifier">header</span><span class="Special">(</span>'<span class="Constant">Content-Type: text/css</span>'<span class="Special">)</span>;
<span class="PreProc">function</span> fill<span class="Special">(</span><span class="Statement">$</span><span class="Identifier">buffer</span><span class="Special">)</span> <span class="Special">{</span>
<span class="Type">global</span> <span class="Statement">$</span><span class="Identifier">font_family</span>;
<span class="Type">global</span> <span class="Statement">$</span><span class="Identifier">file_name</span>;
<span class="Statement">return</span> <span class="Identifier">str_replace</span><span class="Special">(</span>'<span class="Constant">{FILE_NAME}</span>', <span class="Statement">$</span><span class="Identifier">file_name</span>, <span class="Identifier">str_replace</span><span class="Special">(</span>'<span class="Constant">{FONT_FAMILY}</span>', <span class="Statement">$</span><span class="Identifier">font_family</span>, <span class="Statement">$</span><span class="Identifier">buffer</span><span class="Special">))</span>;
<span class="Special">}</span>
<span class="Special">?></span>
<span class="Special"><?php</span> <span class="Identifier">ob_start</span><span class="Special">(</span>'<span class="Constant">fill</span>'<span class="Special">)</span>; <span class="Special">?></span>
@font-face {
font-family: '{FONT_FAMILY}';
src: url('/fonts/{FILE_NAME}.eot');
src: url('/fonts/{FILE_NAME}.eot?#iefix') format('embedded-opentype'),
local('☺'),
url('/fonts/{FILE_NAME}.woff') format('woff'),
url('/fonts/{FILE_NAME}.ttf') format('truetype'),
url('/fonts/{FILE_NAME}.svg#{FILE_NAME}') format('svg');
font-weight: normal;
font-style: normal;
}
<span class="Special"><?php</span> <span class="Identifier">ob_end_flush</span><span class="Special">()</span>; <span class="Special">?></span></pre>
<br />
甚至判斷瀏覽器 User Agent,僅回應指定的 @font-face rule,這樣就不需特別作 IE bullet proof。<br />
<br />
<h4>
NGINX CONFIGURATION</h4>
<div>
<br /></div>
<div>
新增或修改這幾種附檔名的 MIME Type:<br />
<br /></div>
<pre>types {
application/x-font-ttf ttf;
application/x-font-woff woff;
application/vnd.ms-fontobject eot;
}</pre>
<div>
<br />
以及 nginx.conf,
<br />
<br />
<pre>server {
...
location /fonts {
add_header Access-Control-Allow-Origin http://mu.adios.tw;
gzip_types image/svg+xml application/x-font-ttf application/vnd.ms-fontobject;
}
...
}</pre>
<br />
傳輸用 gzip 是讓我們的字體能小一點點(woff 是已經壓過的格式,所以不再 gzip),要注意的是那個 header,W3C 規範瀏覽器必須禮貌性遵守字型的同源政策,也就是:
<br />
<br />
<ul>
<li>你在瀏覽 Host A 的網頁</li>
<li>Host A 的 @font-face src properties 指到 Host B</li>
<li>瀏覽器向 Host B 問字型時,Host B 會先回應含有這條 header 的訊息</li>
<li>瀏覽器將這條 header 比對 Host A,如果一樣,才會下載並使用字型</li>
</ul>
<div>
<br /></div>
<h4>
IE9: CS3111: Unknown Error</h4>
<div>
<br /></div>
<div>
如果 Internet Explorer 9 無法顯示字型,打開開發者工具,檢查看看是不是吐這條訊息,這表示字型檔案錯誤。詳細原因我也不明暸,應該是字體內有些屬性 Windows 不懂,這發生在<b>從 otf 轉換的</b> eot 字型,後來我是拿為原本設計給 windows 的 ttf 格式來轉換 eot,就正常無虞了。</div>
<div>
<br /></div>
<h4>
顯示字型的一致性</h4>
<div>
<br /></div>
<div>
在字型正在被下載的過程中,採用該字體的文字:</div>
<div>
<ul>
<li>Chrome 不顯示任何東西,直到字體下載完,才會顯示</li>
<li>Firefox 顯示預設字型,直到字體下載完,才會更新</li>
</ul>
<div>
<a href="https://developers.google.com/webfonts/docs/webfont_loader">WebFont Loader</a> 能彌平這種不一致性。要嘛就讓所有瀏覽器都不顯示,要嘛就是先顯示預設字型。</div>
</div>
<div>
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com1tag:blogger.com,1999:blog-6996168469965313023.post-47920143462147237122012-07-13T14:04:00.000+08:002012-08-15T17:01:16.632+08:00HTML5 Live Audio Streaming with ffserverRecently I've successfully set up an HTML5 live audio streaming by using ffmpeg and ffserver. It streams well on most HTML5 browsers including latest IE9, Firefox and Chrome. The streaming source comes from an PC running Windows, and the streaming server runs on FreeBSD.<br />
<br />
At streaming source, to make all your sounds (i.e. what you can hear) capable of being captured by ffmpeg, you need to create an virtual device which is DirectShow-compatible so that the latest ffmpeg can recognize it as an audio capturer.<br />
<ul>
<li>download and install <a href="https://github.com/rdp/virtual-audio-capture-grabber-device">virtual-audio-capture-device</a>.</li>
<li>download latest 32-bit <a href="http://ffmpeg.zeranoe.com/builds/">Zeranoe build</a> ffmpeg. (must 32bit one)</li>
</ul>
<div>
There should exist an <b>virtual-audio-capturer</b> entry after checking with the command,<br />
<br />
<pre>ffmpeg -f dshow -list_devices true -i dummy</pre>
<br />
and the following is the command to stream what you hear out to the remote server.<br />
<br /></div>
<pre>ffmpeg -f dshow -i audio=virtual-audio-capturer http://server:8090/feed.ffm</pre>
<br />
At server side, we need to configure two kinds of audio streams in order to provide HTML5 audio compatibilities among mainstream browsers,<br />
<ul>
<li>set up an mp3 stream with <b>libmp3lame </b>audio codec. (IE, Safari, Chrome)</li>
<li>set up an <b>webm</b> stream with <b>libvorbis</b> audio codec. (Firefox, Opera, Chrome)</li>
</ul>
<div>
Adding one more line to both of the streams you just set up,<br />
<br /></div>
<pre>AVOptionAudio flags +global_header</pre>
<br />
to make them live streaming capable.<br />
<br />
You can directly open the streaming in VLC(webm, mp3) or foobar2000(mp3) to test whether it works or not. And note that there are still some issues between ffmpeg and ffserver while streaming.<br />
<br />
<h4>
The MP3 Stream Cannot be Played on Internet Explorer 9</h4>
<br />
After googling, I just know that IE9 accepts only server response of <b>audio/mpeg</b> <span style="background-color: white;">as mime-type to mp3 stream, whereas </span><span style="background-color: white;">ffserver(N-42472-gd3abbb1) responds the old <b>audio/x-mpeg</b> one.</span><br />
<br />
Here is the dirty one-line fix to the issue,<br />
<br />
<pre>diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 8a9f788..14ec70c 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -499,7 +499,7 @@ static int mp3_write_trailer(AVFormatContext *s)
AVOutputFormat ff_mp3_muxer = {
.name = "mp3",
.long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 3"),
- .mime_type = "audio/x-mpeg",
+ .mime_type = "audio/mpeg",
.extensions = "mp3",
.priv_data_size = sizeof(MP3Context),
.audio_codec = CODEC_ID_MP3,
</pre>
<br />
then ffserver feeds IE9 happily.<br />
<br />
<h4>
OGG Stream Format Plays Abnormal on Most Players</h4>
<br />
<span class="Apple-style-span" style="font-weight: normal;">W</span>hen specifying the libvorbis stream with OGG format, audio stream being played on Firefox or Opera will come off and on. The problem exists by directly opening it using VLC or foobar2000. Hence I think it maybe an unknown bug comes with ffserver's OGG format.<br />
<div>
<br />
For the same libvorbis stream, I changed it to using WEBM format, and everything is OK. So I recommend to choose webm as your encapsulation format for libvorbis streams.<br />
<br /></div>
<h4>
Libvorbis Transcoding Fails in a Ranged Bitrate</h4>
<br />
<div>
For the libvorbis codecs, I encountered a strange behavior of transcoding failed at source ffmpeg(N-42347-g299387e). It failed at bitrate 128kb, 160kb and any value lower than 192kb.<br />
<br />
I haven't find out how to fix it yet, so just setting bitrate to 192kb at the moment to prevent the failure transcoding.<br />
<br />
<h4>
Realtime Buffer X% Full</h4>
</div>
<div>
<br /></div>
<div>
if you see this at source point occasionally while streaming stop,<br />
<br />
<pre>[dshow @ 01f1c000] real-time buffer 1412% full! frame dropped!</pre>
<br />
You may increase buffer size by adding <span style="font-family: Courier New, Courier, monospace;">rtbufsize</span> option to prevent this error,<br />
<br />
<pre>ffmpeg -rtbufsize 512000k -f dshow ...</pre>
<br /></div>
Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com0tag:blogger.com,1999:blog-6996168469965313023.post-50161768484910624042010-03-30T14:52:00.000+08:002010-03-30T14:52:51.934+08:00從 select.h 學 bit mask最近在寫的程式需要同時開很多檔案以便做 N-way merge。為了記錄已經 <b><i>open</i></b> 了哪些 file descriptors,就必須要有一個資料結構可以儲存這些開開關關的資訊。<br />
對於處理這種「不是 on,就是 off」狀態的資訊,最直覺的做法就是用 <b>bit mask</b>。 在 FreeBSD amd64 中,一個 <b><i>long</i></b> 型態的變數是 8 bytes, 64 bits,所以一個 <i><b>long</b></i> 就有 64 個 bit flags 可以用,也就是可以記錄由 0 ~ 63 的 fd 編號:<br />
<span class="Apple-style-span" style="font-family: monospace;"> <span style="color: green;">long</span> fd_mask;<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> set on bit no.64 </span><span style="color: #0000c0;">*/</span><br />
fd_mask |= <span style="color: #c00000;">1</span> << <span style="color: #c00000;">63</span>;<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> set on bit no.1 </span><span style="color: #0000c0;">*/</span><br />
fd_mask |= <span style="color: #c00000;">1</span> << <span style="color: #c00000;">0</span>;</span><br />
假如需要記錄的 fd 個數超過 64 個,那就必須另外宣告一個 <b><i>long</i></b> 型態的變數來使用。而把相同功能的變數放在一起最直覺的方式就是用陣列,現在要記錄的是 1024 個 fds(0~1023),那就宣告一個 16 個<b><i> long</i></b> 的陣列:<br />
<span class="Apple-style-span" style="font-family: monospace;"> <span style="color: green;">long</span> fd_setsize = <span style="color: #c00000;">1024</span>;<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> 1024 / 64 = 16 </span><span style="color: #0000c0;">*/</span><br />
<span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">16</span>];</span><br />
接著遇到的問題是,對於一個 fd(0~1023),我怎麼知道要把它定位在「哪一個<b><i> long</i></b> (<b>layer</b>)的哪一個 bit(<b>position</b>)」?透過<b>除法</b>與<b>取餘數</b>可以分別解決這兩個定位的問題,所以:<br />
<span class="Apple-style-span" style="font-family: monospace;"> <span style="color: green;">long</span> fd_setsize = <span style="color: #c00000;">1024</span>;<br />
<span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">16</span>];<br />
<br />
<span style="color: green;">int</span> x;<br />
<span style="color: green;">int</span> layer = x / <span style="color: #c00000;">64</span>;<br />
<span style="color: green;">int</span> position = x % <span style="color: #c00000;">64</span>;</span><br />
有這樣的知識後,我們就可以產生一個設定 <b>bit mask</b> 的函式:<br />
<span class="Apple-style-span" style="font-family: monospace;"> <span style="color: green;">long</span> fd_setsize = <span style="color: #c00000;">1024</span>;<br />
<span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">16</span>];<br />
<span style="color: green;">void</span> fd_set(fd, <span style="color: green;">long</span> *fd_set) {<br />
fd_set[fd_setsize / <span style="color: #c00000;">64</span>] |= (<span style="color: #c00000;">1</span> << (x % <span style="color: #c00000;">64</span>));<br />
}<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> will set 1 on layer 0, bit no.1 </span><span style="color: #0000c0;">*/</span><br />
fd_set(<span style="color: #c00000;">0</span>, fd_mask);<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> will set 1 on layer 15, bit no.64 </span><span style="color: #0000c0;">*/</span><br />
fd_set(<span style="color: #c00000;">1023</span>, fd_mask);</span><br />
這也是在 <b><i>select.h</i></b> 中,<b><i>FD_SET</i></b> 巨集的概念,其它的 <i><b>FD_ZERO</b></i>、<b><i>FD_ISSET</i></b> 和 <b><i>FD_CLR</i></b> 也都採用相同的定位方式。<br />
還有一個問題在於:如何宣告一開始的 <b><i>long</i></b> array 要多大?<br />
如果要處理的 fd 個數可以有 1024 個,那麼由 1024 / 64 得到的值,就會是剛好的大小;但是如果要處理的 fd 個數是 1025 個,那麼除出來的值(沒有小數),會跟上面一樣,因此得到錯誤的結果(需要 17 而不是 16)。<br />
<span class="Apple-style-span" style="font-family: monospace;"><span style="color: #c000c0;"> #define how_big(x) (x) / </span><span style="color: #c00000;">64</span><br />
<span style="color: green;">long</span> fd_mask[how_big(x)];<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> x = 64, fd: 0 ~ 63 </span><span style="color: #0000c0;">*/</span><br />
=> <span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">1</span>];<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> x = 65, fd: 0 ~ 64 </span><span style="color: #0000c0;">*/</span><br />
=> <span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">1</span>]; <span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> wrong, we need 2 layers. </span><span style="color: #0000c0;">*/</span></span><br />
如果把純的除法改成這樣,那問題就解決了:<br />
<span class="Apple-style-span" style="font-family: monospace;"><span style="color: #c000c0;"> #define how_big(x) ((x) + </span><span style="color: #c00000;">64</span><span style="color: #c000c0;"> - </span><span style="color: #c00000;">1</span><span style="color: #c000c0;">) / </span><span style="color: #c00000;">64</span><br />
<span style="color: green;">long</span> fd_mask[how_big(x)];<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> x = 64, fd: 0 ~ 63 </span><span style="color: #0000c0;">*/</span><br />
=> <span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">1</span>];<br />
<span style="color: #0000c0;">/*</span><span style="color: #0000c0;"> x = 65, fd: 0 ~ 64 </span><span style="color: #0000c0;">*/</span><br />
=> <span style="color: green;">long</span> fd_mask[<span style="color: #c00000;">2</span>];</span><br />
實際上,這樣的函數是一個 <i><b>ceiling function</b></i>,剛好符合這個問是的特性:<br />
<span class="Apple-style-span" style="font-family: monospace;"> z = (x + (y - <span style="color: #c00000;">1</span>)) / y, y = <span style="color: #c00000;">64</span><br />
x = <span style="color: #c00000;">0</span>, z => <span style="color: #c00000;">0</span><br />
x = <span style="color: #c00000;">1</span>~<span style="color: #c00000;">64</span>, z => <span style="color: #c00000;">1</span><br />
x = <span style="color: #c00000;">65</span>~<span style="color: #c00000;">128</span>, z => <span style="color: #c00000;">2</span></span><br />
以上,是從 <b><i>select.h </i></b>裡面學到的技巧…。Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com1tag:blogger.com,1999:blog-6996168469965313023.post-31288881014780272182009-05-13T19:13:00.005+08:002009-05-21T18:53:29.744+08:00在 php 裡用 imagick 處理老舊文字<div>我依照<a href="http://www.lunacore.com/photoshop/tutorials/tut024.htm">通緝令教學</a>,先用 gimp 把 background 弄出來,接著使用 php-imagick 去處裡老舊文字的特效,<span class="Apple-style-span" style="font-weight: bold;"><span class="Apple-style-span" style="font-style: italic;">trample_text_layer()</span></span> 大致上就是按照 tutorial 轉換成程式進行。效果還不錯。</div><div><br /></div><div>我也試過 php-gd 來轉,但是我讀入透明的 background 後,輸出就變成不透明,設了一些參數,也是一樣,索性就試試看用 imagemagick 處理。</div><div><br /></div><code></code><div><code><span class="Apple-style-span" style=" line-height: 14px; font-family:Monaco;font-size:11px;"><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 115%/normal Monaco, 'Courier New', monospace; line-height: 1.4em; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; font-size: 115%; "><div class="line" id="LC144" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "><span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">function</span> <span class="nf" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(153, 0, 0); font-weight: bold; ">trample_text_layer</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$draw</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$text_width</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$text_height</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">)</span></div><div class="line" id="LC145" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">{</span></div><div class="line" id="LC146" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">new</span> <span class="nx" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">Imagick</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">();</span></div><div class="line" id="LC147" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">newImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$text_width</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$text_height</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="s1" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(221, 17, 68); ">'none'</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="s1" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(221, 17, 68); ">'png'</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span> </div><div class="line" id="LC148" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">drawImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$draw</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC149" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> </div><div class="line" id="LC150" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$noise_layer</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">clone</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">();</span></div><div class="line" id="LC151" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$noise_layer</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">addNoiseImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nx" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">imagick</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">::</span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">NOISE_POISSON</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC152" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">compositeImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$noise_layer</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nx" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">imagick</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">::</span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">COMPOSITE_DSTIN</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC153" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> </div><div class="line" id="LC154" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">waveImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0.3</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">30</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC155" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">chopImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">2</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC156" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> </div><div class="line" id="LC157" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$width</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">getImageWidth</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">();</span></div><div class="line" id="LC158" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$height</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">getImageHeight</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">();</span></div><div class="line" id="LC159" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> </div><div class="line" id="LC160" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">for</span> <span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">;</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; "><</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$width</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">;</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">+=</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$width</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">/</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">3</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">)</span></div><div class="line" id="LC161" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">{</span></div><div class="line" id="LC162" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="nb" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 134, 179); ">floor</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC163" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$portion</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">=</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">getImageRegion</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nb" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 134, 179); ">floor</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$width</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">/</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">3</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">)</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">1</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$height</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC164" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$portion</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">swirlImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">15</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC165" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">compositeImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$portion</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nx" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">imagick</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">::</span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">COMPOSITE_REPLACE</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$begin</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span></div><div class="line" id="LC166" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">}</span></div><div class="line" id="LC167" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> </div><div class="line" id="LC168" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">-></span><span class="na" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">blurImage</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">(</span><span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0.5</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">,</span> <span class="m" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 153, 153); ">0.1</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">);</span> </div><div class="line" id="LC169" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> </div><div class="line" id="LC170" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "> <span class="k" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; font-weight: bold; ">return</span> <span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; color: rgb(0, 128, 128); ">$im</span><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">;</span></div><div class="line" id="LC171" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; line-height: 1.4em; padding-left: 1em; "><span class="p" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.4em; ">}</span></div></pre></span></code><div></div><div>簡單三步驟是這樣:</div><div><ol><li>加一層 noise layer。</li><li>waveImage(波動)</li><li>swirlImage(中心變形)</li></ol><div>後兩步是為了要出現類似在 photoshop 中 liquify 的效果。</div><div><br /></div><div>成果如下:</div><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_RrEBYXh3BJQ/ShUydHh1zZI/AAAAAAAABgA/FhTGnMneJII/s1600-h/sample.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 180px; height: 291px;" src="http://1.bp.blogspot.com/_RrEBYXh3BJQ/ShUydHh1zZI/AAAAAAAABgA/FhTGnMneJII/s400/sample.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5338228409136172434" /></a><br /></div><div><br /></div><div>整個產生器展示在<a href="http://lab.adios.tw/wanted">這裡</a>。(如果他還活著。)</div><div>有興趣的可以<a href="http://github.com/Adios/Wanted/">下載原始碼</a>。</div><div><br /></div></div>Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com0tag:blogger.com,1999:blog-6996168469965313023.post-3441112967859407082007-03-25T01:24:00.000+08:002008-07-26T06:10:43.993+08:00IRC Interview with WanCW about Function Pointer in C以下的內容是從舊的 blog 轉過來的,當初的發文時間在 2006,05,18。其內容是關於 C 的 Function Pointer 與所謂的 callback 應用。<span class="fullpost"><br /><blockquote><br /><span style="font-family: courier new;">15:25 <Adios> == BEGIN ==</span><br /><span style="font-family: courier new;">15:25 -%- Irssi: Pasting 9 lines to WanCW. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.</span><br /><span style="font-family: courier new;">15:25 <Adios> { /* Welcome to array of function pointers */</span><br /><span style="font-family: courier new;">15:25 <Adios> int i;</span><br /><span style="font-family: courier new;">15:25 <Adios> void (*array[])(int *) = {increase_int, increase_int, square_int, NULL};</span><br /><span style="font-family: courier new;">15:25 <Adios> for(i=0; array[i]!= NULL; i++) {</span><br /><span style="font-family: courier new;">15:25 <Adios> (*(array+i))(a);</span><br /><span style="font-family: courier new;">15:25 <Adios> printf("After %p, c = %d\n", array[i], c);</span><br /><span style="font-family: courier new;">15:25 <Adios> }</span><br /><span style="font-family: courier new;">15:25 <Adios> }</span><br /><span style="font-family: courier new;">15:25 <Adios> return 0;==</span><br /><span style="font-family: courier new;">15:25 <Adios> == end</span><br /><span style="font-family: courier new;">15:26 <Adios> 我剛剛把 jypan 之前較的拿出來看</span><br /><span style="font-family: courier new;">15:26 <Adios> C 可以這樣寫喔@@? void(*arra[])(int *) = () 這行</span><br /><span style="font-family: courier new;">16:17 <WanCW> why not? array of function pointer</span><br /><span style="font-family: courier new;">16:17 <Adios> 那一段看不懂!</span><br /><span style="font-family: courier new;">16:17 <WanCW> void (T)(int *)</span><br /><span style="font-family: courier new;">16:17 <WanCW> 這樣懂嗎?</span><br /><span style="font-family: courier new;">16:18 <Adios> 是這裡不懂吧</span><br /><span style="font-family: courier new;">16:18 <WanCW> void (*T)(int *)</span><br /><span style="font-family: courier new;">16:18 <WanCW> 這樣才對</span><br /><span style="font-family: courier new;">16:18 <WanCW> 哪裡?</span><br /><span style="font-family: courier new;">16:18 <Adios> 就是這裡</span><br /><span style="font-family: courier new;">16:18 <WanCW> void func(int *)</span><br /><span style="font-family: courier new;">16:18 <WanCW> 一個叫做 func 的 function</span><br /><span style="font-family: courier new;">16:18 <WanCW> void (*pFunc)(int *)</span><br /><span style="font-family: courier new;">16:19 <WanCW> 一個叫做 pFunc 的 function pointer, 指向跟 func 長的一樣的 function</span><br /><span style="font-family: courier new;">16:19 <WanCW> void (*apFunc[])(int *)</span><br /><span style="font-family: courier new;">16:20 <WanCW> apFunc 是一個 array, 裡面放的都是像 pFunc 的東西</span><br /><span style="font-family: courier new;">16:20 <WanCW> 了解?</span><br /><span style="font-family: courier new;">16:20 <Adios> 還沒 我思考一下</span><br /><span style="font-family: courier new;">16:21 <WanCW> pFunc = &func</span><br /><span style="font-family: courier new;">16:21 <WanCW> apFunc[0] = pFunc</span><br /><span style="font-family: courier new;">16:21 <WanCW> 大概是這種用法</span><br /><span style="font-family: courier new;">16:21 <WanCW> func(&i);</span><br /><span style="font-family: courier new;">16:21 <WanCW> (*pFunc)(&i)</span><br /><span style="font-family: courier new;">16:22 <WanCW> 阿..不對, 是:</span><br /><span style="font-family: courier new;">16:22 <WanCW> pFunc(&i)</span><br /><span style="font-family: courier new;">16:22 <WanCW> 其實 "func" 也是一個指標</span><br /><span style="font-family: courier new;">16:22 <WanCW> 所以應該是</span><br /><span style="font-family: courier new;">16:22 <WanCW> pFunc = func # 很怪吧? XD</span><br /><span style="font-family: courier new;">16:25 <Adios> 還有那個 { } 的意思在C裡面是怎樣?</span><br /><span style="font-family: courier new;">16:25 <WanCW> init an aray</span><br /><span style="font-family: courier new;">16:25 <WanCW> int a[] = {1, 2, 3};</span><br /><span style="font-family: courier new;">16:25 <WanCW> a[0] == 1, and so on.</span><br /><span style="font-family: courier new;">16:25 <Adios> oh 我說那個 一開始的 { 跟最後依航的 }</span><br /><span style="font-family: courier new;">16:25 <Adios> 就是block</span><br /><span style="font-family: courier new;">16:26 <WanCW> just a block</span><br /><span style="font-family: courier new;">16:26 <Adios> 我以為C應定要有 int main () { }</span><br /><span style="font-family: courier new;">16:26 <WanCW> to create a new scope</span><br /><span style="font-family: courier new;">16:26 <WanCW> 剛剛那是片斷吧?</span><br /><span style="font-family: courier new;">16:26 <Adios> 不是耶</span><br /><span style="font-family: courier new;">16:26 <WanCW> 最後面還有 return 0; 呀</span><br /><span style="font-family: courier new;">16:26 <Adios> http://ant.comm.ccu.edu.tw/course/92_Programming/2_SampleCode/040319_pointer.c</span><br /><span style="font-family: courier new;">16:27 <Adios> 喔 我是說 我以為那是依個函式</span><br /><span style="font-family: courier new;">16:28 <WanCW> 所以他是一個 block to create a scopr</span><br /><span style="font-family: courier new;">16:28 <WanCW> 因為在 C 裡面這樣不合法:</span><br /><span style="font-family: courier new;">16:28 <WanCW> func ()</span><br /><span style="font-family: courier new;">16:28 <WanCW> {</span><br /><span style="font-family: courier new;">16:28 <WanCW> int a;</span><br /><span style="font-family: courier new;">16:28 <WanCW> a++;</span><br /><span style="font-family: courier new;">16:28 <WanCW> int b; // ERROR!!!</span><br /><span style="font-family: courier new;">16:28 <WanCW> }</span><br /><span style="font-family: courier new;">16:28 <Adios> oh</span><br /><span style="font-family: courier new;">16:29 <Adios> 所以直接依個 不具名的 block</span><br /><span style="font-family: courier new;">16:29 <Adios> 就create依個scope了</span><br /><span style="font-family: courier new;">16:29 <WanCW> yes, 變成這樣既就可以:</span><br /><span style="font-family: courier new;">16:29 <WanCW> func ()</span><br /><span style="font-family: courier new;">16:29 <WanCW> {</span><br /><span style="font-family: courier new;">16:29 <WanCW> int a;</span><br /><span style="font-family: courier new;">16:29 <WanCW> a++;</span><br /><span style="font-family: courier new;">16:29 <WanCW> { int b; }</span><br /><span style="font-family: courier new;">16:29 <WanCW> }</span><br /><span style="font-family: courier new;">16:29 <Adios> 我從來不知道 Orz</span><br /><span style="font-family: courier new;">16:29 <Adios> 我以為C沒有</span><br /><span style="font-family: courier new;">16:29 <Adios> 原來C什麼都有</span><br /><span style="font-family: courier new;">16:30 <WanCW> 你錯怪 C 了</span><br /><span style="font-family: courier new;">16:31 <Adios> increase_int 與 & increase_int 都是回傳他的起始位置吧?</span><br /><span style="font-family: courier new;">16:31 <Adios> &increate_int vs increate_int</span><br /><span style="font-family: courier new;">16:31 <WanCW> yes, this is tricky</span><br /><span style="font-family: courier new;">16:32 <WanCW> 就像 int A[] = { 1, 2}</span><br /><span style="font-family: courier new;">16:32 <WanCW> &A == A</span><br /><span style="font-family: courier new;">16:32 <Adios> ok</span><br /><span style="font-family: courier new;">16:32 <WanCW> try it by yourself. :p</span><br /><span style="font-family: courier new;">16:38 <Adios> 好我懂了</span><br /><span style="font-family: courier new;">16:38 <Adios> exp++</span><br /><span style="font-family: courier new;">16:39 <WanCW> level up?</span><br /><span style="font-family: courier new;">16:39 <Adios> not yet</span><br /><span style="font-family: courier new;">16:39 <Adios> 這樣的原理 有沒有通常會運用在怎樣的 手法上?</span><br /><span style="font-family: courier new;">16:40 <WanCW> 哪個 function pointer?</span><br /><span style="font-family: courier new;">16:40 <Adios> function pointer</span><br /><span style="font-family: courier new;">16:40 <WanCW> call back</span><br /><span style="font-family: courier new;">16:41 <WanCW> 最出名的應用</span><br /><span style="font-family: courier new;">:41 <WanCW> qsort</span><br /><span style="font-family: courier new;">16:41 <Adios> 會什麼要叫做 callback 我查過google還是不鳥</span><br /><span style="font-family: courier new;">16:41 <WanCW> I call you and give you a callback, you call back to me by callback.</span><br /><span style="font-family: courier new;">16:42 <Adios> 簡單明瞭 這樣說就瞭了</span><br /><span style="font-family: courier new;">16:43 <Adios> 所以它可以讓 其他function 直接跳到 另依個fuction 而不用透過一層層的return這樣?</span><br /><span style="font-family: courier new;">16:43 <WanCW> 本來是我 call 你, 但是我要讓你能再 回call 我, 就給你一個 "callback"</span><br /><span style="font-family: courier new;">16:43 <WanCW> 不太懂你的意思</span><br /><span style="font-family: courier new;">16:44 <Adios> 如果main 必須要執行兩個functino A, B , 這樣的話 要讓A作完以後 return,B作完以後再reutrn</span><br /><span style="font-family: courier new;">16:45 <Adios> 用callback 的話 A做完可以直接B媽</span><br /><span style="font-family: courier new;">16:45 <WanCW> no, no, no.</span><br /><span style="font-family: courier new;">16:46 <WanCW> 實例 qsort:</span><br /><span style="font-family: courier new;">16:46 <WanCW> qsort 裡面, 會用到 a < b,</span><br /><span style="font-family: courier new;">16:47 <WanCW> 但是 C 沒有 function overriding, 你要比較特別的資料型態(像字串) 必須:</span><br /><span style="font-family: courier new;">16:47 <WanCW> comp (a, b)</span><br /><span style="font-family: courier new;">16:47 <WanCW> 那不同的型態有不同的 compare func,</span><br /><span style="font-family: courier new;">16:48 <Adios> Y</span><br /><span style="font-family: courier new;">16:48 <WanCW> 所以我們會 qsort(A, B, CompFunc)</span><br /><span style="font-family: courier new;">16:48 <WanCW> 讓 qsort 在需要的時候, 去呼叫 CompFunc</span><br /><span style="font-family: courier new;">16:48 <WanCW> 另外一個用途就是像 jypan 寫的, 簡陋的多型</span><br /><span style="font-family: courier new;">16:49 <WanCW> pFunc (a, b); <- different func do diff thing.</span><br /><span style="font-family: courier new;">16:49 <WanCW> 我決定大的邏輯(流程?), 你提供 callback 提供細部實做</span><br /><span style="font-family: courier new;">16:49 <WanCW> --</span><br /><span style="font-family: courier new;">16:50 <WanCW> 例如說: 資料儲存後端可以變化</span><br /><span style="font-family: courier new;">16:50 <WanCW> 那我就可以用 functoin pointer 來切換</span><br /><span style="font-family: courier new;">16:50 <WanCW> 但是程式邏輯不需要改.</span><br /><span style="font-family: courier new;">16:50 <WanCW> --</span><br /><span style="font-family: courier new;">16:50 <Adios> 所以這也是C 要做成多型的手法!</span><br /><span style="font-family: courier new;">16:51 <WanCW> 是的</span><br /><span style="font-family: courier new;">16:51 <WanCW> 其實, C++ 的多型就是用 function pointer table 來實做的</span><br /><span style="font-family: courier new;">16:51 <Adios> !!</span><br /><span style="font-family: courier new;">16:51 <WanCW> class A -> f1, f2, f3</span><br /><span style="font-family: courier new;">16:51 <WanCW> calss B 繼承 A, 改寫 f2</span><br /><span style="font-family: courier new;">16:52 <WanCW> 那他的 function pointer table 的 f2 就跟 A 的不一樣,</span><br /><span style="font-family: courier new;">16:52 <WanCW> 其他一樣</span><br /><span style="font-family: courier new;">16:52 <WanCW> b.f2 (...) ==> b.funcTable[INDEX_OF_f2] (...)</span><br /><span style="font-family: courier new;">16:53 <WanCW> b.f2 (...) ==> funcTableOfB [INDEX_OF_f2] (b, ...)</span><br /><span style="font-family: courier new;">16:53 <WanCW> 後面才對</span><br /><span style="font-family: courier new;">16:53 <WanCW> b 就變成 this!</span><br /><span style="font-family: courier new;">16:53 <WanCW> 詳情請看 Inside C++ Object Model XD</span><br /><span style="font-family: courier new;">16:53 <Adios> 這太深奧了~! 就向史密斯電子一樣</span><br /><span style="font-family: courier new;">16:54 <WanCW> 嗯, Implementation of C++ is very tricky.</span><br /><span style="font-family: courier new;">16:54 <WanCW> ugly</span><br /><span style="font-family: courier new;">16:54 <Adios> 我再慢慢消化吧</span><br /><span style="font-family: courier new;">16:54 <Adios> 我問簡單的</span><br /><span style="font-family: courier new;">16:54 <WanCW> 會用就好, 等你有需要時, 自然就會想到了. XD</span><br /><span style="font-family: courier new;">16:54 <WanCW> 嗯.?</span><br /><span style="font-family: courier new;">16:54 <Adios> 本來是我 call 你, 但是我要讓你能再 回call 我, 就給你一個 "callback"</span><br /><span style="font-family: courier new;">16:55 <Adios> A call B, A give B callback, B can callback to A</span><br /><span style="font-family: courier new;">16:55 <WanCW> yeap</span><br /><span style="font-family: courier new;">16:55 <Adios> 那未什麼不讓 B return 就好</span><br /><span style="font-family: courier new;">16:55 <WanCW> 錯了</span><br /><span style="font-family: courier new;">16:55 <WanCW> A call B, A give B callback C, B can callback to A'side</span><br /><span style="font-family: courier new;">16:56 <WanCW> 兩個是不同 function</span><br /><span style="font-family: courier new;">16:56 <Adios> 哪兩個是不同的funciton!</span><br /><span style="font-family: courier new;">16:56 <WanCW> ruby 的 blocks 其實就是 callback. 只是與法比較高階</span><br /><span style="font-family: courier new;">16:56 <WanCW> 語法</span><br /><span style="font-family: courier new;">16:56 <WanCW> anArray.each {|x| puts x }</span><br /><span style="font-family: courier new;">16:57 <WanCW> --</span><br /><span style="font-family: courier new;">16:57 <Adios> 越來越混亂壓~</span><br /><span style="font-family: courier new;">16:57 <WanCW> for_each (anAray, F)</span><br /><span style="font-family: courier new;">16:57 <WanCW> --</span><br /><span style="font-family: courier new;">16:57 <WanCW> restart.</span><br /><span style="font-family: courier new;">16:57 <WanCW> anArray.each {|x| puts x }</span><br /><span style="font-family: courier new;">16:57 <WanCW> 上面那行你懂意思吧?</span><br /><span style="font-family: courier new;">16:57 <Adios> puts each x in array</span><br /><span style="font-family: courier new;">16:58 <WanCW> yes, and I show you a C++ segment do the same thing.</span><br /><span style="font-family: courier new;">16:58 <Adios> go:</span><br /><span style="font-family: courier new;">17:00 <WanCW> void f (int x)</span><br /><span style="font-family: courier new;">17:00 <WanCW> {</span><br /><span style="font-family: courier new;">17:00 <WanCW> printf ("%d\n", x);</span><br /><span style="font-family: courier new;">17:00 <WanCW> }</span><br /><span style="font-family: courier new;">17:00 <WanCW> for_each (int A[], int size, void (*pf)(int))</span><br /><span style="font-family: courier new;">17:00 <WanCW> {</span><br /><span style="font-family: courier new;">17:00 <WanCW> int i;</span><br /><span style="font-family: courier new;">17:00 <WanCW> for (i=0; i<size; ++i)</span><br /><span style="font-family: courier new;">17:00 <WanCW> pf(x);</span><br /><span style="font-family: courier new;">17:00 <WanCW> }</span><br /><span style="font-family: courier new;">17:00 <WanCW> _END_</span><br /><span style="font-family: courier new;">17:00 <WanCW> then:</span><br /><span style="font-family: courier new;">17:00 <WanCW> int anArray[] = {1, 2, 3};</span><br /><span style="font-family: courier new;">17:01 <WanCW> for_each (anArray, 3, f);</span><br /><span style="font-family: courier new;">17:02 <WanCW> =====</span><br /><span style="font-family: courier new;">17:02 <WanCW> Array.each in Ruby may be this way:</span><br /><span style="font-family: courier new;">17:03 <WanCW> def each(ary)</span><br /><span style="font-family: courier new;">17:03 <WanCW> == abort</span><br /><span style="font-family: courier new;">17:03 <WanCW> 看這個網頁</span><br /><span style="font-family: courier new;">17:03 <WanCW> http://www.ruby-doc.org/core/classes/Array.src/M000412.html</span><br /><span style="font-family: courier new;">17:03 <WanCW> rb_yield 那行就是呼叫 callback # 'yield' means call the block in Ruby language.</span><br /><span style="font-family: courier new;">17:04 <WanCW></span><br /><span style="font-family: courier new;">17:04 <WanCW> 不過,你為啥現在回去看 C ?</span><br /><span style="font-family: courier new;">17:05 <Adios> 想到callback 沒有懂所以要把它弄懂</span><br /><span style="font-family: courier new;">17:05 <WanCW> oh~</span><br /><span style="font-family: courier new;">17:05 <Adios> 以剛剛的C++ code蘭說的話 他可以直接把</span><br /><span style="font-family: courier new;">17:06 <Adios> for( i =0; i<size; ++i) pf(x);</span><br /><span style="font-family: courier new;">17:06 <Adios> 把pf(x) 直接call f 不就好了嗎</span><br /><span style="font-family: courier new;">17:07 <WanCW> 那是因為現在兩個部份是一起寫的,</span><br /><span style="font-family: courier new;">17:07 <WanCW> 如果你想寫個 linked-list library 提供 each 的功能呢?</span><br /><span style="font-family: courier new;">17:07 <WanCW> 那 pf 就是不確定的啦</span><br /><span style="font-family: courier new;">17:08 <WanCW> 等著 library user 決定</span><br /><span style="font-family: courier new;">17:08 <WanCW> 這時候就要用 call back.</span><br /><span style="font-family: courier new;">17:08 <WanCW> --</span><br /><span style="font-family: courier new;">17:08 <Adios> 所以就像是一個 interface</span><br /><span style="font-family: courier new;">17:08 <WanCW> 我會說是插座</span><br /><span style="font-family: courier new;">17:08 <WanCW> yeap, but say the same thing.</span><br /><span style="font-family: courier new;">17:08 <Adios> 好插座</span><br /><span style="font-family: courier new;">17:10 <WanCW> 嗯</span><br /><span style="font-family: courier new;">17:10 <Adios> 好我大概瞭了 #callback是什麼 為什麼要用callback~</span><br /><span style="font-family: courier new;">17:10 <WanCW> 恭喜</span><br /><span style="font-family: courier new;">17:10 <WanCW> Adios 習得 callback 技能.</span><br /><span style="font-family: courier new;">17:10 <Adios> 我po 在 tdiary?</span><br /><span style="font-family: courier new;">17:10 <WanCW> anywhere u like. :)</span><br /><span style="font-family: courier new;">17:10 <Adios> title: IRC Interview with WanCW</span><br /><span style="font-family: courier new;">17:11 <WanCW> # 你不想 po 板上, 怕被發現你不會 call back XD</span><br /><span style="font-family: courier new;">17:11 <WanCW> kidding</span><br /><span style="font-family: courier new;">17:11 <WanCW> 吃飯去, c u</span><br /><span style="font-family: courier new;">17:11 <Adios> 板上太難看 XD</span><br /><span style="font-family: courier new;">17:11 <WanCW> 哈哈~ XD</span><br /><span style="font-family: courier new;">17:11 <Adios> 我用courier打B阿會太長</span><br /></blockquote><br /></span>Anonymoushttp://www.blogger.com/profile/10009999989371791946noreply@blogger.com1