| 1401 | #define ACCEPT_STATIC_OBJECT_TIME 10 /* Seconds */ |
| 1402 | #define EXCLUDE_LEVEL_PERCENT 20 |
| 1403 | void alg_update_reference_frame(struct context *cnt, int action) |
| 1404 | { |
| 1405 | int accept_timer = cnt->lastrate * ACCEPT_STATIC_OBJECT_TIME; |
| 1406 | int i, threshold_ref; |
| 1407 | int *ref_dyn = cnt->imgs.ref_dyn; |
| 1408 | unsigned char *image_virgin = cnt->imgs.image_vprvcy.image_norm; |
| 1409 | unsigned char *ref = cnt->imgs.ref; |
| 1410 | unsigned char *smartmask = cnt->imgs.smartmask_final; |
| 1411 | unsigned char *out = cnt->imgs.img_motion.image_norm; |
| 1412 | |
| 1413 | /* Match rate limit */ |
| 1414 | if (cnt->lastrate > 5) { |
| 1415 | accept_timer /= (cnt->lastrate / 3); |
| 1416 | } |
| 1417 | |
| 1418 | if (action == UPDATE_REF_FRAME) { /* Black&white only for better performance. */ |
| 1419 | threshold_ref = cnt->noise * EXCLUDE_LEVEL_PERCENT / 100; |
| 1420 | |
| 1421 | for (i = cnt->imgs.motionsize; i > 0; i--) { |
| 1422 | /* Exclude pixels from ref frame well below noise level. */ |
| 1423 | if (((int)(abs(*ref - *image_virgin)) > threshold_ref) && (*smartmask)) { |
| 1424 | if (*ref_dyn == 0) { /* Always give new pixels a chance. */ |
| 1425 | *ref_dyn = 1; |
| 1426 | } else if (*ref_dyn > accept_timer) { /* Include static Object after some time. */ |
| 1427 | *ref_dyn = 0; |
| 1428 | *ref = *image_virgin; |
| 1429 | } else if (*out) { |
| 1430 | (*ref_dyn)++; /* Motionpixel? Keep excluding from ref frame. */ |
| 1431 | } else { |
| 1432 | *ref_dyn = 0; /* Nothing special - release pixel. */ |
| 1433 | *ref = (*ref + *image_virgin) / 2; |
| 1434 | } |
| 1435 | |
| 1436 | } else { /* No motion: copy to ref frame. */ |
| 1437 | *ref_dyn = 0; /* Reset pixel */ |
| 1438 | *ref = *image_virgin; |
| 1439 | } |
| 1440 | |
| 1441 | ref++; |
| 1442 | image_virgin++; |
| 1443 | smartmask++; |
| 1444 | ref_dyn++; |
| 1445 | out++; |
| 1446 | } /* end for i */ |
| 1447 | |
| 1448 | } else { /* action == RESET_REF_FRAME - also used to initialize the frame at startup. */ |
| 1449 | /* Copy fresh image */ |
| 1450 | memcpy(cnt->imgs.ref, cnt->imgs.image_vprvcy.image_norm, cnt->imgs.size_norm); |
| 1451 | /* Reset static objects */ |
| 1452 | memset(cnt->imgs.ref_dyn, 0, cnt->imgs.motionsize * sizeof(*cnt->imgs.ref_dyn)); |
| 1453 | } |
| 1454 | } |
no outgoing calls
no test coverage detected