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 INTERFACES_INNERKITS_INCLUDE_IMAGE_FORMAT_CONVERT_H 17 #define INTERFACES_INNERKITS_INCLUDE_IMAGE_FORMAT_CONVERT_H 18 19 #include <memory> 20 21 #include "image_format_convert_utils.h" 22 #include "image_plugin_type.h" 23 #include "image_type.h" 24 #include "pixel_map.h" 25 #include "memory_manager.h" 26 27 namespace OHOS { 28 namespace Media { 29 using uint8_buffer_type = uint8_t *; 30 using const_uint8_buffer_type = const uint8_t *; 31 32 using ConvertFunction = bool(*)(const uint8_t*, const RGBDataInfo&, DestConvertInfo &destInfo, 33 [[maybe_unused]]ColorSpace); 34 using YUVConvertFunction = bool(*)(const uint8_t*, const YUVDataInfo&, DestConvertInfo &destInfo, 35 [[maybe_unused]]ColorSpace); 36 struct ConvertDataInfo { 37 uint8_buffer_type buffer = nullptr; 38 size_t bufferSize; 39 Size imageSize; 40 PixelFormat pixelFormat = PixelFormat::UNKNOWN; 41 ColorSpace colorSpace = ColorSpace::SRGB; 42 YUVDataInfo yuvDataInfo; 43 }; 44 45 class ImageFormatConvert { 46 friend class ImageFormatConvertTest; 47 public: 48 static uint32_t ConvertImageFormat(const ConvertDataInfo &srcDataInfo, DestConvertInfo &destInfo); 49 static uint32_t ConvertImageFormat(std::shared_ptr<PixelMap> &srcPiexlMap, PixelFormat destFormat); 50 static uint32_t MakeDestPixelMapUnique(std::unique_ptr<PixelMap> &destPixelMap, 51 ImageInfo &srcImageinfo, DestConvertInfo &destInfo, void *context); 52 static uint32_t RGBConvertImageFormatOptionUnique(std::unique_ptr<PixelMap> &srcPiexlMap, 53 const PixelFormat &srcFormat, PixelFormat destFormat); 54 static bool SetConvertImageMetaData(std::unique_ptr<PixelMap> &srcPixelMap, std::unique_ptr<PixelMap> &dstPixelMap); 55 static bool SetConvertImageMetaData(std::shared_ptr<PixelMap> &srcPixelMap, std::unique_ptr<PixelMap> &dstPixelMap); 56 private: 57 static bool IsValidSize(const Size &size); 58 static bool CheckConvertDataInfo(const ConvertDataInfo &convertDataInfo); 59 static uint32_t YUVConvertImageFormatOption(std::shared_ptr<PixelMap> &srcPiexlMap, const PixelFormat &srcFormat, 60 PixelFormat destFormat); 61 static size_t GetBufferSizeByFormat(PixelFormat format, const Size &size); 62 static ConvertFunction GetConvertFuncByFormat(PixelFormat srcFormat, PixelFormat destFormat); 63 static YUVConvertFunction YUVGetConvertFuncByFormat(PixelFormat srcFormat, PixelFormat destFormat); 64 static uint32_t MakeDestPixelMap(std::shared_ptr<PixelMap> &destPixelMap, ImageInfo &srcImageinfo, 65 DestConvertInfo &destInfo, void *context); 66 static bool IsSupport(PixelFormat format); 67 static std::unique_ptr<AbsMemory> CreateMemory(PixelFormat pixelFormat, 68 AllocatorType allocatorType, Size size, 69 YUVStrideInfo &strides, uint64_t usage = 0); 70 static uint32_t RGBConvertImageFormatOption(std::shared_ptr<PixelMap> &srcPiexlMap, 71 const PixelFormat &srcFormat, PixelFormat destFormat); 72 static uint32_t YUVConvert(const ConvertDataInfo &srcDataInfo, DestConvertInfo &destInfo); 73 static uint32_t RGBConvert(const ConvertDataInfo &srcDataInfo, DestConvertInfo &destInfo); 74 }; 75 } //OHOS 76 } //Media 77 #endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_FORMAT_CONVERT_H