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 }; 43 44 class ImageFormatConvert { 45 friend class ImageFormatConvertTest; 46 public: 47 static uint32_t ConvertImageFormat(const ConvertDataInfo &srcDataInfo, DestConvertInfo &destInfo); 48 static uint32_t ConvertImageFormat(std::shared_ptr<PixelMap> &srcPiexlMap, PixelFormat destFormat); 49 static uint32_t MakeDestPixelMapUnique(std::unique_ptr<PixelMap> &destPixelMap, 50 ImageInfo &srcImageinfo, DestConvertInfo &destInfo, void *context); 51 static uint32_t RGBConvertImageFormatOptionUnique(std::unique_ptr<PixelMap> &srcPiexlMap, 52 const PixelFormat &srcFormat, PixelFormat destFormat); 53 static bool SetConvertImageMetaData(PixelMap *srcPixelMap, PixelMap *dstPixelMap); 54 private: 55 static bool IsValidSize(const Size &size); 56 static bool CheckConvertDataInfo(const ConvertDataInfo &convertDataInfo); 57 static uint32_t YUVConvertImageFormatOption(std::shared_ptr<PixelMap> &srcPiexlMap, const PixelFormat &srcFormat, 58 PixelFormat destFormat); 59 static size_t GetBufferSizeByFormat(PixelFormat format, const Size &size); 60 static ConvertFunction GetConvertFuncByFormat(PixelFormat srcFormat, PixelFormat destFormat); 61 static YUVConvertFunction YUVGetConvertFuncByFormat(PixelFormat srcFormat, PixelFormat destFormat); 62 static uint32_t MakeDestPixelMap(std::shared_ptr<PixelMap> &destPixelMap, ImageInfo &srcImageinfo, 63 DestConvertInfo &destInfo, void *context); 64 static bool IsSupport(PixelFormat format); 65 static std::unique_ptr<AbsMemory> CreateMemory(PixelFormat pixelFormat, 66 AllocatorType allocatorType, int32_t width, int32_t height, 67 YUVStrideInfo &strides); 68 static uint32_t RGBConvertImageFormatOption(std::shared_ptr<PixelMap> &srcPiexlMap, 69 const PixelFormat &srcFormat, PixelFormat destFormat); 70 }; 71 } //OHOS 72 } //Media 73 #endif // INTERFACES_INNERKITS_INCLUDE_IMAGE_FORMAT_CONVERT_H