karansher / computer-graphics-raster-images

Computer Graphics Assignment about Raster Images
1 stars 0 forks source link

Strange-looking output images #49

Open FarzanehCS opened 2 years ago

FarzanehCS commented 2 years ago

Hello, When I compile the code and get the output images (which are written by the write_ppm function), the ppm files generated look strange! Like for write_ppm("rgb.ppm",rgb,width,height,3); I get this ppm file:

image

This is the simplest case where I create the rgb image by rgba_to_rgb(rgba,width,height,rgb); and then call write_ppm, but not sure why I get this. Here is what I have done: When we turn the rgba to rgb, we only keep the rgb values, i.e. the first, second, and third values of rgba pixels. Also for writing the files, I followed this: https://en.wikipedia.org/wiki/Netpbm#PPM_example

Any help is much appreciated.

JanardanS commented 2 years ago

First things first, there is a limit to how much a line of a ppm file can hold, which is about 70 characters. This is seen in the bottom of the example showcasing P3. So, when writing your rgb values in, make sure the add a new line in from time to time, or else it wont read the rest properly. Secondly, it seems like your not looping through all your data. Make sure your looping through every single element in the data variable, and get the right amount of data depending on number of channels.

FarzanehCS commented 2 years ago

I resolved this. I was not getting the correct indexes while looping.