• 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_impl.h"
17 
18 #include "image_processing_factory.h"
19 #include "vpe_log.h"
20 
21 using namespace OHOS::Media::VideoProcessingEngine;
22 
Create(OH_ImageProcessing ** instance,int type,std::shared_ptr<OpenGLContext> openglContext,ClContext * openclContext)23 ImageProcessing_ErrorCode OH_ImageProcessing::Create(OH_ImageProcessing** instance, int type,
24                                                      std::shared_ptr<OpenGLContext> openglContext,
25                                                      ClContext *openclContext)
26 {
27     CHECK_AND_RETURN_RET_LOG(instance != nullptr && *instance == nullptr, IMAGE_PROCESSING_ERROR_INVALID_INSTANCE,
28         "VPE image processing instance is null or *instance is not null!");
29     CHECK_AND_RETURN_RET_LOG(ImageProcessingFactory::IsValid(type), IMAGE_PROCESSING_ERROR_INVALID_PARAMETER,
30         "VPE image processing type(%{public}d) is invalid!", type);
31 
32     *instance = new(std::nothrow) OH_ImageProcessing(type);
33     CHECK_AND_RETURN_RET_LOG(*instance != nullptr, IMAGE_PROCESSING_ERROR_NO_MEMORY,
34         "VPE image processing out of memory!");
35     auto obj = (*instance)->GetImageProcessing();
36     CHECK_AND_RETURN_RET_LOG(obj != nullptr, IMAGE_PROCESSING_ERROR_CREATE_FAILED,
37         "VPE image processing constructor failed!");
38     obj->opengclContext_ = openclContext;
39     obj->openglContext_ = openglContext;
40     return obj->Initialize();
41 }
42 
Destroy(OH_ImageProcessing * instance)43 ImageProcessing_ErrorCode OH_ImageProcessing::Destroy(OH_ImageProcessing* instance)
44 {
45     CHECK_AND_RETURN_RET_LOG(instance != nullptr, IMAGE_PROCESSING_ERROR_INVALID_INSTANCE,
46         "VPE image processing instance is null!");
47     auto obj = instance->GetImageProcessing();
48     CHECK_AND_RETURN_RET_LOG(obj != nullptr, IMAGE_PROCESSING_ERROR_INVALID_PARAMETER,
49         "VPE image processing instance is empty!");
50     auto errorCode = obj->Deinitialize();
51     delete instance;
52     instance = nullptr;
53     return errorCode;
54 }
55 
OH_ImageProcessing(int type)56 OH_ImageProcessing::OH_ImageProcessing(int type)
57 {
58     imageProcessing_ = ImageProcessingFactory::CreateImageProcessing(type);
59 }
60 
~OH_ImageProcessing()61 OH_ImageProcessing::~OH_ImageProcessing()
62 {
63     imageProcessing_ = nullptr;
64 }
65 
GetImageProcessing()66 std::shared_ptr<IImageProcessingNative> OH_ImageProcessing::GetImageProcessing()
67 {
68     return imageProcessing_;
69 }
70