Loading...
Searching...
No Matches
debayer_egl.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2025, Bryan O'Donoghue.
*
* Authors:
* Bryan O'Donoghue <bryan.odonoghue@linaro.org>
*
*/
#pragma once
#include <memory>
#include <stdint.h>
#include <vector>
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <libcamera/base/object.h>
#include "libcamera/internal/bayer_format.h"
#include "libcamera/internal/egl.h"
#include "libcamera/internal/framebuffer.h"
#include "libcamera/internal/mapped_framebuffer.h"
#include "libcamera/internal/software_isp/benchmark.h"
#include "libcamera/internal/software_isp/swstats_cpu.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES3/gl32.h>
#include "debayer.h"
namespace libcamera {
#define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4
#define DEBAYER_OPENGL_COORDS 4
class DebayerEGL : public Debayer
{
public:
DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);
~DebayerEGL();
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);
int start();
void stop();
const SharedFD &getStatsFD() { return stats_->getStatsFD(); }
unsigned int frameSize();
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
private:
static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
int setupStandardBayerOrder(BayerFormat::Order order);
void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
int initEGLContext();
int generateTextures();
int compileShaderProgram(GLuint &shaderId, GLenum shaderType,
unsigned char *shaderData, int shaderDataLen,
std::vector<std::string> shaderEnv);
int linkShaderProgram(void);
int getShaderVariableLocations();
void setShaderVariableValues(DebayerParams &params);
void configureTexture(GLuint &texture);
int debayerGPU(MappedFrameBuffer &in, int out_fd, DebayerParams &params);
/* Shader program identifiers */
GLuint vertexShaderId_ = 0;
GLuint fragmentShaderId_ = 0;
GLuint programId_ = 0;
/* Pointer to object representing input texture */
std::unique_ptr<eGLImage> eglImageBayerIn_;
std::unique_ptr<eGLImage> eglImageBayerOut_;
/* Shader parameters */
float firstRed_x_;
float firstRed_y_;
GLint attributeVertex_;
GLint attributeTexture_;
GLint textureUniformStep_;
GLint textureUniformSize_;
GLint textureUniformStrideFactor_;
GLint textureUniformBayerFirstRed_;
GLint textureUniformProjMatrix_;
GLint textureUniformBayerDataIn_;
/* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
GLint ccmUniformDataIn_;
/* Black Level compensation */
GLint blackLevelUniformDataIn_;
/* Gamma */
GLint gammaUniformDataIn_;
/* Contrast */
GLint contrastExpUniformDataIn_;
Rectangle window_;
std::unique_ptr<SwStatsCpu> stats_;
eGL egl_;
uint32_t width_;
uint32_t height_;
GLint glFormat_;
unsigned int bytesPerPixel_;
uint32_t shaderStridePixels_;
};
} /* 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::DebayerEGL::strideAndFrameSize
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &outputFormat, const Size &size)
Get the stride and the frame size.
Definition debayer_egl.cpp:373
libcamera::DebayerEGL::process
void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params)
Process the bayer data into the requested format.
Definition debayer_egl.cpp:536
libcamera::DebayerEGL::frameSize
unsigned int frameSize()
Get the output frame size.
Definition debayer_egl.cpp:284
libcamera::DebayerEGL::formats
std::vector< PixelFormat > formats(PixelFormat input)
Get the supported output formats.
Definition debayer_egl.cpp:362
libcamera::DebayerEGL::getStatsFD
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition debayer_egl.h:57
libcamera::DebayerEGL::stop
void stop()
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:603
libcamera::DebayerEGL::patternSize
Size patternSize(PixelFormat inputFormat)
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:352
libcamera::DebayerEGL::start
int start()
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:580
libcamera::DebayerEGL::DebayerEGL
DebayerEGL(std::unique_ptr< SwStatsCpu > stats, const GlobalConfiguration &configuration)
Construct a DebayerEGL object.
Definition debayer_egl.cpp:37
libcamera::DebayerEGL::sizes
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize)
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:612
libcamera::DebayerEGL::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_egl.cpp:289
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::MappedFrameBuffer
Map a FrameBuffer using the MappedBuffer interface.
Definition mapped_framebuffer.h:47
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:247
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::eGL
Helper class for managing OpenGL ES operations.
Definition egl.h:98
framebuffer.h
Internal frame buffer handling support.
mapped_framebuffer.h
Frame buffer memory mapping support.
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