libcamera v0.8.0+rpt20261104
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 <deque>
13#include <memory>
14#include <stdint.h>
15#include <tuple>
16#include <vector>
17
18#define GL_GLEXT_PROTOTYPES
19#define EGL_EGLEXT_PROTOTYPES
21
22#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 CameraManager;
39
40class DebayerEGL : public Debayer
41{
42public:
43 DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm, EGLDisplay display);
45
46 int configure(const StreamConfiguration &inputCfg,
47 const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
48 bool ccmEnabled,
49 bool lscEnabled) override;
50
51 Size patternSize(PixelFormat inputFormat) override;
52
53 std::vector<PixelFormat> formats(PixelFormat input) override;
54 std::tuple<unsigned int, unsigned int> strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) override;
55 uint32_t preferredInputStride(const PixelFormat &inputFormat, const Size &size) override;
56
57 void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params) override;
58 int start() override;
59 void stop() override;
60
61 const SharedFD &getStatsFD() override { return stats_->getStatsFD(); }
62
63 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override;
64
65private:
66 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
67 int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
68 int getShaderVariableLocations();
69 void setShaderVariableValues(eGLImage &eGLImageIn, const DebayerParams &params);
70 int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *mappedInputBuffer, std::optional<DmaSyncer> *inputBufferDmaSyncer);
71
72 eGLImage *getCachedInputFrameBuffer(FrameBuffer *input, std::optional<MappedFrameBuffer> *inMapped, std::optional<DmaSyncer> *inDmaSyncer);
73 eGLImage *getCachedOutputFrameBuffer(FrameBuffer *output);
74
75 /* Shader program identifiers */
76 GLuint vertexShaderId_ = 0;
77 GLuint fragmentShaderId_ = 0;
78 GLuint programId_ = 0;
79
80 /* Pointer to object representing input texture */
81 std::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageInCache_;
82 std::deque<std::pair<SharedFD, std::unique_ptr<eGLImage>>> eglImageOutCache_;
83 unsigned int inputBufferCount_;
84 unsigned int outputBufferCount_;
85
86 /* LSC lookup table */
87 bool lscEnabled_;
88 std::optional<eGLImage> eglImageLscLookup_;
89 std::optional<uint64_t> lscLutVersion_;
90
91 /* Shader parameters */
92 float firstRed_x_;
93 float firstRed_y_;
94 GLint attributeVertex_;
95 GLint attributeTexture_;
96 GLint textureUniformStep_;
97 GLint textureUniformSize_;
98 GLint textureUniformStrideFactor_;
99 GLint textureUniformBayerFirstRed_;
100 GLint textureUniformProjMatrix_;
101
102 GLint textureUniformBayerDataIn_;
103
104 /* Per-frame AWB gains */
105 GLint awbUniformDataIn_;
106
107 /* Lens shading correction */
108 GLint textureUniformLsc_;
109
110 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
111 GLint ccmUniformDataIn_;
112
113 /* Black Level compensation */
114 GLint blackLevelUniformDataIn_;
115
116 /* Gamma */
117 GLint gammaUniformDataIn_;
118
119 /* Contrast */
120 GLint contrastExpUniformDataIn_;
121
122 Size nativeOutputSize_;
123 Rectangle window_;
124 std::unique_ptr<SwStatsCpu> stats_;
125 eGL egl_;
126 uint32_t width_;
127 uint32_t height_;
128 GLint glFormat_;
129 unsigned int bytesPerPixel_;
130 uint32_t shaderStridePixels_;
131};
132
133} /* namespace libcamera */
Provide access and manage all cameras in the system.
Definition camera_manager.h:25
Class for debayering using an EGL Shader.
Definition debayer_egl.h:41
int start() override
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:680
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:374
uint32_t preferredInputStride(const PixelFormat &inputFormat, const Size &size) override
Definition debayer_egl.cpp:381
const SharedFD & getStatsFD() override
Get the file descriptor for the statistics.
Definition debayer_egl.h:61
void stop() override
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:709
Size patternSize(PixelFormat inputFormat) override
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:353
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< const StreamConfiguration > > &outputCfgs, bool ccmEnabled, bool lscEnabled) override
Configure the debayer object according to the passed in parameters.
Definition debayer_egl.cpp:280
std::vector< PixelFormat > formats(PixelFormat input) override
Get the supported output formats.
Definition debayer_egl.cpp:363
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:723
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:627
Base debayering class.
Definition debayer.h:36
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:53
Helper class for managing OpenGL ES operations.
Definition egl.h:103
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:21
Configuration parameters for a stream.
Definition stream.h:40