MCPcopy Create free account
hub / github.com/creatale/node-dv / boxaModifyWithBoxa

Function boxaModifyWithBoxa

deps/leptonica/src/boxfunc4.c:1468–1553  ·  view source on GitHub ↗

! * \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_

Source from the content-addressed store, hash-verified

1466 * </pre>
1467 */
1468BOXA *
1469boxaModifyWithBoxa(BOXA *boxas,
1470 BOXA *boxam,
1471 l_int32 subflag,
1472 l_int32 maxdiff,
1473 l_int32 extrapixels)
1474{
1475l_int32 n, i, ls, ts, rs, bs, ws, hs, lm, tm, rm, bm, wm, hm, ld, td, rd, bd;
1476BOX *boxs, *boxm, *boxd, *boxempty;
1477BOXA *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;

Callers 2

boxaSmoothSequenceLSFunction · 0.85
boxaSmoothSequenceMedianFunction · 0.85

Calls 8

boxaCopyFunction · 0.85
boxaGetCountFunction · 0.85
boxaCreateFunction · 0.85
boxCreateFunction · 0.85
boxaGetValidBoxFunction · 0.85
boxaAddBoxFunction · 0.85
boxGetGeometryFunction · 0.85
boxDestroyFunction · 0.85

Tested by

no test coverage detected