2014-12-30

BPG 圖片格式

採H.265基礎的圖片壓縮新技術BPG,大幅提高低流量畫質
BPG 是由 FFmpeg、QEMU 的作者 Fabrice Bellard 開發的新圖片格式,使用 HEVC (H.265) 的壓縮技術,可比 JPEG 提供更有效率的影像壓縮,特點為:
  • 壓縮率高,相似的品質下,檔案可壓得比 JPEG 小
  • 瀏覽器可利用一個 Javascript decoder 來支援(gzip 壓縮後只有 56KB)
  • 以開放的視訊壓縮標準 HEVC 的 subset 為基礎 (是以 HEVC 的 Still Image Profile 為基礎,故支援 HEVC 的硬體亦可支援 BPG,但 BPG 的 header 與 HEVC 不同,有一些簡化)
  • 支援跟 JPEG 相同的色彩格式(灰階、YCbCr 4:2:0, 4:2:2, 4:4:4),這可在轉換時降低損失。支援 alpha channel。亦支援 RGB, YCgCo 與 CMYK 色彩空間。
  • 原生支援 8~14 bits/per channel,可有較佳的動態範圍 (一般圖片多是 8bits/per channel)
  • 支援無損壓縮
  • 支援各種格式的 metadata,如 EXIF、ICC Profile、XMP

有興趣的可去官方網站,有一些 demo 的鏈結可看

BPG Image Format

BPG Decoding Library 使用一個以 LPGL 2.1 釋出的 FFmpeg 特別修改版作為 HEVC decoder,排除 ffmpeg code 的其他部分,以 BSD 釋出。

BPG Encoder 是以 BSD 釋出。可選用使用 BSD 授權的 JCTVC HEVC reference encoder 或 GPL 授權的 x265 。

HEVC 演算法的某些部分,在某些國家可能有專利保護,LWN.net 的作者認為, BPG 之於 HEVC 令人想起 WebP 與 WebM 的關係,再加上專利問題,難以取代 JPEG 成為主流。

相關網址:


2010-03-12

解決按 Ctrl + Alt + Backspace 無法離開 X Window 的問題


不知從什麼時候開始,我的 debian testing 就已經無法用傳統的 Ctrl+Alt+Backspace 離開 X Window 了,今天 google 了一下,發現似乎 Ubuntu 9.10 也是如此,據說是有人覺得會誤按,所以把它改成預設不啟用了。



Howto Enable Ctrl + Alt + BackSpace in Ubuntu Jaunty 這篇文章說只要在 /etc/X11/xorg.conf 加入 DontZap 的設定就可以重新啟用這組快捷鍵



 Section "ServerFlags"

    # DontZap on for disabling Ctrl+Alt+Backspace killing X

    # DontZap off for enabling Ctrl+Alt+Backspace killing X

    Option "DontZap" "off"

EndSection


不過我在 Debian 上測試無效。



又 google 到 How to enable/disable Ctrl+Alt+Backspace in Ubuntu 9.10 (Karmic) 可在 hal 的設定中修改:



先找到下面的檔案:



/usr/share/hal/fdi/policy/10osvendor/10-x11-input.fdi (inside the
<match key=”info.capabilities” contains=”input.keys”> section):


再修改設定:



<merge key="input.xkb.options" type="string">terminate:ctrl_alt_bksp</merge>


不過 Debian testing (Squeeze) 找不到這個設定



於是只好靠指令



setxkbmap -option terminate:ctrl_alt_bksp


成功了。但是,難道要把它加到 ~/.xinitrc 這麼暴力?再找找看。



後來找到 #bug567808



在 /etc/default/keyboard 中



XKBOPTIONS="terminate:ctrl_alt_bksp" 


YES!解決了。



不記下來肯定等一下就忘記。 :D

2010-03-08

解決 mplayer 雙螢幕播放時外接螢幕無法顯示的問題

使用雙螢幕(顯示同樣內容)時,在預設狀態下,若使用 xv 輸出,mplayer 在外接螢幕上只會出現黑色區塊,要讓影片可以同時在兩個螢幕上顯示,要在 -vo xv 加上一個選項 adaptor=1 才可。

$ mplayer -vo xv:adaptor=1 video.flv

要知道 adaptor 設多少,可用 xvinfo 看,xvinfo 在 Debian 中是包在 x11-utils 中。

我的電腦中,0 代表 Adaptor #0: "ATI Radeon Video Overlay",1 代表 Adaptor #1: "Radeon Textured Video"。如果用 0 播放,就像原本的情況,如果用 1 播放,就正常。

