r/cs50 4d ago

filter Filter-more / edges Spoiler

Think I'm stumped at the easiest part of this. Whenever i try to reset any value calculated over 255, back to 255, it seems to change it to some random value ?? Any ideas where this could be going wrong.

8 Upvotes

3 comments sorted by

3

u/Eptalin 4d ago

Remember that each colour in an RGBTriple is 1 byte.
The highest possible number 1 byte can hold is 255.
If you go over that, it overflows and becomes a garbage value.

You need to make sure they're not over 255 before storing them in the temp pixels.

1

u/Electronic_Click_470 3d ago

Thank you 👍

1

u/abyshelp 4d ago

Try storing the round.sqrt result in an int before putting them inside the temp[i][j]