91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.68MB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-08-11
  • 語言: 其他
  • 標(biāo)簽: 哈夫曼??BMP??費(fèi)諾??

資源簡介

實(shí)現(xiàn)了對一幅BMP格式的圖像進(jìn)行二元霍夫曼編碼和譯碼。 對一幅BMP格式的圖像進(jìn)行二元Fano編碼、譯碼。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include?
#include
#include?
#include?
#include?

using?namespace?std;
unsigned?char*?pBmpBuf; //image?read?pointer
int bmpWidth; //bmpwidth
int bmpHeight; //bmpheight
int BibitCount; //bits?per?pixel
RGBQUAD*?pColorTable; //palette?pointer
BITMAPFILEHEADER*?filehead;
BITMAPINFOHEADER*?infohead;
char?str[100]; //image?file?name/path
int?lineByte; //bits?per?row
int?k; //huffman?point
//build?the?struct?for?Huffman?coding
struct?node
{
short?lson?=?-1;
short?rson?=?-1;
short?num?=?0;
short?parent?=?-1;
int?frequency?=?0;
string??coded;
};
node?anode[2?*?256?-?1];
//get?scale?map??information
bool?readBmp(char*?bmpname)?{
FILE*?fp?=?fopen(bmpname?“rb“);
if?(fp?==?0)
{
cout?< return?false;
}
//skip?file?header
fseek(fp?sizeof(BITMAPFILEHEADER)?0);
//read?the?bitmap?information?header
infohead?=?new?BITMAPINFOHEADER;
fread(infohead?sizeof(BITMAPINFOHEADER)?1?fp);
bmpHeight?=?infohead->biHeight;
bmpWidth?=?infohead->biWidth;
BibitCount?=?infohead->biBitCount;
lineByte?=?ceil(bmpWidth?*?BibitCount?/?8?+?3)?/?4?*?4;
//read?the?palette
if?(BibitCount?==?8)
{
pColorTable?=?new?RGBQUAD[256];
fread(pColorTable?sizeof(RGBQUAD)?256?fp);
}
cout?< //Read?pixel?encoding
int?n;
n?=?lineByte?*?bmpHeight;
pBmpBuf?=?new?unsigned?char[n];
fread(pBmpBuf?1?n?fp);
fclose(fp);
cout?< return?true;
}
//provide?a?sort?and?huffmam?method
bool?complare(node??&anode?node?&b)?{
return?anode.frequency?>?b.frequency;
}
//Traverses?the?image?pixels?that?the?pointer?points?
bool?sortnode(unsigned?char?*pBmpBufnode?anode[])
{
for?(int?i?=?0;?i?<=?255;?i++)
{
anode[i].num?=?i;
}
for?(int?i?=?0;?i? {
anode[int(pBmpBuf[i])].frequency++;
}
sort(anodeanode+256complare);
cout?< return?true;
}
//find?the?two?points?with?the?least?weight?to?construct?Huffman
int?selectmin(int?aint?k)?{
for?(int?i?=?0;?i? {
if?(anode[i].parent?==?-1)?{
a?=?i;
break;
}
}
for?(int?i?=?0;?i? {
if?(anode[i].parent?==?-1?&&??anode[a].frequency?>?anode[i].frequency?)
{
a?=?i;
}
}
anode[a].parent?=?-2;
return?a;
}
//construct?Huffmam
bool?huffman(node?anode[])?{
for?(k?=?256;?k? {
int?a?=?0;
int?b?=?0;
a?=?selectmin(a?k?-?256);
b?=?selectmin(b?k?-?256);
anode[k].frequency?=?anode[a].frequency?+?anode[b].frequency;
anode[a].parent?=?k;
anode[b].parent?=?k;
anode[k].lson?=?a;
anode[k].rson?=?b;
}
return?true?;
}
string?Coded[256];
//code?the?pixel?by?Huffman
bool?coding(node?anode[]string?Coded[])?{
for?(int?i?=?0;?i? {
in

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件????1756088??2019-05-25?22:41??哈夫曼編碼bmp圖像,費(fèi)諾編碼bmp圖像.docx

?????文件??????11246??2019-05-25?22:30??readbmp.cpp

-----------?---------??----------?-----??----

??????????????1767334????????????????????2


評論

共有 條評論