473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

An astonoshing problem...

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..
Sep 14 '08 #1
10 1673
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.
Sep 14 '08 #2
On Sep 14, 9:41*am, Ian Collins <ian-n...@hotmail.comwrote:
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 people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
Sep 14 '08 #3
biplab wrote:
On Sep 14, 9:41 am, Ian Collins <ian-n...@hotmail.comwrote:
>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 people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
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.
Sep 14 '08 #4
On Sat, 13 Sep 2008 21:55:09 -0700 (PDT), biplab <ge*******@gmail.com>
wrote:
>U people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
Being new to C is no excuse for posting the same code repeatedly under
different subjects and ignoring the corrections you have already
received. If you want help, play nice. If not, many will choose to
ignore you.

--
Remove del for email
Sep 14 '08 #5
biplab <ge*******@gmail.comwrites:
On Sep 14, 9:41*am, Ian Collins <ian-n...@hotmail.comwrote:
>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?

U people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
We're trying to help. If you continue to post the same code while
ignoring the good advice you're given, we *can't* help.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 14 '08 #6
On 14 Sep, 05:32, biplab <getbip...@gmail.comwrote:
Sorry to bother again u people with the same code.....but another
astonishing problem arising....please help me....
<snip>
char *fname;
<snip>
>
void main(){

* * * * gets(fname);


Ben Bacarisse pointed this out in a previous thread with
the same example code that you are doing. Since you
call gets with an uninitialized parameter, nothing
after this line needs to be looked at. Fix
this, clean up your code so that it is readable,
and then maybe people will bother looking at it.
People here are willing to help, but they're not
going to do your work for you.

BTW, don't use gets at all. And you
probably should consider passing the filename
as a parameter rather than reading it from
stdin. That is much more conventional.
Sep 14 '08 #7
biplab wrote:
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>
[...]

My advice is to first break up the code into separate functions, where
each function has a clearly defined purpose, and then test each function
independently.

The article "Program Development by Stepwise Refinement" by Niklaus
Wirth might also be of interest:

http://sunnyday.mit.edu/16.355/wirth-refinement.html
August
Sep 14 '08 #8
biplab wrote:
On Sep 14, 9:41 am, Ian Collins <ian-n...@hotmail.comwrote:
>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 people means the experts here...And I am new to C.....therefore
finding these tips a bit tough...plz help me out....
People have tried to give you help, giving you tips about things that
need to be fixed. If you really want help, why are you ignoring the help
you've already received?
Sep 14 '08 #9
biplab wrote:
>
Sorry to bother again u people with the same code.....but another
astonishing problem arising....please help me....
Why? You paid no attention to the earlier help given.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Sep 14 '08 #10
biplab wrote:
>
for(i=0;i<height;i++)............................( b)
{
for(j=0;width;j++)
{
printf("%d\n",rgb1[i][j]);
delay(100);
}
}
....
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
I guess that the inner loop in (b) is printing a __lot__ more than it
really should *cough* infinite loop *cough* :)

But you should seriously listen to what the people in this news group
are trying to tell you!
Sep 15 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.