资源简介

纯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.embed.manifest
     文件         472  2013-05-09 20:50  graphics\graphics\Debug\graphics.exe.embed.manifest.res
     文件         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\link-cvtres.read.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link-cvtres.write.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3368-cvtres.read.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3368-cvtres.write.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3368.read.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3368.write.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3944-cvtres.read.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3944-cvtres.write.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3944.read.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.3944.write.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.5956-cvtres.read.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.5956-cvtres.write.1.tlog
     文件           2  2013-05-30 10:52  graphics\graphics\Debug\link.5956.read.1.tlog
............此处省略28个文件信息

评论

共有 条评论