bmp图象rle无损压缩,求函数

liudashao 2008-09-05 04:26:11
#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;
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( pData, 1, 9608, fp );
fclose( fp );

}
void main()
{
//cout<<"压缩图片成功!"<<endl;
unsigned char pRGB[320*240/8+8];
FILE * fpf = fopen("test.bin","rb");
if (!fpf) return;
fread(pRGB,1,9608,fpf);
Snapshot((BYTE* )pRGB,"C:\\testt.bmp");
//fclose(fpf);
}



这是我的程序能否帮写个rle无损压缩函数把test.bin压缩了.然后改动相映的头,
压缩后的图还能显示出来可以的话,把邮箱给我我把test.bin文件给你发过去
...全文
244 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liudashao 2008-09-11
  • 打赏
  • 举报
回复
BI_RLE4算法:
比如:00 00 00 00 00 06 07 08 09 00 04 45 34 23 45 08 09 09 00 05 05 05 05 05 00 01
这样的一串数据,用BI_RLE4的编码方式算法压缩
压缩后的结果是什么:?
liudashao 2008-09-08
  • 打赏
  • 举报
回复
顶啊
牛人帮我解决啊
liudashao 2008-09-06
  • 打赏
  • 举报
回复
自己顶一下

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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