| 122 | } |
| 123 | |
| 124 | ErrorCode ImageProcess::convert(const uint8_t* source, int iw, int ih, int stride, Tensor* destOrigin) { |
| 125 | auto dest = destOrigin; |
| 126 | if (nullptr == dest || nullptr == source) { |
| 127 | MNN_ERROR("null dest or source for image process\n"); |
| 128 | return INPUT_DATA_ERROR; |
| 129 | } |
| 130 | if (TensorUtils::getDescribeOrigin(dest)->getBackend() == nullptr && destOrigin->buffer().host == nullptr) { |
| 131 | MNN_ERROR("Invalid Tensor, the session may not be ready\n"); |
| 132 | return INPUT_DATA_ERROR; |
| 133 | } |
| 134 | std::shared_ptr<Tensor> tempTensor; |
| 135 | auto ow = dest->width(); |
| 136 | auto oh = dest->height(); |
| 137 | auto bpp = dest->channel(); |
| 138 | auto dimensionFormat = TensorUtils::getDescribe(dest)->dimensionFormat; |
| 139 | auto tensorBn = TensorUtils::getDescribeOrigin(dest)->getBackend(); |
| 140 | auto bnType = MNN_FORWARD_CPU; |
| 141 | if(tensorBn){ |
| 142 | bnType = tensorBn->type(); |
| 143 | } |
| 144 | if (bnType != MNN_FORWARD_CPU) { |
| 145 | tempTensor.reset(Tensor::create({1, bpp, oh, ow}, dest->getType(), nullptr, Tensor::CAFFE_C4),[destOrigin] (void* p) { |
| 146 | auto hostTensor = (Tensor*)p; |
| 147 | destOrigin->copyFromHostTensor(hostTensor); |
| 148 | delete hostTensor; |
| 149 | }); |
| 150 | dest = tempTensor.get(); |
| 151 | } |
| 152 | else if (MNN_DATA_FORMAT_NCHW == dimensionFormat) { |
| 153 | tempTensor.reset(Tensor::create(dest->shape(), dest->getType(), nullptr, Tensor::CAFFE_C4), [destOrigin](void* p) { |
| 154 | auto hostTensor = (Tensor*)p; |
| 155 | CPUTensorConverter::convert(hostTensor, destOrigin); |
| 156 | delete hostTensor; |
| 157 | }); |
| 158 | dest = tempTensor.get(); |
| 159 | } |
| 160 | dimensionFormat = TensorUtils::getDescribe(dest)->dimensionFormat; |
| 161 | if (dimensionFormat == MNN_DATA_FORMAT_NC4HW4) { |
| 162 | bpp = 4; |
| 163 | } |
| 164 | int ic = _getBpp(mInside->config.sourceFormat); |
| 165 | mInside->proc->setPadding(mPaddingValue); |
| 166 | mInside->proc->resizeFunc(ic, iw, ih, bpp, ow, oh, dest->getType(), stride); |
| 167 | return mInside->proc->execFunc(source, stride, dest->host<void>()); |
| 168 | } |
| 169 | |
| 170 | ErrorCode ImageProcess::convert(const uint8_t* source, int iw, int ih, int stride, void* dest, int ow, int oh, |
| 171 | int outputBpp, int outputStride, halide_type_t type) { |