------------------------------------------------------------------------* * Create / Destroy * *------------------------------------------------------------------------*/ ! * \brief kernelCreate() * * \param[in] height, width * \return kernel, or NULL on error * * * Notes: * (1) kernelCreate() initializes all values t
| 103 | * </pre> |
| 104 | */ |
| 105 | L_KERNEL * |
| 106 | kernelCreate(l_int32 height, |
| 107 | l_int32 width) |
| 108 | { |
| 109 | l_uint64 size64; |
| 110 | L_KERNEL *kel; |
| 111 | |
| 112 | PROCNAME("kernelCreate"); |
| 113 | |
| 114 | if (width <= 0) |
| 115 | return (L_KERNEL *)ERROR_PTR("width must be > 0", procName, NULL); |
| 116 | if (height <= 0) |
| 117 | return (L_KERNEL *)ERROR_PTR("height must be > 0", procName, NULL); |
| 118 | |
| 119 | /* Avoid overflow in malloc arg */ |
| 120 | size64 = (l_uint64)width * (l_uint64)height; |
| 121 | if (size64 >= (1LL << 29)) { |
| 122 | L_ERROR("requested width = %d, height = %d\n", procName, width, height); |
| 123 | return (L_KERNEL *)ERROR_PTR("size >= 2^29", procName, NULL); |
| 124 | } |
| 125 | |
| 126 | kel = (L_KERNEL *)LEPT_CALLOC(1, sizeof(L_KERNEL)); |
| 127 | kel->sy = height; |
| 128 | kel->sx = width; |
| 129 | if ((kel->data = create2dFloatArray(height, width)) == NULL) { |
| 130 | LEPT_FREE(kel); |
| 131 | return (L_KERNEL *)ERROR_PTR("data not allocated", procName, NULL); |
| 132 | } |
| 133 | return kel; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /*! |
no test coverage detected