一个惊人的问题......
很抱歉再次打扰你的代码相同.....但另一个
出现了令人惊讶的问题....请帮助我....
#include< stdio.h>
#include< stdlib.h>
#include< dos.h>
#include < mem.h>
#include< string.h>
#include< conio.h>
#include< fcntl.h>
#include< io.h>
#include< math.h>
unsigned char r [360],mini,mode;
unsigned char rgb [256] [3],rgb2 [256] [3],** rgb1,t;
char * fullname;
char * fname;
int hist [256],tmp = 0,sum = 0;
unsigned int screen_width = 320 ;
unsigned int first_row = 0,first_column = 0,last_row = 0,last_column = 0;
int handle,i,j,rem,color_bits;
long int
file_size,data_offset,size_info_header,width,heigh t,compression,
image_size,xpelspermeter,ypelspermeter,colorsused,k,colorsimpt ,p,索引,米ax,min,** sum_hist;
浮动theta,temp;
void drawdot(int x,int y,int pal_index){
_AX = pal_index;
_CX = x;
_DX = y;
_AH = 0x0c;
_BH = 0x00;
geninterrupt(0x10);
}
void main(){
得到(fname);
strcpy(fullname,fname); strcat(fullname," .bmp");
handle = _open(fullname,O_RDONLY) ; if(handle == - 1)exit(EXIT_FAILURE);
_read(handle,r,2); if(r [0]!=''B''| r [1]!=''M'')退出(EXIT_FAILURE);
_read(句柄,r,
4); file_size = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_read(handle,r,2); _ read(handle,r,2);
_read(handle,r,
4); data_offset = r [0] + 256 * r [1] + 65536 * r [2] + 0x1000000 * r [3];
_read(handle,r,
4); size_info_header = r [0] + 256 * r [1] + 65536 * r [2] + 0x1000000 * r [3 ];
如果(size_info_header!= 40)退出(EXIT_FAILURE);
_read(handle,r,4); width = r [0] + 0x100 * r [ 1] + 0x10000 * r [2] + 0x1000000 * r [3];
if(width screen_width)exit(0);
_read(handle,r,4 ); height = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_read(handle,r,2); if(r [0]!= 1)退出(EXIT_FAILURE);
_read(句柄,r,2);
color_bits = r [0];
_read(handle,r,4);
compression = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_read(handle,r,4);
image_size = r [0] + 256 * r [1] + 256 * 256 * r [2] + 256 * 256 * 256 * r [3];
_read(handle,r,4);
xpelspermeter = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_read(handle,r,4);
ypelspermeter = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_read(handle,r,4);
colorsused = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_read(handle,r,4) ;
colorsimpt = r [0] + 0x100 * r [1] + 0x10000 * r [2] + 0x1000000 * r [3];
_AX = 0x1201; _BL = 0x33; geninterrupt(0x10); //不添加RGB
_AX = 0x0013; geninterrupt(0x10); //设置模式13即320x200x256
for(i = 0; i< 256; i ++){
_read(handle,r,4);
rgb [i] [0 ] = R [2]>&2; RGB [I] [1] = R [1]>&2; RGB [I] [2] = R [0]>&2;
}
rgb1 = calloc(height,sizeof(char *));
for(i = 0; i< height; i ++)
rgb1 [i] = calloc(width,sizeof(char));
for(i = 0; i< 256; i ++){
rgb2 [i] [0] = i; rgb2 [i] [1] = i; rgb2 [i] [2] = i;
}
_ES = FP_SEG (rgb2); _ DX = FP_OFF(rgb2);
_BX = 0; _CX = 0x100; _AX = 0x1012;
geninterrupt(0x10); //从rgb设置DAC
first_column =(screen_width-width)/ 2;
last_row = first_row + height-1; last_column = first_column + width-1;
rem = 4 - (width%4);
for(i = 0; i< = height-1; i ++){
_read(handle,r,width);
for(j = 0; j< = width-1; j ++ )
{
// drawdot(first_column + j,last_row-i,r [j]);
rgb1 [i] [j ] =(rgb2 [r [j]] [0] + rgb2 [r [j]] [1] + rgb2 [r [j]] [2])/ 3;
// printf (QUOT;%d\\\
",RGB1 [i] [j]); ............................... ..(a)
//延迟(100);
}
if(rem == 1)_read(handle,r, 1);
else if(rem == 2)_read(handle,r,2);
else if(rem == 3)_read(handle,r, 3); // getch();
}
for(i = 0; i< 256; i ++)
{
hist [i] = 0;
}
for(i = 0; i< height; i ++)
{
for(j = 0; j< width; j ++)
{
k =(long int)rgb1 [i] [j];
hist [k] = h ist [k] +1;
}
}
for(i = 0; i< 256; i ++)
{
if(hist [i]!= 0)
tmp ++;
else continue;
}
sum_hist =(long int **)calloc(tmp,sizeof(long int *));
for(i = 0; i< tmp; i ++)
sum_hist [i] =(long int *)calloc(2,sizeof(long int));
for (i = 0; i< 256; i ++)
{
if(hist [i]!= 0)
{
sum_hist [sum] [0] =(long int)i;
sum_hist [sum] [1] =(long int)hist [i];
sum ++;
}
else继续;
}
for(i = 1; i< tmp ; i ++)
sum_hist [i] [1] + = sum_hist [i-1] [1];
min = sum_hist [0] [1];
max = sum_hist [0] [1];
for(i = 1; i< tmp; i ++)
{
if(min> sum_hist [i] [1])
min = sum_hist [i] [1];
else continue;
}
for(i = 1; i< tmp; i ++)
{
if(max< sum_hist [i] [1 ])
max = sum_hist [i] [1];
其他继续;
}
p =((身高*宽度)-min);
for(i = 0; i< height; i ++)............................(b)
{
for(j = 0; width; j ++)
{
printf("%d \ n", rgb1 [i] [j]);
延迟(100);
}
}
for( i = 0; i< height; i ++)
{
for(j = 0; j< width; j ++)
{
t = rgb1 [i] [j];
// printf("%d \ n",t);
//延迟(100);
for(i = 0; i< tmp; i ++)
{
if(sum_hist [i] [0] == t)
index = sum_hist [i] [1];
}
index = index-min;
rgb1 [i] [j] = abs(指数* 255 / p);
// printf("%d%d \ n",t,rgb1 [i] [ j]);
//延迟(100);
}
}
/ * for(i = 0; i< height; i ++)
{
for(j = 0; j< width; j ++)
drawdot(first_column + j,last_row-i,rgb1 [i] [j]);
} * /
_close(句柄);
getch();
_AX = 0x1201; _BL = 0x33; geninterrupt(0x10); //不要添加RGB
_AX = 0x0003; geninterrupt(0x10); //设置模式3即16色文本
}
这里,当我在任何矩阵中分配值时在同一个块中打印值
..正在给出正确的结果...但是如果我尝试
在另一个块中单独打印值...一些垃圾值
正在打印....说forr rgb1 [] [] ....它给出了正确的
值...(a).. bt一些垃圾值在.........
(b).......并且没有代码超出
for(i = 0 ; i< height; i ++)
{
for(j = 0; j< width; j ++)
{
t = rgb1 [i] [j];
// printf("%d \ n",t);
//延迟(100) ;
for(i = 0; i< tmp; i ++)
{
if(sum_hist [i] [0] == t )
index = sum_hist [i] [1];
}
index = index-min;
RGB1 [i] [j] = ABS(指数* 255 / p);
// printf("%d%d \ n",t,rgb1 [i] [j]);
//延迟( 100);
}
}
正在运行.......
plz澄清一次为从前面的讨论....我不知何故
清楚地看到我的问题的解决方案... PLZ整理出来
再一次......
感谢你..
Sorry to bother again u people with the same code.....but another
astonishing problem arising....please help me....
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <mem.h>
#include <string.h>
#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <math.h>
unsigned char r[360],mini,mode;
unsigned char rgb[256][3],rgb2[256][3],**rgb1,t;
char *fullname;
char *fname;
int hist[256],tmp=0,sum=0;
unsigned int screen_width=320;
unsigned int first_row=0,first_column=0,last_row=0,last_column= 0;
int handle,i,j,rem,color_bits;
long int
file_size,data_offset,size_info_header,width,heigh t,compression,
image_size,xpelspermeter,ypelspermeter,colorsused, k,colorsimpt,p,index,max,min,**sum_hist;
float theta,temp;
void drawdot(int x, int y, int pal_index){
_AX=pal_index;
_CX=x;
_DX=y;
_AH=0x0c;
_BH=0x00;
geninterrupt(0x10);
}
void main(){
gets(fname);
strcpy(fullname,fname);strcat(fullname,".bmp");
handle=_open(fullname,O_RDONLY);if (handle==-1) exit(EXIT_FAILURE);
_read(handle,r,2);if (r[0] !=''B'' | r[1] !=''M'') exit(EXIT_FAILURE);
_read(handle,r,
4);file_size=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,2);_read(handle,r,2);
_read(handle,r,
4);data_offset=r[0]+256*r[1]+65536*r[2]+0x1000000*r[3];
_read(handle,r,
4);size_info_header=r[0]+256*r[1]+65536*r[2]+0x1000000*r[3];
if (size_info_header !=40) exit(EXIT_FAILURE);
_read(handle,r,4);width=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
if (width screen_width) exit(0);
_read(handle,r,4);height=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,2);if (r[0] != 1) exit(EXIT_FAILURE);
_read(handle,r,2);
color_bits=r[0];
_read(handle,r,4);
compression=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
image_size=r[0]+256*r[1]+256*256*r[2]+256*256*256*r[3];
_read(handle,r,4);
xpelspermeter=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
ypelspermeter=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
colorsused=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_read(handle,r,4);
colorsimpt=r[0]+0x100*r[1]+0x10000*r[2]+0x1000000*r[3];
_AX=0x1201;_BL=0x33;geninterrupt(0x10);//don''t add RGB
_AX=0x0013;geninterrupt(0x10);//set mode 13 i.e. 320x200x256
for (i=0;i<256;i++) {
_read(handle,r,4);
rgb[i][0]=r[2]>>2;rgb[i][1]=r[1]>>2;rgb[i][2]=r[0]>>2;
}
rgb1=calloc(height,sizeof(char*));
for(i=0;i<height;i++)
rgb1[i]=calloc(width,sizeof(char));
for (i=0;i<256;i++) {
rgb2[i][0]=i;rgb2[i][1]=i;rgb2[i][2]=i;
}
_ES=FP_SEG(rgb2);_DX=FP_OFF(rgb2);
_BX=0;_CX=0x100; _AX=0x1012;
geninterrupt(0x10);//set DAC from rgb
first_column=(screen_width-width)/2;
last_row=first_row+height-1;last_column=first_column+width-1;
rem=4 - (width % 4);
for (i=0;i<=height-1;i++) {
_read(handle,r,width);
for (j=0;j<=width-1;j++)
{
//drawdot(first_column+j,last_row-i,r[j]);
rgb1[i][j]=(rgb2[r[j]][0]+rgb2[r[j]][1]+rgb2[r[j]][2])/3;
//printf("%d\n",rgb1[i][j]);.................................(a)
//delay(100);
}
if (rem==1) _read(handle,r,1);
else if (rem==2) _read(handle,r,2);
else if (rem==3) _read(handle,r,3);//getch();
}
for(i=0;i<256;i++)
{
hist[i]=0;
}
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
k=(long int)rgb1[i][j];
hist[k]=hist[k]+1;
}
}
for(i=0;i<256;i++)
{
if(hist[i]!=0)
tmp++;
else continue;
}
sum_hist=(long int **)calloc(tmp,sizeof(long int*));
for(i=0;i<tmp;i++)
sum_hist[i]=(long int *)calloc(2,sizeof(long int));
for(i=0;i<256;i++)
{
if(hist[i]!=0)
{
sum_hist[sum][0]=(long int)i;
sum_hist[sum][1]=(long int)hist[i];
sum++;
}
else continue;
}
for(i=1;i<tmp;i++)
sum_hist[i][1]+=sum_hist[i-1][1];
min=sum_hist[0][1];
max=sum_hist[0][1];
for(i=1;i<tmp;i++)
{
if(min>sum_hist[i][1])
min=sum_hist[i][1];
else continue;
}
for(i=1;i<tmp;i++)
{
if(max<sum_hist[i][1])
max=sum_hist[i][1];
else continue;
}
p=((height*width)-min);
for(i=0;i<height;i++)............................( b)
{
for(j=0;width;j++)
{
printf("%d\n",rgb1[i][j]);
delay(100);
}
}
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
t=rgb1[i][j];
//printf("%d\n",t);
//delay(100);
for(i=0;i<tmp;i++)
{
if(sum_hist[i][0]==t)
index=sum_hist[i][1];
}
index=index-min;
rgb1[i][j]=abs(index*255/p);
//printf("%d %d\n",t,rgb1[i][j]);
//delay(100);
}
}
/*for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
drawdot(first_column+j,last_row-i,rgb1[i][j]);
}*/
_close(handle);
getch();
_AX=0x1201;_BL=0x33;geninterrupt(0x10);//don''t add RGB
_AX=0x0003;geninterrupt(0x10);//set mode 3 i.e. 16-color text
}
Here, when I am assigning values in any matrix and printing the values
within the same block..it is giving the correct result...but if I try
to print the values separately in another block...some garbage values
are getting printed....say forr rgb1[][]....it is giving correct
values in ..(a)..bt some garbage values are there in .........
(b).......and no code beyond
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
t=rgb1[i][j];
//printf("%d\n",t);
//delay(100);
for(i=0;i<tmp;i++)
{
if(sum_hist[i][0]==t)
index=sum_hist[i][1];
}
index=index-min;
rgb1[i][j]=abs(index*255/p);
//printf("%d %d\n",t,rgb1[i][j]);
//delay(100);
}
}
is running.......
plz clarify once as from the previous discussion....I somehow not
getting a clear view of solutions of my problems...plz sort it out
once again...
thanking you..
biplab写道:
biplab wrote:
很抱歉再次打扰你的代码相同的人......但是
Sorry to bother again u people with the same code.....but
谁是'你的人'?
为什么你不修理你被告知要解决的问题,或者你只是一个无效的巨魔?
- -
Ian Collins。
Who''s "u people"?
Why don''t you fix what you''ve been told to fix, or are you just an
ineffective troll?
--
Ian Collins.
9月14日,9:41 * am,Ian Collins< ian-n ... @ hotmail。 comwrote:
On Sep 14, 9:41*am, Ian Collins <ian-n...@hotmail.comwrote:
biplab写道:
biplab wrote:
很抱歉再次打扰你peo使用相同的代码.....但是
Sorry to bother again u people with the same code.....but
谁是'你的人'?
为什么难道你不修理你被告知要解决的问题,或者你只是一个无效的巨魔?
-
伊恩柯林斯。
Who''s "u people"?
Why don''t you fix what you''ve been told to fix, or are you just an
ineffective troll?
--
Ian Collins.
U people意味着这里的专家......而且我是C的新手.....所以
找到这些提示了一下艰难... PLZ帮助我....
U people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
biplab写道:
biplab wrote:
9月14日,上午9:41,Ian Collins< ian-n ... @ hotmail.comwrote:
On Sep 14, 9:41 am, Ian Collins <ian-n...@hotmail.comwrote:
> biplab写道:
>biplab wrote:
>>很抱歉再次打扰使用相同代码的人.....但是
>>Sorry to bother again u people with the same code.....but
谁是'你的人'?
为什么不修理你被告知要解决的问题,或者你只是一个无效的巨魔?
-
伊恩柯林斯
Who''s "u people"?
Why don''t you fix what you''ve been told to fix, or are you just an
ineffective troll?
--
Ian Collins.
U人意味着这里的专家...而且我是C的新手.....所以
找到这些提示了一下很难... PLZ帮助我....
U people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
提示1 - 不要在txt中发帖宝贝说话。
提示2 - 不要引用签名。
提示3 - 回到原来的帖子,询问
提供的更正。
>
-
Ian Collins。
Tip 1 - don''t post in txt baby speak.
Tip 2 - don''t quote signatures.
Tip 3 - go back to your original post and ask about the corrections that
were offered.
--
Ian Collins.