Ask Your Question

Revision history [back]

I managed to achieve this using cv::Mat.mul(Cv::Mat,double), but it turns out to be slower than just using integer arithmetic 'manually'

for reference: the openCV algorithm I used was:

vector<cv::Mat> ichans,ochans;
vector<cv::Mat> compchans;
cv::split(rgb,ichans);
cv::split(other.rgb,ochans);
uint8_t b=0xFF;
cv::Mat iA=b-other.alpha;
for (int i=0;i<3;i++) {
    compchans.push_back(ichans[i].mul(iA,1.0/255.0)+ochans[i].mul(other.alpha,1.0/255.0));
}
merge(compchans,rgb);

but, it proved quicker to just do:

for (int i=0;i<w*h*3;i++) {
    rgb.data[i]=(uint8_t)(((((int)rgb.data[i])*(0xFF-other.alpha.data[i/3]))>>8)+((((int)other.rgb.data[i])*((int)other.alpha.data[i/3]))>>8));
}