bool OverlayEffect::draw(ImageOf<PixelRgb>& src2, ImageOf<PixelRgb>& dest2) { if (needRead) { readEffectData(); needRead = false; } dest2 = src2; if (img.isValid()) { for (int x=0; x<dest2.width()&&x<img.width(); x++) { for (int y=0; y<dest2.height()&&y<img.height(); y++) { PixelBgra v = img.pixel(x,y); if (v.a==0) { dest2(x,y) = PixelRgb(v.r,v.g,v.b); } else if (v.a>=127) { // do nothing, leave copied value } else { PixelRgb& o = dest2(x,y); float f = v.a/127.0; if (f>1) f = 1; int r = (int)((1-f)*v.r+f*o.r); int g = (int)((1-f)*v.g+f*o.g); int b = (int)((1-f)*v.b+f*o.b); dest2(x,y) = PixelRgb(r,g,b); } } } } return true; }