hc
2023-02-14 0cc9b7c44253c93447ddf73e206fbdbb3d9f16b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * image_processor.h - 2D Image Process Hardware Implementation
 *
 *  Copyright (c) 2021 Rockchip Electronics Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Cody Xie <cody.xie@rock-chips.com>
 */
#ifndef _IMAGE_PROC_HW_H_
#define _IMAGE_PROC_HW_H_
 
#include <memory>
#include <string>
 
#include "common/rk_aiq_types.h"
#include "xcam_common.h"
 
namespace RkCam {
 
typedef struct {
    int x;      /* upper-left x */
    int y;      /* upper-left y */
    int width;  /* width */
    int height; /* height */
} img_rect_t;
 
typedef struct {
    void* vir_addr;         /* virtual address */
    void* phy_addr;         /* physical address */
    int fd;                 /* shared fd */
    int width;              /* width */
    int height;             /* height */
    int wstride;            /* wstride */
    int hstride;            /* hstride */
    rk_aiq_format_t format; /* format */
} img_buffer_t;
 
class ImageOperator {
 public:
    ImageOperator(const std::string name);
    ImageOperator(const ImageOperator&) = delete;
    ImageOperator& operator=(const ImageOperator&) = delete;
    virtual ~ImageOperator() = default;
 
    const std::string get_name() { return name_; };
 
    virtual XCamReturn crop(const img_buffer_t& src, img_buffer_t& dst, img_rect_t rect,
                            int sync = 1);
    virtual XCamReturn resize(const img_buffer_t& src, img_buffer_t& dst, double fx, double fy,
                              int interpolation = 0, int sync = 1);
    virtual XCamReturn cvtcolor(img_buffer_t& src, img_buffer_t& dst, int sfmt, int dfmt, int mode,
                                int sync = 1);
    virtual XCamReturn rotate(const img_buffer_t& src, img_buffer_t& dst, int rotation,
                              int sync = 1);
    virtual XCamReturn flip(const img_buffer_t& src, img_buffer_t& dst, int mode, int sync = 1);
    virtual XCamReturn copy(const img_buffer_t& src, img_buffer_t& dst, int sync = 1);
 
 private:
    std::string name_;
};
 
class ImageProcessor {
 public:
    ImageProcessor()                      = default;
    ImageProcessor(const ImageProcessor&) = delete;
    ImageProcessor& operator=(const ImageProcessor&) = delete;
    ~ImageProcessor()                                = default;
 
    void set_operator(const std::string& name);
 
    XCamReturn resize(const img_buffer_t& src, img_buffer_t& dst, double factor_x, double factor_y);
    XCamReturn crop(const img_buffer_t& src, img_buffer_t& dst, const img_rect_t& rect);
    XCamReturn cvtcolor(img_buffer_t& src, img_buffer_t& dst, int sfmt, int dfmt, int mode,
                        int sync = 1);
    XCamReturn rotate(const img_buffer_t& src, img_buffer_t& dst, int rotation, int sync = 1);
    XCamReturn flip(const img_buffer_t& src, img_buffer_t& dst, int mode, int sync = 1);
    XCamReturn copy(const img_buffer_t& src, img_buffer_t& dst, int sync = 1);
 
 private:
    std::unique_ptr<ImageOperator> operator_;
};
 
};  // namespace RkCam
 
#endif  // _IMAGE_PROC_HW_H_