Skip to content

Commit

Permalink
add null check for MatUtils (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluaxe authored and gttiankai committed Oct 15, 2020
1 parent f8d927a commit e365d0e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/tnn/utils/mat_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Status MatUtils::Copy(Mat& src, Mat& dst, void* command_queue) {
return Status(TNNERR_PARAM_ERR, "src and dst DeviceType need be equal or one is device cpu");
}
auto converter = MatConverterManager::Shared()->CreateMatConverterAcc(device_type);
if (!converter) {
return Status(TNNERR_INIT_LAYER, "image converter is nil, check device type");
}
return converter->Copy(src, dst, command_queue);
}else {
return Status(TNNERR_PARAM_ERR, "src and dst dims or MatType not equal");
Expand All @@ -56,6 +59,9 @@ Status MatUtils::Resize(Mat& src, Mat& dst, ResizeParam param, void* command_que
return Status(TNNERR_PARAM_ERR, "DeviceType or MatType not equal");
}
auto converter = MatConverterManager::Shared()->CreateMatConverterAcc(src.GetDeviceType());
if (!converter) {
return Status(TNNERR_INIT_LAYER, "image converter is nil, check device type");
}
return converter->Resize(src, dst, param, command_queue);
}

Expand All @@ -70,6 +76,9 @@ Status MatUtils::Crop(Mat& src, Mat& dst, CropParam param, void* command_queue)
return Status(TNNERR_PARAM_ERR, "DeviceType or MatType not equal");
}
auto converter = MatConverterManager::Shared()->CreateMatConverterAcc(src.GetDeviceType());
if (!converter) {
return Status(TNNERR_INIT_LAYER, "image converter is nil, check device type");
}
return converter->Crop(src, dst, param, command_queue);
}

Expand All @@ -78,6 +87,9 @@ Status MatUtils::WarpAffine(Mat& src, Mat& dst, WarpAffineParam param, void* com
return Status(TNNERR_PARAM_ERR, "DeviceType or MatType not equal");
}
auto converter = MatConverterManager::Shared()->CreateMatConverterAcc(src.GetDeviceType());
if (!converter) {
return Status(TNNERR_INIT_LAYER, "image converter is nil, check device type");
}
return converter->WarpAffine(src, dst, param, command_queue);
}

Expand All @@ -86,6 +98,9 @@ Status MatUtils::CvtColor(Mat& src, Mat& dst, ColorConversionType type, void* co
return Status(TNNERR_PARAM_ERR, "DeviceType or MatType not equal");
}
auto converter = MatConverterManager::Shared()->CreateMatConverterAcc(src.GetDeviceType());
if (!converter) {
return Status(TNNERR_INIT_LAYER, "image converter is nil, check device type");
}
return converter->CvtColor(src, dst, type, command_queue);
}

Expand Down

0 comments on commit e365d0e

Please sign in to comment.