libcamera v0.7.0+1595-4b6c47bd-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 <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<const 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, const DebayerParams &params);
54 int start();
55 void stop();
56
57 const SharedFD &getStatsFD() { return stats_->getStatsFD(); }
58
59 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
60
61private:
62 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
63 static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
64 int setupStandardBayerOrder(BayerFormat::Order order);
65 void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
66 int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
67 int initEGLContext();
68 int generateTextures();
69 int compileShaderProgram(GLuint &shaderId, GLenum shaderType,
70 unsigned char *shaderData, int shaderDataLen,
71 std::vector<std::string> shaderEnv);
72 int linkShaderProgram(void);
73 int getShaderVariableLocations();
74 void setShaderVariableValues(const DebayerParams &params);
75 void configureTexture(GLuint &texture);
76 int debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParams &params);
77
78 /* Shader program identifiers */
79 GLuint vertexShaderId_ = 0;
80 GLuint fragmentShaderId_ = 0;
81 GLuint programId_ = 0;
82
83 /* Pointer to object representing input texture */
84 std::unique_ptr<eGLImage> eglImageBayerIn_;
85 std::unique_ptr<eGLImage> eglImageBayerOut_;
86
87 /* Shader parameters */
88 float firstRed_x_;
89 float firstRed_y_;
90 GLint attributeVertex_;
91 GLint attributeTexture_;
92 GLint textureUniformStep_;
93 GLint textureUniformSize_;
94 GLint textureUniformStrideFactor_;
95 GLint textureUniformBayerFirstRed_;
96 GLint textureUniformProjMatrix_;
97
98 GLint textureUniformBayerDataIn_;
99
100 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
101 GLint ccmUniformDataIn_;
102
103 /* Black Level compensation */
104 GLint blackLevelUniformDataIn_;
105
106 /* Gamma */
107 GLint gammaUniformDataIn_;
108
109 /* Contrast */
110 GLint contrastExpUniformDataIn_;
111
112 Rectangle window_;
113 std::unique_ptr<SwStatsCpu> stats_;
114 eGL egl_;
115 uint32_t width_;
116 uint32_t height_;
117 GLint glFormat_;
118 unsigned int bytesPerPixel_;
119 uint32_t shaderStridePixels_;
120};
121
122} /* 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
void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params)
Process the bayer data into the requested format.
Definition debayer_egl.cpp:526
std::tuple< unsigned int, unsigned int > strideAndFrameSize(const PixelFormat &outputFormat, const Size &size)
Get the stride and the frame size.
Definition debayer_egl.cpp:363
std::vector< PixelFormat > formats(PixelFormat input)
Get the supported output formats.
Definition debayer_egl.cpp:352
int configure(const StreamConfiguration &inputCfg, const std::vector< std::reference_wrapper< const StreamConfiguration > > &outputCfgs, bool ccmEnabled)
Configure the debayer object according to the passed in parameters.
Definition debayer_egl.cpp:279
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:593
Size patternSize(PixelFormat inputFormat)
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:342
int start()
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:570
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize)
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:602
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