• 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 
27 namespace OHOS {
28 namespace Media {
29 class ImageSourceNapi {
30 public:
31     ImageSourceNapi();
32     ~ImageSourceNapi();
33 
34     static napi_value Init(napi_env env, napi_value exports);
35     std::shared_ptr<ImageSource> nativeImgSrc = nullptr;
GetIncrementalPixelMap()36     std::shared_ptr<IncrementalPixelMap> GetIncrementalPixelMap()
37     {
38         return navIncPixelMap_;
39     }
40 
41     static std::string filePath_;
42     static int fileDescriptor_;
43     static void* fileBuffer_;
44     static size_t fileBufferSize_;
45 
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     // readonly property
51     static napi_value GetSupportedFormats(napi_env env, napi_callback_info info);
52 
53     // static methods
54     static napi_value CreateImageSource(napi_env env, napi_callback_info info);
55     static napi_value CreateIncrementalSource(napi_env env, napi_callback_info info);
56 
57     static napi_value CreateImageSourceComplete(napi_env env, napi_status status, void *data);
58     // methods
59     static napi_value GetImageInfo(napi_env env, napi_callback_info info);
60     static napi_value CreatePixelMap(napi_env env, napi_callback_info info);
61     static napi_value ModifyImageProperty(napi_env env, napi_callback_info info);
62     static napi_value GetImageProperty(napi_env env, napi_callback_info info);
63     static napi_value UpdateData(napi_env env, napi_callback_info info);
64     static napi_value Release(napi_env env, napi_callback_info info);
65 
66     void release();
67     static thread_local napi_ref sConstructor_;
68     static std::shared_ptr<ImageSource> sImgSrc_;
69     static std::shared_ptr<IncrementalPixelMap> sIncPixelMap_;
70     std::shared_ptr<IncrementalPixelMap> navIncPixelMap_ = nullptr;
71     static napi_ref pixelMapFormatRef_;
72     static napi_ref propertyKeyRef_;
73     static napi_ref imageFormatRef_;
74     static napi_ref alphaTypeRef_;
75     static napi_ref scaleModeRef_;
76     static napi_ref componentTypeRef_;
77 
78     napi_env env_ = nullptr;
79     bool isRelease = false;
80 };
81 } // namespace Media
82 } // namespace OHOS
83 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_SOURCE_NAPI_H_
84