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

libcamera v0.7.1 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
18#include <libcamera/base/object.h>
19
20#include "libcamera/internal/bayer_format.h"
21#include "libcamera/internal/egl.h"
22#include "libcamera/internal/framebuffer.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
55 void process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params) override;
56 int start() override;
57 void stop() override;
58
59 const SharedFD &getStatsFD() override { return stats_->getStatsFD(); }
60
61 SizeRange sizes(PixelFormat inputFormat, const Size &inputSize) override;
62
63private:
64 static int getInputConfig(PixelFormat inputFormat, DebayerInputConfig &config);
65 static int getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config);
66 int initBayerShaders(PixelFormat inputFormat, PixelFormat outputFormat);
67 int getShaderVariableLocations();
68 void setShaderVariableValues(const DebayerParams &params);
69 int debayerGPU(MappedFrameBuffer &in, int out_fd, const DebayerParams &params);
70
71 /* Shader program identifiers */
72 GLuint vertexShaderId_ = 0;
73 GLuint fragmentShaderId_ = 0;
74 GLuint programId_ = 0;
75
76 /* Pointer to object representing input texture */
77 std::unique_ptr<eGLImage> eglImageBayerIn_;
78 std::unique_ptr<eGLImage> eglImageBayerOut_;
79
80 /* Shader parameters */
81 float firstRed_x_;
82 float firstRed_y_;
83 GLint attributeVertex_;
84 GLint attributeTexture_;
85 GLint textureUniformStep_;
86 GLint textureUniformSize_;
87 GLint textureUniformStrideFactor_;
88 GLint textureUniformBayerFirstRed_;
89 GLint textureUniformProjMatrix_;
90
91 GLint textureUniformBayerDataIn_;
92
93 /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
94 GLint ccmUniformDataIn_;
95
96 /* Black Level compensation */
97 GLint blackLevelUniformDataIn_;
98
99 /* Gamma */
100 GLint gammaUniformDataIn_;
101
102 /* Contrast */
103 GLint contrastExpUniformDataIn_;
104
105 Rectangle window_;
106 std::unique_ptr<SwStatsCpu> stats_;
107 eGL egl_;
108 uint32_t width_;
109 uint32_t height_;
110 GLint glFormat_;
111 unsigned int bytesPerPixel_;
112 uint32_t shaderStridePixels_;
113};
114
115} /* namespace libcamera */
bayer_format.h
Class to represent Bayer formats and manipulate them.
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:569
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:362
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:278
libcamera::DebayerEGL::getStatsFD
const SharedFD & getStatsFD() override
Get the file descriptor for the statistics.
Definition debayer_egl.h:59
libcamera::DebayerEGL::stop
void stop() override
Stop the debayering process and perform cleanup.
Definition debayer_egl.cpp:592
libcamera::DebayerEGL::patternSize
Size patternSize(PixelFormat inputFormat) override
Get the width and height at which the bayer pattern repeats.
Definition debayer_egl.cpp:341
libcamera::DebayerEGL::DebayerEGL
DebayerEGL(std::unique_ptr< SwStatsCpu > stats, const CameraManager &cm)
Construct a DebayerEGL object.
Definition debayer_egl.cpp:36
libcamera::DebayerEGL::formats
std::vector< PixelFormat > formats(PixelFormat input) override
Get the supported output formats.
Definition debayer_egl.cpp:351
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:601
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:525
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::MappedFrameBuffer
Map a FrameBuffer using the MappedBuffer interface.
Definition mapped_framebuffer.h:47
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::eGL
Helper class for managing OpenGL ES operations.
Definition egl.h:97
framebuffer.h
Internal frame buffer handling support.
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