2017年1月15日 星期日

[Blog] 在 blog 中張貼程式碼

  • 原理:
    1. 以 HTML的 pre tag來實作, 如 HTML裡的 <img> 表示圖片、<h1>表示等級1的header等等, pre表示的是 pre-formatted text, 會以定寬字型以及保留空格與換行的方式來處理。
    2. 設計特別的 class 來指定這些程式碼, 如 Google 的 prettyprint
    3. 設計 CSS 來 highlight畫面
    4. 利用 javascript 來做是否為keyword等字的判斷, 來highlight特別的字 (每個語言都有自己的 keywords, 如: class、printf 等等, 這些 keywords因語言不同而不同, 所以應該也要有對不同語言提供不同 keywords highlight的功能)
  • 方法:
    1. 載入上面提到的 CSS (以blog-替程式碼上色提供的 sample為例)與 Javascript (以 Google Code Prettify 為例)
      1. 在 Blogger中, 新增 HTML/Javascript 小工具
      <style type='text/css'>
      .pre-highborder{
          border: 1px solid #ff0000;
          padding: 3px 3px 3px 0;
      }
      
      pre.prettyprint, code.prettyprint {
          border-radius: 8px;
          -moz-border-radius: 8px;
          -webkit-border-radius: 8px;
          padding: 5px;
          overflow: auto;
          background-color: #eee !important;
          color: black;
          box-shadow: 0 0 5px #999;
          -moz-box-shadow: 0 0 5px #999;
          -webkit-box-shadow: 0 0 5px #999;
      }
      
      /*font*/
      pre span, code span {
          font-family: 'Consolas', 'Courier New', 'Microsoft JhengHei', sans-serif !important;
          font-size: 12px !important;
      }
      
      /*each line*/
      li.L0, li.L1, li.L2, li.L3, li.L4, li.L5, li.L6, li.L7, li.L8, li.L9 {
          margin: 0 !important;
          padding: 2px 0 2px 4px !important;
          list-style-type:decimal !important;
          border-left: 1px solid #999;
      }
      
      /*even line*/
      li.L1, li.L3, li.L5, li.L7, li.L9 {
          background-color: #f6f6f6 !important;
      }
      
      /*odd line*/
      li.L0, li.L2, li.L4, li.L6, li.L8 {
          background-color: #FFF !important;
      }
      
      /*line-number background color*/
      ol.linenums {
          color: black;
          background-color: #eee;
          margin-left: 10px;
      }
      </style>
       
      <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js">
      </script>
    2. 在自己的程式碼中輸入程式碼區塊
      1. 指定為 pre block, 並指定 class 與特定 config (例如特別的語言: lang-*, support list, 或是顯示行號的 linenum)
        <pre class="prettyprint lang-cpp linenums">code snippet</pre>
      2. 需要注意的是, 這邊的 code snippet要經過處理, 也就是有經過 escape符號預處理, 簡單來說, 通常任何程式語言都會有 escape characters, 簡單就是用以告知 compiler/interpreter, 你就是要用該符號, 例如: printf的語法是 printf("what you want to print"), 但你就是要 print 引號 (")的時候怎麼辦咧? 就是加入 escape character (\), 而在 HTML則是輸入 &lt; &gt; 等等, 不過也有網頁服務直接幫你轉換 => HTMLEscape .net
    3. 另外, 也有很多類似的相關 js 可以套用, 如 SyntaxHighlighter

2017年1月14日 星期六

[Codec] Video Codec 參考書目

覺得不錯的參考書目:

  • H.264 and MPEG-4 Video Compression
    • 雖然年代有點久, 但內容滿適合入門以及了解相關知識,包含簡述codec 發展歷史codec 觀念 (Chapter Video Coding Concept - 包含 block diagram, e.g. DPCM/DCT video encoder/decoder架構)及 standard相關細節 (e.g. Chapter H.264/MPEG4 Part 10)
  • Video Demystified
    • 比較偏向訊號面來講解, e.g. 數位訊號(e.g. PAL, color space)、廣播制式(e.g. DVBC/ATSC)
  • Next Generation Video Coding and Streaming
    • 以 HEVC為主, 滿 spec. 導向, 另外在 container(e.g. mp4, ts), 以及 streaming 著墨較多
以上是目前覺得不錯的書目, 由於工作需要, 所以開始 K相關技術, 若有相關技術可以分享交流, 甚至一起來個讀書會. 都非常歡迎 feedback哦 

2014年11月25日 星期二

[Git] .gitignore

# Mac OS X
.DS_Store
profile

# XCode 
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
xcuserdata/
project.xcworkspace/

# Generated files
*.o
*.pyc
build/
DerivedData
*.hmap
*.ipa
*.moved-aside
.idea/
Pods

# Backup files
*.swp
*~
*.lock
*.out

# version control

*.xccheckout

2014年11月13日 星期四

[Computer Vision] Object Segmentation algorithms

2013年8月17日 星期六

[C++] 印 endl而非 '\n'


  • 問題: 
    • C++中, 平常印訊息用 cout << endl 好, 還是 cout "\n" 好?
  • 解法: 
    • 傾向使用 cout << endl, 原因是, IO的 buffer不會在程式 crash時自動清空 (flush), 也就是有可能一直在錯誤的地方 debug(在程式根本沒執行到的地方 debug, 因為誤以為印出的訊息是正確的), 但 endl中隱含了 flush buffer的動作, 因此可避免此一情形

2013年8月11日 星期日

[Qt] Qt Quick error in re-writing


  • 問題:
    • Qt 利用 Qt Design 設計 UI時, 有時在存檔時會遇到無法更新存檔, 甚至 Qt當掉的問題
    • Qt Quick application在 Build時出現 module QtQuick 1.1 not installed
  • 解法
    • 基本上就是沒有安裝 QtQuick 1.1, 在 main.qml裡頭又 import多個 QtQuick modules造成的, 請檢查 .qml檔的 import設定即可

2013年8月10日 星期六

[CMake] Install command line fail


  • 問題
    • 在安裝 CMake command line tools可能會發生 "Failed create symlink installation may be incomplete" 的錯誤
  • 原因
    • 主要原因是之前安裝過其他版本的 CMake而造成的衝突
  • 解法
    • 自行 link吧!
    • 在 /usr/bin中找到以下相關 binary
      • ccmake
      • cmake
      • cmake-gui
      • cmakexbuild
      • cpack
      • ctest
    • 刪除其 link, 並建立新的link
      • e.g.  sudo ln -s /Applications/CMake\ 2.8-11.app/Contents/bin/cmake /usr/bin/cmake

[Development] Memory leak check -Valgrind


  • 簡介
    • 相信寫 C, C++的人應該不陌生, 該 new空間沒 new, 或是使用完沒 delete, 都會造成 memory的問題, 而 Valgrind便是一套 tool可以幫忙做 memory check
  • 安裝
    • 目前一般 linux已內建, Mac可藉由 MacPort安裝 (sudo port install valgrind)
  • 使用

2013年8月9日 星期五

[Development] qmake


  • 簡介:
    • qmake為 qt提供的 make tool, 可產生不同平台所需的 Makefile
    • .pro 為其特殊的專案檔格式
    • 重要: Qt 專案 build的過程
  • 常用變數:
    • TEMPLATE
      • 可等於 app、lib、subdirs, e.g. TEMPLATE=app, 可用來產生不同的專案類型, 產生的是應用程式、函式庫或子目錄(遞迴式搜尋子資料夾), 預設值為 app
    • HEADERS
      • 設定相關 header files
    • SOURCES
      • 指定所要 build的 c++檔
    • FORMS
      • 指定 Qt Designer產生的 .ui檔, 會呼叫 Qt的工具程式 uic來處理
    • RESOURCES
      • 由程式 rcc來處理 .qrc檔
    • DEFINES
      • 可定義預處理器符號
    • INCLUDEPATH
      • 可指定 C++搜尋目錄, 以設定全域的標頭檔案
    • LIBS
      • 指定連結至專案的函式庫, 可使用絕對路徑或 Unix的 -L, -l flags
    • CONFIG
      • 可設定多種專案與編譯器組態
        • debug
        • release
        • warn_off: default是開啓
        • qt: 預設開啓
        • dll
        • staticlib
        • plugins: 相當於 dll
        • console: 這比較重要, 表示 output需要被寫到 console window, e.g. 使用 cout、cerr等, 對於拿來寫 console application來說, 需設定此項
        • app_bundle、lib_bundle: Mac OS X專用
    • QT
      • 設定所使用的 QT modules, 預設為 core gui (QtCore與 QtGui)
    • VERSION
    • TARGET
      • app 或 lib的名稱, 不包含 prefix, version等
    • DESTDIR
      • build後的目錄
    • DLLdESTDIR
  • 產生特定平台專案檔(假設 Qt專案檔為 hello.pro)
    • General
      • qmke hello.pro, 接著可以用 make or nmake去 build
    • MicroSoft Visual Studio專案檔
      • qmake -tp vc hello.pro
    • Mac OS X 
      • Xcode project
        • qmake -spec macx-xcode hello.pro
      • makefile
        • qmake -spec macx-g++ hello.pro
      • spec選項可以指定"平台-編譯器"的組合, 如上述 macx(平台)-xcode(編譯器)
  • 自動產生 .pro檔
    • qmake -project
      • 會搜尋當前目錄中的 .cpp, .h, .ui檔以產生 .pro
  • 註解: #
  • 相關運算子
    • +=, -=
      • CONFIG = qt
      • CONFIG += release
      • CONFIG -= warn_off
    • *=
      • 當該變數為空, 則 assign, 否則不做任何動作
      • SOURCES *= main.cpp
      • 上式等同於, 若 SOURCES沒指定任何檔案, 則指定為 main.cpp
    • ~=
      • 可替換任何值, 支援 sed語法
      • SOURCES ~= s/\.cpp\b/.cxx/
      • 上式代表將所有 .cpp的附檔名改為 .cxx
  • 存取變數
    • $$variable or $${variable}  -- 在 .pro檔中的值
    • $$(variable) -- 在 qmake執行環境中的環境變數值
    • $(variable) -- makefile 執行環境中的環境變數值
    • $$[variable] -- Qt組態選項值
  • 判斷式
    • 語法
      • condition{
        • then-case
      • }else{
        • else-case
      • }
    • 其中的 condiction可為平台名稱, e.g. win32, unix, or macx, 例如:
      • win32{
        • SOURCES += serial_win.cpp
      • }else{
        • SOURCES += serial_unix.cpp
      • }
    • 單行式
      • macx: SOURCES += serial_mac.cpp
  • project include
    • include(../common.pri)
  • 利用 CMake 產生 Qt應用程式

2013年8月3日 星期六

[C++] 慣用簡潔的 pointer算式

int *p, *q分別指向 source array與 destination array, 若要 copy, 可用 *q++=*p++;

如此直接完成了三個動作:
*q=*p;
q++;
p++;