473,671 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arrays getting disfigured automatically!

Hi, i've been trying to create a program for implementing high/low
pass filters on images. I get the data from a 24 bit .bmp file using
the old file handling techniques. The file handling portion of my
program works like a breeze, it is the arrays that are giving me the
problem.

My I/P file:4*4 pixel 24 bit bmp

I've added the output as well at the end to show the difference in
array contents in the start an at the beginning.

I'm really confused as to why the contents of the array are changing ?

PS:I am not doing any processing on the image yet, just trying to get
the pixel color intensities into the array c and use this to output
the pixel intensities to the new file.

code:

#include <conio.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main() {

FILE *fp1,*fp2;
int a,h=0,w=0,t=0;
int j=0,i=0;
//clrscr();

fp1=fopen("rd.b mp","rb");
fp2=fopen("rd2. bmp","wb");
for (i=0;i<54;i++) {
a=getc(fp1);
putc(a,fp2);

if(i>=18&&i<22)
w+=int(a*(pow(2 56,(i-18))));
if(i>=22&&i<26)
h+=int(a*(pow(2 56,(i-22))));

}
cout<<endl<<"Pi xels to process: "<<h<<" "<<w<<endl;
cout<<"Original image"<<endl;
int *c = new int[w*h*3];
//int c[48]={0};
for (i=0;i<h;i++) {
for (j=0;j<w;j++) {
t=0;
a=getc(fp1);
t+=a;
c[i*w+j]=(int)a;
cout<<c[i*w+j]<<" ";
a=getc(fp1);
t+=a;
c[i*w+j+1]=(int)a;
cout<<c[i*w+j+1]<<" ";
a=getc(fp1);
t=(t+a)/3;
c[i*w+j+2]=(int)a;
cout<<c[i*w+j+2]<<" ";
if(a==-1) break;
}

cout<<endl;
if(a==-1) {
cout<<endl<<"Br eaking..."<<i<< " "<<j; break ;
}
}

cout<<endl<<"Pr ocessed pixels : "<<i<<" "<<j<<endl;
cout<<endl;
int cn=0;

while((a=getc(f p1))!=-1) {
cout<<" "<<a;
cn++;
}
cout<<endl<<"Pi xels not proc : "<<cn/3<<endl;

for (i=0;i<h;i++) {
for (j=0;j<w;j++) {

cout<<c[i*w+j]<<" "<<c[i*w+j+1]<<" "<<c[i*w+j
+2]<<" ";
t=(c[i*w+j]+c[i*w+j+1]+c[i*w+j+2])/3;

putc(t,fp2);
putc(t,fp2);
putc(t,fp2);
}
cout<<endl;
}

Output :

Pixels to process: 4
4
Original
image
0 0 0 255 255 255 0 0 255 255 255
255
255 255 255 255 255 255 255 255 255 255 255
255
255 255 255 255 255 255 255 255 255 255 255
255
255 255 255 255 255 255 255 255 255 255 255
255

Processed pixels : 4
4
Pixels not proc :
0
0 255 0 255 0 255 0 255 255 255 255
255
255 255 255 255 255 255 255 255 255 255 255
255
255 255 255 255 255 255 255 255 255 255 255
255
255 255 255 255 255 255 255 255 255 255 255 255

Thanks
fclose(fp1);
fclose(fp2);
getch();
return 0;
}

Oct 8 '07 #1
2 1316
Code got messed up last time. Modified it...
New code:

#include <conio.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main() {

FILE *fp1,*fp2;
int a,h=0,w=0,t=0;
int j=0,i=0;
//clrscr();

fp1=fopen("rd.b mp","rb");
fp2=fopen("rd2. bmp","wb");

for (i=0;i<54;i++) {
a=getc(fp1);
putc(a,fp2);

if(i>=18&&i<22)
w+=int(a*(pow(2 56,(i-18))));
if(i>=22&&i<26)
h+=int(a*(pow(2 56,(i-22))));

}

