寻找RLE编码,解码源程序和算法(高分)
哪位有比较清晰的,最好带个说明或者有注释...或者提供详细算法思想,不胜感激.
问题点数:120、回复次数:14Top
1 楼tlovexyj(菠萝菠萝蜜)回复于 2001-05-29 15:08:00 得分 0
嘿嘿嘿,俺就有一个,你要吗?
mail俺吧: tlovexyj@21cn.comTop
2 楼crazybit(bit狂)回复于 2001-05-29 15:19:00 得分 10
我以前做过一个PCX图像处理程序,你要吗?
crazybit@sina.comTop
3 楼Kevin_qing()回复于 2001-05-29 15:19:00 得分 80
噢~~这个简单
看我写的文档,在CSDN就有
Top
4 楼Kevin_qing()回复于 2001-05-29 15:20:00 得分 0
噢~~这个简单
看我写的文档,在CSDN就有
Top
5 楼Kevin_qing()回复于 2001-05-29 15:22:00 得分 0
http://www.csdn.net/develop/read_article.asp?id=4986Top
6 楼vertex(新问题)回复于 2001-05-29 15:25:00 得分 0
wu,这个写的不错阿.:)
我写个测试程序试试...Top
7 楼Kevin_qing()回复于 2001-05-29 15:35:00 得分 0
嘿嘿~~~
那个是简单的,现在我写了一个支持变种的RLE类,可以和普通文件一样写入和读出数据。
而且编码位数是可以动态的,比普通RLE好多了Top
8 楼vertex(新问题)回复于 2001-05-29 16:07:00 得分 0
wu?佩服.......不过,我要简单的.....因为比较好懂......瞧,这是刚才我看了你的文章后写的....不过,好乱...
void encode(WORD* in,int width,WORD* out,int& endw)
{
int index=0,count=0;
WORD value=in[index];
index++;
endw=0;
while(index<width)
{
if(in[index]==value)
{
index++;
count=2;
while(index<width && in[index]==value)
{
index++;
count++;
}
endw+=2;
*out=0;//ctrl
out++;
*out=count;
out++;
*out=value;
out++;
value=in[index];
if(index<width)
index++;
}
else
{
*out=0;//tmp count
out++;
count=1;
*out=value;
out++;
endw+=2;
while(index<width && in[index]!=in[index + 1])//下标会越界,呵呵
{
*out=in[index];
out++;
endw++;
count++;
index++;
}
*(out - count - 1) = count;
value = in[index];
if (index < width)
index++;
}
}
}
Top
9 楼Kevin_qing()回复于 2001-05-29 16:19:00 得分 0
好像你是拿来压缩位图的吧
还有width
其实对sprite可以只压缩colorKey就行了,自己写个blt函数,不会比dx的blt慢Top
10 楼vertex(新问题)回复于 2001-05-29 16:44:00 得分 0
对阿,我只试了试对一行进行压缩,呵呵.要ALE blt to screen的...
只压缩colorkey....我不大想用...要压就一块压了贝........blt时,解之前判一下是不是colorkey.....查不多吧
Top
11 楼Kevin_qing()回复于 2001-05-29 16:50:00 得分 0
不是啊,只压缩color Key 可以减少判断的次数,而且不需要判断colorKey
同时压缩率也很不错的。
这样可以把解压和透明blt做到一起Top
12 楼tlovexyj(菠萝菠萝蜜)回复于 2001-05-29 17:58:00 得分 30
贴出来算鸟
// std2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
//RLE Test
void RLE_Compress(const char * &, const int &, char * &, int &);
void RLE_UnCompress(const char * &, const int &, char * &, int &);
int main(int argc, char* argv[])
{
//RLE_Compress
fstream f("std2.opt", ios::in|ios::binary);
if (f.fail())
{
cout << "open file failed...\nexit." << endl;
return 1;
}
f.seekg(0, ios::end);
int i = f.tellg(),
o = 0;
f.seekg(0, ios::beg);
char *r=new char[i],
*w=0;
f.read(r, i);
RLE_Compress(r, i, w, o);
delete []r, r=0;
f.close();
f.open("1.r", ios::app|ios::out|ios::binary);
f.clear();
f.write(w, o);
delete []w, w=0;
f.close();
//RLE_UnCompress
f.open("1.r", ios::in|ios::binary);
f.seekg(0, ios::end);
i = f.tellg();
f.seekg(0, ios::beg);
r=new char[i],
f.read(r, i);
RLE_UnCompress(r, i, w, o);
delete []r, r=0;
f.close();
f.open("restore.rle", ios::app|ios::out);
f.write(w, o);
delete []w, w=0;
f.close();
return 0;
}
void RLE_Compress(const char * &r, const int &size1, char * &w, int &size2)
{
if (r==0)
return;
const char *p=r;
vector <char> rleVector, tVector;
char c=*r;
tVector.push_back(c);
for (int n=0; n<size1; n++)
{
p++;
if (c!=*p)
{
if (!tVector.empty())
{
if (tVector.size()<4)
{
vector <char>::iterator iter=tVector.begin();
while (iter!=tVector.end())
{
if (*iter=='*')
{
rleVector.push_back('*');
rleVector.push_back('*');
}
else
{
rleVector.push_back(*iter);
}
iter++;
}
}
else
{
rleVector.push_back('*');
rleVector.push_back(tVector.size());
rleVector.push_back(tVector.at(0));
}
}
tVector.clear();
}
tVector.push_back(*p);
c=*p;
}
size2=rleVector.size();
w=new char [size2];
for (n=0; n<size2; n++)
w[n]=rleVector.at(n);
#ifdef _DEBUG
cout << "Before RLE the string length is: " << size1 << endl;
cout << "After RLE the string length is: " << size2 << endl;
#endif
}
void RLE_UnCompress(const char * &r, const int &size1, char * &w, int &size2)
{
if (r==0)
return;
const char *p=r;
vector <char> rVector;
for (int n=0; n<size1; n++)
{
if (*p=='*')
{
p++;
if (*p=='*')
{
rVector.push_back('*');
}
else
{
char c=*(p+1);
for (int m=*p; m>0; m--)
{
rVector.push_back(c);
}
p++;
}
}
else
{
rVector.push_back(*p);
}
p++;
}
size2=rVector.size();
w=new char [size2];
for (n=0; n<size2; n++)
w[n]=rVector.at(n);
}Top
13 楼kabob(kk.Chen)回复于 2001-06-01 12:09:00 得分 0
kevin的网名就有个狂字 哈哈Top
14 楼Kevin_qing()回复于 2001-06-01 12:14:00 得分 0
/20Top




