| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* The YUY2 shader code is based on face-responder. The code is under public domain: |
| 4 |
* https://bitbucket.org/nateharward/face-responder/src/0c3b4b957039d9f4bf1da09b9471371942de2601/yuv42201_laplace.frag?at=master |
| 5 |
* |
| 6 |
* All other OpenGL code: |
| 7 |
* |
| 8 |
* Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "capture.h" |
| 12 |
|
| 13 |
#include <QtCore/QTextStream> |
| 14 |
#include <QtCore/QCoreApplication> |
| 15 |
#include <QtGui/QOpenGLContext> |
| 16 |
#if QT_VERSION < 0x060000 |
| 17 |
#include <QtGui/QOpenGLPaintDevice> |
| 18 |
#else |
| 19 |
#include <QOpenGLPaintDevice> |
| 20 |
#endif |
| 21 |
#include <QtGui/QContextMenuEvent> |
| 22 |
#include <QtGui/QKeyEvent> |
| 23 |
#include <QtGui/QPainter> |
| 24 |
#include <QtCore/QSocketNotifier> |
| 25 |
#include <QtMath> |
| 26 |
#include <QTimer> |
| 27 |
#include <QApplication> |
| 28 |
|
| 29 |
#include "v4l2-info.h" |
| 30 |
|
| 31 |
void CaptureWin::initializeGL() |
| 32 |
{ |
| 33 |
initializeOpenGLFunctions(); |
| 34 |
glDisable(GL_BLEND); |
| 35 |
glDisable(GL_DEPTH_TEST); |
| 36 |
|
| 37 |
// Check if the the GL_FRAMEBUFFER_SRGB feature is available. |
| 38 |
// If it is, then the GPU can perform the SRGB transfer function |
| 39 |
// for us. |
| 40 |
GLint res = 0; |
| 41 |
if (context()->hasExtension("GL_EXT_framebuffer_sRGB")) |
| 42 |
glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &res); |
| 43 |
checkError("InitializeGL Part 1"); |
| 44 |
|
| 45 |
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); |
| 46 |
m_haveSwapBytes = glGetError() == GL_NO_ERROR; |
| 47 |
|
| 48 |
if (m_verbose) { |
| 49 |
printf("OpenGL %sdoes%s support GL_UNPACK_SWAP_BYTES\n", |
| 50 |
context()->isOpenGLES() ? "ES " : "", |
| 51 |
m_haveSwapBytes ? "" : " not"); |
| 52 |
} |
| 53 |
if (m_uses_gl_red && glGetString(GL_VERSION)[0] < '3') { |
| 54 |
fprintf(stderr, "The openGL implementation does not support GL_RED/GL_RG\n"); |
| 55 |
std::exit(EXIT_FAILURE); |
| 56 |
} |
| 57 |
|
| 58 |
QColor bg = QWidget::palette().color(QWidget::backgroundRole()); |
| 59 |
glClearColor(bg.red() / 255.0f, |
| 60 |
bg.green() / 255.0f, |
| 61 |
bg.blue() / 255.0f, |
| 62 |
0.0f); |
| 63 |
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 64 |
checkError("InitializeGL Part 2"); |
| 65 |
m_program = new QOpenGLShaderProgram(this); |
| 66 |
m_updateShader = true; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
void CaptureWin::paintGL() |
| 71 |
{ |
| 72 |
if (m_v4l_fmt.g_width() < 16 || m_v4l_fmt.g_frame_height() < 16) |
| 73 |
return; |
| 74 |
|
| 75 |
if (m_mode == AppModeV4L2) { |
| 76 |
if (m_v4l_queue == NULL || m_nextIndex == -1) |
| 77 |
return; |
| 78 |
|
| 79 |
cv4l_buffer buf(*m_v4l_queue, m_curIndex); |
| 80 |
|
| 81 |
m_fd->qbuf(buf); |
| 82 |
for (unsigned i = 0; i < m_v4l_queue->g_num_planes(); i++) { |
| 83 |
m_curData[i] = m_nextData[i]; |
| 84 |
m_curSize[i] = m_nextSize[i]; |
| 85 |
m_curIndex = m_nextIndex; |
| 86 |
m_nextIndex = -1; |
| 87 |
m_nextData[i] = 0; |
| 88 |
m_nextSize[i] = 0; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
if (m_curData[0] == NULL) { |
| 94 |
// No data, just clear display |
| 95 |
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 96 |
glClear(GL_COLOR_BUFFER_BIT); |
| 97 |
checkError("paintGL - no data"); |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
if (m_updateShader) { |
| 102 |
m_updateShader = false; |
| 103 |
if (!supportedFmt(m_v4l_fmt.g_pixelformat())) { |
| 104 |
fprintf(stderr, "OpenGL ES unsupported format 0x%08x ('%s').\n", |
| 105 |
m_v4l_fmt.g_pixelformat(), fcc2s(m_v4l_fmt.g_pixelformat()).c_str()); |
| 106 |
|
| 107 |
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 108 |
glClear(GL_COLOR_BUFFER_BIT); |
| 109 |
checkError("paintGL - no data"); |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
changeShader(); |
| 114 |
} |
| 115 |
|
| 116 |
if (!supportedFmt(m_v4l_fmt.g_pixelformat())) |
| 117 |
return; |
| 118 |
|
| 119 |
m_program->bind(); |
| 120 |
|
| 121 |
switch (m_v4l_fmt.g_pixelformat()) { |
| 122 |
case V4L2_PIX_FMT_YUYV: |
| 123 |
case V4L2_PIX_FMT_YVYU: |
| 124 |
case V4L2_PIX_FMT_UYVY: |
| 125 |
case V4L2_PIX_FMT_VYUY: |
| 126 |
render_YUY2(m_v4l_fmt.g_pixelformat()); |
| 127 |
break; |
| 128 |
|
| 129 |
case V4L2_PIX_FMT_NV16: |
| 130 |
case V4L2_PIX_FMT_NV61: |
| 131 |
case V4L2_PIX_FMT_NV16M: |
| 132 |
case V4L2_PIX_FMT_NV61M: |
| 133 |
render_NV16(m_v4l_fmt.g_pixelformat()); |
| 134 |
break; |
| 135 |
|
| 136 |
case V4L2_PIX_FMT_NV12: |
| 137 |
case V4L2_PIX_FMT_NV21: |
| 138 |
case V4L2_PIX_FMT_NV12M: |
| 139 |
case V4L2_PIX_FMT_NV21M: |
| 140 |
render_NV12(m_v4l_fmt.g_pixelformat()); |
| 141 |
break; |
| 142 |
|
| 143 |
case V4L2_PIX_FMT_NV24: |
| 144 |
case V4L2_PIX_FMT_NV42: |
| 145 |
render_NV24(m_v4l_fmt.g_pixelformat()); |
| 146 |
break; |
| 147 |
|
| 148 |
case V4L2_PIX_FMT_YUV422P: |
| 149 |
case V4L2_PIX_FMT_YUV420: |
| 150 |
case V4L2_PIX_FMT_YVU420: |
| 151 |
case V4L2_PIX_FMT_YUV420M: |
| 152 |
case V4L2_PIX_FMT_YVU420M: |
| 153 |
case V4L2_PIX_FMT_YUV422M: |
| 154 |
case V4L2_PIX_FMT_YVU422M: |
| 155 |
case V4L2_PIX_FMT_YUV444M: |
| 156 |
case V4L2_PIX_FMT_YVU444M: |
| 157 |
render_YUV(m_v4l_fmt.g_pixelformat()); |
| 158 |
break; |
| 159 |
|
| 160 |
case V4L2_PIX_FMT_YUV444: |
| 161 |
case V4L2_PIX_FMT_YUV555: |
| 162 |
case V4L2_PIX_FMT_YUV565: |
| 163 |
case V4L2_PIX_FMT_YUV32: |
| 164 |
case V4L2_PIX_FMT_AYUV32: |
| 165 |
case V4L2_PIX_FMT_XYUV32: |
| 166 |
case V4L2_PIX_FMT_VUYA32: |
| 167 |
case V4L2_PIX_FMT_VUYX32: |
| 168 |
case V4L2_PIX_FMT_YUVA32: |
| 169 |
case V4L2_PIX_FMT_YUVX32: |
| 170 |
render_YUV_packed(m_v4l_fmt.g_pixelformat()); |
| 171 |
break; |
| 172 |
|
| 173 |
case V4L2_PIX_FMT_SBGGR8: |
| 174 |
case V4L2_PIX_FMT_SGBRG8: |
| 175 |
case V4L2_PIX_FMT_SGRBG8: |
| 176 |
case V4L2_PIX_FMT_SRGGB8: |
| 177 |
case V4L2_PIX_FMT_SBGGR10: |
| 178 |
case V4L2_PIX_FMT_SGBRG10: |
| 179 |
case V4L2_PIX_FMT_SGRBG10: |
| 180 |
case V4L2_PIX_FMT_SRGGB10: |
| 181 |
case V4L2_PIX_FMT_SBGGR12: |
| 182 |
case V4L2_PIX_FMT_SGBRG12: |
| 183 |
case V4L2_PIX_FMT_SGRBG12: |
| 184 |
case V4L2_PIX_FMT_SRGGB12: |
| 185 |
case V4L2_PIX_FMT_SBGGR16: |
| 186 |
case V4L2_PIX_FMT_SGBRG16: |
| 187 |
case V4L2_PIX_FMT_SGRBG16: |
| 188 |
case V4L2_PIX_FMT_SRGGB16: |
| 189 |
render_Bayer(m_v4l_fmt.g_pixelformat()); |
| 190 |
break; |
| 191 |
|
| 192 |
case V4L2_PIX_FMT_GREY: |
| 193 |
case V4L2_PIX_FMT_Y10: |
| 194 |
case V4L2_PIX_FMT_Y12: |
| 195 |
case V4L2_PIX_FMT_Y16: |
| 196 |
case V4L2_PIX_FMT_Y16_BE: |
| 197 |
case V4L2_PIX_FMT_Z16: |
| 198 |
case V4L2_PIX_FMT_RGB332: |
| 199 |
case V4L2_PIX_FMT_BGR666: |
| 200 |
case V4L2_PIX_FMT_RGB555: |
| 201 |
case V4L2_PIX_FMT_XRGB555: |
| 202 |
case V4L2_PIX_FMT_ARGB555: |
| 203 |
case V4L2_PIX_FMT_RGB555X: |
| 204 |
case V4L2_PIX_FMT_XRGB555X: |
| 205 |
case V4L2_PIX_FMT_ARGB555X: |
| 206 |
case V4L2_PIX_FMT_RGBX555: |
| 207 |
case V4L2_PIX_FMT_RGBA555: |
| 208 |
case V4L2_PIX_FMT_XBGR555: |
| 209 |
case V4L2_PIX_FMT_ABGR555: |
| 210 |
case V4L2_PIX_FMT_BGRX555: |
| 211 |
case V4L2_PIX_FMT_BGRA555: |
| 212 |
case V4L2_PIX_FMT_RGB444: |
| 213 |
case V4L2_PIX_FMT_XRGB444: |
| 214 |
case V4L2_PIX_FMT_ARGB444: |
| 215 |
case V4L2_PIX_FMT_XBGR444: |
| 216 |
case V4L2_PIX_FMT_ABGR444: |
| 217 |
case V4L2_PIX_FMT_RGBX444: |
| 218 |
case V4L2_PIX_FMT_RGBA444: |
| 219 |
case V4L2_PIX_FMT_BGRX444: |
| 220 |
case V4L2_PIX_FMT_BGRA444: |
| 221 |
case V4L2_PIX_FMT_RGB565: |
| 222 |
case V4L2_PIX_FMT_RGB565X: |
| 223 |
case V4L2_PIX_FMT_RGB24: |
| 224 |
case V4L2_PIX_FMT_BGR24: |
| 225 |
case V4L2_PIX_FMT_RGB32: |
| 226 |
case V4L2_PIX_FMT_BGR32: |
| 227 |
case V4L2_PIX_FMT_XRGB32: |
| 228 |
case V4L2_PIX_FMT_XBGR32: |
| 229 |
case V4L2_PIX_FMT_ARGB32: |
| 230 |
case V4L2_PIX_FMT_ABGR32: |
| 231 |
case V4L2_PIX_FMT_RGBX32: |
| 232 |
case V4L2_PIX_FMT_BGRX32: |
| 233 |
case V4L2_PIX_FMT_RGBA32: |
| 234 |
case V4L2_PIX_FMT_BGRA32: |
| 235 |
case V4L2_PIX_FMT_HSV24: |
| 236 |
case V4L2_PIX_FMT_HSV32: |
| 237 |
default: |
| 238 |
render_RGB(m_v4l_fmt.g_pixelformat()); |
| 239 |
break; |
| 240 |
} |
| 241 |
|
| 242 |
static unsigned long long tot_t; |
| 243 |
static unsigned cnt; |
| 244 |
GLuint query; |
| 245 |
QSize s = correctAspect(m_viewSize); |
| 246 |
bool scale = m_scrollArea->widgetResizable(); |
| 247 |
|
| 248 |
glViewport(scale ? (size().width() - s.width()) / 2 : 0, |
| 249 |
scale ? (size().height() - s.height()) / 2 : 0, |
| 250 |
s.width(), s.height()); |
| 251 |
|
| 252 |
if (m_reportTimings) { |
| 253 |
glGenQueries(1, &query); |
| 254 |
glBeginQuery(GL_TIME_ELAPSED, query); |
| 255 |
} |
| 256 |
|
| 257 |
GLuint VertexArrayID; |
| 258 |
glGenVertexArrays(1, &VertexArrayID); |
| 259 |
glBindVertexArray(VertexArrayID); |
| 260 |
|
| 261 |
// Define Quad surface to draw to, vertices sequenced for GL_TRIANGLE_FAN |
| 262 |
// Adjusting these will make the screen to draw to smaller or larger |
| 263 |
const GLfloat quadVertex[] = { |
| 264 |
-1.0f, -1.0f, // Left Bottom |
| 265 |
+1.0f, -1.0f, // Right Bottom |
| 266 |
+1.0f, +1.0f, // Rigth Top |
| 267 |
-1.0f, +1.0f // Left Top |
| 268 |
}; |
| 269 |
|
| 270 |
// Normalized texture coords to be aligned to draw quad corners, same sequence but 0,0 is Left Top |
| 271 |
const GLuint texCoords[] = { |
| 272 |
0, 1, |
| 273 |
1, 1, |
| 274 |
1, 0, |
| 275 |
0, 0 |
| 276 |
}; |
| 277 |
|
| 278 |
GLuint vertexbuffer; |
| 279 |
glGenBuffers(1, &vertexbuffer); |
| 280 |
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); |
| 281 |
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertex), quadVertex, GL_STATIC_DRAW); |
| 282 |
|
| 283 |
GLuint uvbuffer; |
| 284 |
glGenBuffers(1, &uvbuffer); |
| 285 |
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); |
| 286 |
glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW); |
| 287 |
|
| 288 |
// Attach Quad positions to vertex shader "position" attribute (location = 0) |
| 289 |
glEnableVertexAttribArray(0); |
| 290 |
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); |
| 291 |
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); |
| 292 |
|
| 293 |
// Attach texture corner positions to vertex shader "texCoord" attribute (location = 1) |
| 294 |
glEnableVertexAttribArray(1); |
| 295 |
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); |
| 296 |
glVertexAttribPointer(1, 2, GL_UNSIGNED_INT, GL_FALSE, 0, (void*)0); |
| 297 |
|
| 298 |
// Draw quad with texture |
| 299 |
glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 300 |
|
| 301 |
// Disable attrib arrays |
| 302 |
glDisableVertexAttribArray(0); |
| 303 |
glDisableVertexAttribArray(1); |
| 304 |
glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 305 |
glDeleteBuffers(1, &vertexbuffer); |
| 306 |
|
| 307 |
checkError("paintGL"); |
| 308 |
|
| 309 |
if (m_reportTimings) { |
| 310 |
glEndQuery(GL_TIME_ELAPSED); |
| 311 |
GLuint t; |
| 312 |
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &t); |
| 313 |
glDeleteQueries(1, &query); |
| 314 |
|
| 315 |
cnt++; |
| 316 |
tot_t += t; |
| 317 |
unsigned ave = tot_t / cnt; |
| 318 |
printf("Average render time: %09u ns, frame %d render time: %09u ns\n", |
| 319 |
ave, cnt, t); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
static const char *prog = |
| 324 |
#include "v4l2-convert.h" |
| 325 |
; |
| 326 |
|
| 327 |
struct define { |
| 328 |
const char *name; |
| 329 |
unsigned id; |
| 330 |
}; |
| 331 |
|
| 332 |
#define DEF(c) { .name = #c, .id = c } |
| 333 |
|
| 334 |
static const struct define defines[] = { |
| 335 |
DEF(V4L2_PIX_FMT_YUYV), |
| 336 |
DEF(V4L2_PIX_FMT_YVYU), |
| 337 |
DEF(V4L2_PIX_FMT_UYVY), |
| 338 |
DEF(V4L2_PIX_FMT_VYUY), |
| 339 |
DEF(V4L2_PIX_FMT_YUV422P), |
| 340 |
DEF(V4L2_PIX_FMT_YVU420), |
| 341 |
DEF(V4L2_PIX_FMT_YUV420), |
| 342 |
DEF(V4L2_PIX_FMT_NV12), |
| 343 |
DEF(V4L2_PIX_FMT_NV21), |
| 344 |
DEF(V4L2_PIX_FMT_NV16), |
| 345 |
DEF(V4L2_PIX_FMT_NV61), |
| 346 |
DEF(V4L2_PIX_FMT_NV24), |
| 347 |
DEF(V4L2_PIX_FMT_NV42), |
| 348 |
DEF(V4L2_PIX_FMT_NV16M), |
| 349 |
DEF(V4L2_PIX_FMT_NV61M), |
| 350 |
DEF(V4L2_PIX_FMT_YVU420M), |
| 351 |
DEF(V4L2_PIX_FMT_YUV420M), |
| 352 |
DEF(V4L2_PIX_FMT_YVU422M), |
| 353 |
DEF(V4L2_PIX_FMT_YUV422M), |
| 354 |
DEF(V4L2_PIX_FMT_YVU444M), |
| 355 |
DEF(V4L2_PIX_FMT_YUV444M), |
| 356 |
DEF(V4L2_PIX_FMT_NV12M), |
| 357 |
DEF(V4L2_PIX_FMT_NV21M), |
| 358 |
DEF(V4L2_PIX_FMT_YUV444), |
| 359 |
DEF(V4L2_PIX_FMT_YUV555), |
| 360 |
DEF(V4L2_PIX_FMT_YUV565), |
| 361 |
DEF(V4L2_PIX_FMT_YUV32), |
| 362 |
DEF(V4L2_PIX_FMT_AYUV32), |
| 363 |
DEF(V4L2_PIX_FMT_XYUV32), |
| 364 |
DEF(V4L2_PIX_FMT_VUYA32), |
| 365 |
DEF(V4L2_PIX_FMT_VUYX32), |
| 366 |
DEF(V4L2_PIX_FMT_YUVA32), |
| 367 |
DEF(V4L2_PIX_FMT_YUVX32), |
| 368 |
DEF(V4L2_PIX_FMT_RGB32), |
| 369 |
DEF(V4L2_PIX_FMT_XRGB32), |
| 370 |
DEF(V4L2_PIX_FMT_ARGB32), |
| 371 |
DEF(V4L2_PIX_FMT_RGBX32), |
| 372 |
DEF(V4L2_PIX_FMT_RGBA32), |
| 373 |
DEF(V4L2_PIX_FMT_BGR32), |
| 374 |
DEF(V4L2_PIX_FMT_XBGR32), |
| 375 |
DEF(V4L2_PIX_FMT_ABGR32), |
| 376 |
DEF(V4L2_PIX_FMT_BGRX32), |
| 377 |
DEF(V4L2_PIX_FMT_BGRA32), |
| 378 |
DEF(V4L2_PIX_FMT_RGB24), |
| 379 |
DEF(V4L2_PIX_FMT_BGR24), |
| 380 |
DEF(V4L2_PIX_FMT_RGB565), |
| 381 |
DEF(V4L2_PIX_FMT_RGB565X), |
| 382 |
DEF(V4L2_PIX_FMT_RGB444), |
| 383 |
DEF(V4L2_PIX_FMT_XRGB444), |
| 384 |
DEF(V4L2_PIX_FMT_ARGB444), |
| 385 |
DEF(V4L2_PIX_FMT_XBGR444), |
| 386 |
DEF(V4L2_PIX_FMT_ABGR444), |
| 387 |
DEF(V4L2_PIX_FMT_RGBX444), |
| 388 |
DEF(V4L2_PIX_FMT_RGBA444), |
| 389 |
DEF(V4L2_PIX_FMT_BGRX444), |
| 390 |
DEF(V4L2_PIX_FMT_BGRA444), |
| 391 |
DEF(V4L2_PIX_FMT_RGB555), |
| 392 |
DEF(V4L2_PIX_FMT_XRGB555), |
| 393 |
DEF(V4L2_PIX_FMT_ARGB555), |
| 394 |
DEF(V4L2_PIX_FMT_RGB555X), |
| 395 |
DEF(V4L2_PIX_FMT_XRGB555X), |
| 396 |
DEF(V4L2_PIX_FMT_ARGB555X), |
| 397 |
DEF(V4L2_PIX_FMT_RGBX555), |
| 398 |
DEF(V4L2_PIX_FMT_RGBA555), |
| 399 |
DEF(V4L2_PIX_FMT_XBGR555), |
| 400 |
DEF(V4L2_PIX_FMT_ABGR555), |
| 401 |
DEF(V4L2_PIX_FMT_BGRX555), |
| 402 |
DEF(V4L2_PIX_FMT_BGRA555), |
| 403 |
DEF(V4L2_PIX_FMT_RGB332), |
| 404 |
DEF(V4L2_PIX_FMT_BGR666), |
| 405 |
DEF(V4L2_PIX_FMT_SBGGR8), |
| 406 |
DEF(V4L2_PIX_FMT_SGBRG8), |
| 407 |
DEF(V4L2_PIX_FMT_SGRBG8), |
| 408 |
DEF(V4L2_PIX_FMT_SRGGB8), |
| 409 |
DEF(V4L2_PIX_FMT_SBGGR10), |
| 410 |
DEF(V4L2_PIX_FMT_SGBRG10), |
| 411 |
DEF(V4L2_PIX_FMT_SGRBG10), |
| 412 |
DEF(V4L2_PIX_FMT_SRGGB10), |
| 413 |
DEF(V4L2_PIX_FMT_SBGGR12), |
| 414 |
DEF(V4L2_PIX_FMT_SGBRG12), |
| 415 |
DEF(V4L2_PIX_FMT_SGRBG12), |
| 416 |
DEF(V4L2_PIX_FMT_SRGGB12), |
| 417 |
DEF(V4L2_PIX_FMT_SBGGR16), |
| 418 |
DEF(V4L2_PIX_FMT_SGBRG16), |
| 419 |
DEF(V4L2_PIX_FMT_SGRBG16), |
| 420 |
DEF(V4L2_PIX_FMT_SRGGB16), |
| 421 |
DEF(V4L2_PIX_FMT_HSV24), |
| 422 |
DEF(V4L2_PIX_FMT_HSV32), |
| 423 |
DEF(V4L2_PIX_FMT_GREY), |
| 424 |
DEF(V4L2_PIX_FMT_Y10), |
| 425 |
DEF(V4L2_PIX_FMT_Y12), |
| 426 |
DEF(V4L2_PIX_FMT_Y16), |
| 427 |
DEF(V4L2_PIX_FMT_Y16_BE), |
| 428 |
DEF(V4L2_PIX_FMT_Z16), |
| 429 |
|
| 430 |
DEF(V4L2_FIELD_ANY), |
| 431 |
DEF(V4L2_FIELD_NONE), |
| 432 |
DEF(V4L2_FIELD_TOP), |
| 433 |
DEF(V4L2_FIELD_BOTTOM), |
| 434 |
DEF(V4L2_FIELD_INTERLACED), |
| 435 |
DEF(V4L2_FIELD_SEQ_TB), |
| 436 |
DEF(V4L2_FIELD_SEQ_BT), |
| 437 |
DEF(V4L2_FIELD_ALTERNATE), |
| 438 |
DEF(V4L2_FIELD_INTERLACED_TB), |
| 439 |
DEF(V4L2_FIELD_INTERLACED_BT), |
| 440 |
|
| 441 |
DEF(V4L2_COLORSPACE_DEFAULT), |
| 442 |
DEF(V4L2_COLORSPACE_SMPTE170M), |
| 443 |
DEF(V4L2_COLORSPACE_SMPTE240M), |
| 444 |
DEF(V4L2_COLORSPACE_REC709), |
| 445 |
DEF(V4L2_COLORSPACE_470_SYSTEM_M), |
| 446 |
DEF(V4L2_COLORSPACE_470_SYSTEM_BG), |
| 447 |
DEF(V4L2_COLORSPACE_SRGB), |
| 448 |
DEF(V4L2_COLORSPACE_OPRGB), |
| 449 |
DEF(V4L2_COLORSPACE_BT2020), |
| 450 |
DEF(V4L2_COLORSPACE_RAW), |
| 451 |
DEF(V4L2_COLORSPACE_DCI_P3), |
| 452 |
|
| 453 |
DEF(V4L2_XFER_FUNC_DEFAULT), |
| 454 |
DEF(V4L2_XFER_FUNC_709), |
| 455 |
DEF(V4L2_XFER_FUNC_SRGB), |
| 456 |
DEF(V4L2_XFER_FUNC_OPRGB), |
| 457 |
DEF(V4L2_XFER_FUNC_SMPTE240M), |
| 458 |
DEF(V4L2_XFER_FUNC_NONE), |
| 459 |
DEF(V4L2_XFER_FUNC_DCI_P3), |
| 460 |
DEF(V4L2_XFER_FUNC_SMPTE2084), |
| 461 |
|
| 462 |
DEF(V4L2_YCBCR_ENC_DEFAULT), |
| 463 |
DEF(V4L2_YCBCR_ENC_601), |
| 464 |
DEF(V4L2_YCBCR_ENC_709), |
| 465 |
DEF(V4L2_YCBCR_ENC_XV601), |
| 466 |
DEF(V4L2_YCBCR_ENC_XV709), |
| 467 |
DEF(V4L2_YCBCR_ENC_BT2020), |
| 468 |
DEF(V4L2_YCBCR_ENC_BT2020_CONST_LUM), |
| 469 |
DEF(V4L2_YCBCR_ENC_SMPTE240M), |
| 470 |
DEF(V4L2_HSV_ENC_180), |
| 471 |
DEF(V4L2_HSV_ENC_256), |
| 472 |
|
| 473 |
DEF(V4L2_QUANTIZATION_DEFAULT), |
| 474 |
DEF(V4L2_QUANTIZATION_FULL_RANGE), |
| 475 |
DEF(V4L2_QUANTIZATION_LIM_RANGE), |
| 476 |
{ NULL, 0 } |
| 477 |
}; |
| 478 |
|
| 479 |
void CaptureWin::changeShader() |
| 480 |
{ |
| 481 |
if (m_screenTextureCount) |
| 482 |
glDeleteTextures(m_screenTextureCount, m_screenTexture); |
| 483 |
m_program->removeAllShaders(); |
| 484 |
checkError("Render settings.\n"); |
| 485 |
|
| 486 |
QString code; |
| 487 |
|
| 488 |
if (context()->isOpenGLES()) |
| 489 |
code = "#version 300 es\n" |
| 490 |
"precision mediump float;\n"; |
| 491 |
else |
| 492 |
code = "#version 330\n"; |
| 493 |
code += QString( |
| 494 |
"const float tex_w = %1.0;\n" |
| 495 |
"const float tex_h = %2.0;\n" |
| 496 |
"#define FIELD %3\n" |
| 497 |
"#define IS_RGB %4\n" |
| 498 |
"#define PIXFMT %5u\n" |
| 499 |
"#define COLSP %6\n" |
| 500 |
"#define XFERFUNC %7\n" |
| 501 |
"#define YCBCRENC %8\n" |
| 502 |
"#define QUANT %9\n\n" |
| 503 |
"#define IS_HSV %10\n" |
| 504 |
"#define HSVENC %11\n") |
| 505 |
.arg(m_v4l_fmt.g_width()) |
| 506 |
.arg(m_v4l_fmt.g_height()) |
| 507 |
.arg(m_v4l_fmt.g_field()) |
| 508 |
.arg(m_is_rgb) |
| 509 |
.arg(m_v4l_fmt.g_pixelformat()) |
| 510 |
.arg(m_v4l_fmt.g_colorspace()) |
| 511 |
.arg(m_accepts_srgb ? V4L2_XFER_FUNC_NONE : m_v4l_fmt.g_xfer_func()) |
| 512 |
.arg(m_v4l_fmt.g_ycbcr_enc()) |
| 513 |
.arg(m_v4l_fmt.g_quantization()) |
| 514 |
.arg(m_is_hsv) |
| 515 |
.arg(m_v4l_fmt.g_hsv_enc()); |
| 516 |
|
| 517 |
for (unsigned i = 0; defines[i].name; i++) |
| 518 |
code += QString("#define ") + defines[i].name + " " + QString("%1").arg(defines[i].id) + "u\n"; |
| 519 |
code += "#line 1\n"; |
| 520 |
|
| 521 |
code += prog; |
| 522 |
|
| 523 |
bool src_ok = m_program->addShaderFromSourceCode( |
| 524 |
QOpenGLShader::Fragment, code); |
| 525 |
|
| 526 |
if (!src_ok) { |
| 527 |
fprintf(stderr, "OpenGL Error: fragment shader compilation failed.\n"); |
| 528 |
std::exit(EXIT_FAILURE); |
| 529 |
} |
| 530 |
|
| 531 |
// Mandatory vertex shader replaces fixed pipeline in GLES 2.0. In this case just a feedthrough shader. |
| 532 |
QString vertexShaderSrc; |
| 533 |
|
| 534 |
if (context()->isOpenGLES()) |
| 535 |
vertexShaderSrc = "#version 300 es\n" |
| 536 |
"precision mediump float;\n"; |
| 537 |
else |
| 538 |
vertexShaderSrc = "#version 330\n"; |
| 539 |
|
| 540 |
vertexShaderSrc += |
| 541 |
"layout(location = 0) in vec2 position;\n" |
| 542 |
"layout(location = 1) in vec2 texCoord;\n" |
| 543 |
"out vec2 vs_TexCoord;\n" |
| 544 |
"void main() {\n" |
| 545 |
" gl_Position = vec4(position, 0.0, 1.0);\n" |
| 546 |
" vs_TexCoord = texCoord;\n" |
| 547 |
"}\n"; |
| 548 |
|
| 549 |
src_ok = m_program->addShaderFromSourceCode( |
| 550 |
QOpenGLShader::Vertex, vertexShaderSrc); |
| 551 |
|
| 552 |
if (!src_ok) { |
| 553 |
fprintf(stderr, "OpenGL Error: vertex shader compilation failed.\n"); |
| 554 |
std::exit(EXIT_FAILURE); |
| 555 |
} |
| 556 |
|
| 557 |
if (!m_program->bind()) { |
| 558 |
fprintf(stderr, "OpenGL Error: shader bind failed.\n"); |
| 559 |
std::exit(EXIT_FAILURE); |
| 560 |
} |
| 561 |
|
| 562 |
GLint loc = m_program->uniformLocation("uvtex"); |
| 563 |
|
| 564 |
if (loc >= 0) |
| 565 |
m_program->setUniformValue(loc, 1); |
| 566 |
loc = m_program->uniformLocation("utex"); |
| 567 |
if (loc >= 0) |
| 568 |
m_program->setUniformValue(loc, 1); |
| 569 |
loc = m_program->uniformLocation("vtex"); |
| 570 |
if (loc >= 0) |
| 571 |
m_program->setUniformValue(loc, 2); |
| 572 |
|
| 573 |
switch (m_v4l_fmt.g_pixelformat()) { |
| 574 |
case V4L2_PIX_FMT_YUYV: |
| 575 |
case V4L2_PIX_FMT_YVYU: |
| 576 |
case V4L2_PIX_FMT_UYVY: |
| 577 |
case V4L2_PIX_FMT_VYUY: |
| 578 |
shader_YUY2(); |
| 579 |
break; |
| 580 |
|
| 581 |
case V4L2_PIX_FMT_NV16: |
| 582 |
case V4L2_PIX_FMT_NV61: |
| 583 |
case V4L2_PIX_FMT_NV16M: |
| 584 |
case V4L2_PIX_FMT_NV61M: |
| 585 |
shader_NV16(); |
| 586 |
break; |
| 587 |
|
| 588 |
case V4L2_PIX_FMT_NV12: |
| 589 |
case V4L2_PIX_FMT_NV21: |
| 590 |
case V4L2_PIX_FMT_NV12M: |
| 591 |
case V4L2_PIX_FMT_NV21M: |
| 592 |
shader_NV12(); |
| 593 |
break; |
| 594 |
|
| 595 |
case V4L2_PIX_FMT_NV24: |
| 596 |
case V4L2_PIX_FMT_NV42: |
| 597 |
shader_NV24(); |
| 598 |
break; |
| 599 |
|
| 600 |
case V4L2_PIX_FMT_YUV444: |
| 601 |
case V4L2_PIX_FMT_YUV555: |
| 602 |
case V4L2_PIX_FMT_YUV565: |
| 603 |
case V4L2_PIX_FMT_YUV32: |
| 604 |
case V4L2_PIX_FMT_AYUV32: |
| 605 |
case V4L2_PIX_FMT_XYUV32: |
| 606 |
case V4L2_PIX_FMT_VUYA32: |
| 607 |
case V4L2_PIX_FMT_VUYX32: |
| 608 |
case V4L2_PIX_FMT_YUVA32: |
| 609 |
case V4L2_PIX_FMT_YUVX32: |
| 610 |
shader_YUV_packed(); |
| 611 |
break; |
| 612 |
|
| 613 |
case V4L2_PIX_FMT_YUV422P: |
| 614 |
case V4L2_PIX_FMT_YUV420: |
| 615 |
case V4L2_PIX_FMT_YVU420: |
| 616 |
case V4L2_PIX_FMT_YUV420M: |
| 617 |
case V4L2_PIX_FMT_YVU420M: |
| 618 |
case V4L2_PIX_FMT_YUV422M: |
| 619 |
case V4L2_PIX_FMT_YVU422M: |
| 620 |
case V4L2_PIX_FMT_YUV444M: |
| 621 |
case V4L2_PIX_FMT_YVU444M: |
| 622 |
shader_YUV(); |
| 623 |
break; |
| 624 |
|
| 625 |
case V4L2_PIX_FMT_SBGGR8: |
| 626 |
case V4L2_PIX_FMT_SGBRG8: |
| 627 |
case V4L2_PIX_FMT_SGRBG8: |
| 628 |
case V4L2_PIX_FMT_SRGGB8: |
| 629 |
case V4L2_PIX_FMT_SBGGR10: |
| 630 |
case V4L2_PIX_FMT_SGBRG10: |
| 631 |
case V4L2_PIX_FMT_SGRBG10: |
| 632 |
case V4L2_PIX_FMT_SRGGB10: |
| 633 |
case V4L2_PIX_FMT_SBGGR12: |
| 634 |
case V4L2_PIX_FMT_SGBRG12: |
| 635 |
case V4L2_PIX_FMT_SGRBG12: |
| 636 |
case V4L2_PIX_FMT_SRGGB12: |
| 637 |
case V4L2_PIX_FMT_SBGGR16: |
| 638 |
case V4L2_PIX_FMT_SGBRG16: |
| 639 |
case V4L2_PIX_FMT_SGRBG16: |
| 640 |
case V4L2_PIX_FMT_SRGGB16: |
| 641 |
shader_Bayer(); |
| 642 |
break; |
| 643 |
|
| 644 |
case V4L2_PIX_FMT_RGB332: |
| 645 |
case V4L2_PIX_FMT_BGR666: |
| 646 |
case V4L2_PIX_FMT_RGB444: |
| 647 |
case V4L2_PIX_FMT_XRGB444: |
| 648 |
case V4L2_PIX_FMT_ARGB444: |
| 649 |
case V4L2_PIX_FMT_XBGR444: |
| 650 |
case V4L2_PIX_FMT_ABGR444: |
| 651 |
case V4L2_PIX_FMT_RGBX444: |
| 652 |
case V4L2_PIX_FMT_RGBA444: |
| 653 |
case V4L2_PIX_FMT_BGRX444: |
| 654 |
case V4L2_PIX_FMT_BGRA444: |
| 655 |
case V4L2_PIX_FMT_RGB555: |
| 656 |
case V4L2_PIX_FMT_XRGB555: |
| 657 |
case V4L2_PIX_FMT_ARGB555: |
| 658 |
case V4L2_PIX_FMT_RGB555X: |
| 659 |
case V4L2_PIX_FMT_XRGB555X: |
| 660 |
case V4L2_PIX_FMT_ARGB555X: |
| 661 |
case V4L2_PIX_FMT_RGBX555: |
| 662 |
case V4L2_PIX_FMT_RGBA555: |
| 663 |
case V4L2_PIX_FMT_XBGR555: |
| 664 |
case V4L2_PIX_FMT_ABGR555: |
| 665 |
case V4L2_PIX_FMT_BGRX555: |
| 666 |
case V4L2_PIX_FMT_BGRA555: |
| 667 |
case V4L2_PIX_FMT_RGB565: |
| 668 |
case V4L2_PIX_FMT_RGB565X: |
| 669 |
case V4L2_PIX_FMT_RGB24: |
| 670 |
case V4L2_PIX_FMT_BGR24: |
| 671 |
case V4L2_PIX_FMT_RGB32: |
| 672 |
case V4L2_PIX_FMT_BGR32: |
| 673 |
case V4L2_PIX_FMT_XRGB32: |
| 674 |
case V4L2_PIX_FMT_XBGR32: |
| 675 |
case V4L2_PIX_FMT_ARGB32: |
| 676 |
case V4L2_PIX_FMT_ABGR32: |
| 677 |
case V4L2_PIX_FMT_RGBX32: |
| 678 |
case V4L2_PIX_FMT_BGRX32: |
| 679 |
case V4L2_PIX_FMT_RGBA32: |
| 680 |
case V4L2_PIX_FMT_BGRA32: |
| 681 |
case V4L2_PIX_FMT_GREY: |
| 682 |
case V4L2_PIX_FMT_Y10: |
| 683 |
case V4L2_PIX_FMT_Y12: |
| 684 |
case V4L2_PIX_FMT_Y16: |
| 685 |
case V4L2_PIX_FMT_Y16_BE: |
| 686 |
case V4L2_PIX_FMT_Z16: |
| 687 |
case V4L2_PIX_FMT_HSV24: |
| 688 |
case V4L2_PIX_FMT_HSV32: |
| 689 |
default: |
| 690 |
shader_RGB(); |
| 691 |
break; |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
void CaptureWin::shader_YUV() |
| 696 |
{ |
| 697 |
unsigned vdiv = 2, hdiv = 2; |
| 698 |
|
| 699 |
switch (m_v4l_fmt.g_pixelformat()) { |
| 700 |
case V4L2_PIX_FMT_YUV422P: |
| 701 |
case V4L2_PIX_FMT_YUV422M: |
| 702 |
case V4L2_PIX_FMT_YVU422M: |
| 703 |
vdiv = 1; |
| 704 |
break; |
| 705 |
case V4L2_PIX_FMT_YUV444M: |
| 706 |
case V4L2_PIX_FMT_YVU444M: |
| 707 |
vdiv = hdiv = 1; |
| 708 |
break; |
| 709 |
} |
| 710 |
|
| 711 |
m_screenTextureCount = 3; |
| 712 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 713 |
|
| 714 |
glActiveTexture(GL_TEXTURE0); |
| 715 |
configureTexture(0); |
| 716 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 717 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 718 |
checkError("YUV shader texture 0"); |
| 719 |
|
| 720 |
glActiveTexture(GL_TEXTURE1); |
| 721 |
configureTexture(1); |
| 722 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, 0, |
| 723 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 724 |
checkError("YUV shader texture 1"); |
| 725 |
|
| 726 |
glActiveTexture(GL_TEXTURE2); |
| 727 |
configureTexture(2); |
| 728 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, 0, |
| 729 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 730 |
checkError("YUV shader texture 2"); |
| 731 |
} |
| 732 |
|
| 733 |
void CaptureWin::shader_NV12() |
| 734 |
{ |
| 735 |
m_screenTextureCount = 2; |
| 736 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 737 |
|
| 738 |
glActiveTexture(GL_TEXTURE0); |
| 739 |
configureTexture(0); |
| 740 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 741 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 742 |
checkError("NV12 shader texture 0"); |
| 743 |
|
| 744 |
glActiveTexture(GL_TEXTURE1); |
| 745 |
configureTexture(1); |
| 746 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height() / 2, 0, |
| 747 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 748 |
checkError("NV12 shader texture 1"); |
| 749 |
} |
| 750 |
|
| 751 |
void CaptureWin::shader_NV24() |
| 752 |
{ |
| 753 |
m_screenTextureCount = 2; |
| 754 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 755 |
|
| 756 |
glActiveTexture(GL_TEXTURE0); |
| 757 |
configureTexture(0); |
| 758 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 759 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 760 |
checkError("NV24 shader texture 0"); |
| 761 |
|
| 762 |
glActiveTexture(GL_TEXTURE1); |
| 763 |
configureTexture(1); |
| 764 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 765 |
GL_RG, GL_UNSIGNED_BYTE, NULL); |
| 766 |
checkError("NV24 shader texture 1"); |
| 767 |
} |
| 768 |
|
| 769 |
void CaptureWin::shader_NV16() |
| 770 |
{ |
| 771 |
m_screenTextureCount = 2; |
| 772 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 773 |
|
| 774 |
glActiveTexture(GL_TEXTURE0); |
| 775 |
configureTexture(0); |
| 776 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 777 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 778 |
checkError("NV16 shader texture 0"); |
| 779 |
|
| 780 |
glActiveTexture(GL_TEXTURE1); |
| 781 |
configureTexture(1); |
| 782 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 783 |
GL_RED, GL_UNSIGNED_BYTE, NULL); |
| 784 |
checkError("NV16 shader texture 1"); |
| 785 |
} |
| 786 |
|
| 787 |
void CaptureWin::shader_YUY2() |
| 788 |
{ |
| 789 |
m_screenTextureCount = 1; |
| 790 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 791 |
configureTexture(0); |
| 792 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_v4l_fmt.g_width() / 2, m_v4l_fmt.g_height(), 0, |
| 793 |
GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 794 |
|
| 795 |
checkError("YUY2 shader"); |
| 796 |
} |
| 797 |
|
| 798 |
void CaptureWin::shader_RGB() |
| 799 |
{ |
| 800 |
m_screenTextureCount = 1; |
| 801 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 802 |
glActiveTexture(GL_TEXTURE0); |
| 803 |
configureTexture(0); |
| 804 |
|
| 805 |
GLint internalFmt = m_accepts_srgb ? GL_SRGB8_ALPHA8 : GL_RGBA8; |
| 806 |
|
| 807 |
switch (m_v4l_fmt.g_pixelformat()) { |
| 808 |
case V4L2_PIX_FMT_RGB555: |
| 809 |
case V4L2_PIX_FMT_XRGB555: |
| 810 |
case V4L2_PIX_FMT_ARGB555: |
| 811 |
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 812 |
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); |
| 813 |
break; |
| 814 |
|
| 815 |
case V4L2_PIX_FMT_RGB444: |
| 816 |
case V4L2_PIX_FMT_ARGB444: |
| 817 |
case V4L2_PIX_FMT_XRGB444: |
| 818 |
case V4L2_PIX_FMT_ABGR444: |
| 819 |
case V4L2_PIX_FMT_XBGR444: |
| 820 |
case V4L2_PIX_FMT_RGBA444: |
| 821 |
case V4L2_PIX_FMT_RGBX444: |
| 822 |
case V4L2_PIX_FMT_BGRA444: |
| 823 |
case V4L2_PIX_FMT_BGRX444: |
| 824 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 825 |
GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NULL); |
| 826 |
break; |
| 827 |
|
| 828 |
case V4L2_PIX_FMT_RGB555X: |
| 829 |
case V4L2_PIX_FMT_XRGB555X: |
| 830 |
case V4L2_PIX_FMT_ARGB555X: |
| 831 |
case V4L2_PIX_FMT_XBGR555: |
| 832 |
case V4L2_PIX_FMT_ABGR555: |
| 833 |
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 834 |
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); |
| 835 |
break; |
| 836 |
|
| 837 |
case V4L2_PIX_FMT_RGBX555: |
| 838 |
case V4L2_PIX_FMT_RGBA555: |
| 839 |
case V4L2_PIX_FMT_BGRX555: |
| 840 |
case V4L2_PIX_FMT_BGRA555: |
| 841 |
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 842 |
GL_BGRA, GL_UNSIGNED_SHORT_5_5_5_1, NULL); |
| 843 |
break; |
| 844 |
|
| 845 |
case V4L2_PIX_FMT_BGR666: |
| 846 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 847 |
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, NULL); |
| 848 |
break; |
| 849 |
|
| 850 |
case V4L2_PIX_FMT_RGB332: |
| 851 |
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 852 |
GL_RGB, GL_UNSIGNED_BYTE_3_3_2, NULL); |
| 853 |
break; |
| 854 |
|
| 855 |
case V4L2_PIX_FMT_RGB565: |
| 856 |
case V4L2_PIX_FMT_RGB565X: |
| 857 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 858 |
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); |
| 859 |
break; |
| 860 |
case V4L2_PIX_FMT_RGB32: |
| 861 |
case V4L2_PIX_FMT_ARGB32: |
| 862 |
case V4L2_PIX_FMT_XRGB32: |
| 863 |
case V4L2_PIX_FMT_RGBA32: |
| 864 |
case V4L2_PIX_FMT_RGBX32: |
| 865 |
case V4L2_PIX_FMT_HSV32: |
| 866 |
case V4L2_PIX_FMT_BGR32: |
| 867 |
case V4L2_PIX_FMT_ABGR32: |
| 868 |
case V4L2_PIX_FMT_XBGR32: |
| 869 |
case V4L2_PIX_FMT_BGRA32: |
| 870 |
case V4L2_PIX_FMT_BGRX32: |
| 871 |
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 872 |
GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 873 |
break; |
| 874 |
case V4L2_PIX_FMT_GREY: |
| 875 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 876 |
GL_RED_INTEGER, GL_UNSIGNED_BYTE, NULL); |
| 877 |
break; |
| 878 |
case V4L2_PIX_FMT_Y10: |
| 879 |
case V4L2_PIX_FMT_Y12: |
| 880 |
case V4L2_PIX_FMT_Y16: |
| 881 |
case V4L2_PIX_FMT_Y16_BE: |
| 882 |
case V4L2_PIX_FMT_Z16: |
| 883 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 884 |
GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL); |
| 885 |
break; |
| 886 |
case V4L2_PIX_FMT_RGB24: |
| 887 |
case V4L2_PIX_FMT_BGR24: |
| 888 |
case V4L2_PIX_FMT_HSV24: |
| 889 |
default: |
| 890 |
glTexImage2D(GL_TEXTURE_2D, 0, m_accepts_srgb ? GL_SRGB8 : GL_RGB8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 891 |
GL_RGB, GL_UNSIGNED_BYTE, NULL); |
| 892 |
break; |
| 893 |
} |
| 894 |
|
| 895 |
checkError("RGB shader"); |
| 896 |
} |
| 897 |
|
| 898 |
void CaptureWin::shader_Bayer() |
| 899 |
{ |
| 900 |
m_screenTextureCount = 1; |
| 901 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 902 |
glActiveTexture(GL_TEXTURE0); |
| 903 |
configureTexture(0); |
| 904 |
|
| 905 |
switch (m_v4l_fmt.g_pixelformat()) { |
| 906 |
case V4L2_PIX_FMT_SBGGR8: |
| 907 |
case V4L2_PIX_FMT_SGBRG8: |
| 908 |
case V4L2_PIX_FMT_SGRBG8: |
| 909 |
case V4L2_PIX_FMT_SRGGB8: |
| 910 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 911 |
GL_RED_INTEGER, GL_UNSIGNED_BYTE, NULL); |
| 912 |
break; |
| 913 |
case V4L2_PIX_FMT_SBGGR10: |
| 914 |
case V4L2_PIX_FMT_SGBRG10: |
| 915 |
case V4L2_PIX_FMT_SGRBG10: |
| 916 |
case V4L2_PIX_FMT_SRGGB10: |
| 917 |
case V4L2_PIX_FMT_SBGGR12: |
| 918 |
case V4L2_PIX_FMT_SGBRG12: |
| 919 |
case V4L2_PIX_FMT_SGRBG12: |
| 920 |
case V4L2_PIX_FMT_SRGGB12: |
| 921 |
case V4L2_PIX_FMT_SBGGR16: |
| 922 |
case V4L2_PIX_FMT_SGBRG16: |
| 923 |
case V4L2_PIX_FMT_SGRBG16: |
| 924 |
case V4L2_PIX_FMT_SRGGB16: |
| 925 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 926 |
GL_RED_INTEGER, GL_UNSIGNED_SHORT, NULL); |
| 927 |
break; |
| 928 |
} |
| 929 |
|
| 930 |
checkError("Bayer shader"); |
| 931 |
} |
| 932 |
|
| 933 |
void CaptureWin::shader_YUV_packed() |
| 934 |
{ |
| 935 |
m_screenTextureCount = 1; |
| 936 |
glGenTextures(m_screenTextureCount, m_screenTexture); |
| 937 |
glActiveTexture(GL_TEXTURE0); |
| 938 |
configureTexture(0); |
| 939 |
|
| 940 |
switch (m_v4l_fmt.g_pixelformat()) { |
| 941 |
case V4L2_PIX_FMT_YUV555: |
| 942 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 943 |
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); |
| 944 |
break; |
| 945 |
|
| 946 |
case V4L2_PIX_FMT_YUV444: |
| 947 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA4, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 948 |
GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NULL); |
| 949 |
break; |
| 950 |
|
| 951 |
case V4L2_PIX_FMT_YUV565: |
| 952 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB565, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 953 |
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); |
| 954 |
break; |
| 955 |
case V4L2_PIX_FMT_YUV32: |
| 956 |
case V4L2_PIX_FMT_AYUV32: |
| 957 |
case V4L2_PIX_FMT_XYUV32: |
| 958 |
case V4L2_PIX_FMT_VUYA32: |
| 959 |
case V4L2_PIX_FMT_VUYX32: |
| 960 |
case V4L2_PIX_FMT_YUVA32: |
| 961 |
case V4L2_PIX_FMT_YUVX32: |
| 962 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), 0, |
| 963 |
GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 964 |
break; |
| 965 |
} |
| 966 |
|
| 967 |
checkError("Packed YUV shader"); |
| 968 |
} |
| 969 |
|
| 970 |
void CaptureWin::render_YUV(__u32 format) |
| 971 |
{ |
| 972 |
unsigned vdiv = 2, hdiv = 2; |
| 973 |
int idxU = 0; |
| 974 |
int idxV = 0; |
| 975 |
|
| 976 |
switch (format) { |
| 977 |
case V4L2_PIX_FMT_YUV444M: |
| 978 |
case V4L2_PIX_FMT_YVU444M: |
| 979 |
vdiv = hdiv = 1; |
| 980 |
break; |
| 981 |
case V4L2_PIX_FMT_YUV422P: |
| 982 |
idxU = m_v4l_fmt.g_width() * m_v4l_fmt.g_height(); |
| 983 |
idxV = idxU + (idxU / 2); |
| 984 |
vdiv = 1; |
| 985 |
break; |
| 986 |
case V4L2_PIX_FMT_YUV422M: |
| 987 |
case V4L2_PIX_FMT_YVU422M: |
| 988 |
vdiv = 1; |
| 989 |
break; |
| 990 |
case V4L2_PIX_FMT_YUV420: |
| 991 |
idxU = m_v4l_fmt.g_width() * m_v4l_fmt.g_height(); |
| 992 |
idxV = idxU + (idxU / 4); |
| 993 |
break; |
| 994 |
case V4L2_PIX_FMT_YVU420: |
| 995 |
idxV = m_v4l_fmt.g_width() * m_v4l_fmt.g_height(); |
| 996 |
idxU = idxV + (idxV / 4); |
| 997 |
break; |
| 998 |
} |
| 999 |
|
| 1000 |
glActiveTexture(GL_TEXTURE0); |
| 1001 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1002 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1003 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1004 |
checkError("YUV paint ytex"); |
| 1005 |
|
| 1006 |
glActiveTexture(GL_TEXTURE1); |
| 1007 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]); |
| 1008 |
switch (format) { |
| 1009 |
case V4L2_PIX_FMT_YUV422P: |
| 1010 |
case V4L2_PIX_FMT_YUV420: |
| 1011 |
case V4L2_PIX_FMT_YVU420: |
| 1012 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, |
| 1013 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[0] == NULL ? NULL : &m_curData[0][idxU]); |
| 1014 |
break; |
| 1015 |
case V4L2_PIX_FMT_YUV420M: |
| 1016 |
case V4L2_PIX_FMT_YUV422M: |
| 1017 |
case V4L2_PIX_FMT_YUV444M: |
| 1018 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, |
| 1019 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[1]); |
| 1020 |
break; |
| 1021 |
case V4L2_PIX_FMT_YVU420M: |
| 1022 |
case V4L2_PIX_FMT_YVU422M: |
| 1023 |
case V4L2_PIX_FMT_YVU444M: |
| 1024 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, |
| 1025 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[2]); |
| 1026 |
break; |
| 1027 |
} |
| 1028 |
checkError("YUV paint utex"); |
| 1029 |
|
| 1030 |
glActiveTexture(GL_TEXTURE2); |
| 1031 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[2]); |
| 1032 |
switch (format) { |
| 1033 |
case V4L2_PIX_FMT_YUV422P: |
| 1034 |
case V4L2_PIX_FMT_YUV420: |
| 1035 |
case V4L2_PIX_FMT_YVU420: |
| 1036 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, |
| 1037 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[0] == NULL ? NULL : &m_curData[0][idxV]); |
| 1038 |
break; |
| 1039 |
case V4L2_PIX_FMT_YUV420M: |
| 1040 |
case V4L2_PIX_FMT_YUV422M: |
| 1041 |
case V4L2_PIX_FMT_YUV444M: |
| 1042 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, |
| 1043 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[2]); |
| 1044 |
break; |
| 1045 |
case V4L2_PIX_FMT_YVU420M: |
| 1046 |
case V4L2_PIX_FMT_YVU422M: |
| 1047 |
case V4L2_PIX_FMT_YVU444M: |
| 1048 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / hdiv, m_v4l_fmt.g_height() / vdiv, |
| 1049 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[1]); |
| 1050 |
break; |
| 1051 |
} |
| 1052 |
checkError("YUV paint vtex"); |
| 1053 |
} |
| 1054 |
|
| 1055 |
void CaptureWin::render_NV12(__u32 format) |
| 1056 |
{ |
| 1057 |
glActiveTexture(GL_TEXTURE0); |
| 1058 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1059 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1060 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1061 |
checkError("NV12 paint ytex"); |
| 1062 |
|
| 1063 |
glActiveTexture(GL_TEXTURE1); |
| 1064 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]); |
| 1065 |
switch (format) { |
| 1066 |
case V4L2_PIX_FMT_NV12: |
| 1067 |
case V4L2_PIX_FMT_NV21: |
| 1068 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height() / 2, |
| 1069 |
GL_RED, GL_UNSIGNED_BYTE, |
| 1070 |
m_curData[0] ? m_curData[0] + m_v4l_fmt.g_width() * m_v4l_fmt.g_height() : NULL); |
| 1071 |
break; |
| 1072 |
case V4L2_PIX_FMT_NV12M: |
| 1073 |
case V4L2_PIX_FMT_NV21M: |
| 1074 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height() / 2, |
| 1075 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[1]); |
| 1076 |
break; |
| 1077 |
} |
| 1078 |
checkError("NV12 paint uvtex"); |
| 1079 |
} |
| 1080 |
|
| 1081 |
void CaptureWin::render_NV24(__u32 format) |
| 1082 |
{ |
| 1083 |
glActiveTexture(GL_TEXTURE0); |
| 1084 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1085 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline()); |
| 1086 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1087 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1088 |
checkError("NV24 paint ytex"); |
| 1089 |
|
| 1090 |
glActiveTexture(GL_TEXTURE1); |
| 1091 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]); |
| 1092 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline()); |
| 1093 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1094 |
GL_RG, GL_UNSIGNED_BYTE, |
| 1095 |
m_curData[0] ? m_curData[0] + m_v4l_fmt.g_sizeimage() / 3 : NULL); |
| 1096 |
checkError("NV24 paint uvtex"); |
| 1097 |
} |
| 1098 |
|
| 1099 |
void CaptureWin::render_NV16(__u32 format) |
| 1100 |
{ |
| 1101 |
glActiveTexture(GL_TEXTURE0); |
| 1102 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1103 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline()); |
| 1104 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1105 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1106 |
checkError("NV16 paint ytex"); |
| 1107 |
|
| 1108 |
glActiveTexture(GL_TEXTURE1); |
| 1109 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[1]); |
| 1110 |
switch (format) { |
| 1111 |
case V4L2_PIX_FMT_NV16: |
| 1112 |
case V4L2_PIX_FMT_NV61: |
| 1113 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1114 |
GL_RED, GL_UNSIGNED_BYTE, |
| 1115 |
m_curData[0] ? m_curData[0] + m_v4l_fmt.g_sizeimage() / 2 : NULL); |
| 1116 |
break; |
| 1117 |
case V4L2_PIX_FMT_NV16M: |
| 1118 |
case V4L2_PIX_FMT_NV61M: |
| 1119 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1120 |
GL_RED, GL_UNSIGNED_BYTE, m_curData[1]); |
| 1121 |
break; |
| 1122 |
} |
| 1123 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 1124 |
checkError("NV16 paint uvtex"); |
| 1125 |
} |
| 1126 |
|
| 1127 |
void CaptureWin::render_YUY2(__u32 format) |
| 1128 |
{ |
| 1129 |
glActiveTexture(GL_TEXTURE0); |
| 1130 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1131 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 4); |
| 1132 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width() / 2, m_v4l_fmt.g_height(), |
| 1133 |
GL_RGBA, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1134 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 1135 |
checkError("YUY2 paint"); |
| 1136 |
} |
| 1137 |
|
| 1138 |
void CaptureWin::render_RGB(__u32 format) |
| 1139 |
{ |
| 1140 |
glActiveTexture(GL_TEXTURE0); |
| 1141 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1142 |
|
| 1143 |
switch (format) { |
| 1144 |
case V4L2_PIX_FMT_RGB332: |
| 1145 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline()); |
| 1146 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1147 |
GL_RGB, GL_UNSIGNED_BYTE_3_3_2, m_curData[0]); |
| 1148 |
break; |
| 1149 |
|
| 1150 |
case V4L2_PIX_FMT_RGB444: |
| 1151 |
case V4L2_PIX_FMT_XRGB444: |
| 1152 |
case V4L2_PIX_FMT_ARGB444: |
| 1153 |
case V4L2_PIX_FMT_XBGR444: |
| 1154 |
case V4L2_PIX_FMT_ABGR444: |
| 1155 |
case V4L2_PIX_FMT_RGBX444: |
| 1156 |
case V4L2_PIX_FMT_RGBA444: |
| 1157 |
case V4L2_PIX_FMT_BGRX444: |
| 1158 |
case V4L2_PIX_FMT_BGRA444: |
| 1159 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1160 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1161 |
GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, m_curData[0]); |
| 1162 |
break; |
| 1163 |
|
| 1164 |
case V4L2_PIX_FMT_GREY: |
| 1165 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline()); |
| 1166 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1167 |
GL_RED_INTEGER, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1168 |
break; |
| 1169 |
|
| 1170 |
case V4L2_PIX_FMT_Y10: |
| 1171 |
case V4L2_PIX_FMT_Y12: |
| 1172 |
case V4L2_PIX_FMT_Y16: |
| 1173 |
case V4L2_PIX_FMT_Z16: |
| 1174 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1175 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1176 |
GL_RED_INTEGER, GL_UNSIGNED_SHORT, m_curData[0]); |
| 1177 |
break; |
| 1178 |
case V4L2_PIX_FMT_Y16_BE: |
| 1179 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1180 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1181 |
GL_RED_INTEGER, GL_UNSIGNED_SHORT, m_curData[0]); |
| 1182 |
break; |
| 1183 |
|
| 1184 |
case V4L2_PIX_FMT_RGB555: |
| 1185 |
case V4L2_PIX_FMT_XRGB555: |
| 1186 |
case V4L2_PIX_FMT_ARGB555: |
| 1187 |
case V4L2_PIX_FMT_XBGR555: |
| 1188 |
case V4L2_PIX_FMT_ABGR555: |
| 1189 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1190 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1191 |
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, m_curData[0]); |
| 1192 |
break; |
| 1193 |
|
| 1194 |
case V4L2_PIX_FMT_RGB555X: |
| 1195 |
case V4L2_PIX_FMT_XRGB555X: |
| 1196 |
case V4L2_PIX_FMT_ARGB555X: |
| 1197 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1198 |
// Note: most likely for big-endian systems SWAP_BYTES should be true |
| 1199 |
// for the RGB555 format, and false for this format. This would have |
| 1200 |
// to be tested first, though. |
| 1201 |
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); |
| 1202 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1203 |
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, m_curData[0]); |
| 1204 |
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); |
| 1205 |
break; |
| 1206 |
|
| 1207 |
case V4L2_PIX_FMT_RGBX555: |
| 1208 |
case V4L2_PIX_FMT_RGBA555: |
| 1209 |
case V4L2_PIX_FMT_BGRX555: |
| 1210 |
case V4L2_PIX_FMT_BGRA555: |
| 1211 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1212 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1213 |
GL_BGRA, GL_UNSIGNED_SHORT_5_5_5_1, m_curData[0]); |
| 1214 |
break; |
| 1215 |
|
| 1216 |
case V4L2_PIX_FMT_RGB565: |
| 1217 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1218 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1219 |
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, m_curData[0]); |
| 1220 |
break; |
| 1221 |
|
| 1222 |
case V4L2_PIX_FMT_RGB565X: |
| 1223 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1224 |
// Note: most likely for big-endian systems SWAP_BYTES should be true |
| 1225 |
// for the RGB565 format, and false for this format. This would have |
| 1226 |
// to be tested first, though. |
| 1227 |
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE); |
| 1228 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1229 |
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, m_curData[0]); |
| 1230 |
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); |
| 1231 |
break; |
| 1232 |
|
| 1233 |
case V4L2_PIX_FMT_RGB32: |
| 1234 |
case V4L2_PIX_FMT_XRGB32: |
| 1235 |
case V4L2_PIX_FMT_ARGB32: |
| 1236 |
case V4L2_PIX_FMT_RGBX32: |
| 1237 |
case V4L2_PIX_FMT_RGBA32: |
| 1238 |
case V4L2_PIX_FMT_HSV32: |
| 1239 |
case V4L2_PIX_FMT_BGR32: |
| 1240 |
case V4L2_PIX_FMT_XBGR32: |
| 1241 |
case V4L2_PIX_FMT_ABGR32: |
| 1242 |
case V4L2_PIX_FMT_BGRX32: |
| 1243 |
case V4L2_PIX_FMT_BGRA32: |
| 1244 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 4); |
| 1245 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1246 |
GL_RGBA, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1247 |
break; |
| 1248 |
case V4L2_PIX_FMT_BGR666: |
| 1249 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 4); |
| 1250 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1251 |
GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, m_curData[0]); |
| 1252 |
break; |
| 1253 |
|
| 1254 |
case V4L2_PIX_FMT_RGB24: |
| 1255 |
case V4L2_PIX_FMT_BGR24: |
| 1256 |
case V4L2_PIX_FMT_HSV24: |
| 1257 |
default: |
| 1258 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 3); |
| 1259 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1260 |
GL_RGB, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1261 |
break; |
| 1262 |
} |
| 1263 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 1264 |
checkError("RGB paint"); |
| 1265 |
} |
| 1266 |
|
| 1267 |
void CaptureWin::render_Bayer(__u32 format) |
| 1268 |
{ |
| 1269 |
glActiveTexture(GL_TEXTURE0); |
| 1270 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1271 |
|
| 1272 |
switch (format) { |
| 1273 |
case V4L2_PIX_FMT_SBGGR8: |
| 1274 |
case V4L2_PIX_FMT_SGBRG8: |
| 1275 |
case V4L2_PIX_FMT_SGRBG8: |
| 1276 |
case V4L2_PIX_FMT_SRGGB8: |
| 1277 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline()); |
| 1278 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1279 |
GL_RED_INTEGER, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1280 |
break; |
| 1281 |
case V4L2_PIX_FMT_SBGGR10: |
| 1282 |
case V4L2_PIX_FMT_SGBRG10: |
| 1283 |
case V4L2_PIX_FMT_SGRBG10: |
| 1284 |
case V4L2_PIX_FMT_SRGGB10: |
| 1285 |
case V4L2_PIX_FMT_SBGGR12: |
| 1286 |
case V4L2_PIX_FMT_SGBRG12: |
| 1287 |
case V4L2_PIX_FMT_SGRBG12: |
| 1288 |
case V4L2_PIX_FMT_SRGGB12: |
| 1289 |
case V4L2_PIX_FMT_SBGGR16: |
| 1290 |
case V4L2_PIX_FMT_SGBRG16: |
| 1291 |
case V4L2_PIX_FMT_SGRBG16: |
| 1292 |
case V4L2_PIX_FMT_SRGGB16: |
| 1293 |
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_v4l_fmt.g_bytesperline() / 2); |
| 1294 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1295 |
GL_RED_INTEGER, GL_UNSIGNED_SHORT, m_curData[0]); |
| 1296 |
break; |
| 1297 |
} |
| 1298 |
checkError("Bayer paint"); |
| 1299 |
} |
| 1300 |
|
| 1301 |
void CaptureWin::render_YUV_packed(__u32 format) |
| 1302 |
{ |
| 1303 |
glActiveTexture(GL_TEXTURE0); |
| 1304 |
glBindTexture(GL_TEXTURE_2D, m_screenTexture[0]); |
| 1305 |
|
| 1306 |
switch (format) { |
| 1307 |
case V4L2_PIX_FMT_YUV555: |
| 1308 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1309 |
GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, m_curData[0]); |
| 1310 |
break; |
| 1311 |
|
| 1312 |
case V4L2_PIX_FMT_YUV444: |
| 1313 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1314 |
GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, m_curData[0]); |
| 1315 |
break; |
| 1316 |
|
| 1317 |
case V4L2_PIX_FMT_YUV565: |
| 1318 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1319 |
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, m_curData[0]); |
| 1320 |
break; |
| 1321 |
|
| 1322 |
case V4L2_PIX_FMT_YUV32: |
| 1323 |
case V4L2_PIX_FMT_AYUV32: |
| 1324 |
case V4L2_PIX_FMT_XYUV32: |
| 1325 |
case V4L2_PIX_FMT_VUYA32: |
| 1326 |
case V4L2_PIX_FMT_VUYX32: |
| 1327 |
case V4L2_PIX_FMT_YUVA32: |
| 1328 |
case V4L2_PIX_FMT_YUVX32: |
| 1329 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), |
| 1330 |
GL_RGBA, GL_UNSIGNED_BYTE, m_curData[0]); |
| 1331 |
break; |
| 1332 |
} |
| 1333 |
checkError("Packed YUV paint"); |
| 1334 |
} |