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 struct YuvPixels {
32     uint8_t *srcPixels;
33     uint8_t *dstPixels;
34     float xAxis;
35     float yAxis;
36 };
37 
38 class PixelYuvExtUtils {
39 public:
40     static bool BGRAToYuv420(const uint8_t *src, uint8_t *dst, int srcW, int srcH,
41         PixelFormat pixelFormat, YUVDataInfo &yuvDataInfo);
42     static bool Yuv420ToBGRA(const uint8_t *sample, uint8_t *dst_argb, Size &size,
43         PixelFormat pixelFormat, YUVDataInfo &info);
44     static bool Yuv420ToARGB(const uint8_t *sample, uint8_t *dst_argb, Size &size,
45         PixelFormat pixelFormat, YUVDataInfo &info);
46     static bool YuvRotate(uint8_t* srcPixels, const PixelFormat& format, YUVDataInfo& info, Size& dstSize,
47         uint8_t* dstPixels, YUVStrideInfo& dstStrides, OpenSourceLibyuv::RotationMode &rotateNum);
48     static void ConvertYuvMode(OpenSourceLibyuv ::FilterMode &filterMode, const AntiAliasingOption &option);
49     static void ScaleYuv420(float xAxis, float yAxis, const AntiAliasingOption &option,
50         YuvImageInfo &yuvInfo, uint8_t *src, uint8_t *dst, YUVStrideInfo &dstStrides);
51     static void ScaleYuv420(int32_t dst_width, int32_t dst_height, const AntiAliasingOption &option,
52         YuvImageInfo &yuvInfo, uint8_t *src, uint8_t *dst, YUVStrideInfo &dstStrides);
53     static bool Mirror(uint8_t *src, uint8_t *dst, Size &size, PixelFormat format, YUVDataInfo &info,
54         YUVStrideInfo &dstStrides, bool isReversed);
55     static bool FlipXaxis(uint8_t *src, uint8_t *dst, Size &size, PixelFormat format, YUVDataInfo &info,
56         YUVStrideInfo &dstStrides);
57     static bool NV12Rotate(uint8_t *src, PixelSize &size, YUVDataInfo &info,
58         OpenSourceLibyuv::RotationMode &rotateNum, uint8_t* dst, YUVStrideInfo &dstStrides);
59 };
60 } // namespace Media
61 } // namespace OHOS
62 #endif // RAMEWORKS_INNERKITSIMPL_UTILS_INCLUDE_PIXEL_YUV_EXT_UTILS_H