473,788 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to read a c program

Hi!

I'm not very familiar to C, but I do know a little.
No I'm trying to read someone elses program, and this line (and
simular, less complex lines) realy confuses me. Can someone explain?
I'm not new to the concept of pointers, so I think that I have a fair
chance. :-)

What is this line doing?!?:
srcptr=(MY_PIXE L*)(source->imageData+(t op-j)*source->widthStep)+(le ft-i);

Some header:
#define MY_PIXEL unsigned char
//Only the intresting variabels.
typedef struct _IplImage {
char *imageData; ///< Pointer to aligned image
int widthStep; ///< The size of aligned line in
bytes
...
} IplImage;
int i,j
int left,top;
MY_PIXEL *srcptr;
IplImage *source; // standard Ipl.

best regards,
Andreas Lundgren
Nov 13 '05 #1
1 1790
Andreas wrote:
Hi!

I'm not very familiar to C, but I do know a little.
No I'm trying to read someone elses program, and this line (and
simular, less complex lines) realy confuses me. Can someone explain?
I'm not new to the concept of pointers, so I think that I have a fair
chance. :-)

What is this line doing?!?:
srcptr=(MY_PIXE L*)(source->imageData+(t op-j)*source->widthStep)+(le ft-i);
It's using source->imageData as the start of a 2D array and casting the
entry's address from a pointer to a char to a pointer to an unsigned char,
basically. The arithmetic part is equivalent to:

int x = left - i;
int y = (top - j) * source->widthStep;
source->imageData[x][y];

Or maybe it's [y][x], I always get those confused. In any case, it's
converting a coordinate that's relative to some sub-area of the image
to a coordinate that's relative to the upper-left corner of the entire
image.

Matt Gregory

Some header:
#define MY_PIXEL unsigned char
//Only the intresting variabels.
typedef struct _IplImage {
char *imageData; ///< Pointer to aligned image
int widthStep; ///< The size of aligned line in
bytes
...
} IplImage;
int i,j
int left,top;
MY_PIXEL *srcptr;
IplImage *source; // standard Ipl.

best regards,
Andreas Lundgren


Nov 13 '05 #2

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

Similar topics

5
1850
by: jdh2358 | last post by:
I have a python file that is trying to read raw data from a raw partition on a dying dist, eg f = file('/dev/sda') f.seek(SOMEWHERE) s = f.read(SOMEBYTES) On some blocks, the read succeeds, on others it fails and an IOError is thrown, and on others it appears to hang indefinitely and will not respond to any attempt to kill it with 'kill -9 PID', etc.
8
2092
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is, I've been playing with Qt in KDE on a Slackware 10.0 system, and following their cookbook exercises, and everything's working, and I have no clue what the code is doing, i.e.. how do I connect my brain to the ascii in the files to the stuff on...
4
2497
by: yo_mismo | last post by:
Hi everyone, I'm trying to read the first line of a file this way: .... .... .... .... new_line=0; while((read=read(fd, &info, sizeof(info))) > 0 && !new_line){ if (strcmp(&info, "\n") != 0){
0
7013
by: Taran | last post by:
I am having this issue with both Visual C++ 6.0 and Visual Studio 2005 Beta 2. I have the SDK and DDK installed. I am trying to write a program to retrieve the EDID for a specific monitor in a multi-monitor system. I already know how to get this information from the registry, but I wish to get the EDID from the monitor directly. So far I have been unable to compile my program. The compiler generates over 102 errors and 54 warnings,...
1
1549
by: Ty Moffett | last post by:
I am trying to write a little app that will perform unattended installations of various software packages. I have a text file, each line is a string containing the complete command to start a silent/unattended install. I have successfully read the entire file and each line gets added to the queue. On this line "myProcess.StartInfo.FileName(myQ.Dequeue)" i get an error: C:\Documents and Settings\tmoffett\My Documents\Visual Studio...
5
1887
by: jmsxp | last post by:
Hi all, I am in my infancy with programming, so please forgive stupid questions... I am attempting to write a C# program that will launch Trillian (well, that is just a part of the overall program). I can get the program to start using System.Diagnostics.Process.Start(@"C:\Program Files\Trillian\trillian.exe");
3
2746
by: jdjohns74 | last post by:
I've never written a Python program before and I'm trying to read a config file with file path/names (eg. c:\\python24\\*.dll, ... *.exe) to create an ouput file of filename + md5 values. I'm confused. I'm trying to lern how to use Wing IDE and step through the Stack Data. It seems to be working but on the for fn in filelist: data = file(fn,'rb').read() I get a IOError: (2, 'No such file or directory', 'c') Traceback...
1
1508
by: James Johnston | last post by:
I've never written a Python program before and I'm trying to read a config file with file path/names (eg. c:\\python24\\*.dll, ... *.exe) to create an output file of filename + md5 values. I'm confused. I'm trying to learn how to use Wing IDE and step through the Stack Data. It seems to be working but on the for fn in filelist: data = file(fn,'rb').read() I get a
7
2116
by: JoeC | last post by:
I am trying to create a windows program that reads binary graphics as a resource. This has nothing to do with win32 but conversion of data with memcpy. graphic::graphic(UINT uiResID, HINSTANCE hinstance){ size = 32; bitData.clear(); void * p = NULL; // point to the data int end; BYTE data;
5
1995
by: tedpottel | last post by:
Hi, My program reads as follows import urllib print "-------- Google Web Page --------" print urllib.urlopen('http://www.google.com//').read() print "-------- Google Search Web Page --------"
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10175
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...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7518
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
6750
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
5399
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
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.