just fixed it. so the code was wrote in wrong order and the Ternary Operator was missing a ()
void sepia(int height, int width, RGBTRIPLE image[height][width])
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
int sepiaBlue = round(.272 * image[i][j].rgbtRed + .534 * image[i][j].rgbtGreen + .131 *...
When you divide the 3 colors by 3 you'll probably get a decimal point value. If you receive it in a 'int' variable you'll get a trimmed number. (the decimal part will be removed) The way to do it is round() it.
instead of using BYTE before sepiaRed, sepiaBlue, sepiaGreen, originalRed, originalBlue and originalGreen, use float
Also, don't forget to round the values of sepia Red, Blue and Green using the round() function defined in math.h
Look at the following code:
if(SEPIA[k] > 255)
SEPIA[k] = 255;
What is the value of k? Where is it incremented? Is it possible that some code was forgotten to be added? ;-)
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)
If you look at the extended check50 results in the link at the end of the message, there are more clues to be found.
For the greyscale issue, the last pixel in the 3x3 image is off by 1, to the high direction. The problem lies here:
int average = (int) ceilf(avg);
The code should be using a rounding function, not a ceiling function. The ceiling function ...
It's very readable as it is, with little inefficiency. The only things that I can think of doing would be to delete the temp vars original(color) and use the array vars directly. That would eliminate 3 assignments. The improvement in efficiency would be trivial though.
Next, each if/else sequence could be replaced by using the ternary operator. For example:
The results are displayed in your question. If the code tries to store a number greater than 8 bits (greater than 255) in a one-byte data type, it generates a runtime overflow error. Nothing will be stored and the program will terminate with an error condition.
Perhaps you should add some code that will check for x > 255 and if true, store 255. OR, use ...