• 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 FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_UTILS_H
17 #define FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_UTILS_H
18 
19 #include <cstdlib>
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 class PixelMap;
31 
32 class ImageUtils {
33 public:
34     static bool GetFileSize(const std::string &pathName, size_t &size);
35     static bool GetFileSize(const int fd, size_t &size);
36     static bool GetInputStreamSize(std::istream &inputStream, size_t &size);
37     static int32_t GetPixelBytes(const PixelFormat &pixelFormat);
38     static bool PathToRealPath(const std::string &path, std::string &realPath);
39     static bool FloatCompareZero(float src);
40     static AlphaType GetValidAlphaTypeByFormat(const AlphaType &dstType, const PixelFormat &format);
41     static bool IsValidImageInfo(const ImageInfo &info);
42     static MultimediaPlugin::PluginServer& GetPluginServer();
43     static bool CheckMulOverflow(int32_t width, int32_t bytesPerPixel);
44     static bool CheckMulOverflow(int32_t width, int32_t height, int32_t bytesPerPixel);
45     static void BGRAToARGB(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount);
46     static void ARGBToBGRA(uint8_t* srcPixels, uint8_t* dstPixels, uint32_t byteCount);
47     static int32_t SurfaceBuffer_Reference(void* buffer);
48     static int32_t SurfaceBuffer_Unreference(void* buffer);
49     static void DumpPixelMapIfDumpEnabled(std::unique_ptr<PixelMap>& pixelMap, uint64_t imageId = 0);
50     static void DumpPixelMapBeforeEncode(PixelMap& pixelMap);
51     static void DumpDataIfDumpEnabled(const char* data, const size_t& totalSize, const std::string& fileSuffix = "dat",
52         uint64_t imageId = 0);
53 
54 private:
55     static uint32_t RegisterPluginServer();
56     static uint32_t SaveDataToFile(const std::string& fileName, const char* data, const size_t& totalSize);
57     static std::string GetLocalTime();
58     static std::string GetPixelMapName(PixelMap* pixelMap);
59 };
60 } // namespace Media
61 } // namespace OHOS
62 #endif // FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_IMAGE_UTILS_H
63