----------------------------------------------------------------------* * 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
| 676 | * </pre> |
| 677 | */ |
| 678 | L_KERNEL * |
| 679 | kernelCreateFromString(l_int32 h, |
| 680 | l_int32 w, |
| 681 | l_int32 cy, |
| 682 | l_int32 cx, |
| 683 | const char *kdata) |
| 684 | { |
| 685 | l_int32 n, i, j, index; |
| 686 | l_float32 val; |
| 687 | L_KERNEL *kel; |
| 688 | NUMA *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 | /*----------------------------------------------------------------------* |
nothing calls this directly
no test coverage detected