/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Linaro
*
* viewfinderGL.cpp - OpenGL Viewfinder for rendering by OpenGL shader
*/
#include "viewfinder_gl.h"
#include <QByteArray>
#include <QFile>
#include <QImage>
#include <libcamera/formats.h>
static const QList<libcamera::PixelFormat> supportedFormats{
/* YUV - packed (single plane) */
libcamera::formats::UYVY,
libcamera::formats::VYUY,
libcamera::formats::YUYV,
libcamera::formats::YVYU,
/* YUV - semi planar (two planes) */
libcamera::formats::NV12,
libcamera::formats::NV21,
libcamera::formats::NV16,
libcamera::formats::NV61,
libcamera::formats::NV24,
libcamera::formats::NV42,
/* YUV - fully planar (three planes) */
libcamera::formats::YUV420,
libcamera::formats::YVU420,
/* RGB */
libcamera::formats::ABGR8888,
libcamera::formats::ARGB8888,
libcamera::formats::BGRA8888,
libcamera::formats::RGBA8888,
libcamera::formats::BGR888,
libcamera::formats::RGB888,
/* Raw Bayer 8-bit */
libcamera::formats::SBGGR8,
libcamera::formats::SGBRG8,
libcamera::formats::SGRBG8,
libcamera::formats::SRGGB8,
/* Raw Bayer 10-bit packed */
libcamera::formats::SBGGR10_CSI2P,
libcamera::formats::SGBRG10_CSI2P,
libcamera::formats::SGRBG10_CSI2P,
libcamera::formats::SRGGB10_CSI2P,
/* Raw Bayer 12-bit packed */
libcamera::formats::SBGGR12_CSI2P,
libcamera::formats::SGBRG12_CSI2P,
libcamera::formats::SGRBG12_CSI2P,
libcamera::formats::SRGGB12_CSI2P,
};
ViewFinderGL::ViewFinderGL(QWidget *parent)
: QOpenGLWidget(parent), buffer_(nullptr), data_(nullptr),
vertexBuffer_(QOpenGLBuffer::VertexBuffer)
{
}
ViewFinderGL::~ViewFinderGL()
{
removeShader();
}
const QList<libcamera::PixelFormat> &ViewFinderGL::nativeFormats() const
{
return supportedFormats;
}
int ViewFinderGL::setFormat(const libcamera::PixelFormat &format,
const QSize &size)
{
if (format != format_) {
/*
* If the fragment already exists, remove it and create a new
* one for the new format.
*/
if (shaderProgram_.isLinked()) {
shaderProgram_.release();
shaderProgram_.removeShader(fragmentShader_.get());
fragmentShader_.reset();
}
if (!selectFormat(format))
return -1;
format_ = format;
}
size_ = size;
updateGeometry();
return 0;
}
void ViewFinderGL::stop()
{
if (buffer_) {
renderComplete(buffer_);
buffer_ = nullptr;
}
}
|