libcamera v0.7.0+1-4ceceb68
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
debayer_egl.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2025, Bryan O'Donoghue.
4 *
5 * Authors:
6 * Bryan O'Donoghue <bryan.odonoghue@linaro.org>
7 *
8 */
9
10#pragma once
11
12#include <memory>
13#include <stdint.h>
14#include <vector>
15
16#define GL_GLEXT_PROTOTYPES
17#define EGL_EGLEXT_PROTOTYPES
19
21#include "libcamera/internal/egl.h"
24#include "libcamera/internal/software_isp/benchmark.h"
25#include "libcamera/internal/software_isp/swstats_cpu.h"
26
27#include <EGL/egl.h>
28#include <EGL/eglext.h>
29#include <GLES3/gl32.h>
30
31#include "debayer.h"
32
33namespace libcamera {
34
35#define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4
36#define DEBAYER_OPENGL_COORDS 4
37
38class DebayerEGL : public Debayer
39{
40public:
41 DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const GlobalConfiguration &configuration);
43
44 int configure(const StreamConfiguration &inputCfg,
45 const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs,
46 bool ccmEnabled);
47
48 Size patternSize(PixelFormat inputFormat);
49
50 std::vector<PixelFormat> formats(PixelFormat input);
51 std::tuple<unsigned int, unsigned int> strideAndFrameSize(const PixelFormat &outputFormat, const Size &size);
52
53 void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params);
54 int start();
55 void stop();
56
57 const SharedFD &getStatsFD() { return stats_->getStatsFD(); }
58 unsigned int frameSize();
59
60 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
61
62private:
63 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
64 static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
65 int setupStandardBayerOrder(BayerFormat::Order order);
66 void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
67 int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
68 int initEGLContext();
69 int generateTextures();
70 int compileShaderProgram(GLuint &shaderId, GLenum shaderType,
71 unsigned char *shaderData, int shaderDataLen,
72 std::vector<std::string> shaderEnv);
73 int linkShaderProgram(void);
74 int getShaderVariableLocations();
75 void setShaderVariableValues(DebayerParams &params);
76 void configureTexture(GLuint &texture);
77 int debayerGPU(MappedFrameBuffer &in, int out_fd, DebayerParams &params);
78
79 /* Shader program identifiers */
80 GLuint vertexShaderId_ = 0;
81 GLuint fragmentShaderId_ = 0;
82 GLuint programId_ = 0;
83
84 /* Pointer to object representing input texture */
85 std::unique_ptr<eGLImage> eglImageBayerIn_;
86 std::unique_ptr<eGLImage> eglImageBayerOut_;
87
88 /* Shader parameters */
89 float firstRed_x_;
90 float firstRed_y_;
91 GLint attributeVertex_;
92 GLint attributeTexture_;
93 GLint textureUniformStep_;
94 GLint textureUniformSize_;
95 GLint textureUniformStrideFactor_;
96 GLint textureUniformBayerFirstRed_;
97 GLint textureUniformProjMatrix_;
98
99 GLint textureUniformBayerDataIn_;
100
101 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
102 GLint ccmUniformDataIn_;
103
104 /* Black Level compensation */
105 GLint blackLevelUniformDataIn_;
106
107 /* Gamma */
108 GLint gammaUniformDataIn_;
109
110 /* Contrast */
111 GLint contrastExpUniformDataIn_;
112
113 Rectangle window_;
114 std::unique_ptr<SwStatsCpu> stats_;
115 eGL egl_;
116 uint32_t width_;
117 uint32_t height_;
118 GLint glFormat_;
119 unsigned int bytesPerPixel_;
120 uint32_t shaderStridePixels_;
121};
122
123} /* 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 using an EGL Shader.
Definition debayer_egl.h:39
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
void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, DebayerParams params)
Process the bayer data into the requested format.
Definition debayer_egl.cpp:536
unsigned int frameSize()
Get the output frame size.
Definition debayer_egl.cpp:284
std::vector< PixelFormat > formats(PixelFormat input)
Get the supported output formats.
Definition debayer_egl.cpp:362
const SharedFD & getStatsFD()
Get the file descriptor for the statistics.
Definition debayer_egl.h:57
void stop()
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:603
Size patternSize(PixelFormat inputFormat)
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:352
int start()
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:580
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize)
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:612
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
Base debayering class.
Definition debayer.h:36
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
Support for global libcamera configuration.
Definition global_configuration.h:22
Map a FrameBuffer using the MappedBuffer interface.
Definition mapped_framebuffer.h:47
libcamera image pixel format
Definition pixel_format.h:17
Describe a rectangle's position and dimensions.
Definition geometry.h:247
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
Describe a range of sizes.
Definition geometry.h:205
Describe a two-dimensional size.
Definition geometry.h:51
Helper class for managing OpenGL ES operations.
Definition egl.h:98
Internal frame buffer handling support.
Frame buffer memory mapping support.
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:20
Configuration parameters for a stream.
Definition stream.h:40