bmp图象rle无损压缩,求函数
#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文件给你发过去