• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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_PIXEL_YUV_EXT_UTILS_H
17 #define FRAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_PIXEL_YUV_EXT_UTILS_H
18 
19 #include <cstdlib>
20 #include <cstdio>
21 #include <string>
22 #include "image_type.h"
23 #include "iosfwd"
24 
25 #include "image_convert_tools.h"
26 #include "image_converter.h"
27 #include "pixel_yuv_utils.h"
28 
29 namespace OHOS {
30 namespace Media {
31 enum YuvSizeType {
32     FLOAT,
33     INT,
34 };
35 
36 struct YuvPixels {
37     uint8_t *srcPixels;
38     uint8_t *dstPixels;
39     float xAxis;
40     float yAxis;
41     int32_t dstWidth;
42     int32_t dstHeight;
43     YuvSizeType sizeType = YuvSizeType::FLOAT;
44 };
45 
46 struct YuvCopyInfo {
47     uint32_t dstHeight;
48     uint32_t pixelsSize;
49 };
50 
51 class PixelYuvExtUtils {
52 public:
53     static bool BGRAToYuv420(const uint8_t *src, uint8_t *dst, int srcW, int srcH,
54         PixelFormat pixelFormat, YUVDataInfo &yuvDataInfo);
55     static bool Yuv420ToBGRA(const uint8_t *sample, uint8_t *dst_argb, Size &size,
56         PixelFormat pixelFormat, YUVDataInfo &info);
57     static bool Yuv420ToARGB(const uint8_t *sample, uint8_t *dst_argb, Size &size,
58         PixelFormat pixelFormat, YUVDataInfo &info);
59     static bool YuvRotate(uint8_t* srcPixels, const PixelFormat& format, YUVDataInfo& info, Size& dstSize,
60         uint8_t* dstPixels, YUVStrideInfo& dstStrides, OpenSourceLibyuv::RotationMode &rotateNum);
61     static void ConvertYuvMode(OpenSourceLibyuv ::FilterMode &filterMode, const AntiAliasingOption &option);
62     static void ScaleYuv420(float xAxis, float yAxis, const AntiAliasingOption &option,
63         YuvImageInfo &yuvInfo, uint8_t *src, uint8_t *dst, YUVStrideInfo &dstStrides);
64     static void ScaleYuv420(int32_t dstWidth, int32_t dstHeight, const AntiAliasingOption &option,
65         YuvImageInfo &yuvInfo, uint8_t *src, uint8_t *dst, YUVStrideInfo &dstStrides);
66     static bool Mirror(uint8_t *src, uint8_t *dst, Size &size, PixelFormat format, YUVDataInfo &info,
67         YUVStrideInfo &dstStrides, bool isReversed);
68     static bool FlipXaxis(uint8_t *src, uint8_t *dst, Size &size, PixelFormat format, YUVDataInfo &info,
69         YUVStrideInfo &dstStrides);
70     static bool NV12Rotate(uint8_t *src, PixelSize &size, YUVDataInfo &info,
71         OpenSourceLibyuv::RotationMode &rotateNum, uint8_t* dst, YUVStrideInfo &dstStrides);
72 };
73 } // namespace Media
74 } // namespace OHOS
75 #endif // RAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_PIXEL_YUV_EXT_UTILS_H