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_CONVERTER_INCLUDE_POST_PROC_H_ 17 #define FRAMEWORKS_INNERKITSIMPL_CONVERTER_INCLUDE_POST_PROC_H_ 18 19 #include <vector> 20 #include "basic_transformer.h" 21 #include "image_type.h" 22 #include "pixel_map.h" 23 #include "scan_line_filter.h" 24 25 namespace OHOS { 26 namespace Media { 27 enum class CropValue : int32_t { INVALID, VALID, NOCROP }; 28 29 class PostProc { 30 public: 31 uint32_t DecodePostProc(const DecodeOptions &opts, PixelMap &pixelMap, 32 FinalOutputStep finalOutputStep = FinalOutputStep::NO_CHANGE); 33 uint32_t ConvertProc(const Rect &cropRect, ImageInfo &dstImageInfo, PixelMap &pixelMap, ImageInfo &srcImageInfo); 34 static bool IsHasCrop(const Rect &rect); 35 bool HasPixelConvert(const ImageInfo &srcImageInfo, ImageInfo &dstImageInfo); 36 bool RotatePixelMap(float rotateDegrees, PixelMap &pixelMap); 37 bool ScalePixelMap(const Size &size, PixelMap &pixelMap); 38 bool ScalePixelMap(float scaleX, float scaleY, PixelMap &pixelMap); 39 bool TranslatePixelMap(float tX, float tY, PixelMap &pixelMap); 40 bool CenterScale(const Size &size, PixelMap &pixelMap); 41 static CropValue GetCropValue(const Rect &rect, const Size &size); 42 static CropValue ValidCropValue(Rect &rect, const Size &size); 43 44 private: 45 static uint8_t *AllocSharedMemory(const Size &size, const uint64_t bufferSize, int &fd); 46 uint32_t NeedScanlineFilter(const Rect &cropRect, const Size &srcSize, const bool &hasPixelConvert); 47 void GetDstImageInfo(const DecodeOptions &opts, PixelMap &pixelMap, 48 ImageInfo srcImageInfo, ImageInfo &dstImageInfo); 49 uint32_t PixelConvertProc(ImageInfo &dstImageInfo, PixelMap &pixelMap, ImageInfo &srcImageInfo); 50 uint32_t AllocBuffer(ImageInfo imageInfo, uint8_t **resultData, uint64_t &dataSize, int &fd); 51 bool AllocHeapBuffer(uint64_t bufferSize, uint8_t **buffer); 52 void ReleaseBuffer(AllocatorType allocatorType, int fd, uint64_t dataSize, uint8_t **buffer); 53 bool Transform(BasicTransformer &trans, const PixmapInfo &input, PixelMap &pixelMap); 54 void ConvertPixelMapToPixmapInfo(PixelMap &pixelMap, PixmapInfo &pixmapInfo); 55 void SetScanlineCropAndConvert(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo, 56 ScanlineFilter &scanlineFilter, bool hasPixelConvert); 57 bool CenterDisplay(PixelMap &pixelMap, int32_t srcWidth, int32_t srcHeight, int32_t targetWidth, 58 int32_t targetHeight); 59 uint32_t CheckScanlineFilter(const Rect &cropRect, ImageInfo &dstImageInfo, PixelMap &pixelMap, 60 int32_t pixelBytes, ScanlineFilter &scanlineFilter); 61 DecodeOptions decodeOpts_; 62 }; 63 } // namespace Media 64 } // namespace OHOS 65 66 #endif // FRAMEWORKS_INNERKITSIMPL_CONVERTER_INCLUDE_POST_PROC_H_ 67