! * \brief boxaModifyWithBoxa() * * \param[in] boxas * \param[in] boxam boxa with boxes used to modify those in boxas * \param[in] subflag L_USE_MINSIZE, L_USE_MAXSIZE, * L_SUB_ON_LOC_DIFF, L_SUB_ON_SIZE_DIFF, * L_USE_CAPPED_MIN, L_USE_CAPPED_MAX * \param[in] maxdiff parameter used with L_SUB_ON_LOC_DIFF, * L_
| 1466 | * </pre> |
| 1467 | */ |
| 1468 | BOXA * |
| 1469 | boxaModifyWithBoxa(BOXA *boxas, |
| 1470 | BOXA *boxam, |
| 1471 | l_int32 subflag, |
| 1472 | l_int32 maxdiff, |
| 1473 | l_int32 extrapixels) |
| 1474 | { |
| 1475 | l_int32 n, i, ls, ts, rs, bs, ws, hs, lm, tm, rm, bm, wm, hm, ld, td, rd, bd; |
| 1476 | BOX *boxs, *boxm, *boxd, *boxempty; |
| 1477 | BOXA *boxad; |
| 1478 | |
| 1479 | PROCNAME("boxaModifyWithBoxa"); |
| 1480 | |
| 1481 | if (!boxas) |
| 1482 | return (BOXA *)ERROR_PTR("boxas not defined", procName, NULL); |
| 1483 | if (!boxam) { |
| 1484 | L_WARNING("boxam not defined; returning copy", procName); |
| 1485 | return boxaCopy(boxas, L_COPY); |
| 1486 | } |
| 1487 | if (subflag != L_USE_MINSIZE && subflag != L_USE_MAXSIZE && |
| 1488 | subflag != L_SUB_ON_LOC_DIFF && subflag != L_SUB_ON_SIZE_DIFF && |
| 1489 | subflag != L_USE_CAPPED_MIN && subflag != L_USE_CAPPED_MAX) { |
| 1490 | L_WARNING("invalid subflag; returning copy", procName); |
| 1491 | return boxaCopy(boxas, L_COPY); |
| 1492 | } |
| 1493 | n = boxaGetCount(boxas); |
| 1494 | if (n != boxaGetCount(boxam)) { |
| 1495 | L_WARNING("boxas and boxam sizes differ; returning copy", procName); |
| 1496 | return boxaCopy(boxas, L_COPY); |
| 1497 | } |
| 1498 | |
| 1499 | boxad = boxaCreate(n); |
| 1500 | boxempty = boxCreate(0, 0, 0, 0); /* placeholders */ |
| 1501 | for (i = 0; i < n; i++) { |
| 1502 | boxs = boxaGetValidBox(boxas, i, L_CLONE); |
| 1503 | boxm = boxaGetValidBox(boxam, i, L_CLONE); |
| 1504 | if (!boxs || !boxm) { |
| 1505 | boxaAddBox(boxad, boxempty, L_COPY); |
| 1506 | } else { |
| 1507 | boxGetGeometry(boxs, &ls, &ts, &ws, &hs); |
| 1508 | boxGetGeometry(boxm, &lm, &tm, &wm, &hm); |
| 1509 | rs = ls + ws - 1; |
| 1510 | bs = ts + hs - 1; |
| 1511 | rm = lm + wm - 1; |
| 1512 | bm = tm + hm - 1; |
| 1513 | if (subflag == L_USE_MINSIZE) { |
| 1514 | ld = L_MAX(ls, lm); |
| 1515 | rd = L_MIN(rs, rm); |
| 1516 | td = L_MAX(ts, tm); |
| 1517 | bd = L_MIN(bs, bm); |
| 1518 | } else if (subflag == L_USE_MAXSIZE) { |
| 1519 | ld = L_MIN(ls, lm); |
| 1520 | rd = L_MAX(rs, rm); |
| 1521 | td = L_MIN(ts, tm); |
| 1522 | bd = L_MAX(bs, bm); |
| 1523 | } else if (subflag == L_SUB_ON_LOC_DIFF) { |
| 1524 | ld = (L_ABS(lm - ls) <= maxdiff) ? ls : lm - extrapixels; |
| 1525 | td = (L_ABS(tm - ts) <= maxdiff) ? ts : tm - extrapixels; |
no test coverage detected