• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "image_processing_factory.h"
17 
18 #include <functional>
19 #include <unordered_map>
20 
21 #include "vpe_log.h"
22 #include "image_processing_native_template.h"
23 #include "metadata_generator_image_native.h"
24 #include "detail_enhancer_image_native.h"
25 #include "colorspace_converter_image_native.h"
26 
27 using namespace OHOS::Media::VideoProcessingEngine;
28 
29 namespace {
30 template <typename T>
Create()31 std::shared_ptr<IImageProcessingNative> Create()
32 {
33     return ImageProcessingNativeTemplate<T>::Create();
34 }
35 // NOTE: Add VPE feature type like below.
36 // VPE feature map begin
37 const std::unordered_map<int, std::function<std::shared_ptr<IImageProcessingNative>()>> CREATORS = {
38     { IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER, Create<DetailEnhancerImageNative> },
39     { IMAGE_PROCESSING_TYPE_COLOR_SPACE_CONVERSION, Create<ColorspaceConverterImageNative> },
40     { IMAGE_PROCESSING_TYPE_COMPOSITION, Create<ColorspaceConverterImageNative> },
41     { IMAGE_PROCESSING_TYPE_DECOMPOSITION, Create<ColorspaceConverterImageNative> },
42     { IMAGE_PROCESSING_TYPE_METADATA_GENERATION, Create<MetadataGeneratorImageNative> },
43     // ...
44 };
45 // VPE feature map end
46 }
47 
IsValid(int type)48 bool ImageProcessingFactory::IsValid(int type)
49 {
50     if (access("/system/lib64/libvideoprocessingengine_ext.z.so", 0)) {
51         if (type != IMAGE_PROCESSING_TYPE_DETAIL_ENHANCER) {
52             return false;
53         }
54     }
55     return CREATORS.find(type) != CREATORS.end();
56 }
57 
CreateImageProcessing(int type)58 std::shared_ptr<IImageProcessingNative> ImageProcessingFactory::CreateImageProcessing(int type)
59 {
60     auto it = CREATORS.find(type);
61     if (it == CREATORS.end()) {
62         VPE_LOGE("Unknown type:%{public}d!", type);
63         return nullptr;
64     }
65     return it->second();
66 }
67