cout<<endl<<"Pi xels to process: "<<h<<" "<<w<<endl;
cout<<"Original image"<<endl;
int *c = new int[w*h*3];
//int c[48]={0};

for (i=0;i<h;i++) {
for (j=0;j<w;j++) {
t=0;
a=getc(fp1);
t+=a;
c[i*w+j]=(int)a;
cout<<c[i*w+j]<<" ";
a=getc(fp1);
t+=a;
c[i*w+j+1]=(int)a;
cout<<c[i*w+j+1]<<" ";
a=getc(fp1);
t=(t+a)/3;
c[i*w+j+2]=(int)a;
cout<<c[i*w+j+2]<<" ";
if(a==-1) break;
}

cout<<endl;
if(a==-1) {
cout<<endl<<"Br eaking..."<<i<< " "<<j; break ;
}
}

cout<<endl<<"Pr ocessed pixels : "<<i<<" "<<j<<endl;
cout<<endl;
int cn=0;

while((a=getc(f p1))!=-1) {
cout<<" "<<a;
cn++;
}
cout<<endl<<"Pi xels not proc : "<<cn/3<<endl;

for (i=0;i<h;i++) {
for (j=0;j<w;j++) {

cout<<c[i*w+j]<<" "<<c[i*w+j+1]<<" "<<c[i*w+j
+2]<<" ";
t=(c[i*w+j]+c[i*w+j+1]+c[i*w+j+2])/3;

putc(t,fp2);
putc(t,fp2);
putc(t,fp2);
}
cout<<endl;
}
fclose(fp1);
fclose(fp2);
getch();
return 0;

}
Oct 8 '07 #2
On Oct 8, 9:14 am, rgh...@gmail.co m wrote:
if(i>=18&&i<22)
w+=int(a*(pow(2 56,(i-18))));
if(i>=22&&i<26)
h+=int(a*(pow(2 56,(i-22))));
You really don't want to be using pow here; use <<
instead.

Oct 8 '07 #3

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

Similar topics

2
5096
by: Jason | last post by:
I have a number of arrays that are populated with database values. I need to determine which array has the highest ubound out of all the arrays. The array size will always change based on the database record. Therefore, I need to be able to throw the arrays into a function that will automatically determine the highest ubound array. I was wondering if anyone might have a clean function that can do this. I have created a function that...
19
2840
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type > >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type > >array-of-size-N-of-type-T (with some exceptions, which is curious). > > So far > >the consensus seems to be that while everyone is aware of this no one knows
46
4682
by: Blue Ocean | last post by:
How do I do it? I'm doing a practice problem which includes me implementing a set of ints as a class. I don't want to use vector because that would be cheating. ;) I don't want to spend enough time on it to make it a treeset, so I'm just gonna do an array set. It's gonna have a static const int default size, and it's going to have a member private int threshold. Once the size of the set passes the threshold, the next call to any...
21
3923
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to "browse" it). So I expected that when I run this program, I get both c1.A and c2.A pointing to the same address, and changing c1.A means that also c2.A changes too. ----- BEGIN example CODE -----------
79
3391
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The Shocking Truth: C Arrays and Pointers Are NOT the Same! 9: More about Arrays 10: More about Pointers What blows me out of the water is the fact that 'every' programmer
10
3156
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences in levels of indirection, so I feel it must have something to do with the way I am representing the array in the call and the return. Below I have commented the problem parts. Thanks in advance for any help offered. Pete
10
4984
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I get an error: ---------------- An unhandled exception of type 'System.NullReferenceException' occured in
16
3485
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
9
1799
by: Oliver Graeser | last post by:
Hi All, I do some ensemble averaging calculation that requires me to accumulate very many distributions which I store in arrays. Basically something like class AdaptiveNW{ public: int** getDegreeDistribution(); ....... }
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.