For a posterization algorithmn I’m going to need to average the color values (QRgb) present in my std::vector.
How would you suggest to do it? Sum the 3 components separately then average them? Otherwise?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since
QRgbis just a 32-bit unsigned int in ARGB format it doesn’t suffice for adding colors, which will most likely result in overflow. But alsoQColordoesn’t suffice as it uses fixed-point 16-bit integers for the color components and therefore also cannot cope with colors out of the valid [0,1] range. So you cannot useQRgborQColorfor this as they clamp each partial sum to the valid range. Neither can you predivide the colors before adding them because of their limited precision.So your best bet would really just be to sum up the individual components using floating point numbers and then divide them by the vector size: