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