当前位置:操作系统 > 安卓/Android >>

Android培训班(26)

<!-- @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);

}

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,