libcamera: src/libcamera/software_isp/debayer_egl.h Source File

libcamera v0.7.2 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
20#include <libcamera/base/object.h>
21
22#include "libcamera/internal/egl.h"
23#include "libcamera/internal/mapped_framebuffer.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
40 class DebayerEGL : public Debayer
41{
42public:
43 DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm);
44 ~DebayerEGL();
45
46 int configure(const StreamConfiguration &inputCfg,
47 const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
48 bool ccmEnabled) override;
49
50 Size patternSize(PixelFormat inputFormat) override;
51
52 std::vector<PixelFormat> formats(PixelFormat input) override;
53 std::tuple<unsigned int, unsigned int> strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) override;
54 uint32_t preferredInputStride(const PixelFormat &inputFormat, const Size &size) override;
55
56 void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params) override;
57 int start() override;
58 void stop() override;
59
60 const SharedFD &getStatsFD() override { return stats_->getStatsFD(); }
61
62 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override;
63
64private:
65 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
66 static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &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 /* Shader parameters */
87 float firstRed_x_;
88 float firstRed_y_;
89 GLint attributeVertex_;
90 GLint attributeTexture_;
91 GLint textureUniformStep_;
92 GLint textureUniformSize_;
93 GLint textureUniformStrideFactor_;
94 GLint textureUniformBayerFirstRed_;
95 GLint textureUniformProjMatrix_;
96
97 GLint textureUniformBayerDataIn_;
98
99 /* Per-frame AWB gains */
100 GLint awbUniformDataIn_;
101
102 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
103 GLint ccmUniformDataIn_;
104
105 /* Black Level compensation */
106 GLint blackLevelUniformDataIn_;
107
108 /* Gamma */
109 GLint gammaUniformDataIn_;
110
111 /* Contrast */
112 GLint contrastExpUniformDataIn_;
113
114 Size nativeOutputSize_;
115 Rectangle window_;
116 std::unique_ptr<SwStatsCpu> stats_;
117 eGL egl_;
118 uint32_t width_;
119 uint32_t height_;
120 GLint glFormat_;
121 unsigned int bytesPerPixel_;
122 uint32_t shaderStridePixels_;
123};
124
125} /* namespace libcamera */
libcamera::CameraManager
Provide access and manage all cameras in the system.
Definition camera_manager.h:25
libcamera::DebayerEGL::start
int start() override
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:677
libcamera::DebayerEGL::strideAndFrameSize
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:375
libcamera::DebayerEGL::preferredInputStride
uint32_t preferredInputStride(const PixelFormat &inputFormat, const Size &size) override
Definition debayer_egl.cpp:388
libcamera::DebayerEGL::configure
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:287
libcamera::DebayerEGL::getStatsFD
const SharedFD & getStatsFD() override
Get the file descriptor for the statistics.
Definition debayer_egl.h:60
libcamera::DebayerEGL::stop
void stop() override
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:694
libcamera::DebayerEGL::patternSize
Size patternSize(PixelFormat inputFormat) override
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:354
libcamera::DebayerEGL::DebayerEGL
DebayerEGL(std::unique_ptr< SwStatsCpu > stats, const CameraManager &cm)
Construct a DebayerEGL object.
Definition debayer_egl.cpp:44
libcamera::DebayerEGL::formats
std::vector< PixelFormat > formats(PixelFormat input) override
Get the supported output formats.
Definition debayer_egl.cpp:364
libcamera::DebayerEGL::sizes
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:703
libcamera::DebayerEGL::process
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:625
libcamera::Debayer::Debayer
Debayer(const CameraManager &cm)
Construct a Debayer object.
Definition debayer.cpp:59
libcamera::FrameBuffer
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:50
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::eGLImage
Helper class for managing EGL image resources.
Definition egl.h:50
libcamera::eGL
Helper class for managing OpenGL ES operations.
Definition egl.h:100
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