求rle压缩函数

liudashao 2008-08-25 01:48:56
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef unsigned short WORD;
#include <pshpack2.h>
typedef struct {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BMPFILEHEADER_T;

struct BMPFILEHEADER_S{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
};

typedef struct{
DWORD biSize;
DWORD biWidth;
DWORD biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
DWORD biXPelsPerMeter;
DWORD biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BMPINFOHEADER_T;
unsigned char array[8]={0,0,0,0,0xff,0xff,0xff,0};
void Snapshot( BYTE * pData, char * filename )
{
int width=320;
int height=240;
int size = width*height/8;
BMPFILEHEADER_T bfh;
bfh.bfType = 0x4d42;
bfh.bfSize = size + sizeof( BMPFILEHEADER_T ) + sizeof( BMPINFOHEADER_T )+8;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = bfh.bfSize - size;

BMPINFOHEADER_T bih;
bih.biSize = sizeof(BMPINFOHEADER_T);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount =1;
bih.biCompression = 0; /*******************/
bih.biSizeImage = size;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;

FILE * fp = fopen( filename,"wb");
if( !fp ) return;

fwrite( &bfh, 1, sizeof(BMPFILEHEADER_T), fp);
fwrite( &bih, 1, sizeof(BMPINFOHEADER_T), fp);
fwrite( array, 1, 8,fp);
fwrite( pData, 1, size, fp );
fclose( fp );

}
void main()
{

unsigned char pRGB[320*240/8];
FILE * fpf = fopen("keyima.bin","rb");
if (!fpf) return;
fread(pRGB,1,9600,fpf);
Snapshot((BYTE* )pRGB,"C:\\test.bmp" );
}


上面的程序
哪位大哥能帮我写个rle无损压缩的函数,把上面的位图压缩小点
急求谢谢了,分不够的话可以追加,急要这个压缩函数,帮帮忙啊大哥大姐们!

...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liudashao 2008-08-28
  • 打赏
  • 举报
回复
谢谢各位了
_石头_ 2008-08-27
  • 打赏
  • 举报
回复
爱莫能助阿!帮顶一下!
wangdeqie 2008-08-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 liudashao 的回复:]
求求各位帮帮忙啊
[/Quote]
很想帮你,可惜偶对压缩算法也没啥研究,看看这个http://www.cnblogs.com/jillzhang/archive/2006/11/06/551298.html
liudashao 2008-08-27
  • 打赏
  • 举报
回复
求求各位帮帮忙啊

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