libcamera v0.7.1+1-5701eb5f-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 <tuple>
15#include <vector>
16
17#define GL_GLEXT_PROTOTYPES
18#define EGL_EGLEXT_PROTOTYPES
20
21#include "libcamera/internal/egl.h"
23#include "libcamera/internal/software_isp/benchmark.h"
24#include "libcamera/internal/software_isp/swstats_cpu.h"
25
26#include <EGL/egl.h>
27#include <EGL/eglext.h>
28#include <GLES3/gl32.h>
29
30#include "debayer.h"
31
32namespace libcamera {
33
34#define DEBAYER_EGL_MIN_SIMPLE_RGB_GAIN_TEXTURE_UNITS 4
35#define DEBAYER_OPENGL_COORDS 4
36
37class CameraManager;
38
39class DebayerEGL : public Debayer
40{
41public:
42 DebayerEGL(std::unique_ptr<SwStatsCpu> stats, const CameraManager &cm);
44
45 int configure(const StreamConfiguration &inputCfg,
46 const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
47 bool ccmEnabled) override;
48
49 Size patternSize(PixelFormat inputFormat) override;
50
51 std::vector<PixelFormat> formats(PixelFormat input) override;
52 std::tuple<unsigned int, unsigned int> strideAndFrameSize(const PixelFormat &outputFormat, const Size &size) override;
53
54 void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params) override;
55 int start() override;
56 void stop() override;
57
58 const SharedFD &getStatsFD() override { return stats_->getStatsFD(); }
59
60 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override;
61
62private:
63 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
64 static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
65 int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
66 int getShaderVariableLocations();
67 void setShaderVariableValues(const DebayerParams &params);
68 int debayerGPU(FrameBuffer *input, FrameBuffer *output, const DebayerParams &params, std::optional<MappedFrameBuffer> *mappedInputBuffer, std::optional<DmaSyncer> *inputBufferDmaSyncer);
69
70 /* Shader program identifiers */
71 GLuint vertexShaderId_ = 0;
72 GLuint fragmentShaderId_ = 0;
73 GLuint programId_ = 0;
74
75 /* Pointer to object representing input texture */
76 std::unique_ptr<eGLImage> eglImageBayerIn_;
77 std::unique_ptr<eGLImage> eglImageBayerOut_;
78
79 /* Shader parameters */
80 float firstRed_x_;
81 float firstRed_y_;
82 GLint attributeVertex_;
83 GLint attributeTexture_;
84 GLint textureUniformStep_;
85 GLint textureUniformSize_;
86 GLint textureUniformStrideFactor_;
87 GLint textureUniformBayerFirstRed_;
88 GLint textureUniformProjMatrix_;
89
90 GLint textureUniformBayerDataIn_;
91
92 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
93 GLint ccmUniformDataIn_;
94
95 /* Black Level compensation */
96 GLint blackLevelUniformDataIn_;
97
98 /* Gamma */
99 GLint gammaUniformDataIn_;
100
101 /* Contrast */
102 GLint contrastExpUniformDataIn_;
103
104 Rectangle window_;
105 std::unique_ptr<SwStatsCpu> stats_;
106 eGL egl_;
107 uint32_t width_;
108 uint32_t height_;
109 GLint glFormat_;
110 unsigned int bytesPerPixel_;
111 uint32_t shaderStridePixels_;
112};
113
114} /* 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:40
int start() override
Execute a start signal in the debayer object from workerthread context.
Definition debayer_egl.cpp:610
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:377
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:293
const SharedFD & getStatsFD() override
Get the file descriptor for the statistics.
Definition debayer_egl.h:58
void stop() override
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:633
Size patternSize(PixelFormat inputFormat) override
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:356
std::vector< PixelFormat > formats(PixelFormat input) override
Get the supported output formats.
Definition debayer_egl.cpp:366
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override
Get the supported output sizes for the given input format and size.
Definition debayer_egl.cpp:642
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:558
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 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