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

Function kernelCreateFromString

deps/leptonica/src/kernel.c:678–723  ·  view source on GitHub ↗

----------------------------------------------------------------------* * Making a kernel from a compiled string * *----------------------------------------------------------------------*/ ! * \brief kernelCreateFromString() * * \param[in] h, w height, width * \param[in] cy, cx origin * \param[in] kdata * \return kernel of the given size, or

Source from the content-addressed store, hash-verified

676 * </pre>
677 */
678L_KERNEL *
679kernelCreateFromString(l_int32 h,
680 l_int32 w,
681 l_int32 cy,
682 l_int32 cx,
683 const char *kdata)
684{
685l_int32 n, i, j, index;
686l_float32 val;
687L_KERNEL *kel;
688NUMA *na;
689
690 PROCNAME("kernelCreateFromString");
691
692 if (h < 1)
693 return (L_KERNEL *)ERROR_PTR("height must be > 0", procName, NULL);
694 if (w < 1)
695 return (L_KERNEL *)ERROR_PTR("width must be > 0", procName, NULL);
696 if (cy < 0 || cy >= h)
697 return (L_KERNEL *)ERROR_PTR("cy invalid", procName, NULL);
698 if (cx < 0 || cx >= w)
699 return (L_KERNEL *)ERROR_PTR("cx invalid", procName, NULL);
700
701 kel = kernelCreate(h, w);
702 kernelSetOrigin(kel, cy, cx);
703 na = parseStringForNumbers(kdata, " \t\n");
704 n = numaGetCount(na);
705 if (n != w * h) {
706 kernelDestroy(&kel);
707 numaDestroy(&na);
708 fprintf(stderr, "w = %d, h = %d, num ints = %d\n", w, h, n);
709 return (L_KERNEL *)ERROR_PTR("invalid integer data", procName, NULL);
710 }
711
712 index = 0;
713 for (i = 0; i < h; i++) {
714 for (j = 0; j < w; j++) {
715 numaGetFValue(na, index, &val);
716 kernelSetElement(kel, i, j, val);
717 index++;
718 }
719 }
720
721 numaDestroy(&na);
722 return kel;
723}
724
725
726/*----------------------------------------------------------------------*

Callers

nothing calls this directly

Calls 8

kernelCreateFunction · 0.85
kernelSetOriginFunction · 0.85
parseStringForNumbersFunction · 0.85
numaGetCountFunction · 0.85
kernelDestroyFunction · 0.85
numaDestroyFunction · 0.85
numaGetFValueFunction · 0.85
kernelSetElementFunction · 0.85

Tested by

no test coverage detected