libcamera v0.7.2+1-2f862c3e-dirty (2026-10-05T14:46:06UTC)-nvm
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 <array>
13#include <deque>
14#include <memory>
15#include <stdint.h>
16#include <tuple>
17#include <vector>
18
19#define GL_GLEXT_PROTOTYPES
20#define EGL_EGLEXT_PROTOTYPES
22
23#include "libcamera/internal/egl.h"
25#include "libcamera/internal/software_isp/benchmark.h"
26#include "libcamera/internal/software_isp/swstats_cpu.h"
27
28#include <EGL/egl.h>
29#include <EGL/eglext.h>
30#include <GLES3/gl32.h>
31
32#include "debayer.h"
33
34namespace libcamera {
35
36#define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4
37#define DEBAYER_OPENGL_COORDS 4
38
39class CameraManager;
40
41class DebayerEGL : public Debayer
42{
43public:
44 DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm,
45 bool quadBayer = false);
47
48 int configure(const StreamConfiguration &inputCfg,
49 const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
50 bool ccmEnabled) override;
51
52 Size patternSize(PixelFormat inputFormat) override;
53
54 std::vector<PixelFormat> formats(PixelFormat input) override;
55 std::tuple<unsigned int, unsigned int> strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) override;
56 uint32_t preferredInputStride(const PixelFormat &inputFormat, const Size &size) override;
57
58 void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params) override;
59 int start() override;
60 void stop() override;
61
62 const SharedFD &getStatsFD() override { return stats_->getStatsFD(); }
63
64 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override;
65
66private:
67 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
68 static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
69 int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
70 int getShaderVariableLocations();
71 void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams &params);
72 int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *mappedInputBuffer, std::optional<DmaSyncer> *inputBufferDmaSyncer);
73
74 eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer);
75 eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output);
76
77 /* Shader program identifiers */
78 GLuint vertexShaderId_ = 0;
79 GLuint fragmentShaderId_ = 0;
80 GLuint programId_ = 0;
81
82 /* Pointer to object representing input texture */
83 std::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageInCache_;
84 std::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageOutCache_;
85 unsigned int inputBufferCount_;
86 unsigned int outputBufferCount_;
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 std::array<GLfloat, 8> textureCoordinates_;
99
100 GLint textureUniformBayerDataIn_;
101
102 /* Per-frame AWB gains */
103 GLint awbUniformDataIn_;
104
105 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
106 GLint ccmUniformDataIn_;
107
108 /* Black Level compensation */
109 GLint blackLevelUniformDataIn_;
110
111 /* Gamma */
112 GLint gammaUniformDataIn_;
113
114 /* Contrast */
115 GLint contrastExpUniformDataIn_;
116
117 Size nativeOutputSize_;
118 Rectangle window_;
119 std::unique_ptr<SwStatsCpu> stats_;
120 eGL egl_;
121 uint32_t width_;
122 uint32_t height_;
123 GLint glFormat_;
124 unsigned int bytesPerPixel_;
125 uint32_t shaderStridePixels_;
126};
127
128} /* namespace libcamera */
Provide access and manage all cameras in the system.
Definition camera_manager.h:25
DebayerEGL(std::unique_ptr< SwStatsCpu > stats, const CameraManager &cm, bool quadBayer=false)
Construct a DebayerEGL object.
Definition debayer_egl.cpp:46
int start() override
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:691
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) override
Get the stride and the frame size.
Definition debayer_egl.cpp:389
uint32_t preferredInputStride(const PixelFormat &inputFormat, const Size &size) override
Definition debayer_egl.cpp:402
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< const StreamConfiguration > > &outputCfgs, bool ccmEnabled) override
Configure the debayer object according to the passed in parameters.
Definition debayer_egl.cpp:292
const SharedFD & getStatsFD() override
Get the file descriptor for the statistics.
Definition debayer_egl.h:62
void stop() override
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:708
Size patternSize(PixelFormat inputFormat) override
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:365
std::vector< PixelFormat > formats(PixelFormat input) override
Get the supported output formats.
Definition debayer_egl.cpp:375
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:717
void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params) override
Process the bayer data into the requested format.
Definition debayer_egl.cpp:639
Debayer(const CameraManager &cm, bool quadBayer=false)
Construct a Debayer object.
Definition debayer.cpp:59
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
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 EGL image resources.
Definition egl.h:50
Helper class for managing OpenGL ES operations.
Definition egl.h:100
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