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 FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_UTILS_H_ 17 #define FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_UTILS_H_ 18 19 #include <stdint.h> 20 #include <cstdio> 21 #include <string> 22 #include "image_type.h" 23 #include "iosfwd" 24 25 namespace OHOS { namespace MultimediaPlugin { class PluginServer; } } 26 namespace OHOS { 27 namespace Media { 28 const std::string IMAGE_ENCODE_FORMAT = "encodeFormat"; 29 constexpr uint32_t MALLOC_MAX_LENTH = 0x40000000; 30 31 class ImageUtils { 32 public: 33 static bool GetFileSize(const std::string &pathName, size_t &size); 34 static bool GetFileSize(const int fd, size_t &size); 35 static bool GetInputStreamSize(std::istream &inputStream, size_t &size); 36 static int32_t GetPixelBytes(const PixelFormat &pixelFormat); 37 static bool PathToRealPath(const std::string &path, std::string &realPath); 38 static bool FloatCompareZero(float src); 39 static AlphaType GetValidAlphaTypeByFormat(const AlphaType &dstType, const PixelFormat &format); 40 static bool IsValidImageInfo(const ImageInfo &info); 41 static MultimediaPlugin::PluginServer& GetPluginServer(); 42 static bool CheckMulOverflow(int32_t width, int32_t bytesPerPixel); 43 static bool CheckMulOverflow(int32_t width, int32_t height, int32_t bytesPerPixel); 44 45 private: 46 static uint32_t RegisterPluginServer(); 47 }; 48 } // namespace Media 49 } // namespace OHOS 50 #endif // FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_UTILS_H_ 51