2009年11月18日 星期三

IT project 3

Online Banking System = =...

沒想到少考慮到 joint 的部分,

結果竟然要大改,不如全部重寫 = =

到現在只弄完基本架構及 OpenAccount 跟 CloseAccount,

還有八個method要趕... 不過先把時間撥給專題吧= =a

話說明天SE的循序圖跟活動圖沒做    掰

2009年11月16日 星期一

Ubuntu 9.10 Release!!

Ubuntu 9.10 is so fast that set up done in 25 seconds in my laptop.

And the theme's good to look.

We can use:

1. Octave to run Matlab codes

2. Skype

3. Amarok for music( or Rythmbox for dynamic rolling lyrics )

4. Totem for videos and also PPS

5. BBS by PCMANX

6. IE for linux in Lazyscript( or firefox, opera )

7. KTorrent for P2P

8. aMSN, KMess, emesene, ... for MSN

9. OpenOffice for word, excel, powerpoint

10. Adobe reader for pdf files

11. Real Player 11 for .rm .rmvb

12. GPaint or GIMP for Paint

13. Mozilla FTP

14. Eclipse or codeblocks for compile java and C/C++ file respectively

Except playing games, why we need windows? XDDDDDDDDDDDDD"

2009年10月7日 星期三

Java 安裝與環境設置

至 Java 官方網站下載 JDK 環境來安裝

選擇單純的

Java SE Development Kit (JDK)
JDK 6 Update 16
This special release provides a few key fixes.

來安裝即可,記得要先把舊版的 Java 都先移除乾淨。

接著再按照此網站來設定環境變數,便可在命令提示字元作編譯跟執行的動作。

以下是 TCP Socket 的 Java code... 其中 127.0.0.1 為本機位址,1234是隨便開的 port number

程式會將 Clinet 送過去的字串轉成大寫送回。

// Server端

import java.lang.*;
import java.io.*;
import java.net.*;

class Socket_Server
{
   public static void main(String args[]) throws Exception
   {
    String clientSentence; 
    String capitalizedSentence; 
    ServerSocket welcomeSocket = new ServerSocket(1234); 
    while(true)
    { 
     Socket connectionSocket = welcomeSocket.accept(); 
     BufferedReader inFromClient = new BufferedReader
         (new InputStreamReader(connectionSocket.getInputStream())); 
     DataOutputStream outToClient = new DataOutputStream
         (connectionSocket.getOutputStream()); 
     clientSentence = inFromClient.readLine(); 
     System.out.println("1234: " + clientSentence ); 
     capitalizedSentence = clientSentence.toUpperCase() + '\n'; 
     outToClient.writeBytes(capitalizedSentence); 
    }
   }
}

// Client端

import java.lang.*;
import java.io.*;
import java.net.*;

class Socket_Client
{
   public static void main(String args[]) throws Exception
   {
    String sentence;
    String modifiedSentence; 
    BufferedReader inFromUser = new BufferedReader
        (new InputStreamReader(System.in)); 
    Socket clientSocket = new Socket("127.0.0.1", 1234); 
    DataOutputStream outToServer = new DataOutputStream
      (clientSocket.getOutputStream()); 
    BufferedReader inFromServer = new BufferedReader
      (new InputStreamReader(clientSocket.getInputStream())); 
    sentence = inFromUser.readLine(); 
    outToServer.writeBytes(sentence + '\n'); 
    modifiedSentence = inFromServer.readLine(); 
    System.out.println("FROM SERVER: " + modifiedSentence); 
    clientSocket.close(); 
   }
}

2009年9月17日 星期四

修改開機選單

若是XP系統則可針對boot.ini檔案做修改

若是Vista則是在"控制台→系統管理工具→系統設定→開機"的地方選擇

也可以調整等待時間,

若是想重置開機選單則可在選擇登入OS的時候在Vista的選項按F8

接著進入"修復電腦→下一步→系統修復選項→命令提示字元"

輸入Bootrec.exe按下Enter

接著打入以下指令:

bcdedit /export C:\BCD_Backup
c:
cd boot
attrib bcd -s -h -r
ren c:\boot\bcd bcd.old
bootrec /RebuildBcd

就可以重製開機選單了,不過是英文介面。

以上是微軟公布的相關辦法

連結:

如何在 Windows 修復環境內使用 Bootrec.exe 工具,來疑難排解及修復 Windows Vista 中的啟動問題

2009年9月9日 星期三

Opera 在背景開新分頁

除了使用滑鼠中鍵之外,

在Opera網址列輸入 Opera:config

會進入"功能設定編輯器"

使用搜尋查到 "Open New Window in Background" 這項

打勾之後儲存便可以使新分頁都開啟在背景了~

Linkin Park - "New Divide"

2009年8月28日 星期五

2009年8月26日 星期三

Opera 10.0 Release Candidate

據說速度加速了40%

實際上與9.64版的比較感覺真的快超多 XD

而且會將上次瀏覽的網頁與現在新開的頁面做區隔!

多國語言版下載

以下是更動部分↓

Changelog:

