libcamera v0.2.0+3-70b69666-nvm
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
debayer_cpu.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2023, Linaro Ltd
4 * Copyright (C) 2023, Red Hat Inc.
5 *
6 * Authors:
7 * Hans de Goede <hdegoede@redhat.com>
8 *
9 * debayer_cpu.h - CPU based debayering header
10 */
11
12#pragma once
13
14#include <memory>
15#include <stdint.h>
16#include <vector>
17
19
21#include "libcamera/internal/software_isp/swstats_cpu.h"
22#include "libcamera/internal/software_isp/debayer.h"
23
24namespace libcamera {
25
32class DebayerCpu : public Debayer, public Object
33{
34public:
35 /*
36 * FIXME this should be a plain (implementation independent) SwStats
37 * this can be fixed once getStats() is dropped.
38 */
43 DebayerCpu(std::unique_ptr<SwStatsCpu> stats);
45
46 /*
47 * Setup the Debayer object according to the passed in parameters.
48 * Return 0 on success, a negative errno value on failure
49 * (unsupported parameters).
50 */
51 int configure(const StreamConfiguration &inputCfg,
52 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs);
53
54 /*
55 * Get width and height at which the bayer-pattern repeats.
56 * Return pattern-size or an empty Size for an unsupported inputFormat.
57 */
58 Size patternSize(PixelFormat inputFormat);
59
60 std::vector<PixelFormat> formats(PixelFormat input);
61 std::tuple<unsigned int, unsigned int>
62 strideAndFrameSize(const PixelFormat &outputFormat, const Size &size);
63
64 void process(FrameBuffer *input, FrameBuffer *output, DebayerParams params);
65 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
66
72 const SharedFD &getStatsFD() { return stats_->getStatsFD(); }
73
79 unsigned int frameSize() { return outputConfig_.frameSize; }
80
81private:
82 void setupInputMemcpy(const uint8_t *linePointers[]);
83 void shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src);
84 void memcpyNextLine(const uint8_t *linePointers[]);
85 void process2(const uint8_t *src, uint8_t *dst);
86 void process4(const uint8_t *src, uint8_t *dst);
87 /* 8-bit raw bayer format */
88 void debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
89 void debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
90 /* unpacked 10-bit raw bayer format */
91 void debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
92 void debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
93 /* unpacked 12-bit raw bayer format */
94 void debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
95 void debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
96 /* CSI-2 packed 10-bit raw bayer format (all the 4 orders) */
97 void debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
98 void debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
99 void debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]);
100 void debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]);
101 /* IGIG_GBGR_IGIG_GRGB unpacked 10-bit raw bayer format */
102 void debayerIGIG10Line0(uint8_t *dst, const uint8_t *src[]);
103 void debayerGBGR10Line1(uint8_t *dst, const uint8_t *src[]);
104 void debayerIGIG10Line2(uint8_t *dst, const uint8_t *src[]);
105 void debayerGRGB10Line3(uint8_t *dst, const uint8_t *src[]);
106
107 typedef void (DebayerCpu::*debayerFn)(uint8_t *dst, const uint8_t *src[]);
108
109 struct DebayerInputConfig {
110 Size patternSize;
111 unsigned int bpp; /* Memory used per pixel, not precision */
112 unsigned int stride;
113 std::vector<PixelFormat> outputFormats;
114 };
115
116 struct DebayerOutputConfig {
117 unsigned int bpp; /* Memory used per pixel, not precision */
118 unsigned int stride;
119 unsigned int frameSize;
120 };
121
122 int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
123 int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
124 int setupStandardBayerOrder(BayerFormat::Order order);
125 int setDebayerFunctions(PixelFormat inputFormat, PixelFormat outputFormat);
126
127 uint8_t gamma_[1024];
128 uint8_t red_[256];
129 uint8_t green_[256];
130 uint8_t blue_[256];
131 debayerFn debayer0_;
132 debayerFn debayer1_;
133 debayerFn debayer2_;
134 debayerFn debayer3_;
135 Rectangle window_;
136 DebayerInputConfig inputConfig_;
137 DebayerOutputConfig outputConfig_;
138 std::unique_ptr<SwStatsCpu> stats_;
139 uint8_t *lineBuffers_[5];
140 unsigned int lineBufferIndex_;
141 unsigned int x_shift_; /* Offset of 0/1 applied to window_.x */
142 bool enableInputMemcpy_;
143 bool swapRedBlueGains_;
144 float gamma_correction_;
145 int measuredFrames_;
146 int64_t frameProcessTime_;
147 /* Skip 30 frames for things to stabilize then measure 30 frames */
148 static const int framesToSkip = 30;
149 static const int framesToMeasure = 60;
150};
151
152} /* namespace libcamera */
Class to represent Bayer formats and manipulate them.
Order
The order of the colour channels in the Bayer pattern.
Definition bayer_format.h:25
Class for debayering on the CPU.
Definition debayer_cpu.h:33
Size patternSize(PixelFormat inputFormat)
Get the width and height at which the bayer pattern repeats.
Definition debayer_cpu.cpp:723
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize)
Get the supported output sizes for the given input format and size.
Definition debayer_cpu.cpp:993
unsigned int frameSize()
Get the output frame size.
Definition debayer_cpu.h:79
void process(FrameBuffer *input, FrameBuffer *output, DebayerParams params)
Process the bayer data into the requested format.
Definition debayer_cpu.cpp:914
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< StreamConfiguration > > &outputCfgs)
Configure the debayer object according to the passed in parameters.
Definition debayer_cpu.cpp:651
std::vector< PixelFormat > formats(PixelFormat input)
Get the supported output formats.
Definition debayer_cpu.cpp:733
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &outputFormat, const Size &size)
Get the stride and the frame size.
Definition debayer_cpu.cpp:744
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition debayer_cpu.h:72
Base debayering class.
Definition debayer.h:37
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
Base object to support automatic signal disconnection.
Definition object.h:25
libcamera image pixel format
Definition pixel_format.h:18
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
Describe a range of sizes.
Definition geometry.h:201
Describe a two-dimensional size.
Definition geometry.h:53
Top-level libcamera namespace.
Definition backtrace.h:17
Base object to support automatic signal disconnection.
Struct to hold the debayer parameters.
Definition debayer_params.h:18
Configuration parameters for a stream.
Definition stream.h:41