延伸閱讀:

在 Linux 上安裝 flashplugin for firefox 與簡單測試記錄

由於 Linux 上 firefox 在用的 flashplugin (flashplayer-mozilla 10.0.42) 效能太差,今天看到 flashplayer 10.1beta3 釋出的消息,就衝了。


Adobe Labs 下載給 Linux 用的 tarball。


$ tar zxvf flashplayer10_1_p3_linux_022310.tar.gz


什麼?竟然只有 libflashplayer.so 一個檔案!只好手動安裝。


$ sudo mkdir -p /usr/local/lib/mozilla/flashplayer-10.1b3-mozilla


$ cp ./libflashplayer.so /usr/local/lib/flashplayer-10.1b3-mozilla/


$ sudo chmod 644 /usr/local/lib/flashplayer-10.1b3-mozilla/libflashplayer.so


$ sudo update-alternatives --install /usr/lib/mozilla/plugins/flash-mozilla.so flash-mozilla.so /usr/local/lib/flashplayer-10.1.b3-mozilla/libflashplayer.so 60


這邊稍微解說一下。Debian 的 /etc/alternatives 裡頭是一堆 links,這些 links 可能是某種類型的程式,或者有許多衍生版本的程式,比如說:x-window-manager、x-terminal-emulator、x-www-browser 就是前者,vim、awk 是後者。用 ls -l 去看,可以發現它們指向真正的程式所在。聰明的人可能已經猜到了,沒錯, 這是 Debian 管理同類型程式的一個系統,例如:當系統要呼叫終端機時,到底要呼叫 mlterm 還是 lilyterm?寫系統 script 的人怎麼知道使用者習慣用那一種 terminal 呢?在 Debian,只要寫 x-terminal-emulator 就可以了,我們可以用 update-alternatives 指定 x-terminal-emulator 會指向那一個程式。


所以上面的命令的意思,就是:iceweasel 需要 flashplugin 時,會讀取 /usr/lib/mozilla/plugins/flash-mozilla.so ,這個 link 會指向 /etc/alternatives/flash-mozilla.so,這個 flash-mozilla.so 要指向先前拷貝好的 /usr/local/lib/flashplayer-10.1.b3-mozilla/libflashplayer.so ,並指定優先權為 60。我的系統中另外還有 flashplayer 10.0.42 與 gnash 0.8.6,但因 10.0.42 與 gnash 預設的優先權只有 10,所以系統以後就會以這邊安裝的 10.1.b3 作為 flash-mozilla.so 的預設。


以後如果要改用其他的 flashplayer,可用下面指令來切換:


$ sudo update-alternatives --config flash-mozilla.so


如果要移除


$ sudo update-alternatives --remove flash-mozilla /usr/local/lib/flashplayer-10.1.b3-mozilla/libflashplayer.so


好,安裝完成,然後測試看那個 flashplayer 好用吧!


我的測試很簡略,模擬平常使用的方式,開啟 65 個之前在逛的網頁,加上 蕭邦冬風練習曲


測試環境:Pentium M 1.86 GHz + 1G Ram + Iceweasel 3.5.6 + Debian Squeeze


開啟瀏覽器後,等待頁面完全 loading 後,CPU Usage 穩定下來,約十幾,最多有時跳到二十幾。聽完一遍 蕭邦冬風練習曲後,再放一遍,第二次才用 top 監看 CPU usage (為了去除網路不穩的因素)


播完後,把前後的 CPU usage 去掉,然後平均


flashplayer 10.0.42 的平均 CPU 使用率是 59.7


flashplayer 10.1.beta3 是 49.6


gnash 0.8.6 是 58.6


