MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / blend

Function blend

jni/venus/region_operation.cpp:1259–1309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1257}
1258
1259void blend(cv::Mat& dst, const cv::Mat& src, const cv::Point2i& position, float amount/* = 1.0f */)
1260{
1261 assert(src.channels() == 4 && dst.channels() == 4 && src.depth() == dst.depth());
1262
1263 Rect2i rect1(position.x, position.y, src.cols, src.rows);
1264 Rect2i rect2(0, 0, dst.cols, dst.rows);
1265 rect1 &= rect2;
1266
1267 switch(dst.type())
1268 {
1269 case CV_8UC4:
1270 for(int r = rect1.y; r < (rect1.y + rect1.height); ++r)
1271 for(int c = rect1.x; c < (rect1.x + rect1.width); ++c)
1272 {
1273 const cv::Vec4b& src_color = src.at<cv::Vec4b>(r - position.y, c - position.x);
1274 cv::Vec4b& dst_color = dst.at<cv::Vec4b>(r, c);
1275
1276 const int src_alpha = cvRound(src_color[3] * amount), isc_alpha = 255 - src_alpha;
1277 for(int i = 0; i < 3; ++i)
1278 dst_color[i] = (src_color[i] * src_alpha + dst_color[i] * isc_alpha + 128)/255;
1279 }
1280 break;
1281 case CV_32FC3:
1282 for(int r = rect1.y; r < (rect1.y + rect1.height); ++r)
1283 for(int c = rect1.x; c < (rect1.x + rect1.width); ++c)
1284 {
1285 const cv::Vec4f& src_color = src.at<cv::Vec4f>(r - position.y, c - position.x);
1286 cv::Vec3f& dst_color = dst.at<cv::Vec3f>(r, c);
1287
1288 const float src_alpha = src_color[3] * amount, isc_alpha = 1.0f - src_alpha;
1289 for(int i = 0; i < 3; ++i)
1290 dst_color[i] = (src_color[i] * src_alpha + dst_color[i] * isc_alpha);
1291 }
1292 break;
1293 case CV_32FC4:
1294 for(int r = rect1.y; r < (rect1.y + rect1.height); ++r)
1295 for(int c = rect1.x; c < (rect1.x + rect1.width); ++c)
1296 {
1297 const cv::Vec4f& src_color = src.at<cv::Vec4f>(r - position.y, c - position.x);
1298 cv::Vec4f& dst_color = dst.at<cv::Vec4f>(r, c);
1299
1300 const float src_alpha = src_color[3] * amount, isc_alpha = 1.0f - src_alpha;
1301 for(int i = 0; i < 3; ++i)
1302 dst_color[i] = (src_color[i] * src_alpha + dst_color[i] * isc_alpha);
1303 }
1304 break;
1305 default:
1306 assert(false);
1307 break;
1308 }
1309}
1310
1311void blend(cv::Mat& dst, const cv::Mat& src, const cv::Mat& mask, const cv::Point2i& position, float amount/* = 1.0f*/)
1312{

Calls

no outgoing calls

Tested by

no test coverage detected