資源簡介
純c語言實現bmp圖像的雙線性插值放大,最近鄰插值放大,

代碼片段和文件信息
#include“bmp_geotry.h“
void?BmpRead(Bitmap*bmpconst?char?*str)
{???
FILE*fp=NULL;
if((fp=fopen(str“r“))==NULL)
{
printf(“can?not?open?the?image“);
return?;
}
ULONG?width=0height=0line_width=0off_bits=0;
USHORT?bit_count=0pal_length=0;
fseek(fp100);
fread(&off_bits41fp);
fseek(fp180);
fread(&width41fp);
fread(&height41fp);
fseek(fp280);
fread(&bit_count21fp);
//調色板數據讀取
pal_length=off_bits-54;
if(bit_count==8)
{
bmp->palette=(PUCHAR)malloc(pal_length*sizeof(UCHAR));
if(!bmp->palette)
printf(“palette?have?no?memeory“);
}
else?
{
bmp->palette=0;
}
if(bmp->palette)
{
fseek(fp540);
fread(bmp->palettepal_length1fp);
}
line_width=(width*bit_count+31)/32*4;
//將圖像文件的數據存到bmp結構體中
bmp->line_width=line_width;
bmp->width=width;
bmp->height=height;
bmp->bit_count=bit_count;
bmp->pal_length=pal_length;
bmp->ptr=(PUCHAR)malloc(line_width*height*sizeof(UCHAR));
if(!bmp->ptr)
{
printf(“can?not?allocnate?for?the?bitmap.\n“);
bmp->width=0;
bmp->bit_count=0;
bmp->height=0;
}
fseek(fpoff_bits0);
fread(bmp->ptrline_width*height1fp);
printf(“Bitmap?Width?:%ld\n“bmp->width);
????printf(“Bitmap?Heigh?:%ld\n“bmp->height);
????printf(“Bitmap?BitCount:%d\n“bmp->bit_count);
}
void?BmpSaved(const?char?*strBitmap?bmp)
{
FILE*fp=NULL;
ULONG?dw=0;
USHORT?w=0;
if((fp=fopen(str“wb“))==NULL)
{
printf(“fail?to?save“);
}
?w=19778;
??fwrite(&w21fp);
??dw=14;
??fwrite(&dw41fp);
??w=0;
??fwrite(&w21fp);
??fwrite(&w21fp);
??if(bmp.bit_count==8)?dw=1078;
??else?dw=54;
??fwrite(&dw41fp);
??dw=40;
??fwrite(&dw41fp);
??dw=bmp.width;
??fwrite(&dw41fp);
??dw=bmp.height;
??fwrite(&dw41fp);
??w=0;
??fwrite(&w21fp);
??w?=?bmp.bit_count;
??fwrite(?&w?2?1?fp?);//寫入位數
??dw?=?0;
??fwrite(?&dw?4?1?fp?);
??dw?=?bmp.height?*?(?bmp.width?*?bmp.bit_count?+?31?)?/?32?*?4;//求出像素區的大小
??fwrite(?&dw?4?1?fp?);//寫入像素區的大小的值
??dw?=?0;
??fwrite(?&dw?4?1?fp?);
??fwrite(?&dw?4?1?fp?);
??fwrite(?&dw?4?1?fp?);
??fwrite(?&dw?4?1fp?);
??if(?bmp.palette?!=?0?)
{
????fwrite(?bmp.palette?1024?1?fp?);
}
??dw?=?bmp.height?*?(?bmp.width?*?bmp.bit_count?+?31?)?/?32?*?4;
??fwrite(?bmp.ptr?dw?1?fp?);//寫入圖像部分
??fclose(fp);
}
void?BilinearStretch(Bitmap?bmpdouble?Scaleconst?char?*str)
{????
//為變換后的圖像申請內存
ULONG?dwidth=(ULONG)(bmp.width*Scale);
ULONG?dheight=(ULONG)(bmp.height*Scale);
ULONG?line_width=(dwidth*bmp.bit_count+31)/32*4;
long?sum=dheight*line_width;
PUCHAR?dst=(PUCHAR)malloc(sum*Scale*Scale*sizeof(UCHAR));
double?ratio=1/Scale;//反向映射比列
int?xy?ij;//循環變量
double?tmpxtmpy;
double?uv;
double?final;
UCHAR?color[2][2];
int?nPos=0;
if(Scale<0)?return;
if(Scale==1)
{
??BmpSaved(str?bmp);
??return;
}
???
for(j=0;j for(i=0;i {
tmpx=i*ratio;
tmpy=j*
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-05-30?14:29??graphics\
?????目錄???????????0??2013-05-29?13:54??graphics\Debug\
?????文件???????33792??2013-05-30?10:52??graphics\Debug\graphics.exe
?????文件??????375216??2013-05-30?10:52??graphics\Debug\graphics.ilk
?????文件??????560128??2013-05-30?10:52??graphics\Debug\graphics.pdb
?????目錄???????????0??2013-05-30?10:26??graphics\graphics\
?????目錄???????????0??2013-05-30?10:52??graphics\graphics\Debug\
?????文件???????14528??2013-05-30?10:52??graphics\graphics\Debug\CL.read.1.tlog
?????文件????????1286??2013-05-30?10:52??graphics\graphics\Debug\CL.write.1.tlog
?????文件???????20458??2013-05-30?10:51??graphics\graphics\Debug\bmp_geotry.obj
?????文件????????1958??2013-05-30?10:52??graphics\graphics\Debug\cl.command.1.tlog
?????文件?????????406??2013-05-09?20:50??graphics\graphics\Debug\graphics.exe.em
?????文件?????????472??2013-05-09?20:50??graphics\graphics\Debug\graphics.exe.em
?????文件?????????381??2013-05-30?10:52??graphics\graphics\Debug\graphics.exe.intermediate.manifest
?????文件??????????54??2013-05-30?10:52??graphics\graphics\Debug\graphics.lastbuildstate
?????文件????????2050??2013-05-30?10:52??graphics\graphics\Debug\graphics.log
?????文件?????????206??2013-05-09?20:50??graphics\graphics\Debug\graphics_manifest.rc
?????文件???????19731??2013-05-09?20:50??graphics\graphics\Debug\graphics_outtext.obj
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
?????文件???????????2??2013-05-30?10:52??graphics\graphics\Debug\li
............此處省略28個文件信息
- 上一篇:canny邊緣檢測的c語言實現
- 下一篇:英語詞典數據結構課設
評論
共有 條評論