-
大小: 4.52MB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-09-18
- 語(yǔ)言: C/C++
- 標(biāo)簽:
資源簡(jiǎn)介
24位圖轉(zhuǎn)化為8位圖的C++代碼,很好用的

代碼片段和文件信息
#include?“StdAfx.h“
#include?“BMPIMAGE.h“
#include?
#include?
BMPIMAGE::BMPIMAGE(void)
{
}
BMPIMAGE::~BMPIMAGE(void)
{
}
//計(jì)算平方差的函數(shù)
int?PFC(int?color1?int?color2)
{
????int?xyz;
????x?=?(color1?&?0xf)?-?(color2?&?0xf);
????y?=?((color1>>4)?&?0xf)?-?((color2>>4)?&?0xf);
????z?=?((color1>>8)?&?0xf)?-?((color2>>8)?&?0xf);
????return?(x*x?+?y*y?+?z*z);
};
//直接插入排序
int?Sort1(int?*src?int?*attach?int?n)
{
????int?cur?cur1;
????int?ijk=0;
????for?(i?=?1;?i?????{
????????cur?????=?src[i];
????????cur1?=?attach[i];
????????for?(j?=?i?-?1;?j?>=?0;?j--)
????????{
????????????if?(cur?>?src[j])
????????????{
????????????????src[j+1]????=?src[j];
????????????????attach[j+1]?=?attach[j];
????????????}
????????????else
????????????????break;
????????}
????????src[j+1]??=?cur;
????????attach[j+1]?=?cur1;
????}
????return?0;
}
//快速排序
int?Sort2(int?*src?int?*attach?int?n)
{
????if?(n?<=?12)
????????return?Sort1(src?attach?n);
????int?low?=?1?high?=?n?-?1;
????int?tmp;
????while?(low?<=?high)
????{
????????while?(src[low]?>=?src[0])
????????{
????????????if?(++low?>?n?-?1)
????????????????break;
????????}
????????while?(src[high]?????????{
????????????if?(--high?1)
????????????????break;
????????}
????????if?(low?>?high)
????????????break;
????????{
????????????tmp????????????????=?src[low];
????????????src[low]????????=?src[high];
????????????src[high]????????=?tmp;
????????????tmp????????????????=?attach[low];
????????????attach[low]????????=?attach[high];
????????????attach[high]????=?tmp;
????????}
????????low++;
????????high--;
????}
????
????{
????????tmp????????????????=?src[low?-?1];
????????src[low?-?1]????=?src[0];
????????src[0]????????????=?tmp;
????????tmp????????????????=?attach[low?-?1];
????????attach[low?-?1]????=?attach[0];
????????attach[0]????????=?tmp;
????}
????if?(low?>?1)
????????Sort2(src?attach?low?-?1);
????if?(low?????????Sort2(&src[low]?&attach[low]?n?-?low);
????return?0;
}
//將24bit的象素顏色數(shù)據(jù)轉(zhuǎn)換為256色圖的圖像數(shù)據(jù)(即索引值)
int?Transfer(WORD?*color24bit?int?len?BYTE?*Index?RGBMixPlate?*mainColor)
{
????int?usedTimes[4096]?=?{0};
????int?miniColor[4096];
????for?(int?i?=?0;?i?4096;?i++)
????????miniColor[i]?=?i;
????int?i?=?0;
????for?(i?=?0;?i?????{
????????assert(color24bit[i]?4096);
????????usedTimes[color24bit[i]]++;
????}
????int?numberOfColors?=?0;
????for?(i?=?0;?i?4096;?i++)
????{
????????if?(usedTimes[i]?>?0)
????????????numberOfColors++;
????}
????//對(duì)usedTimes進(jìn)行排序,排序過程中minColor數(shù)組(保存了顏色值)也作與useTimes
????//數(shù)組相似的交換
????Sort2(usedTimes?miniColor?4096);
????//usedTimes數(shù)組中是各顏色使用頻率,從高到低排列,顯然第numberOfColor個(gè)之后的都為0
????//miniColor數(shù)組中是相應(yīng)的顏色數(shù)據(jù)
????//將前256個(gè)顏色數(shù)據(jù)保存到256色位圖的調(diào)色盤中
????for?(i?=?0;?i?256;?i++)
????{
????????mainColor[i].rgbBlue????=?(BYTE)((miniColor[i]>>8)<<4);
????????mainColor[i].rgbGreen????=?(BYTE)(((miniColor[i]>
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-09-07?17:08??TestImage24depthto8\
?????目錄???????????0??2015-09-07?15:17??TestImage24depthto8\Debug\
?????文件???????35328??2015-09-07?15:24??TestImage24depthto8\Debug\TestImage24depthto8.exe
?????文件??????363084??2015-09-07?15:24??TestImage24depthto8\Debug\TestImage24depthto8.ilk
?????文件??????510976??2015-09-07?15:24??TestImage24depthto8\Debug\TestImage24depthto8.pdb
?????目錄???????????0??2015-09-07?15:25??TestImage24depthto8\TestImage24depthto8\
?????目錄???????????0??2015-09-07?15:21??TestImage24depthto8\TestImage24depthto8\11\
?????文件?????2359350??2015-09-07?15:21??TestImage24depthto8\TestImage24depthto8\11\Desert24.bmp
?????文件????????4399??2015-09-07?15:09??TestImage24depthto8\TestImage24depthto8\BMPIMAGE.cpp
?????文件????????3929??2015-09-07?15:09??TestImage24depthto8\TestImage24depthto8\BMPIMAGE.h
?????目錄???????????0??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\
?????文件???????11787??2015-09-07?15:09??TestImage24depthto8\TestImage24depthto8\Debug\BMPIMAGE.obj
?????文件????????4892??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\CL.read.1.tlog
?????文件????????2216??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\CL.write.1.tlog
?????文件?????????406??2015-09-07?15:04??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.exe.em
?????文件?????????472??2015-09-07?15:04??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.exe.em
?????文件?????????381??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.exe.intermediate.manifest
?????文件??????????71??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.lastbuildstate
?????文件????????3259??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.log
?????文件???????15076??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.obj
?????文件?????1179648??2015-09-07?15:04??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8.pch
?????文件?????????228??2015-09-07?15:04??TestImage24depthto8\TestImage24depthto8\Debug\TestImage24depthto8_manifest.rc
?????文件????????2528??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\cl.command.1.tlog
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
?????文件???????????2??2015-09-07?15:24??TestImage24depthto8\TestImage24depthto8\Debug\li
............此處省略30個(gè)文件信息
評(píng)論
共有 條評(píng)論