aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2015-09-21 10:27:20 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2015-09-21 10:27:20 +0200
commit941f5fc8d8dbbe2750e00f5a43c7d1d6b74f4220 (patch)
treeba87a08ab1053fb0ed0cdb78a30e791259994f76
parent11adf49a3b565fedd20f5a57bc2dd293d3b386a3 (diff)
qv4l2: add support for Bayer 10 and 12 bits.bayer10
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
-rw-r--r--utils/qv4l2/capture-win-gl.cpp125
1 files changed, 100 insertions, 25 deletions
diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp
index 5ee943e9..8b8b0741 100644
--- a/utils/qv4l2/capture-win-gl.cpp
+++ b/utils/qv4l2/capture-win-gl.cpp
@@ -350,6 +350,14 @@ bool CaptureWinGLEngine::hasNativeFormat(__u32 format)
V4L2_PIX_FMT_SGBRG8,
V4L2_PIX_FMT_SGRBG8,
V4L2_PIX_FMT_SRGGB8,
+ V4L2_PIX_FMT_SBGGR10,
+ V4L2_PIX_FMT_SGBRG10,
+ V4L2_PIX_FMT_SGRBG10,
+ V4L2_PIX_FMT_SRGGB10,
+ V4L2_PIX_FMT_SBGGR12,
+ V4L2_PIX_FMT_SGBRG12,
+ V4L2_PIX_FMT_SGRBG12,
+ V4L2_PIX_FMT_SRGGB12,
V4L2_PIX_FMT_YUYV,
V4L2_PIX_FMT_YVYU,
V4L2_PIX_FMT_UYVY,
@@ -446,6 +454,14 @@ void CaptureWinGLEngine::changeShader()
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
+ case V4L2_PIX_FMT_SBGGR10:
+ case V4L2_PIX_FMT_SGBRG10:
+ case V4L2_PIX_FMT_SGRBG10:
+ case V4L2_PIX_FMT_SRGGB10:
+ case V4L2_PIX_FMT_SBGGR12:
+ case V4L2_PIX_FMT_SGBRG12:
+ case V4L2_PIX_FMT_SGRBG12:
+ case V4L2_PIX_FMT_SRGGB12:
shader_Bayer(m_frameFormat);
break;
@@ -576,6 +592,14 @@ void CaptureWinGLEngine::paintGL()
case V4L2_PIX_FMT_SGBRG8:
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
+ case V4L2_PIX_FMT_SBGGR10:
+ case V4L2_PIX_FMT_SGBRG10:
+ case V4L2_PIX_FMT_SGRBG10:
+ case V4L2_PIX_FMT_SRGGB10:
+ case V4L2_PIX_FMT_SBGGR12:
+ case V4L2_PIX_FMT_SGBRG12:
+ case V4L2_PIX_FMT_SGRBG12:
+ case V4L2_PIX_FMT_SRGGB12:
render_Bayer(m_frameFormat);
break;
@@ -1498,9 +1522,10 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
break;
case V4L2_PIX_FMT_Y16:
case V4L2_PIX_FMT_Y16_BE:
- internalFmt = manualTransform ? GL_LUMINANCE : GL_SLUMINANCE;
+ manualTransform = true;
+ internalFmt = GL_R16;
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, m_frameHeight, 0,
- GL_LUMINANCE, GL_UNSIGNED_SHORT, NULL);
+ GL_RED, GL_UNSIGNED_SHORT, NULL);
break;
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
@@ -1537,6 +1562,10 @@ void CaptureWinGLEngine::shader_RGB(__u32 format)
" float b = ub / 63.0;"
" float g = ug / 63.0;"
" float r = ur / 63.0;";
+ else if (format == V4L2_PIX_FMT_Y16 || format == V4L2_PIX_FMT_Y16_BE)
+ codeHead += " float r = color.r;"
+ " float g = color.r;"
+ " float b = color.r;";
else if (format == V4L2_PIX_FMT_BGR24)
codeHead += " float r = color.b;"
" float g = color.g;"
@@ -1602,12 +1631,12 @@ void CaptureWinGLEngine::render_RGB(__u32 format)
case V4L2_PIX_FMT_Y16:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
- GL_LUMINANCE, GL_UNSIGNED_SHORT, m_frameData);
+ GL_RED, GL_UNSIGNED_SHORT, m_frameData);
break;
case V4L2_PIX_FMT_Y16_BE:
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
- GL_LUMINANCE, GL_UNSIGNED_SHORT, m_frameData);
+ GL_RED, GL_UNSIGNED_SHORT, m_frameData);
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
break;
@@ -1668,9 +1697,7 @@ void CaptureWinGLEngine::shader_Bayer(__u32 format)
glActiveTexture(GL_TEXTURE0);
configureTexture(0);
- GLint internalFmt = (m_quantization == V4L2_QUANTIZATION_LIM_RANGE ||
- m_xfer_func != V4L2_XFER_FUNC_SRGB) ?
- GL_LUMINANCE : GL_SLUMINANCE;
+ GLint internalFmt = GL_RED;
switch (format) {
case V4L2_PIX_FMT_SBGGR8:
@@ -1678,7 +1705,19 @@ void CaptureWinGLEngine::shader_Bayer(__u32 format)
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, m_frameHeight, 0,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
+ GL_RED, GL_UNSIGNED_BYTE, NULL);
+ break;
+ case V4L2_PIX_FMT_SBGGR10:
+ case V4L2_PIX_FMT_SGBRG10:
+ case V4L2_PIX_FMT_SGRBG10:
+ case V4L2_PIX_FMT_SRGGB10:
+ case V4L2_PIX_FMT_SBGGR12:
+ case V4L2_PIX_FMT_SGBRG12:
+ case V4L2_PIX_FMT_SGRBG12:
+ case V4L2_PIX_FMT_SRGGB12:
+ internalFmt = GL_R16;
+ glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, m_frameHeight, 0,
+ GL_RED, GL_UNSIGNED_SHORT, NULL);
break;
}
@@ -1709,24 +1748,51 @@ void CaptureWinGLEngine::shader_Bayer(__u32 format)
/* Poor quality Bayer to RGB conversion, but good enough for now */
switch (format) {
case V4L2_PIX_FMT_SBGGR8:
- codeHead += " r = texture2D(tex, vec2(cell.x + texl_w, cell.y + texl_h)).y;"
- " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x + texl_w : cell.x, xy.y)).y;"
- " b = texture2D(tex, cell).y;";
+ case V4L2_PIX_FMT_SBGGR10:
+ case V4L2_PIX_FMT_SBGGR12:
+ codeHead += " r = texture2D(tex, vec2(cell.x + texl_w, cell.y + texl_h)).r;"
+ " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x + texl_w : cell.x, xy.y)).r;"
+ " b = texture2D(tex, cell).r;";
break;
case V4L2_PIX_FMT_SGBRG8:
- codeHead += " r = texture2D(tex, vec2(cell.x, cell.y + texl_h)).y;"
- " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x : cell.x + texl_w, xy.y)).y;"
- " b = texture2D(tex, vec2(cell.x + texl_w, cell.y)).y;";
+ case V4L2_PIX_FMT_SGBRG10:
+ case V4L2_PIX_FMT_SGBRG12:
+ codeHead += " r = texture2D(tex, vec2(cell.x, cell.y + texl_h)).r;"
+ " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x : cell.x + texl_w, xy.y)).r;"
+ " b = texture2D(tex, vec2(cell.x + texl_w, cell.y)).r;";
break;
case V4L2_PIX_FMT_SGRBG8:
- codeHead += " r = texture2D(tex, vec2(cell.x + texl_w, cell.y)).y;"
- " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x : cell.x + texl_w, xy.y)).y;"
- " b = texture2D(tex, vec2(cell.x, cell.y + texl_h)).y;";
+ case V4L2_PIX_FMT_SGRBG10:
+ case V4L2_PIX_FMT_SGRBG12:
+ codeHead += " r = texture2D(tex, vec2(cell.x + texl_w, cell.y)).r;"
+ " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x : cell.x + texl_w, xy.y)).r;"
+ " b = texture2D(tex, vec2(cell.x, cell.y + texl_h)).r;";
break;
case V4L2_PIX_FMT_SRGGB8:
- codeHead += " b = texture2D(tex, vec2(cell.x + texl_w, cell.y + texl_h)).y;"
- " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x + texl_w : cell.x, xy.y)).y;"
- " r = texture2D(tex, cell).y;";
+ case V4L2_PIX_FMT_SRGGB10:
+ case V4L2_PIX_FMT_SRGGB12:
+ codeHead += " b = texture2D(tex, vec2(cell.x + texl_w, cell.y + texl_h)).r;"
+ " g = texture2D(tex, vec2((cell.y == xy.y) ? cell.x + texl_w : cell.x, xy.y)).r;"
+ " r = texture2D(tex, cell).r;";
+ break;
+ }
+
+ switch (format) {
+ case V4L2_PIX_FMT_SBGGR10:
+ case V4L2_PIX_FMT_SGBRG10:
+ case V4L2_PIX_FMT_SGRBG10:
+ case V4L2_PIX_FMT_SRGGB10:
+ codeHead += " b = b * (65535.0 / 255.0);"
+ " g = g * (65535.0 / 255.0);"
+ " r = r * (65535.0 / 255.0);";
+ break;
+ case V4L2_PIX_FMT_SBGGR12:
+ case V4L2_PIX_FMT_SGBRG12:
+ case V4L2_PIX_FMT_SGRBG12:
+ case V4L2_PIX_FMT_SRGGB12:
+ codeHead += " b = b * (65535.0 / 1023.0);"
+ " g = g * (65535.0 / 1023.0);"
+ " r = r * (65535.0 / 1023.0);";
break;
}
@@ -1734,11 +1800,9 @@ void CaptureWinGLEngine::shader_Bayer(__u32 format)
if (m_quantization == V4L2_QUANTIZATION_LIM_RANGE)
codeTail += codeRGBNormalize();
- if (m_quantization == V4L2_QUANTIZATION_LIM_RANGE ||
- m_xfer_func != V4L2_XFER_FUNC_SRGB)
- codeTail += codeTransformToLinear();
- codeTail += codeColorspaceConversion() +
+ codeTail += codeTransformToLinear() +
+ codeColorspaceConversion() +
codeTransformToNonLinear() +
codeSuffix;
@@ -1773,7 +1837,18 @@ void CaptureWinGLEngine::render_Bayer(__u32 format)
case V4L2_PIX_FMT_SGRBG8:
case V4L2_PIX_FMT_SRGGB8:
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, m_frameData);
+ GL_RED, GL_UNSIGNED_BYTE, m_frameData);
+ break;
+ case V4L2_PIX_FMT_SBGGR10:
+ case V4L2_PIX_FMT_SGBRG10:
+ case V4L2_PIX_FMT_SGRBG10:
+ case V4L2_PIX_FMT_SRGGB10:
+ case V4L2_PIX_FMT_SBGGR12:
+ case V4L2_PIX_FMT_SGBRG12:
+ case V4L2_PIX_FMT_SGRBG12:
+ case V4L2_PIX_FMT_SRGGB12:
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight,
+ GL_RED, GL_UNSIGNED_SHORT, m_frameData);
break;
}
checkError("Bayer paint");

Privacy Policy