|
Re: incorrect subtraction in get color pixel value
Welcome to the matrix.
Since computers are typically expected to be really fast, they take lots of shortcuts. They take advantage of not doing the things that people aren't looking at, etc. They are just as capable of being careful and accurate, but that is a tradeoff, and most people prefer their video fast instead of accurate.
What you are discovering in this instance, is that it is common for images to be saved with one byte for red, green, and blue. One byte can only hold 256 unique values, so the computer scientists decided to use them as an unsigned integers. Integers are specialized and can only store the a fixed set of values. Booleans can only store two value, bytes 256, shorts can store 65536, and longs can only store a measly 4 billion values. All of these share a similar discrete mathematical system that defines the results of addition, subtraction, multiplication, and other operations.
Is the result correct? It works as intended, but not the same as a calculator. That tradeoff allows it to do specialized work quickly. Can you figure out how to get the answer you wanted? Or can you describe what answer you wanted?
Greg McKaskle
|