結論: flashplayer 10.1.beta 3 的 CPU 使用效率稍有改善。(雖然 CPU 使用率還是高得我想!@#$@…)

2010-01-23

imagemagick 文字轉圖片

imagemagick 中的 convert 可以把字型顯示在圖檔中

$convert [-display X-SERVER] {[-family FAMILY_NAME]|[-font FONT_PATH]} [-pointsize POINT_SIZE] label:STRING FILE_NAME

  • -display X-SERVER 向這裡指定的 X-SERVER 要求字型或圖片
  • -family FAMILY_NAME 使用指定的 font family 顯示文字
  • -font FONT_PATH 使用指定的 font 顯示文字 (name 是字型的路徑)
  • -pointsize POINT_SIZE 指定字型尺寸
  • -stretch STRETCH 指定字型的 stretch (Any,Condensed,Expanded,ExtraCondensed, ExtraExpanded,Normal...)
  • -style STYLE 指定字型的 style (Any,Italic,Normal,Oblique)
  • label:STRING STRING 代表圖檔內要顯示的文字
  • FILE_NAME 圖檔名稱

顯示系統安裝的字型清單

$ convert -list font
如果是 IM 6.3.5-7 之前,顯示字型清單要用
$ convert -list type

顯示支援的 font style

$ convert -list style

顯示支援的 font stretch

$ convert -list stretch

如果要顯示的字數較多,可在 label 指定要顯示的文字檔

$ convert -family Arial -pointsize 24 label:@font-test.txt font-test-arial.png

不曉得是我不會用,還是 imagemagick 有 bug,到目前為止,指定 -family 一直無法成功,但用 -font 指定字型路徑就沒問題。而指定了 -font 好像也就不要 -stretch 或 -style 了。

例:用 cwyen 顯示

旭日東昇,但依舊寒風刺骨
雪地上的屍體
見證著平民之女與甘願放棄優渥生活的阿乙之間
炙熱的愛
直到永遠

先將這段文字在目前所在的資料夾中存成文字檔 font-test-cht.txt
$ convert -font /usr/local/share/fonts/truetype/cwyen.ttf -pointsize 32 label:@font-test-cht.txt font-test-cht.png

$ display font-test-cht.png

如果要讓圖片更花俏,可:

加上色彩

-background BACKGROUND_COLOR
-fill FOREGROUND_COLOR
-list color (查詢內建的色彩關鍵字)

指定 size

-size WidthxHeight

在指定位置加上文字

-annotate +X+Y 'text'

字的輪廓加上外框 (加在 font 後面)

-stroke STROKE_COLOR
-strokewidth STROKE_WIDTH (不必指定單位,單位好像固定是 px ?)

圖片邊緣改為斜邊並加上光影

-raise WxH 左、上邊框亮,右、下邊框暗,W 是左、右邊框的寬度,H 是上、下邊框寬度
+raise WxH 左、上邊框暗,右、下邊框亮


其他花俏的東西以後有空再研究



參考資料

man convert
ImageMagick v6 Examples -- Text to Image Handling

Google Chrome 4 字型描繪尚待解決的幾個問題

最重大的當然就是 - 不理會 fontconfig 的設定,下面幾個 issues 可能是同一問題

  • Issue 18159: Chrome doesn't honor fontconfig settings

  • Issue 12179: System font hinting settings are not obeyed

  • Issue 29871: Chrome font rendering seems fuzzy compared to Firefox (on Linux)(這個 bug 有附比較多圖,其實,有些人家回報 chrome 太模糊的我反而覺得比較好看)

  • Issue 29817: font rendering
  • Issue 26206: Chrome doesn't respect fontconfig's hinting flags

另外,Chrome 對於字型 kerning 的解讀還需要加強 (相當有趣的發現!)

  • Issue 21207: Font rendering issue: kerning doesn't match Firefox

還有偽粗體的問題 (直接看 Issue 中的圖比較清楚)

  • Issue 22360: synthesized bold (fake bold) glyphs get horribly blurred when native bold is not availble

2010-01-11

限制 CPU 使用率的工具 - cpulimit

CPULIMIT



cpulimit 可限制指定程式的 CPU 使用率


在 Debian 中的安裝方式



# aptitude install cpulimit

語法簡介



$ sudo cpulimit [-e EXECUTABLE|-p PID|-P ABSOLUTE_PATH_TO_EXECUTABLE] [-l LIMIT]


  • 目標程式可用三種方式指定,用 -e 指定執行檔的名稱,用 -p 指定 PID,或 -P 指定絕對路徑

  • CPU 使用率的限制,用 -l 指定,-l 後面直接輸入整數即可,代表百分率


例子



限制 PID 為 10796 的 process CPU 使用率為 50%



$ sudo cpulimit -p 10796 -l 50
Process 10796 detected


限制 firefox 的 CPU 使用率為 50%



$ sudo cpulimit -e firefox-bin -l 50
Warning: no target process found. Waiting for it..


奇怪,抓不到?



$ ls -l /usr/lib/iceweasel/firefox-bin
lrwxrwxrwx 1 root root 31 2009-12-01 03:00 /usr/lib/iceweasel/firefox-bin -> ../xulrunner-1.9/xulrunner-stub


$ sudo cpulimit -e xulrunner-stub -l 50
Process 10796 detected


這次抓到了。所以,cpulimit 對 softlink 無效,必需找出 softlink 的 target。


參考資訊:


How To Limit CPU Usage Of A Process With cpulimit (Debian/Ubuntu)