• 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_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 #include "post_proc_slr.h"
25 
26 namespace OHOS {
27 namespace Media {
28 enum class CropValue : int32_t { INVALID, VALID, NOCROP };
29 
30 class PostProc {
31 public:
32     uint32_t DecodePostProc(const DecodeOptions &opts, PixelMap &pixelMap,
33                             FinalOutputStep finalOutputStep = FinalOutputStep::NO_CHANGE);
34     uint32_t ConvertProc(const Rect &cropRect, ImageInfo &dstImageInfo, PixelMap &pixelMap, ImageInfo &srcImageInfo);
35     static bool IsHasCrop(const Rect &rect);
36     bool HasPixelConvert(const ImageInfo &srcImageInfo, ImageInfo &dstImageInfo);
37     bool RotatePixelMap(float rotateDegrees, PixelMap &pixelMap);
38     bool ScalePixelMap(const Size &size, PixelMap &pixelMap);
39     bool ScalePixelMap(float scaleX, float scaleY, PixelMap &pixelMap);
40     bool TranslatePixelMap(float tX, float tY, PixelMap &pixelMap);
41     bool CenterScale(const Size &size, PixelMap &pixelMap);
42     static CropValue GetCropValue(const Rect &rect, const Size &size);
43     static CropValue ValidCropValue(Rect &rect, const Size &size);
44     bool ScalePixelMapWithSLR(const Size &desiredSize, PixelMap &pixelMap, bool useLap = true);
45     bool ScalePixelMapEx(const Size &desiredSize, PixelMap &pixelMap,
46         const AntiAliasingOption &option = AntiAliasingOption::NONE);
47 #if !defined(_WIN32) && !defined(_APPLE) && !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
48     static bool RotateInRectangularSteps(PixelMap &pixelMap, float degrees, bool useGpu = false);
49     static bool ScalePixelMapWithGPU(PixelMap &pixelMap, const Size &desiredSize,
50         const AntiAliasingOption &option, bool useGpu = false);
51 #endif
52 
53 private:
54     static uint8_t *AllocSharedMemory(const Size &size, const uint64_t bufferSize, int &fd, uint32_t uniqueId);
55     static uint8_t *AllocDmaMemory(ImageInfo info, const uint64_t bufferSize,
56                                    void **nativeBuffer, int &targetRowStride);
57     uint32_t NeedScanlineFilter(const Rect &cropRect, const Size &srcSize, const bool &hasPixelConvert);
58     void GetDstImageInfo(const DecodeOptions &opts, PixelMap &pixelMap,
59                          ImageInfo srcImageInfo, ImageInfo &dstImageInfo);
60     uint32_t PixelConvertProc(ImageInfo &dstImageInfo, PixelMap &pixelMap, ImageInfo &srcImageInfo);
61     uint32_t AllocBuffer(ImageInfo imageInfo, uint8_t **resultData, uint64_t &dataSize, int &fd, uint32_t uniqueId);
62     bool AllocHeapBuffer(uint64_t bufferSize, uint8_t **buffer);
63     void ReleaseBuffer(AllocatorType allocatorType, int fd, uint64_t dataSize,
64                        uint8_t **buffer, void *nativeBuffer = nullptr);
65     bool Transform(BasicTransformer &trans, const PixmapInfo &input, PixelMap &pixelMap);
66     void ConvertPixelMapToPixmapInfo(PixelMap &pixelMap, PixmapInfo &pixmapInfo);
67     void SetScanlineCropAndConvert(const Rect &cropRect, ImageInfo &dstImageInfo, ImageInfo &srcImageInfo,
68                                    ScanlineFilter &scanlineFilter, bool hasPixelConvert);
69     bool CenterDisplay(PixelMap &pixelMap, int32_t srcWidth, int32_t srcHeight, int32_t targetWidth,
70                        int32_t targetHeight);
71     uint32_t CheckScanlineFilter(const Rect &cropRect, ImageInfo &dstImageInfo, PixelMap &pixelMap,
72                                  int32_t pixelBytes, ScanlineFilter &scanlineFilter);
73     bool CopyPixels(PixelMap& pixelMap, uint8_t* dstPixels, const Size& dstSize,
74                     const int32_t srcWidth, const int32_t srcHeight,
75                     int srcRowStride = 0, int targetRowStride = 0);
76     bool ProcessScanlineFilter(ScanlineFilter &scanlineFilter, const Rect &cropRect, PixelMap &pixelMap,
77                                uint8_t *resultData, uint32_t rowBytes);
78 private:
79     DecodeOptions decodeOpts_;
80 };
81 } // namespace Media
82 } // namespace OHOS
83 
84 #endif // FRAMEWORKS_INNERKITSIMPL_CONVERTER_INCLUDE_POST_PROC_H
85