|
-
January 1st, 2019, 11:45 AM
#6
Re: Reading PPM format images
Hey 2kaud,
I just have a few questions to your code above.
What exactly is happening in this part?
unsigned int read = 0;
if ((read = fread(pixels, 1, size, fr)) != size) {...}
return pixels;
1. What do you store in read and why do you need it?
2. And what are you doing with pixels?
For me it looks like the data/content of the picture is in pixels?
I am confused because you store width, height, maximum(rgb?) and this 3 are also the only output of printf.
Nothing happens with the data/content.
Is it also possible to store the data outside the function?
Just for me to understand.
This Part is to read and store the header
Code:
fscanf(fr, "%9s", header);
if (strcmp(header, p6))
printf("Incorrect header %s found\n", header);
else
if (fscanf(fr, "%d %d\n%d\n", width, height, maximum) != 3)
puts("Invalid header values");
else {
const unsigned int size = *width * *height * 3;
and this part is for the data/content
Code:
if ((pixels = malloc(size)) == NULL)
puts("Error allocating memory");
else {
unsigned int read = 0;
if ((read = fread(pixels, 1, size, fr)) != size) {
printf("Error reading binary data. Wanted %i, got %i\n", size, read);
free(pixels);
pixels = NULL;
}
}
}
fclose(fr);
return pixels;
But i dont see/understand what you are doing with pixels? 
It's an old post and if you read this and help me understand i owe you more than one beer.
Thank you and br
Last edited by 2kaud; January 2nd, 2019 at 04:47 AM.
Reason: Adjusted code headers
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|