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 
29 namespace OHOS {
30 namespace Media {
31 class SendableImageSourceNapi {
32 public:
33     SendableImageSourceNapi();
34     ~SendableImageSourceNapi();
35     std::shared_ptr<ImageSource> nativeImgSrc = nullptr;
36     static thread_local std::string filePath_;
37     static thread_local int fileDescriptor_;
38     static thread_local void* fileBuffer_;
39     static thread_local size_t fileBufferSize_;
40 
GetIncrementalPixelMap()41     std::shared_ptr<IncrementalPixelMap> GetIncrementalPixelMap()
42     {
43         return navIncPixelMap_;
44     }
45     static napi_value Init(napi_env env, napi_value exports);
46 private:
47     static napi_value Constructor(napi_env env, napi_callback_info info);
48     static void Destructor(napi_env env, void *nativeObject, void *finalize);
49 
50     static napi_value CreateImageSource(napi_env env, napi_callback_info info);
51     static napi_value CreatePixelMap(napi_env env, napi_callback_info info);
52     static napi_value Release(napi_env env, napi_callback_info info);
53 
54     void release();
55     static thread_local napi_ref sConstructor_;
56     static thread_local std::shared_ptr<ImageSource> sImgSrc_;
57     static std::shared_ptr<IncrementalPixelMap> sIncPixelMap_;
58     std::shared_ptr<IncrementalPixelMap> navIncPixelMap_ = nullptr;
59     static napi_ref pixelMapFormatRef_;
60     static napi_ref propertyKeyRef_;
61     static napi_ref imageFormatRef_;
62     static napi_ref alphaTypeRef_;
63     static napi_ref scaleModeRef_;
64     static napi_ref componentTypeRef_;
65     static napi_ref decodingDynamicRangeRef_;
66     static napi_ref decodingResolutionQualityRef_;
67 
68     napi_env env_ = nullptr;
69     bool isRelease = false;
70 };
71 }
72 }
73 
74 #endif