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 IMAGE_SOURCE_NAPI_H_ 17 #define 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 private: 43 static napi_value Constructor(napi_env env, napi_callback_info info); 44 static void Destructor(napi_env env, void *nativeObject, void *finalize); 45 46 // readonly property 47 static napi_value GetSupportedFormats(napi_env env, napi_callback_info info); 48 49 // static methods 50 static napi_value CreateImageSource(napi_env env, napi_callback_info info); 51 static napi_value CreateIncrementalSource(napi_env env, napi_callback_info info); 52 53 static napi_value CreateImageSourceComplete(napi_env env, napi_status status, void *data); 54 // methods 55 static napi_value GetImageInfo(napi_env env, napi_callback_info info); 56 static napi_value CreatePixelMap(napi_env env, napi_callback_info info); 57 static napi_value ModifyImageProperty(napi_env env, napi_callback_info info); 58 static napi_value GetImageProperty(napi_env env, napi_callback_info info); 59 static napi_value UpdateData(napi_env env, napi_callback_info info); 60 static napi_value Release(napi_env env, napi_callback_info info); 61 62 static thread_local napi_ref sConstructor_; 63 static std::shared_ptr<ImageSource> sImgSrc_; 64 static std::shared_ptr<IncrementalPixelMap> sIncPixelMap_; 65 std::shared_ptr<IncrementalPixelMap> navIncPixelMap_ = nullptr; 66 67 napi_env env_ = nullptr; 68 napi_ref wrapper_ = nullptr; 69 70 bool isRelease = false; 71 }; 72 } // namespace Media 73 } // namespace OHOS 74 #endif /* PIXEL_MAP_NAPI_H_ */ 75