Loading...
Searching...
No Matches
debayer_cpu.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2023, Linaro Ltd
* Copyright (C) 2023-2026 Red Hat Inc.
*
* Authors:
* Hans de Goede <hdegoede@redhat.com>
*
* CPU based debayering header
*/
#pragma once
#include <memory>
#include <stdint.h>
#include <vector>
#include <libcamera/base/object.h>
#include "libcamera/internal/bayer_format.h"
#include "libcamera/internal/global_configuration.h"
#include "libcamera/internal/software_isp/debayer_params.h"
#include "libcamera/internal/software_isp/swstats_cpu.h"
#include "debayer.h"
namespace libcamera {
class DebayerCpu : public Debayer
{
public:
DebayerCpu(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);
~DebayerCpu();
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs,
bool ccmEnabled);
Size patternSize(PixelFormat inputFormat);
std::vector<PixelFormat> formats(PixelFormat input);
std::tuple<unsigned int, unsigned int>
strideAndFrameSize(const PixelFormat &outputFormat, const Size &size);
void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params);
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
const SharedFD &getStatsFD() { return stats_->getStatsFD(); }
private:
using debayerFn = void (DebayerCpu::*)(uint8_t *dst, const uint8_t *src[]);
/* 8-bit raw bayer format */
template<bool addAlphaByte, bool ccmEnabled>
void debayer8_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
template<bool addAlphaByte, bool ccmEnabled>
void debayer8_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
/* unpacked 10-bit raw bayer format */
template<bool addAlphaByte, bool ccmEnabled>
void debayer10_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
template<bool addAlphaByte, bool ccmEnabled>
void debayer10_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
/* unpacked 12-bit raw bayer format */
template<bool addAlphaByte, bool ccmEnabled>
void debayer12_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
template<bool addAlphaByte, bool ccmEnabled>
void debayer12_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
/* CSI-2 packed 10-bit raw bayer format (all the 4 orders) */
template<bool addAlphaByte, bool ccmEnabled>
void debayer10P_BGBG_BGR888(uint8_t *dst, const uint8_t *src[]);
template<bool addAlphaByte, bool ccmEnabled>
void debayer10P_GRGR_BGR888(uint8_t *dst, const uint8_t *src[]);
template<bool addAlphaByte, bool ccmEnabled>
void debayer10P_GBGB_BGR888(uint8_t *dst, const uint8_t *src[]);
template<bool addAlphaByte, bool ccmEnabled>
void debayer10P_RGRG_BGR888(uint8_t *dst, const uint8_t *src[]);
static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
int setupStandardBayerOrder(BayerFormat::Order order);
int setDebayerFunctions(PixelFormat inputFormat,
PixelFormat outputFormat,
bool ccmEnabled);
void setupInputMemcpy(const uint8_t *linePointers[]);
void shiftLinePointers(const uint8_t *linePointers[], const uint8_t *src);
void memcpyNextLine(const uint8_t *linePointers[]);
void process2(uint32_t frame, const uint8_t *src, uint8_t *dst);
void process4(uint32_t frame, const uint8_t *src, uint8_t *dst);
void updateGammaTable(DebayerParams &params);
void updateLookupTables(DebayerParams &params);
/* Max. supported Bayer pattern height is 4, debayering this requires 5 lines */
static constexpr unsigned int kMaxLineBuffers = 5;
static constexpr unsigned int kRGBLookupSize = 256;
static constexpr unsigned int kGammaLookupSize = 1024;
struct CcmColumn {
int16_t r;
int16_t g;
int16_t b;
};
using LookupTable = std::array<uint8_t, kRGBLookupSize>;
using CcmLookupTable = std::array<CcmColumn, kRGBLookupSize>;
LookupTable red_;
LookupTable green_;
LookupTable blue_;
CcmLookupTable redCcm_;
CcmLookupTable greenCcm_;
CcmLookupTable blueCcm_;
std::array<double, kGammaLookupSize> gammaTable_;
LookupTable gammaLut_;
bool ccmEnabled_;
DebayerParams params_;
debayerFn debayer0_;
debayerFn debayer1_;
debayerFn debayer2_;
debayerFn debayer3_;
Rectangle window_;
std::unique_ptr<SwStatsCpu> stats_;
std::vector<uint8_t> lineBuffers_[kMaxLineBuffers];
unsigned int lineBufferLength_;
unsigned int lineBufferPadding_;
unsigned int lineBufferIndex_;
unsigned int xShift_; /* Offset of 0/1 applied to window_.x */
bool enableInputMemcpy_;
};
} /* namespace libcamera */
bayer_format.h
Class to represent Bayer formats and manipulate them.
libcamera::BayerFormat::Order
Order
The order of the colour channels in the Bayer pattern.
Definition bayer_format.h:25
libcamera::DebayerCpu
Class for debayering on the CPU.
Definition debayer_cpu.h:30
libcamera::DebayerCpu::process
void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params)
Process the bayer data into the requested format.
Definition debayer_cpu.cpp:845
libcamera::DebayerCpu::patternSize
Size patternSize(PixelFormat inputFormat)
Get the width and height at which the bayer pattern repeats.
Definition debayer_cpu.cpp:569
libcamera::DebayerCpu::sizes
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize)
Get the supported output sizes for the given input format and size.
Definition debayer_cpu.cpp:893
libcamera::DebayerCpu::configure
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< StreamConfiguration > > &outputCfgs, bool ccmEnabled)
Configure the debayer object according to the passed in parameters.
Definition debayer_cpu.cpp:481
libcamera::DebayerCpu::DebayerCpu
DebayerCpu(std::unique_ptr< SwStatsCpu > stats, const GlobalConfiguration &configuration)
Constructs a DebayerCpu object.
Definition debayer_cpu.cpp:43
libcamera::DebayerCpu::formats
std::vector< PixelFormat > formats(PixelFormat input)
Get the supported output formats.
Definition debayer_cpu.cpp:579
libcamera::DebayerCpu::strideAndFrameSize
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &outputFormat, const Size &size)
Get the stride and the frame size.
Definition debayer_cpu.cpp:590
libcamera::DebayerCpu::getStatsFD
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition debayer_cpu.h:44
libcamera::Debayer::Debayer
Debayer(const GlobalConfiguration &configuration)
Construct a Debayer object.
Definition debayer.cpp:61
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
libcamera::GlobalConfiguration
Support for global libcamera configuration.
Definition global_configuration.h:22
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera::SharedFD
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
libcamera::SizeRange
Describe a range of sizes.
Definition geometry.h:205
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
object.h
Base object to support automatic signal disconnection.
libcamera::DebayerParams
Struct to hold the debayer parameters.
Definition debayer_params.h:20
libcamera::StreamConfiguration
Configuration parameters for a stream.
Definition stream.h:40