• 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 #ifndef INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_SENDABLE_NAPI_H
17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_SENDABLE_NAPI_H
18 
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 #include "image_type.h"
22 #include "image_log.h"
23 #include "image_source.h"
24 #include "pixel_map.h"
25 #include "sendable_pixel_map_napi.h"
26 #include "media_errors.h"
27 #include "image_napi_utils.h"
28 #include "image_dfx.h"
29 
30 namespace OHOS {
31 namespace Media {
32 class SendableImageSourceNapi {
33 public:
34     SendableImageSourceNapi();
35     ~SendableImageSourceNapi();
36     std::shared_ptr<ImageSource> nativeImgSrc = nullptr;
37     static thread_local std::string filePath_;
38     static thread_local int fileDescriptor_;
39     static thread_local void* fileBuffer_;
40     static thread_local size_t fileBufferSize_;
41 
GetIncrementalPixelMap()42     std::shared_ptr<IncrementalPixelMap> GetIncrementalPixelMap()
43     {
44         return navIncPixelMap_;
45     }
46     static napi_value Init(napi_env env, napi_value exports);
47 private:
48     static napi_value Constructor(napi_env env, napi_callback_info info);
49     static void Destructor(napi_env env, void *nativeObject, void *finalize);
50 
51     static napi_value CreateImageSource(napi_env env, napi_callback_info info);
52     static napi_value CreatePixelMap(napi_env env, napi_callback_info info);
53     static napi_value Release(napi_env env, napi_callback_info info);
54 
55     void release();
56     static thread_local napi_ref sConstructor_;
57     static thread_local std::shared_ptr<ImageSource> sImgSrc_;
58     static std::shared_ptr<IncrementalPixelMap> sIncPixelMap_;
59     std::shared_ptr<IncrementalPixelMap> navIncPixelMap_ = nullptr;
60     static napi_ref pixelMapFormatRef_;
61     static napi_ref propertyKeyRef_;
62     static napi_ref imageFormatRef_;
63     static napi_ref alphaTypeRef_;
64     static napi_ref scaleModeRef_;
65     static napi_ref componentTypeRef_;
66     static napi_ref decodingDynamicRangeRef_;
67     static napi_ref decodingResolutionQualityRef_;
68 
69     napi_env env_ = nullptr;
70     bool isRelease = false;
71 };
72 }
73 }
74 
75 #endif