• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef INTERFACES_KITS_JS_COMMON_INCLUDE_DETAIL_ENHANCE_NAPI_H
17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_DETAIL_ENHANCE_NAPI_H
18 
19 #include "detail_enhancer_image.h"
20 #include "image_type.h"
21 #include "pixel_map_napi.h"
22 
23 namespace OHOS {
24 namespace Media {
25 class DetailEnhanceNapi {
26 public:
27     DetailEnhanceNapi();
28     ~DetailEnhanceNapi();
29 
30     static napi_value Process(napi_env env, napi_callback_info info);
31     static napi_value Init(napi_env env, napi_callback_info info);
32     static napi_value Destroy(napi_env env, napi_callback_info info);
33 private:
34     struct DetailEnhanceContext {
35         napi_env env;
36         napi_deferred deferred;
37         napi_ref callbackRef;
38         std::shared_ptr<PixelMap> inputPixelMap = nullptr;
39         double xArg = 0;
40         double yArg = 0;
41     };
42     struct NapiValues {
43         napi_status status;
44         napi_value thisVar = nullptr;
45         napi_value result = nullptr;
46         napi_value* argv = nullptr;
47         size_t argc;
48         std::unique_ptr<DetailEnhanceContext> context;
49     };
50 
51     static ImageType ParserImageType(napi_env env, napi_value argv);
52     static bool PrepareNapiEnv(napi_env env, napi_callback_info info, struct NapiValues* nVal);
53     static napi_value DetailEnhanceImpl(napi_env env, std::unique_ptr<DetailEnhanceContext>& context);
54     static void SetDstPixelMapInfo(OHOS::Media::PixelMap &source, void* dstPixels, uint32_t dstPixelsSize,
55         std::unique_ptr<OHOS::Media::AbsMemory>& memory, OHOS::Media::PixelMap &dstPixelMap);
56     static bool AllocMemory(OHOS::Media::PixelMap &source, OHOS::Media::PixelMap &dstPixelMap);
57     static std::unique_ptr<OHOS::Media::PixelMap> CreateDstPixelMap(OHOS::Media::PixelMap &source,
58         const OHOS::Media::InitializationOptions &opts);
59     static sptr<OHOS::SurfaceBuffer> GetSurfaceBufferFromDMAPixelMap(
60         const std::shared_ptr<OHOS::Media::PixelMap>& pixelmap);
61 };
62 
63 static std::shared_ptr<OHOS::Media::VideoProcessingEngine::DetailEnhancerImage> mDetailEnh;
64 static std::mutex lock_{std::mutex()};
65 }
66 }
67 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_DETAIL_ENHANCE_NAPI_H