1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include <algorithm> 17 18 #include "minddata/dataset/kernels/ir/vision/convert_color_ir.h" 19 20 #ifndef ENABLE_ANDROID 21 #include "minddata/dataset/kernels/image/convert_color_op.h" 22 #endif 23 24 #include "minddata/dataset/kernels/ir/validators.h" 25 26 namespace mindspore { 27 namespace dataset { 28 namespace vision { 29 #ifndef ENABLE_ANDROID 30 // ConvertColorOperation ConvertColorOperation(ConvertMode convert_mode)31ConvertColorOperation::ConvertColorOperation(ConvertMode convert_mode) : convert_mode_(convert_mode) {} 32 33 ConvertColorOperation::~ConvertColorOperation() = default; 34 Name() const35std::string ConvertColorOperation::Name() const { return kConvertColorOperation; } 36 ValidateParams()37Status ConvertColorOperation::ValidateParams() { 38 if (convert_mode_ < ConvertMode::COLOR_BGR2BGRA || convert_mode_ > ConvertMode::COLOR_RGBA2GRAY) { 39 std::string err_msg = "ConvertColorOperation: convert_mode must be in ConvertMode."; 40 MS_LOG(ERROR) << err_msg; 41 RETURN_STATUS_SYNTAX_ERROR(err_msg); 42 } 43 return Status::OK(); 44 } 45 Build()46std::shared_ptr<TensorOp> ConvertColorOperation::Build() { 47 std::shared_ptr<ConvertColorOp> tensor_op = std::make_shared<ConvertColorOp>(convert_mode_); 48 return tensor_op; 49 } 50 to_json(nlohmann::json * out_json)51Status ConvertColorOperation::to_json(nlohmann::json *out_json) { 52 nlohmann::json args; 53 args["convert_mode"] = convert_mode_; 54 *out_json = args; 55 return Status::OK(); 56 } 57 from_json(nlohmann::json op_params,std::shared_ptr<TensorOperation> * operation)58Status ConvertColorOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) { 59 CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("convert_mode") != op_params.end(), "Failed to find convert_mode"); 60 ConvertMode convert_mode = static_cast<ConvertMode>(op_params["convert_mode"]); 61 *operation = std::make_shared<vision::ConvertColorOperation>(convert_mode); 62 return Status::OK(); 63 } 64 65 #endif 66 } // namespace vision 67 } // namespace dataset 68 } // namespace mindspore 69