1 /* 2 * Copyright (C) 2022 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_PACKER_NAPI_H 17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_PACKER_NAPI_H 18 19 #include <cerrno> 20 #include <dirent.h> 21 #include <fcntl.h> 22 #include <ftw.h> 23 #include <securec.h> 24 #include <sys/stat.h> 25 #include <unistd.h> 26 #include <variant> 27 28 #include "image_packer.h" 29 #include "image_type.h" 30 #include "image_source.h" 31 #include "napi/native_api.h" 32 #include "napi/native_node_api.h" 33 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM) 34 #include "picture_napi.h" 35 #endif 36 #include "pixel_map.h" 37 #include "image_source_napi.h" 38 39 namespace OHOS { 40 namespace Media { 41 class ImagePackerNapi { 42 public: 43 ImagePackerNapi(); 44 ~ImagePackerNapi(); 45 static napi_value Init(napi_env env, napi_value exports); 46 static napi_value CreateImagePacker(napi_env env, napi_callback_info info); 47 static std::shared_ptr<ImagePacker> GetNative(ImagePackerNapi* napi); 48 49 private: 50 static napi_value Constructor(napi_env env, napi_callback_info info); 51 static void Destructor(napi_env env, void *nativeObject, void *finalize); 52 static napi_value Packing(napi_env env, napi_callback_info info); 53 static napi_value PackToData(napi_env env, napi_callback_info info); 54 static napi_value Packing(napi_env env, napi_callback_info info, bool needReturnError); 55 static napi_value PackingFromPixelMap(napi_env env, napi_callback_info info); 56 static napi_value PackToFile(napi_env env, napi_callback_info info); 57 static napi_value Release(napi_env env, napi_callback_info info); 58 static napi_value GetSupportedFormats(napi_env env, napi_callback_info info); 59 60 void release(); 61 bool isRelease = false; 62 static thread_local napi_ref sConstructor_; 63 static thread_local std::shared_ptr<ImagePacker> sImgPck_; 64 static napi_ref packingDynamicRangeRef_; 65 napi_env env_ = nullptr; 66 std::shared_ptr<ImagePacker> nativeImgPck = nullptr; 67 }; 68 } // namespace Media 69 } // namespace OHOS 70 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_IMAGE_PACKER_NAPI_H 71