Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PPM Parser

Name: Anonymous 2012-09-22 14:36

I try hard to avoid asking for help here, but I just can't figure this shit out.

I need to write a PPM Parser for a CS class and I am having trouble writing the image data.

It seems to read it fine, but when I write a file it writes the image 3 times on the top row.

Here is the code:
http://pastebin.com/seEp9wnU

I left out the header file.

Here is the output
http://i.imgur.com/dr7wK.jpg

Thanks for any help.

Name: Anonymous 2012-09-22 14:40

anal cunt

Name: Anonymous 2012-09-22 15:26

>>1

You should improve the implementation by including the color channel
as a third dimension in the array. Then you don't need to store
width*length pointers and width*length 3 element arrays on the heap.

I don't normally help with solve my bug threads, but image related
bugs always produce such interesting and puzzling results. They
are actually fun to think about.

Check out your write routine. If it is printing a three color
channel PPM, it should print three colors for each pixel. Does it
do that?

[spoiler]
These are actually spoilers

Why are the sub images mostly gray? Only the first color
channel is being printed. This causes three adjacent pixels to be
combined in a single three color pixel. Because most pixels that
are next to each other are close in color intensities, the result
is a mostly gray image.
But colored artifacts can be
seen on the borders of the sub images. Why is this? Here,
pixels from the opposite horizontal sides of the image are
combined into one, and their intensity values for the used color
channel differ. In the image, the colors range between sharp red
and blue and green. This only occurs on the single pixel thick
lines dividing the sub images.


Only one third of the output image is populated with information.
Why? Because only one third of the images data is being
printed.
A more interesting artifact is why the image is
replicated three times along the top one third thick row. Why is
this? If you look closely at the image, you'll see that
rows of pixels are missing. This can be seen by looking at the
horizontal pattern on the air intake for the engine in the front
of the car. In the original image, the horizontal gaps are all
well defined and easy to see. In the sub images of the output
image, the horizontal pattern is distorted. The reason for this is
that each sub image only contains 1 out of 3 rows of the original
image. The rows of the image are down sampled and the effect on
the air intake is known as aliasing. Bad aliasing artifacts are
very easy to see whenever there are patterns of strips or checker
boards. But back to the point, because only one third of the data
is being printed, each printed row is only one third the width of
the image. But the ppm format assumes the data is filling each
row, so it takes three rows of data that are each one third the
width of the image, and puts it as a row of the image. So the
first row of the first sub image corresponds to the first row of
the original image, the first row of the second sub image
corresponds to the second row of the original image, the first row
of the third sub image corresponds to the third row of the
original image, and the second row of the first sub image
corresponds to the fourth row of the original image, and so on.
Each image gets one third of the rows of the original image, and
the result is three different down sampled versions of the
original image.


Don't change these.
Name: Email:
Entire Thread Thread List