I have a simple double for to convert rgb image to grayscale but I have some odd behavior on windows using VS compiler. I noticed that two of my implementation have different results. The first one :
int ok = 0, nok = 0;
for(int y = 0; y < img.height(); y++){
uchar *line = img.getLine(y);
for(int x = 0; x < img.width(); x++){
*(destinationPtr++) = ((*(line++)) + (*(line++)) + (*(line++)))/3;
}
}
And the second one :
int ok = 0, nok = 0;
for(int y = 0; y < img.height(); y++){
uchar *line = img.getLine(y);
for(int x = 0; x < img.width(); x++){
uchar r = *(line++);
uchar g = *(line++);
uchar b = *(line++);
*(destinationPtr++) = (r+g+b)/3;
}
}
After a few tests I think the problem in my first implementation, the code is executed with this order :
*(destinationPtr) = ((*(line)) + (*(line)) + (*(line)))/3;
destinationPtr++;
line++;
line++;
line++;
And on my Linux compilation with GCC I don't have this issue, do you have the reason of this ? the post-increment is not a standard thing ?