Android培訓班(26)

來源:互聯網
上載者:User

<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->

接著來分析函數 to_565_rle,這個函數主要實現從24位顏色變換為565的16位顏色表示,並且進行行程壓縮編碼,代碼如下:

void to_565_rle(void)

{

unsigned char in[3];

unsigned short last, color, count;

unsigned total = 0;

count = 0;

while(read(0, in, 3) == 3) {

從標準輸入的檔案,每次讀取三個位元組,如果讀取不夠三個位元組,就退出處理。

color = to565(in[0],in[1],in[2]);

每三個位元組作為一個像素點,然後通過宏 to565變換為565的16位表示。

下面這段代碼進行遊程編碼,並寫到標準輸出檔案裡。

if (count) {

if ((color == last) && (count != 65535)) {

count++;

continue;

} else {

write(1, &count, 2);

write(1, &last, 2);

total += count;

}

}

last = color;

count = 1;

}

下面這段代碼寫入最後一個像素的資料。

if (count) {

write(1, &count, 2);

write(1, &last, 2);

total += count;

}

這裡提示總共處理多少個像素數。

fprintf(stderr,"%d pixels",total);

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.