Help explaining syntax and code

Hi,
I found some code in a book on digital image processing and I am hoping you can help explain what each part of the code does.

I have attached the "zoom" part of teh program, and then the structure of the "image" part of the code as well. Thanks,

Dennis
Zoom.jpg
Image.jpg
datopdogg7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DanRollinsCommented:
The zoom() fn looks at each pixel in the source (input) and outputs a block of four identically-colored pixels to the destination (output) image.


source bitmap:
XXX
XoX
XXX
destination after zoom:
XXXXXX
XXXXXX
XXooXX
XXooXX
XXXXXX
XXXXXX
 
 
source bitmap:
oXX
XoX
XXo
 
destination after zoom:
ooXXXX
ooXXXX
XXooXX
XXooXX
XXXXoo
XXXXoo

Open in new window

0
datopdogg7Author Commented:
Sorry I should have been more specific, I know what the code does (as I got it from a book), but I don't understand the code line by line.
0
Infinity08Commented:
What's your level of experience with C ?
Are there any parts you do understand ? If so, can you point out the parts that you don't understand ?
0
DanRollinsCommented:
In the first loop, i and j are your y (vertical) and x (horizontal) coordinates, respectively.
The loop plugs those values into the idx macro.
The idx macro is accessing Im, which is, I presume, an instance of the Image structure.
Pixels (image data) are layed out in rows and columns. To access the pixel at row X and column Y, you multiply Y times the row value and add the column value. For instance, an image like this:
    oXXX // each row is 4 wide
    oXXX
    XoXX
is in memory like this
    oXXXoXXXXoXX
so, for instance, to get the highlighted o in the third line, you know its (X,Y) is (1,2) because numbering begins with 0. The formula from the macro multiplies Y times the width of each line (Im->Cols) and adds X. In the example above, that is:    Y*cols_per_row +X
    (2*4) + 1 = 9
If you count over nine from the left in the "in memory" data, you will be accessing the desired pixel (the highlighted o).
Finally the program loops through the entire Im structure array, and outputs four pixels to the Out structure array.
That's all there is too it.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.