ColorI convolution (ColorI * ColorI)
by Orion Elenzil · 05/08/2009 (12:20 pm) · 1 comments
eg, ColorI(255, 128, 64, 255) * ColorI(128, 255, 255, 64) = 128, 128, 64, 64.
this is only worth posting because of the small gotcha of adding 255 to the product before dividing by 256. otherwise input values get shrunk by one when convolved with values of 255.
this is based on a TGE 1.3.5 codebase.
color.h
in the declaration of class ColorI, add the following after the declarations of operators *= and *:
then down after the definition of the * operator, ColorI ColorI::operator*(const F32 in_mul), add this:
this is only worth posting because of the small gotcha of adding 255 to the product before dividing by 256. otherwise input values get shrunk by one when convolved with values of 255.
this is based on a TGE 1.3.5 codebase.
color.h
in the declaration of class ColorI, add the following after the declarations of operators *= and *:
ColorI& operator*=(const ColorI& in_mul); ColorI operator*(const ColorI& in_mul) const;
then down after the definition of the * operator, ColorI ColorI::operator*(const F32 in_mul), add this:
inline ColorI& ColorI::operator*=(const ColorI& in_mul)
{
red = U8((U32(red ) * U32(in_mul.red ) + 255) >> 8);
green = U8((U32(green) * U32(in_mul.green) + 255) >> 8);
blue = U8((U32(blue ) * U32(in_mul.blue ) + 255) >> 8);
alpha = U8((U32(alpha) * U32(in_mul.alpha) + 255) >> 8);
return *this;
}
inline ColorI ColorI::operator*(const ColorI& in_mul) const
{
ColorI temp(*this);
temp *= in_mul;
return temp;
}About the author
Torque 3D Owner Guimo
Thanks!
Guimo