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