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_PACKER_NAPI_H_ 17 #define 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 #include "pixel_map.h" 34 #include "image_source_napi.h" 35 36 namespace OHOS { 37 namespace Media { 38 class ImagePackerNapi { 39 public: 40 ImagePackerNapi(); 41 ~ImagePackerNapi(); 42 static napi_value Init(napi_env env, napi_value exports); 43 static napi_value CreateImagePacker(napi_env env, napi_callback_info info); 44 45 private: 46 static napi_value Constructor(napi_env env, napi_callback_info info); 47 static void Destructor(napi_env env, void *nativeObject, void *finalize); 48 static napi_value Packing(napi_env env, napi_callback_info info); 49 static napi_value PackingFromPixelMap(napi_env env, napi_callback_info info); 50 static napi_value Release(napi_env env, napi_callback_info info); 51 static napi_value GetSupportedFormats(napi_env env, napi_callback_info info); 52 53 static thread_local napi_ref sConstructor_; 54 static std::shared_ptr<ImageSource> sImgSource_; 55 static std::shared_ptr<ImagePacker> sImgPck_; 56 57 napi_env env_ = nullptr; 58 napi_ref wrapper_ = nullptr; 59 std::shared_ptr<ImagePacker> nativeImgPck = nullptr; 60 }; 61 } // namespace Media 62 } // namespace OHOS 63 #endif /* IMAGE_PACKER_NAPI_H_ */ 64