| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 752 人关注过本帖
标题:[求助]BMP图像分离程序
取消只看楼主 加入收藏
新男孩
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2007-8-15
收藏
 问题点数:0 回复次数:1 
[求助]BMP图像分离程序
因为工作中要急用到这段程序,可是现在不懂!希望高手可以耐心帮忙看看,整个程序的流程是怎样走的?还有在程序中一些注释到的地方提出了问题,希望可以帮忙解答!若是没有时间能够解决所有问题,就请解答三个“严重不懂”的地方,谢谢!



#include <stdlib.h>

//在VC++6.0中编译总是报致命错误,说是没有这个库函数或找不到它的路径(严重不懂)
#include <graphics.h>

#include <math.h>
#include <dos.h>
#include <stdio.h>
#include <process.h>
#include <bios.h>
#include <conio.h>
#include <malloc.h>
#include <mem.h>

#define Width 640
#define Height 480
unsigned char bin[8] =
{
0x80,0x40,0x20,0x10,
0x08,0x04,0x02,0x01
};
int vga_default[16][3] =
{
0,0,0,
0,0,42,
0,42,0,
0,42,42,
42,0,0,
42,0,42,
42,21,0,
42,42,42,
21,21,21,
21,21,63,
0,63,0,
0,63,63,
63,21,17,
63,19,63,
63,63,0,
63,63,63
};
typedef struct BMP_file
{
unsigned short bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
}bitmapfile;
typedef struct BMP_info
{
unsigned long biSize;
unsigned long biWidth;
unsigned long biHeight;
int biPlanes;
int biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXpelspermeter;
unsigned long biYpelspermeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
}bitmapinfo;

typedef struct RGB_BMP_typ
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}RGB_BMP,*RGB_BMP_ptr;

typedef struct bmp_picture_typ
{
bitmapfile file;
bitmapinfo ifo;
RGB_BMP palette[256];
char far *buffer;
}bmp_picture,*bmp_picture_ptr;

void Check_Bmp(bmp_picture_ptr bmp_ptr)
{
if(bmp_ptr->file.bfType!=0x4d42)
{
printf("Not a BMP file!\n");
exit(1);
}
if(bmp_ptr->info.biCompression!=0)
{
printf("Can not display a compressed bmp file!\n");
exit(1);
}
if(bmp_ptr->info.biBitCount!=8)
{
printf("Not a index 256color bmp file!\n");
exit(1);
}
}

//这个函数是什么功能?
void Set_BMP_Palette_Register(int index,RGB_BMP_ptr color)
{
outportb(0x3c6,0xff);
outportb(0x3c8,index);
outportb(0x3c9,color->red);
outportb(0x3c9,color->green);
outportb(0x3c9,color->blue);
}

void save_bmp()
{
FILE *fp;
FILE *fh;
FILE *fd;
int *bmp256;
int i,j,k,x;
int temp = 0;
long width,height;
int color;
unsigned char tempbuffer[640]; //这个变量什么作用?
bmp_picture pic;

width=Width;height=Height;

fp=fopen("mset.bmp","a+b");
if(fp==NULL)
{
printf("can not open the file!");
exit(1);
};

fd=fopen("msetdata.bmp","w+b");
if(fd==NULL)
{
printf("can not open the filedata!");
exit(1);
}
fseek(fh,0,SEEK_SET);//这个函数在程序中什么功能?

pic.file.bfType = 0x4d42;
pic.file.bfSize = 1078+640*480;
pic.file.Reserved1 = 0;
pic.file.Reserved2 = 0;
pic.file.bfOffset = 1078;

pic.info.biSize = 40;
pic.info.biWidth = 640;
pic.info.biHeight = 480;
pic.info.biPlanes = 1;
pic.info.biBitCount = 8;
pic.info.biCompression = 0;
pic.info.biSizeImage = 640*480;
pic.info.biXpelspermeter = 3780;
pic.info.biYpelspermeter = 3780;
pic.info.biClrUsed = 0;
pic.info.biClrImportant = 0;

fwrite(&pic.file,sizeof(bitmapfile),1,fp);
fwrite(&pic.info,sizeof(bitmapinfo),1,fp);

//此处for循环和fwrite()什么功能?
for(i=0;i<16;i++)
{
pic.palette[i].red = vga_default[i][0]*4;
pic.palette[i].green = vga_default[i][1]*4;
pic.palette[i].blue = vga_default[i][2]*4;
}
fwrite(pic.palette,1,1024,fp);

fseek(fd,0L,SEEK_SET);
pic.buffer = malloc(660);

//此处for循环什么功能?
for(i=479;i>=0;i--)
{
getimage(0,i,639,i,tempbuffer); //这个函数什么作用?(严重不懂)
for(j=0;j<640;j++)
{
//这条语句是什么算法?(严重不懂)
pic.buffer[j] =
(( (tempbuffer[4+j/8]&bin[j%8])/bin[j%8])*0x08)|
(( (tempbuffer[84+j/8]&bin[j%8])/bin[j%8])*0x04)|
(( (tempbuffer[164+j/8]&bin[j%8])/bin[j%8])*0x02)|
(( (tempbuffer[244+j/8]&bin[j%8])/bin[j%8])*0x01);
}

fwrite(pic.buffer,1,640,fd);
}
rewind(fd);
for(i=479;i>=0;i--)
{
fwrite(fd,1,640,fp);
}

fclose(fd);
fclose(fp);
}

void BMP_Delete(bmp_picture_ptr image)
{
free(image->buffer);
}

void mandelbrot(cxmin,cxmax,cymin,cymax,kmax)
float cxmin,cxmax,cymin,cymax;
int kmax;
{
int k,i,j;
float R=4,sx=640,sy=480,r,dx,dy,x0,y0,x,y,x1;
dx = (cxmax-cxmin)/sx;
dy = (cymax-cymin)/sy;

for(i=0;i<sx;i++)
for(j=0;j<sy;j++)
{
x0=cxmin+i*dx;
y0=cymin+j*dy;
x=0;y=0;k=0;
r=x*x+y*y;

while((r<R) && (k<kmax))
{
x1 = x*x-y*y+x0;
y = 2*x*y+y0;
x = x1;
r = x*x+y*y;
k++;
}

if(k<kmax)
putpixel(i,j,k/10+1);
}
}

void main()
{
int driver,mode;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,"");
mandelbrot(-2.25,0.75,-1.5,1.5,100);
if (getch()=='s')
{
printf("The picture is saving now!\n");
save_bmp();
printf("The picture had saving ok!\n");
}

getch();
closegraph();
}
搜索更多相关主题的帖子: BMP include 图像 流程 
2007-08-15 23:28
新男孩
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2007-8-15
收藏
得分:0 
回复:(radcat) 是TC的头文件,找...
从网上找的,最近有工作要用到,所以求助下大家,谢谢你了!
2007-08-16 23:43
快速回复:[求助]BMP图像分离程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026584 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved