• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_NAPI_H_
17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_NAPI_H_
18 
19 #include "pixel_map.h"
20 #include "image_type.h"
21 #include "image_source.h"
22 #include "napi/native_api.h"
23 #include "napi/native_node_api.h"
24 #include "pixel_map_napi.h"
25 #include "incremental_pixel_map.h"
26 #include "image_resource_utils.h"
27 
28 namespace OHOS {
29 namespace Media {
30 class ImageSourceNapi {
31 public:
32     ImageSourceNapi();
33     ~ImageSourceNapi();
34 
35     static napi_value Init(napi_env env, napi_value exports);
36     std::shared_ptr<ImageSource> nativeImgSrc = nullptr;
GetIncrementalPixelMap()37     std::shared_ptr<IncrementalPixelMap> GetIncrementalPixelMap()
38     {
39         return navIncPixelMap_;
40     }
41 
42     static std::string filePath_;
43     static int fileDescriptor_;
44     static void* fileBuffer_;
45     static size_t fileBufferSize_;
46     static int32_t CreateImageSourceNapi(napi_env env, napi_value* result);
47     void SetIncrementalPixelMap(std::shared_ptr<IncrementalPixelMap> incrementalPixelMap);
48     void SetNativeImageSource(std::shared_ptr<ImageSource> imageSource);
49     void SetImageResource(ImageResource resource);
50     ImageResource GetImageResource();
51 
52 private:
53     static napi_value Constructor(napi_env env, napi_callback_info info);
54     static void Destructor(napi_env env, void *nativeObject, void *finalize);
55 
56     // readonly property
57     static napi_value GetSupportedFormats(napi_env env, napi_callback_info info);
58 
59     // static methods
60     static napi_value CreateImageSource(napi_env env, napi_callback_info info);
61     static napi_value CreateIncrementalSource(napi_env env, napi_callback_info info);
62 
63     static napi_value CreateImageSourceComplete(napi_env env, napi_status status, void *data);
64     // methods
65     static napi_value GetImageInfo(napi_env env, napi_callback_info info);
66     static napi_value CreatePixelMap(napi_env env, napi_callback_info info);
67     static napi_value ModifyImageProperty(napi_env env, napi_callback_info info);
68     static napi_value GetImageProperty(napi_env env, napi_callback_info info);
69     static napi_value UpdateData(napi_env env, napi_callback_info info);
70     static napi_value Release(napi_env env, napi_callback_info info);
71     static napi_value CreatePixelMapList(napi_env env, napi_callback_info info);
72     static napi_value GetDelayTime(napi_env env, napi_callback_info info);
73     static napi_value GetFrameCount(napi_env env, napi_callback_info info);
74 
75     void release();
76     static thread_local napi_ref sConstructor_;
77     static std::shared_ptr<ImageSource> sImgSrc_;
78     static std::shared_ptr<IncrementalPixelMap> sIncPixelMap_;
79     std::shared_ptr<IncrementalPixelMap> navIncPixelMap_ = nullptr;
80     static napi_ref pixelMapFormatRef_;
81     static napi_ref propertyKeyRef_;
82     static napi_ref imageFormatRef_;
83     static napi_ref alphaTypeRef_;
84     static napi_ref scaleModeRef_;
85     static napi_ref componentTypeRef_;
86 
87     napi_env env_ = nullptr;
88     bool isRelease = false;
89     ImageResource resource_;
90 };
91 } // namespace Media
92 } // namespace OHOS
93 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_NAPI_H_
94