• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 OHOS_COLOR_FORMAT_PROCESS_H
17 #define OHOS_COLOR_FORMAT_PROCESS_H
18 
19 #include "securec.h"
20 
21 #include "abstract_data_process.h"
22 #include "data_buffer.h"
23 #include "dcamera_pipeline_source.h"
24 #include "image_common_type.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 class ColorFormatProcess : public AbstractDataProcess {
29 public:
ColorFormatProcess(const std::weak_ptr<DCameraPipelineSource> & callbackPipSource)30     explicit ColorFormatProcess(const std::weak_ptr<DCameraPipelineSource>& callbackPipSource)
31         : callbackPipelineSource_(callbackPipSource) {}
32     ~ColorFormatProcess();
33 
34     int32_t InitNode(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig,
35         VideoConfigParams& processedConfig) override;
36     int32_t ProcessData(std::vector<std::shared_ptr<DataBuffer>>& inputBuffers) override;
37     void ReleaseProcessNode() override;
38 
39 private:
40     bool IsConvertible(const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig);
41     int32_t GetImageUnitInfo(ImageUnitInfo& imgInfo, const std::shared_ptr<DataBuffer>& imgBuf);
42     bool CheckColorProcessInputInfo(const ImageUnitInfo& srcImgInfo);
43     bool CheckColorConvertInfo(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
44     bool IsCorrectImageUnitInfo(const ImageUnitInfo& imgInfo);
45     void SeparateUVPlaneByRow(const uint8_t *srcUVPlane, uint8_t *dstUPlane, uint8_t *dstVPlane,
46         int32_t srcHalfWidth);
47     int32_t SeparateNV12UVPlane(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
48     void CombineUVPlaneByRow(const uint8_t *srcUPlane, const uint8_t *srcVPlane, uint8_t *dstUVPlane,
49         int32_t dstHalfWidth);
50     int32_t CombineNV12UVPlane(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
51     int32_t CopyYPlane(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
52     int32_t ColorConvertNV12ToNV21(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
53     int32_t ColorConvertNV12ToI420(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
54     int32_t ColorConvertByColorFormat(const ImageUnitInfo& srcImgInfo, const ImageUnitInfo& dstImgInfo);
55     int32_t ColorFormatDone(std::vector<std::shared_ptr<DataBuffer>>& outputBuffers);
56 
57 private:
58     constexpr static int32_t YUV_BYTES_PER_PIXEL = 3;
59     constexpr static int32_t Y2UV_RATIO = 2;
60 
61     std::weak_ptr<DCameraPipelineSource> callbackPipelineSource_;
62     VideoConfigParams sourceConfig_;
63     VideoConfigParams targetConfig_;
64     VideoConfigParams processedConfig_;
65     std::atomic<bool> isColorFormatProcess_ = false;
66 };
67 } // namespace DistributedHardware
68 } // namespace OHOS
69 #endif // OHOS_COLOR_FORMAT_PROCESS_H
70