User Interface:
New application icon(感覺以前的比較好看)
Fixed the new tab button on the sides(ctrl+tab間隔變大了,比較清楚)
Various small Visual Tabs fixes(以下我都不知道是殺毀= =")
Fixed a BitTorrent crash
Fix to jumping up/down of the new tab button while on the sides
Fixed Bug DSK-195906 (Opera error page selects URL field when displayed, also when focus is already inside URL field)
Fixed Bug DSK-257578 ("..." in site titles in some cases overlap the close button)
Fixed Bug DSK-258585 (Can't remove menu button when main menu is disabled): The menu button can be removed as any other toolbar button now (upgraders may have to reset the toolbar first)
Fixed Bug DSK-261205 (Strings don't fit in Preferences > Downloads [pl])
Fixed Bug DSK-261206 (Strings don't fit in Preferences > Programs [pl])
Fixed Bug DSK-261757 (Missing "splitter" in bookmark split view)
Fixed Bug DSK-261933 (Text cut off in startup dialog (Polish translation))
Fixed Bug DSK-261962 ("Reset Toolbar to Its Default" resets all toolbars, not just the current)
Fixed Bug DSK-262181 (Empty [dropdown widget] section added to custom shortcuts by update)
Fixed Bug DSK-262283 (Skin.ini section inconsistencies)

Core
Various crash fixes
Fixed Bug CORE-19376 (Crash navigating history)
Fixed Bug CORE-23125 (Adding IFRAME with javascript: src through DOM adds history entry (Yandex))

Opera Mail:
Fixed a crash
Fixed Bug DSK-245600 (Mail imported into account with no downloading of message bodies loses bodies)
Fixed Bug DSK-261035 (Crash when opening image attachments)
Fixed Bug DSK-261459 (Go to Unread View when requested, don't reuse a maximized mail view)

Windows
Crash Fix
Reverted Fix to Bug DSK-241262 (Error message when opening HTML files if Opera is not already running): This caused DSK-262363
Fixed Bug DSK-259756 (Installer removes icon pinned to the Windows 7 task bar)
Fixed Bug DSK-260498 (The list of closed tabs needs clicks to be shown)
Fixed Bug DSK-262363 (Other programs using the http protocol to open websites in Opera just open blank page in Windows Vista and Windows 7)
Fixed Bug DSK-259743 (Closed tabs and new tab buttons have non-native looks in native skin)
Fixed Bug DSK-262120 (Panel selector buttons in Native skin get Standard style when not on the left)
Fixed Bug DSK-262272 (Closed tabs and new tab positioned incorrectly when tabbar is placed on left or right side)

Mac
Fixed Bug DSK-261726 (Closed Tabs button overlaps tabs when set to right or left and new tab button is disabled)

Unix
Fixed Bug DSK-259575 (Dead keys don't seem to work on widgets)
Fixed Bug DSK-250495 (Spell checking not working for some UNIX users)

2009年8月22日 星期六

10000 - Longest Paths

Time limit: 3.000 seconds
                                      Longest Paths
It is a well known fact that some people do not have their social abilities completely enabled. One example is the lack of talent for calculating distances and intervals of time. This causes some people to always choose the longest way to go from one place to another, with the consequence that they are late to whatever appointments they have, including weddings and programming contests. This can be highly annoying for their friends.
César has this kind of problem. When he has to go from one point to another he realizes that he has to visit many people, and thus always chooses the longest path. One of César's friends, Felipe, has understood the nature of the problem. Felipe thinks that with the help of a computer he might be able to calculate the time that César is going to need to arrive to his destination. That way he could spend his time in something more enjoyable than waiting for César.

Your goal is to help Felipe developing a program that computes the length of the longest path that can be constructed in a given graph from a given starting point (César's residence). You can assume that the graph has no cycles (there is no path from any node to itself), so César will reach his destination in a finite time. In the same line of reasoning, nodes are not considered directly connected to themselves.
Input
The input consists of a number of cases. The first line on each case contains a positive number n ( ) that specifies the number of points that César might visit (i.e., the number of nodes in the graph).
A value of n = 0 indicates the end of the input.

After this, a second number s is provided, indicating the starting point in César's journey ( ). Then, you are given a list of pairs of places p and q, one pair per line, with the places on each line separated by white-space. The pair `` " indicates that César can visit q after p.
A pair of zeros (``0 0") indicates the end of the case.

As mentioned before, you can assume that the graphs provided will not be cyclic.
Output
For each test case you have to find the length of the longest path that begins at the starting place. You also have to print the number of the final place of such longest path. If there are several paths of maximum length, print the final place with smallest number.

Print a new line after each test case.

Sample Input
2
1
1 2
0 0
5
3
1 2
3 5
3 1
2 4
4 5
0 0
5
5
5 1
5 2
5 3
5 4
4 1
4 2
0 0
0

Sample Output
Case 1: The longest path from 1 has length 1, finishing at 2.

Case 2: The longest path from 3 has length 4, finishing at 5.

Case 3: The longest path from 5 has length 2, finishing at 1.

=====================================================

#include <stdio.h>
#include <stdlib.h>

// function prototype
void DFS(int data_num, int from, int step);

// data structure
struct FromTo
{
 int p;
 int q;
};

struct FromTo FromTo[100];
int longest_path;
int finish_point;

int main()
{
 freopen("Input.txt", "r", stdin);
 freopen("Output.txt", "w", stdout);
   
 int start_point;
 int point_num;
 int p, q;
 int case_num = 1;
   
 while(1)
 {  
  int data_num = 0;
  scanf("%d", &point_num);
  if(!point_num)
   break;
  for(int i=0; i<100; i++)
   FromTo[i].p = FromTo[i].q = -1;
  scanf("%d", &start_point);
  for(int i=0; scanf("%d %d", &p, &q) == 2; i++)
  {
   if(!p && !q)
    break;
   FromTo[i].p = p;
   FromTo[i].q = q;
   data_num++;
  }
  longest_path = 0;
  DFS(data_num, start_point, 0);
   
  printf("Case %d: The longest path from %d has length %d, finishing at %d.\n\n",
      case_num++, start_point, longest_path, finish_point);
 }
   
 return 0;
}

void DFS(int data_num, int from, int step)
{
 for(int i=0; i<data_num; i++)
  if(FromTo[i].p == from)
  {
   if(++step > longest_path)
   {
    longest_path = step;
    finish_point = FromTo[i].q;
   }
   DFS(data_num, FromTo[i].q, step);
   --step;
  }
}

2009年7月31日 星期五

Meeting @ VPON

昨天去了新眾電腦股份有限公司
因為產學計畫所以要跟他們報告目前做了什麼
沒想到對方對這個很有興趣 XD" 大概剛好搭上潮流的順風車吧
不過也要努力開始做了 雖然能找到的論文好少 = =
好不容易看了一篇到最後又是似是而非 又是一篇地雷論文
硬著頭皮看第二篇... gogo QQ

開會的過程還好蠻輕鬆的
並沒有想像中的嚴肅
也真的體會到學界跟業界的差距
有些要求他們講的很簡單
我們要做出來卻有一定難度
不過也不好意思說甚麼 XD"
在一旁跟學長聊天偷笑 呵呵
不好意思最後是冠宇學長幫忙簽約
好像把你賣掉一樣 哈哈哈 XDDDDDDDDDDDD" 為了你要認真做!!

超狠的老爸XDDDDDDDDDDDDD

2009年7月18日 星期六

爆破狂:電話簿摩擦力



原來最大靜摩擦力可以這麼強 = =.... 太扯了

佩服那個實驗室的人 XD" 租來戰車耶!!

兩本書可以產生8000磅的作用力 媽呀 = =.....不可思議

人材再留失!! 體委會無能?! 17歲桌球冠軍遭挖角



本來很看好陳建安的說
去年三峽鎮長盃有看到他比賽XD 整個超猛的阿
積分260x排名第二名與第一名僅差了幾十分,可惜了
台灣真的很不重視運動員(怒ˋ ˊ )

2009年7月16日 星期四

牛寶@三峽

一家新開的牛肉麵館,位於北大正門直走一段的右手處,
半筋半肉很好吃,不過刀切面有點硬,細麵下次再試試看,
湯頭也不錯,缺點就是出餐速度太慢,還頻頻送錯,
也有漏煮的錯誤,昨天去吃還有一個死小孩一直吵,
人少的時候可去吃,有無限紅茶。評價中。

Ps. 隔壁要開麻辣燙,期待ing

雙打積分賽@淡水新興國小

第一次參加積分賽,雖然是雙打且不會算上積分,
卻是難忘的經驗阿,早上7:30就在北車淡水線集合,

可惡阿幹竟然差點遲到,還好最後有趕上比賽,雖然沒有暖身就上場了,
不過幸好對手都不強,還連贏兩組,雖然我們也打得很爛 = =

連贏兩組之後就連輸兩組了,輸給怪老伯伯的組合,
日直反面長顆不加海綿,打起來真是討厭 = = 而且老伯伯發球都不太拋球的啦
也不等對方準備好就直接發球,不喜歡 =3=

最後輸給兩個國小女生吧,不知道要怎麼打他們,不過大概也是最後一場沒力的關係吧,
也沒甚麼在攻擊就輸光光了XD" 還剛好被趕來的Angie看到 =..=

值得一提是離開前贏了彭大帥=.=+ 從2:0逆轉到2:3贏
打最開心的就這一場了吧 XD" 推 YE7 是好拍,打起來比70g的舊拍穩超多

打完之後吃了淡水阿給,覺得醬汁好鹹,不喜歡,不過感謝彭大帥的烤魷魚,
超美味的XD" 除了第一口會被粉嗆到之外 哈哈

總的來說是還不錯的經驗,期待下次單打的積分賽XD"...我應該有1400吧 哈哈
北大積分團GOGO~~~

Opera - 一款好用的瀏覽器

推薦一款好用的瀏覽器 Opera
雖然FireFox好用卻越包越多,大小越來越肥胖,
相較之下Opera速度依舊第一且體積更輕薄,
且有幾項方便的功能!

1. 可在網址列輸入 "g 關鍵字" 就會以google來搜尋關鍵字,
若是輸入 "y 關鍵字" 則會以yahoo來搜尋,
且搜尋引擎是可以自己設定的!!

2. 新增分頁那邊不會是空白頁,而是快速撥號頁,
如下圖,有九個快速頁面可以點選,
不需要在打網址而直接可連上最常使用的網頁!!












3. 下載檔案的視窗是單獨一個分頁,
不像是火狐還會跳一個小視窗出來很占位置。












如果google chrome分頁不是開process使電腦效能耗很大,
且論壇以及一些網站排版能正常顯示的話,
也不失為一款好的瀏覽器。速度也是很快的。

不過在google chrome改善以前還是首推Opera或是火狐:D

2009年7月12日 星期日

2009年6月18日 星期四

慌張的期末

事情突然多了出來 = =
好多範圍要考
好多project要交

還好 = = 經過一段不分日夜的時間
反正一忙也不會記得哪天是哪天
昨天阿通回信說收到類神經作業了 XD
也算是了卻一樁心事,動態宣告物件真是太優了 = =+
雖然index的公式腦殘寫了半死,物件函式的動態宣告也著實費了一番功夫,
不過也學到了很多東西,暑假想來練習VC的視窗程式,
畢竟 BCB 仍然沒有VC大宗阿

現在只剩下DB要考 = = 大概GG了吧,還有最後大魔王
Compiler 專案要交,可是感覺自己會寫不出來啊 ~~~ T^T

2009年6月16日 星期二

2009年6月3日 星期三

賣二手膠皮

目前的底板是 Andro Super Core System Carbon Light Off+

中文好像叫做超輕碳王吧 =ˇ=... 當初買70g 真是超輕

不過最近似乎有60g的削球板(被超越了XD")

屬於硬板,我覺得震手感蠻重的,手感蠻難抓的,不過削球加旋真的很方便,

台內小球也很靈活XD" 輕版的好處之一吧

不過拉loop或是speedo感覺持球沒什麼手感,攢點錢暑假可能買支 Yasaka Extra 7 來玩玩

======================以上是廣告文======================

目前玩過了蠻多張膠皮的,有些沒用到的想賣二手 =ˇ= 有興趣的可以聯絡我

Andro Revolution 紅色 2.1mm:

一張很硬的皮,配上碳板殺起球來聲音超清脆響亮 = = 而且速度很快,
不過當初基本攻不好,用這張皮弧圈拉不起來,故只玩了一個禮拜就被我拔下來了,
算目前手中最新的皮吧。

BTY Sriver FX 黑色 2.1mm:

剛買拍子的時候所配的皮,練手感用的,後來就換掉了,
沒甚麼特別的印象,比Sriver軟,FX型號應該是蝴蝶家族中最軟的那種,
也是唯一用過的日本皮,適合初學者用(?)。

Donic Quattro Formula 黑色 2.0mm:

超軟的皮,又Q又軟,跟果凍一樣(= =?),軟的很噁心= =,
純木板請勿嚐試,加上又只有2.0,非常容易透板,放反手推擋很爽,
只有拍面有僑好,馬上啪一下就彈回去,但是可以做的變化就相對少,
不過發切跟玩削球很讚,MAX比較優,控制較容易,但是紅色那張被我打爛了 = =b
這張因為反手想練弧圈所以拔下來。

Andro Plasma 380 紅色 Max:

38度德國皮,軟硬度算是中下吧,不過由於是MAX,所以這張皮不上不下 = =
不知道該怎麼說,就430或是470的可能比較優吧 = = 這張皮打起來很尷尬。

Ps. a. 價格可議
b. 推 Andro Roxon 系列,目前德系中top好皮之一。

2009年5月22日 星期五

菁英盃

有些許慌張,或許是因為感冒了

扁桃腺又發炎了,吃藥的關係

最近幾次練球都打沒多久就沒力了

腳步都跟不上,攻擊位置都沒到當然也都失誤

後天的比賽遇到不錯的強敵,希望能以百分百的狀態上場

最近要養足精神,要調整心態,我需要自信!

I need to trust myself.

2009年5月18日 星期一

手桌球

去年某天晚上12點無聊 = =

竟然就拍成這個影片

放上來當分享 =ˇ= 在此感謝葉子無私的貢獻!!

2009年4月18日 星期六

Charlie The Unicorn with chinese subtitles







目前有這三集有中文字幕,都沒有甚麼特別的點 = =...

可是看了就想笑 Orz..... 尤其是香蕉王 嘴角失守....

第一集的梗是 Candy(糖果) 跟 Kidney(腎臟) 發音很像...

2009年3月25日 星期三

矩陣相乘

兩個二為矩陣的相乘,矩陣元素為浮點數,
Input 為 M1.txt M2.txt
Ouput 為 Output.txt
文字檔格式為
row
column
elements
例如2x3的矩陣:
2
3
1 2 3
4 5 6
=====結構與函式定義=====
// Matrix Structure
typedef struct MATRIX
{
 int row;
 int column;
 float **data;
}MAT;

// M3 = M1 * M2
MAT M1, M2, M3;

void Init(MAT &mat);
void Multiply(const MAT mat1, const MAT mat2, MAT &mat3);
void Clear();

=====Main.cpp=====
#include "matrix.h"
#include <stdio.h>

#define FtoI // Float to Integer

int main(int argc, char **argv)
{
 freopen("M1.txt","r",stdin);
 scanf("%d", &M1.row);
 scanf("%d", &M1.column);
 Init(M1);

 freopen("M2.txt","r",stdin);
 scanf("%d", &M2.row);
 scanf("%d", &M2.column);
 Init(M2);

 freopen("Output.txt","w",stdout);
 Multiply(M1, M2, M3);

 Clear();

 return 0;
}

// Allocate memory space to matrix structure
void Init(MAT &mat)
{
 mat.data = new float*[mat.row];

 for(int i=0; i<mat.row; i++)
  mat.data[i] = new float[mat.column];

 for(int i=0;i<mat.row;i++)
  for(int j=0;j<mat.column;j++)
  {
   float temp;
   scanf("%f", &temp);
   mat.data[i][j] = temp;
  }
}

// M3 = M1 * M2
void Multiply(const MAT mat1, const MAT mat2, MAT &mat3)
{
 if(mat1.column == mat2.row)
 {
  mat3.row = mat1.row;
  mat3.column = mat2.column;
  mat3.data = new float*[mat3.row];
  for(int i=0; i<mat3.row; i++)
   mat3.data[i] = new float[mat3.column];

  // Multiply
  for(int k=0; k<mat2.column; k++)
   for(int i=0; i<mat1.row; i++)
   {
    mat3.data[i][k] = 0;  // Set M3 to zero
    for(int j=0; j<mat2.row; j++)
     mat3.data[i][k] += mat1.data[i][j] * mat2.data[j][k];
   }

  printf("%d\n%d\n", mat3.row, mat3.column);
  for(int i=0;i<mat3.row;i++)
  {
   for(int j=0;j<mat3.column;j++)
#ifdef FtoI
    printf("%d\t", (int)mat3.data[i][j]);
#else
    printf("%f\t", mat3.data[i][j]);
#endif
   printf("\n");
  }
 }
 else
  printf("Dimentions error.\n");
}

// Release the memory space
void Clear()
{
 delete M1.data;
 delete M2.data;
 delete M3.data;
}

2009年3月15日 星期日

九年國教之上課塗鴉篇

http://www.wretch.cc/blog/b771018/13339407

只能說,台灣的未來 XD?

2009年3月1日 星期日

2009年2月24日 星期二

Lost In Translation

YouTube 配樂連結

實在是很平靜很耐聽又有味道的一首歌

加上女主角又很美

感覺 很棒

有機會來看看這部片好了 ( 愛情,不用翻譯 )

應該是不錯,是Scarlett Johansson早期所拍的電影

電影簡介

2009年2月23日 星期一

洋蔥頭腦殘檢定

看笨版意外看到的測驗 =ˇ=.... 檢測自己的腦殘程度!!

洋蔥頭腦殘檢定 ~~~ 不知道為什麼竟然是博客來的網頁 XDDDD

我的測驗結果:












Angie的測驗結果:












只能說 =ˇ= 其實還蠻準的嘛 XDDDDDDDDDDD

2009年2月11日 星期三

CodeBlocks、Dev-C++ 使用 OpenCV

CodeBlocks 設置方法Dev-C++ 設置方法

CodeBlocks:
1. Project → Build options...
2. Linker settings 中的 Other linker options: 加入
 -lhighgui -lcv -lcxcore
3. Serach directories 中的 Compiler 加入
 C:\Program Files\OpenCV\cxcore\include
 C:\Program Files\OpenCV\otherlibs\highgui
 C:\Program Files\OpenCV\cv\include
4.
Serach directories 中的 Linker 加入
 C:\Program Files\OpenCV\lib

Dev-C++:
1. 在 Tools → Compiler Options → Compiler → 將 Linker Command 的框框勾起來且加
 -lhighgui -lcv -lcxcore -lcvaux -lcvcam
2. Tools → Compiler Options → Directories → Libraries 加入
 C:\Program Files\OpenCV\lib
3. Tools → Compiler Options → Directories → C Includes 加入
 C:\Program Files\OpenCV\cxcore\include
 C:\Program Files\OpenCV\cv\include
 C:\Program Files\OpenCV\otherlibs\highgui
 C:\Program Files\OpenCV\cvaux\include
 C:\Program Files\OpenCV\otherlibs\cvcam\include
4. Tools → Compiler Options → Compiler → Directories → C++ Includes
 C:\Program Files\OpenCV\cxcore\include
 C:\Program Files\OpenCV\cv\include
 C:\Program Files\OpenCV\otherlibs\highgui
 C:\Program Files\OpenCV\cvaux\include
 C:\Program Files\OpenCV\otherlibs\cvcam\include

使用 CodeBlocks 每次開新專案都要重新再加入路徑

而 Dev-C++ 則不用

但是用 Dev-C++ 又不好 tracing code = =.... 真是討厭

Asshole Mario



這個版本真的是超難的啦 = =~~~

竟然還有神人可以破關 Orz...

其他還有各關的影片在 YouTube 搜尋 Asshole Mario 即可找到~

2009年1月14日 星期三

She's like the Swallow - Williams College Elizabethans



以前在合唱團有唱過這首,同樣是STAB混聲四部,

好懷念,希望可以復團,好想唱歌。

2009年1月11日 星期日

Yesterday Once More - 木匠兄妹



When I was young I'd listen to the radio.當我還是小女還時,我常聽收音機。
Waiting for my favorite songs.等待著我心愛的歌。
When they played I'd sing along.當它們播放出來的時候,我會跟著唱。
It make me smile.這令我笑容滿面。

Those were such happy times and not so long ago.不久前的回憶那真是段美好的時光。
How I wondered where they'd gone.我不知道那段美好時光怎麼消失了。
But they're back again just like a long lost friend.現在它們就像久無音信的老朋友又回來了。
All the songs I love so well.所有的歌都是我所喜歡的。
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!

Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!

When they get to the part.當他們唱到那段-
Where he's breaking her heart.男孩使女孩傷心的部分時。
It can really make me cry.也讓我流下了眼淚。
Just like before.就像昔日一樣。
It's yesterday once more ! 仿佛昨日重現!
(Shoobie do lang lang)
(Shoobie do lang lang)
Looking back on how it was in years gone by. 回首過去的幾年。
And the good times that had.以及我曾擁有的好時光。
Makes today seem rather sad.使今日更加傷感。
So much has changed ! 太多的轉變!

It was songs of love that I would sing to them.那些舊日跟唱過的舊情歌。
And I'd memorise each word.我仍然記得沒一句歌詞。
Those old melodies still sound so good to me.那些舊旋律聽起來仍然那麼悅耳。
As they melt the years away.它們使歲月消融!
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!

Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!
All my best memorise come back clearly to me.所有美好的回憶都在我腦海裡清晰的浮現!
Some can even make me cry.有些甚至令我淚流滿脈面。

Just like before.就象昔日一樣。
It's yesterday once more ! 仿佛昨日重現!
(Shoobie do lang lang)
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!
Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!
Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!

Love Is All Around - Wet Wet Wet



Love Is All Around

I feel it in my fingers, I feel it in my toes
Love is all around me and so the feeling grows
It's written on the wind, it's everywhere I go
So if you really love me, come on and let it show
You know I love you I always will
My mind's made up by the way that I feel
There's no beginning, there'll be no end
'Cause on my love you can depend
I see your face before me, as I lay on my bed
I kinda get to thinking of all the things we said
You gave a promise to me, and I gave mine to you
I need someone beside me in everything I do
You know I love you I always will
My mind's made up by the way that I feel
There's no beginning, there'll be no end
'Cause on my love you can depend
It's written on the wind, it's everywhere I go
So if you really love me, come on and let it show
Come on and let it show

2009年1月6日 星期二

Matrix

CvArr → CvMat → IplImage ( 繼承關係 )
Even though OpenCV is implemented in C, the structures used in OpenCV have an object-oriented design; in effect, IplImage is derived from CvMat, which is derived from CvArr

1.
When CvArr* appears, it is acceptable to pass CvMat* or IplImage* to the routine.

可以用 CvArr * 去接 CvMat 或是 IplImage

上層往下指,上層的每一個成員下層也一定都有,所以一定都會對滿

反之,下層有的上層不見得有,所以下層的指標有些會接不到東西,就錯誤

故可以用上層的指標去接下層的成員函式。

2.
CvArr, can be thought of as an abstract base class from which CvMat is itself derived.

抽象基礎類別

是把最底層的class成員函數都宣告成virtual,本身的class沒辦法實體化

只提供該有哪些function的功能

實體的使用內容卻是由衍生出來的class去各自設計

也就是提供類似模組或樣版

第二點的參考資料來源:奇摩知識+

萍聚

選擇 - 林子祥 葉蒨文

是否 - 葉蒨文



當初我的合唱團老師也有唱過此首的男聲獨唱版

可惜沒找到來源,也很好聽!!

2009年1月5日 星期一

重病

經過了一個周末的煎熬

加上昨晚全身發冷似乎還發燒了 Orz

今天終於去看了校醫

症狀:喉嚨吞嚥會痛、脖子很緊、全身無力、身體發冷

沒想到竟然是扁桃腺發炎加上喉嚨有痰,哭哭

好像好久沒有生這麼重的病了吧

記得高中以來也沒有這樣過

偏偏又發生在期末考前,考試掰掰 = =... 睡覺重要 XD?

校醫還說要開抗生素給我吃= = 偏偏學校的抗生素又只有一種

如果吃了兩天還是有發燒到39度以上或是吞嚥會痛,

就要住院 = =~~~ 很無奈,學校都提供免費的校醫了

醫療資源也不順便升級一些,嘖嘖~~ 有貪污吧 =口=+

A Not-So-Simple Transformation











左為cvPyrDown()兩次的結果,
  右為cvCanny()一次的結果。

// Example 2-5. Using cvPyrDown() to create a new image that is half the width and height of the input image

// Example 2-6. The Canny edge detector writes its output to a single channel (grayscale) image
// Example 2-7. Combining the pyramid down operator (twice) and the Canny subroutine in a simple image pipeline
// Example 2-8. Simplifying the image pipeline of Example 2-7 by making the individual stages release their intermediate memory allocations

#include "highgui.h"
#include "cv.h"

IplImage *doPyrDown( IplImage * , int );
IplImage *doCanny( IplImage * , double , double , double );

int main( int argc , char **argv )
{
 cvNamedWindow( "Input" , CV_WINDOW_AUTOSIZE );
 cvNamedWindow( "Output1" , CV_WINDOW_AUTOSIZE );
 //cvNamedWindow( "Output2" , CV_WINDOW_AUTOSIZE );
 //cvNamedWindow( "Output3" , CV_WINDOW_AUTOSIZE );

 IplImage *image = cvLoadImage( argv[1] , 0);
 IplImage *out1 = doPyrDown( image , IPL_GAUSSIAN_5x5 );
 //IplImage *out2 = doPyrDown( out1 , IPL_GAUSSIAN_5x5 );
 //IplImage *out3 = doCanny( out2 , 10 , 100 , 3 );
 out1 = doPyrDown( out1 , IPL_GAUSSIAN_5x5 );
 cvShowImage( "Input" , out1 );
 out1 = doCanny( out1 , 10 , 100 , 3 );

 //cvShowImage( "Input" , image );
 cvShowImage( "Output1" , out1 );
 //cvShowImage( "Output2" , out2 );
 //cvShowImage( "Output3" , out3 );

 cvWaitKey( 0 );

 cvReleaseImage( &image );
 cvReleaseImage( &out1 );
 //cvReleaseImage( &out2 );
 //cvReleaseImage( &out3 );

 cvDestroyWindow( "Input" );
 cvDestroyWindow( "Output1" );
 //cvDestroyWindow( "Output2" );
 //cvDestroyWindow( "Output3" );
 return 0;
}

// Example 2-5.
IplImage *doPyrDown( IplImage *in , int filter )
{
 // Best to make sure input image is divisible by two.
 //
 assert( in->width%2 == 0 && in->height%2 == 0 );

 IplImage *out = cvCreateImage( cvSize( in->width/2 , in->height/2 ) , in->depth , in->nChannels );
 cvPyrDown( in , out , filter );
 return out;
}

// Example 2-6.
IplImage *doCanny( IplImage *in , double lowThresh , double highThresh , double aperture )
{
 if( in->nChannels != 1 )
  return 0; // Canny only handles gray scale iamges

 IplImage *out = cvCreateImage( cvGetSize( in ) , IPL_DEPTH_8U , 1 );
 cvCanny( in , out , lowThresh , highThresh , aperture );
 return out;
}

2009年1月4日 星期日

Equalization using VB













←開檔













←依序為原圖、灰階、灰階均化、轉回彩色















←存檔


' 背景需要先拉入OpenFileDialog與SaveFileDialog物件

' RGB 轉成 YIQ 並且顯示灰階
  Dim i, j, r, g, b, Y, imgW, imgH As Integer
  Dim bmp As New Bitmap(PictureBox1.Image)
  imgW = bmp.Width
  imgH = bmp.Height
  Dim bmp1 As New Bitmap(imgW, imgH)

  For i = 0 To imgW - 1
   For j = 0 To imgH - 1
    r = bmp.GetPixel(i, j).R
    g = bmp.GetPixel(i, j).G
    b = bmp.GetPixel(i, j).B
    Y = (0.299 * r + 0.587 * g + 0.114 * b)
    If Y < 0 Then
     Y = 0
    ElseIf Y > 255 Then
     Y = 255
    End If
    bmp1.SetPixel(i, j, Color.FromArgb(Y, Y, Y))
   Next
  Next

  PictureBox2.SizeMode = PictureBox1.SizeMode
  PictureBox2.Image = bmp1

' 對灰階影像做亮度均化
  Dim imgW, imgH, i, j, Y As Integer
  Dim bmp As New Bitmap(PictureBox2.Image)

  imgW = bmp.Width
  imgH = bmp.Height
  Dim bmp1 As New Bitmap(imgW, imgH)
  Dim N(255) As Integer

  For i = 0 To imgW - 1
   For j = 0 To imgH - 1
    Y = bmp.GetPixel(i, j).R
    N(Y) = N(Y) + 1
   Next
  Next

  For i = 1 To 255
   N(i) = N(i - 1) + N(i)
  Next

  j = imgW * imgH

  For i = 0 To 255
   ' 四捨五入
   If (N(i) * 255 / j * 10) Mod 10 < 5 Then
    N(i) = N(i) * 255 / j
   Else
    N(i) = N(i) * 255 / j + 1
   End If
   If N(i) > 255 Then
    N(i) = 255
   ElseIf N(i) < 0 Then
   N(i) = 0
   End If
  Next

  For i = 0 To imgW - 1
   For j = 0 To imgH - 1
    Y = N(bmp.GetPixel(i, j).R)
    bmp1.SetPixel(i, j, Color.FromArgb(Y, Y, Y))
   Next
  Next

  PictureBox3.SizeMode = PictureBox2.SizeMode
  PictureBox3.Image = bmp1

' 將均化過的Y與沒變的IQ轉回RGB
  Dim i, j, r, g, b, Y, AI, Q, imgW, imgH As Integer
  Dim bmp As New Bitmap(PictureBox1.Image)
  Dim bmp1 As New Bitmap(PictureBox3.Image)
  imgW = bmp.Width
  imgH = bmp.Height
  Dim bmp2 As New Bitmap(imgW, imgH)

  For i = 0 To imgW - 1
   For j = 0 To imgH - 1
    r = bmp.GetPixel(i, j).R
    g = bmp.GetPixel(i, j).G
    b = bmp.GetPixel(i, j).B
    Y = bmp1.GetPixel(i, j).R
    AI = (0.596 * r - 0.274 * g - 0.322 * b)
    Q = (0.211 * r - 0.522 * g + 0.311 * b)

    r = (1 * Y + 0.956 * AI + 0.632 * Q)
    If r < 0 Then
     r = 0
    ElseIf r > 255 Then
     r = 255
    End If
    g = (1 * Y - 0.272 * AI - 0.648 * Q)
    If g < 0 Then
     g = 0
    ElseIf g > 255 Then
     g = 255
    End If
    b = (1 * Y - 1.105 * AI + 0.705 * Q)
    If b < 0 Then
     b = 0
    ElseIf b > 255 Then
     b = 255
    End If
    bmp2.SetPixel(i, j, Color.FromArgb(r, g, b))
   Next
  Next

  PictureBox4.SizeMode = PictureBox3.SizeMode
  PictureBox4.Image = bmp2

' 讀檔
  Dim openFileDialog1 As New OpenFileDialog()
  openFileDialog1.Filter = "Bmp Files|*.bmp"
  openFileDialog1.Title = "Select a Bitmap File"

  If openFileDialog1.ShowDialog() = DialogResult.OK Then
   PictureBox1.Image = Image.FromFile(openFileDialog1.FileName)
   Button1.Enabled = True
   Label1.Visible = True
  End If

' 存檔
  Dim saveFileDialog1 As New SaveFileDialog()
  saveFileDialog1.Filter = "Bitmap Image|*.bmp"
  saveFileDialog1.Title = "Save an Bitmap File"
  saveFileDialog1.ShowDialog()

  ' If the file name is not an empty string open it for saving.
  If saveFileDialog1.FileName <> "" Then
   ' Saves the Image via a FileStream created by the OpenFile method.
   Dim fs As System.IO.FileStream = CType _ (saveFileDialog1.OpenFile(), System.IO.FileStream)
   ' Saves the Image in the appropriate ImageFormat based upon the
   ' file type selected in the dialog box.
   ' NOTE that the FilterIndex property is one-based.
   Me.PictureBox2.Image.Save(fs, _ System.Drawing.Imaging.ImageFormat.Bmp)

   fs.Close()
  End If

A Simple Transformation

// If the resource is not from bitmap file but from avi file, then each frame of the output
// will up-side down, I still not find out what reason.

// Example 2-4. Loading and then smoothing an image before it is displayed on the screen


#include "cv.h"
#include "highgui.h"

void example2_4( IplImage *);

int main(int argc,char **argv)
{
 IplImage *image = cvLoadImage( argv[1] );
 example2_4( image );
 cvReleaseImage( &image );
 return 0;
}

void example2_4( IplImage *image )
{
 // Create some windows to show the input
 // and output image in.
 //
 cvNamedWindow( "Example4-in" );
 cvNamedWindow( "Example4-out" );

 // Create a window to show our input image
 //
 cvShowImage( "Example4-in" , image );

 // Create an image to hold the smoothed output
 //
 IplImage *out = cvCreateImage( cvGetSize(image) , IPL_DEPTH_8U , 3 );

 // Do the smoothing
 //
 cvSmooth( image , out , CV_GAUSSIAN , 31 , 31);

 // Show the smoothed image in the output window
 //
 cvShowImage( "Example4-out" , out );

 //Be tidy
 //
 cvReleaseImage( &out );

 // Wait for the user to hit a key, then clean up the windows
 //
 cvWaitKey( 0 );
 cvDestroyWindow( "Example4-in" );
 cvDestroyWindow( "Example4-out" );
}

Trackbar Slider

// Example 2-3. Program to add a trackbar slider to the basic viewr window: when the slider is
// moved, the function onTrackbarSlide() is called and then passed to the slider's new value

#include "cv.h"
#include "highgui.h"

void onTrackbarSlide(int);

int g_slider_position = 0;
CvCapture *g_capture = NULL;

int main(int argc, char **argv)
{
 cvNamedWindow("Example3",CV_WINDOW_AUTOSIZE);
 g_capture = cvCreateFileCapture(argv[1]);

 // we use it when we want to query some data from the CvCapture structure
 // it will return how many frames are in the video
 int frames = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
 IplImage *frame;
 if(frames!=0)
  for(;;g_slider_position++)
  {
   // the last parameter is a callback function that reset the position of trackbar slider
   cvCreateTrackbar("Position","Example3",&g_slider_position,frames,onTrackbarSlide);
   frame = cvQueryFrame( g_capture );
   if( !frame )
    break;
   cvShowImage("Example3",frame);
   char c = cvWaitKey(33);
   if( c==27 )
    break;
   while((c=='p')||(c=='P'))
   {
    c = cvWaitKey(0);
    if( c==27 )
    {
     cvReleaseCapture( &g_capture );
     cvDestroyWindow("Example3");
     return 0;
    }
    if( (c=='c')||(c=='C')||(c==13) )
     break;
    else
     c='p';
   }
  }
 cvReleaseCapture( &g_capture );
 cvDestroyWindow("Example3");
 return 0;
}

void onTrackbarSlide(int pos)
{
 cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);
}

AVI Video

// Example 2-2. A simple OpenCV program for playing a video file from disk

#include "highgui.h"

int main(int argc, char **argv)
{
 cvNamedWindow("Example2",CV_WINDOW_AUTOSIZE);
 // it will also allocate a memory for the image
 CvCapture *capture = cvCreateFileCapture(argv[1]);
 IplImage *frame;
 while(1)
 {
  frame = cvQueryFrame( capture );
  if( !frame )
   break;
  cvShowImage( "Example2", frame );
  // 30 frames per second = 30 frames / 1000 ms = 1 frame / 33 ms
  // if no stdin then it will return -1

  char c = cvWaitKey(33);
  if(c==27)
   break;
  // pause while pressing p or P
  while((c=='p')||(c=='P'))
  {
   c = cvWaitKey(0);
   if(c==27)
   {
    cvReleaseCapture( &capture );
    cvDestroyWindow( "Example" );
    return 0;
   }
   // continue the video while pressing c, C or enter
   if((c=='c')||(c=='C')||(c==13))
    break;
   else
    c='p';
  }
 }
 // it will also called "cvReleaseImage()" for the "frame" pointer
 cvReleaseCapture( &capture );
 cvDestroyWindow( "Example2" );
 return 0;
}

Babylon - Gregorian Chants

2009年1月2日 星期五

二零零八跨年

今年依舊是在詠寧家跨年

成員:我、Angie、丁丁、左左、殺手、詠寧、啾啾

好不容易熬玩歷史課回家匆匆洗了個澡便趕往中壢

抵達目的地後不久沒想到意外的來了神秘嘉賓:聰明人跟宅豪











←右手邊的看起來不只宅,還呆呆的 XD"


好不容易大家都到齊了,舟車勞苦之後都飢腸轆轆,

便東西先放在一旁沒整頓就整群先去中原夜市覓食了,

找來找去都沒找到詠寧哥哥說的"傻蛋的窩",只好作罷,

走著走著倒是意外的發現了一家"塞納河"的義大利麵店,

感覺裝潢得很溫馨,裡面的服務生也很親切,給人感覺很舒服,

出餐雖然頗久 ( XD" 吃了快兩個小時吧 ) 但是卻是平常所感受不到的悠哉,

跟米卡果然不能比 = =+ 應該說米卡真的是太不好吃了,

大推這家店的手工蛋糕,在中原夜市的三井電腦斜對面巷子進去,











←巧克力部分超美味,吃起來很綿密不會膩


有機會可以再去吃吃看,為了美食到處奔波阿 XDDDD

回去的途中還順手夾了一個長頸鹿充氣娃娃,不過卻花了五十元,

感覺是被騙錢了 =口=... 不過大家卻玩得莫名很high...XD?












←啾啾的牙突











←被小惡魔硬是戴上去的丁丁,可憐的應該是長頸鹿...

中間就是倒數跨年啦,其間還打了蠻久的桌球 XD"

沒辦法,誰叫有一半都是系桌的,哈哈哈

大家都老了 =.=.... 沒辦法通霄到天亮,

不過也可能是因為宵夜吃鐵板燒加上冰火的關係吧,天氣太冷,

/* 家樂福買的澳洲培根肉串,結果是羊肉 = = 黑店 大家以後不要去阿...不爽 */

酒足飯飽之後喝完酒暖暖地好舒服超想睡 XD

隔天中午吃了到中壢一定要吃的牛肉麵!

之前吃過了永川、老師傅牛肉麵之後,這次主打:老三牛肉麵

坦白說,我覺得比老師傅差,且又忘記弄我們點的東西,

讓我們等超久 = =... 不開心~~~~~ 不推! 還是老師傅好吃!

計畫中的重頭戲就是巧克力火鍋啦! 今年突發奇想,繼去年豆漿火鍋之後,

今年特別一點,不過因為有一半的人有事先走,QQ

所以剩下一半的人吃了幾乎全部的東西,吃的超飽,可能一段時間不會吃甜食了吧我猜~










←啾啾(左)跟我(右)的傑作,啾咪跟囧 XDDD 超可愛的啦,棉花糖+巧克力醬愛不釋手












←蘋果麵包做地,也很好吃 >///<














←離開前的KUSO~ 倒掛金鉤 XD" 感覺很蠢 哈哈哈


Ps. 番外篇 ~ 到三峽吃完晚餐之後騎車回宿舍,沒想到紅燈左轉被抓到了 XD
      哭哭,騎車以來第一張紅單,沒想到在元旦來臨了
      XD 噴1,800...唉 Orz 以後的日子怎麼過阿 QQ

2009年1月1日 星期四

Equalization using VC

專案屬性組態屬性連結器輸入其他相依性 加入 gdiplus.dll

按 Enter 會依序出現












← 一開始顯示測試原圖













← 顯示原圖的灰階影像













← 經過亮度均化後的灰階影像













← 將修改過後的YIQ轉回RGB













← 直接對RGB做亮度均化,出現色偏


===========================================================
Header File

#include <windows.h>
#include <gdiplus.h>

using namespace Gdiplus;

#ifndef _CVE_H_
#define _CVE_H_

Graphics* graphics;
Image* image;
Pen* pen;

/* RGB layers of the image */
int** i_R;
int** i_G;
int** i_B;
/* RGB layers of the image */
int** i_Red;
int** i_Green;
int** i_Blue;
/* YIQ layers of the image */
int** iY_Gray;
int** iI_Gray;
int** iQ_Gray;
/* calculation of RGB layers */
int* num_R;
int* num_G;
int* num_B;
/* probability of RGB layers */
double* pro_R;
double* pro_G;
double* pro_B;
/* probability of gray level */
double* pro_Gray;
/* calculation of gray level */
int* num_Gray;

/* decide to take which processing action */
int flag;
/* image height and width */
int i_Height, i_Width;
/* total pixels */
double i_Pixels;

#endif
===========================================================
CPP FILE

#include "CVE.h"

using namespace Gdiplus;

/* function prototype */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void Clear();
void myKeys(HWND);
void OnPaint(HDC);
void Setup1();
void Setup2(HDC);

/* WinMain , the program entry point */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int iCmdShow)
{
 HWND hWnd;
 MSG msg;
 WNDCLASS wndClass;
 GdiplusStartupInput gdiplusStartupInput;
 ULONG_PTR gdiplusToken;

 /* initilize the flag to show the original image at first */
 flag = 1;

 /* Initialize GDI+. */
 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

 wndClass.style = CS_HREDRAW | CS_VREDRAW;
 wndClass.lpfnWndProc = WndProc;
 wndClass.cbClsExtra = 0;
 wndClass.cbWndExtra = 0;
 wndClass.hInstance = hInstance;
 wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
 wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
 wndClass.lpszMenuName = NULL;
 wndClass.lpszClassName = TEXT("Equalization");

 RegisterClass(&wndClass);
 Setup1();

 hWnd = CreateWindow(
  TEXT("Equalization"),       // window class name
  TEXT("CVHW Equalization"),     // window caption
  WS_OVERLAPPEDWINDOW,   // window style
  CW_USEDEFAULT,       // initial x position
  CW_USEDEFAULT,         // initial y position
  i_Width * 2,               // initial x size
  i_Height * 2,               // initial y size
  NULL,              // parent window handle
  NULL,              // window menu handle
  hInstance,             // program instance handle
  NULL);              // creation parameters

 HDC hdc = GetDC(hWnd);
 Setup2(hdc);

 ShowWindow(hWnd, iCmdShow);
 UpdateWindow(hWnd);

 while(1)
 {
  if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  {
   if (msg.message == WM_QUIT)
    break;
   TranslateMessage(&msg);
   DispatchMessage(&msg);
  }
  else
   myKeys(hWnd);
 }

 GdiplusShutdown(gdiplusToken);
 Clear();
 return (int)msg.wParam;
}

/* WndProc */
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;

 switch(message)
 {
  case WM_PAINT:
   hdc = BeginPaint(hWnd, &ps);
   OnPaint(hdc);
   EndPaint(hWnd, &ps);
   return 0;
  case WM_DESTROY:
   PostQuitMessage(0);
   return 0;
  default:
   return DefWindowProc(hWnd, message, wParam, lParam);
 }
}

/* free memory */
void Clear()
{
 delete i_Red;
 delete i_Green;
 delete i_Blue;
 delete i_R;
 delete i_G;
 delete i_B;
 delete iY_Gray;
 delete iI_Gray;
 delete iQ_Gray;

 delete [] num_Gray;
 delete [] pro_Gray;
 delete [] num_R;
 delete [] num_G;
 delete [] num_B;
 delete [] pro_R;
 delete [] pro_G;
 delete [] pro_B;
}

/* keyboard events */
void myKeys(HWND hwnd)
{
 static int count=2;

 /* press ESC to exit program */
 if(GetKeyState(27) & 0x80)
  exit(0);

 /* press enter to continue the next image */
 if(GetKeyState(13) & 0x80)
 {
  flag = (count%=7)++;
  InvalidateRect(hwnd, NULL, FALSE);
 }
}

/* initialize_1 */
void Setup1()
{
 image = new Image(L"test.jpg");
 if(image->GetHeight() == 0 && image->GetWidth() == 0)
  image = new Image(L"test.bmp");
 i_Height = image->GetHeight();
 i_Width = image->GetWidth();
}

/* initialize_2 */
void Setup2(HDC hdc)
{
 graphics = new Graphics(hdc);

 pen = new Pen(Color(0,0,255), 3);

 i_Pixels = (double)(i_Height * i_Width);

 num_Gray = new int[256];
 pro_Gray = new double[256];
 num_R = new int[256];
 num_G = new int[256];
 num_B = new int[256];
 pro_R = new double[256];
 pro_G = new double[256];
 pro_B = new double[256];

 for(int i = 0; i < 256; i++)
 {
  num_Gray[i] = 0;
  pro_Gray[i] = 0;
  num_R[i] = 0;
  num_G[i] = 0;
  num_B[i] = 0;
  pro_R[i] = 0;
  pro_G[i] = 0;
  pro_B[i] = 0;
 }

 i_Red = new int*[i_Height];
 i_Green = new int*[i_Height];
 i_Blue = new int*[i_Height];
 iY_Gray = new int*[i_Height];
 iI_Gray = new int*[i_Height];
 iQ_Gray = new int*[i_Height];
 i_R = new int*[i_Height];
 i_G = new int*[i_Height];
 i_B = new int*[i_Height];

 for(int i = 0; i < i_Height;i++)
 {
  i_Red[i] = new int[i_Width];
  i_Green[i] = new int[i_Width];
  i_Blue[i] = new int[i_Width];
  iY_Gray[i] = new int[i_Width];
  iI_Gray[i] = new int[i_Width];
  iQ_Gray[i] = new int[i_Width];
  i_R[i] = new int[i_Width];
  i_G[i] = new int[i_Width];
  i_B[i] = new int[i_Width];
 }
}

/* image processing */
void OnPaint(HDC hdc)
{
 COLORREF color;
 switch(flag)
 {
  /* show the original image */
  case 1:
   graphics->DrawImage(image, 0, 0, i_Width, i_Height);
   break;
  /* show the gray level of the image */
  case 2:
   for(int i = 0; i < i_Height; i++)
    for(int j = 0; j < i_Width; j++)
    {
     color = GetPixel(hdc, j ,i);

     i_Red[i][j] = i_R[i][j] = GetRValue(color);
     i_Green[i][j] = i_G[i][j] = GetGValue(color);
     i_Blue[i][j] = i_B[i][j] = GetBValue(color);

     iY_Gray[i][j] = (int)(0.299 * i_Red[i][j] + 0.587 * i_Green[i][j] + 0.114 * i_Blue[i][j]);
     iI_Gray[i][j] = (int)(0.596 * i_Red[i][j] - 0.274 * i_Green[i][j] - 0.322 * i_Blue[i][j]);
     iQ_Gray[i][j] = (int)(0.211 * i_Red[i][j] - 0.522 * i_Green[i][j] + 0.311 * i_Blue[i][j]);

     num_Gray[iY_Gray[i][j]]++;
     num_R[i_R[i][j]]++;
     num_G[i_G[i][j]]++;
     num_B[i_B[i][j]]++;

     color = RGB(iY_Gray[i][j], iY_Gray[i][j], iY_Gray[i][j]);
     SetPixel(hdc, j + i_Width, i, color);
    }
   break;
  /* show the gray level of the image after equalizing */
  case 3:
   for(int i = 1; i < 256; i++)
   {
    num_Gray[i] += num_Gray[i-1];
    num_R[i]+=num_R[i-1];
    num_G[i]+=num_G[i-1];
    num_B[i]+=num_B[i-1];
   }

   for(int i = 0; i < 256; i++)
   {
    pro_Gray[i] = double(num_Gray[i]) / i_Pixels;
    pro_R[i] = double(num_R[i]) / i_Pixels;
    pro_G[i] = double(num_G[i]) / i_Pixels;
    pro_B[i] = double(num_B[i]) / i_Pixels;
   }

   for(int i = 0; i < i_Height; i++)
    for(int j = 0; j < i_Width; j++)
    {
     iY_Gray[i][j] = (int)(pro_Gray[iY_Gray[i][j]] * 255);
     i_R[i][j] = (int)(pro_R[i_R[i][j]] * 255);
     i_G[i][j] = (int)(pro_G[i_G[i][j]] * 255);
     i_B[i][j] = (int)(pro_B[i_B[i][j]] * 255);

     color = RGB(iY_Gray[i][j], iY_Gray[i][j], iY_Gray[i][j]);
     SetPixel(hdc, j, i + i_Height, color);
    }
   break;
  /* YIQ→RGB */
  case 4:
   for(int i = 0; i < i_Height; i++)
    for(int j = 0; j < i_Width; j++)
    {
     i_Red[i][j] = (int)(1 * iY_Gray[i][j] + 0.956 * iI_Gray[i][j] + 0.632 * iQ_Gray[i][j]);
     if(i_Red[i][j]>255)
      i_Red[i][j]=255;
     else if(i_Red[i][j]<0)
      i_Red[i][j]=0;

     i_Green[i][j]= (int)(1 * iY_Gray[i][j] - 0.272 * iI_Gray[i][j] - 0.648 * iQ_Gray[i][j]);
     if(i_Green[i][j]>255)
      i_Green[i][j]=255;
     else if(i_Green[i][j]<0)
      i_Green[i][j]=0;

     i_Blue[i][j]= (int)(1 * iY_Gray[i][j] - 1.105 * iI_Gray[i][j] + 0.705 * iQ_Gray[i][j]);
     if(i_Blue[i][j]>255)
      i_Blue[i][j]=255;
     else if(i_Blue[i][j]<0)
      i_Blue[i][j]=0;
     color = RGB(i_Red[i][j], i_Green[i][j], i_Blue[i][j]);
     SetPixel(hdc, j + i_Width, i + i_Height, color);
    }
   break;
  /* equalize directly to each R, G, B layer */
  case 5:
   for(int i = 0; i < i_Height; i++)
    for(int j = 0; j < i_Width; j++)
    {
     color = RGB(i_R[i][j], i_G[i][j], i_B[i][j]);
     SetPixel(hdc, j, i, color);
    }
   break;
  default:
   break;
 }
}
===========================================================