|
@@ -1,6 +1,7 @@
|
|
|
#include "gles2_debayer.h"
|
|
|
|
|
|
#include "camera.h"
|
|
|
+#include "dcp.h"
|
|
|
#include "gl_util.h"
|
|
|
#include <stdlib.h>
|
|
|
|
|
@@ -18,12 +19,13 @@ struct _GLES2Debayer {
|
|
|
GLuint uniform_texture;
|
|
|
GLuint uniform_color_matrix;
|
|
|
GLuint uniform_row_length;
|
|
|
+ GLuint uniform_inv_gamma;
|
|
|
|
|
|
GLuint quad;
|
|
|
};
|
|
|
|
|
|
GLES2Debayer *
|
|
|
-gles2_debayer_new(int format, int xfer)
|
|
|
+gles2_debayer_new(int format)
|
|
|
{
|
|
|
uint32_t pixfmt = libmegapixels_format_to_v4l_pixfmt(format);
|
|
|
if (pixfmt != V4L2_PIX_FMT_SBGGR8 && pixfmt != V4L2_PIX_FMT_SGBRG8 &&
|
|
@@ -37,14 +39,12 @@ gles2_debayer_new(int format, int xfer)
|
|
|
glGenFramebuffers(1, &frame_buffer);
|
|
|
check_gl();
|
|
|
|
|
|
- char format_def[96];
|
|
|
- bool is_srgb = xfer == LIBMEGAPIXELS_XFER_SRGB;
|
|
|
+ char format_def[64];
|
|
|
snprintf(format_def,
|
|
|
- 96,
|
|
|
- "#define CFA_%s\n#define BITS_%d\n#define COLORSPACE_%s\n",
|
|
|
+ 64,
|
|
|
+ "#define CFA_%s\n#define BITS_%d\n",
|
|
|
libmegapixels_format_cfa(format),
|
|
|
- libmegapixels_format_bits_per_pixel(format),
|
|
|
- is_srgb ? "SRGB" : "RAW");
|
|
|
+ libmegapixels_format_bits_per_pixel(format));
|
|
|
|
|
|
const GLchar *def[1] = { format_def };
|
|
|
|
|
@@ -77,6 +77,7 @@ gles2_debayer_new(int format, int xfer)
|
|
|
self->uniform_texture = glGetUniformLocation(self->program, "texture");
|
|
|
self->uniform_color_matrix =
|
|
|
glGetUniformLocation(self->program, "color_matrix");
|
|
|
+ self->uniform_inv_gamma = glGetUniformLocation(self->program, "inv_gamma");
|
|
|
if (libmegapixels_format_bits_per_pixel(self->format) == 10)
|
|
|
self->uniform_row_length =
|
|
|
glGetUniformLocation(self->program, "row_length");
|
|
@@ -115,8 +116,7 @@ gles2_debayer_configure(GLES2Debayer *self,
|
|
|
const uint32_t src_height,
|
|
|
const uint32_t rotation,
|
|
|
const bool mirrored,
|
|
|
- const float *colormatrix,
|
|
|
- const uint8_t blacklevel)
|
|
|
+ struct MPCameraCalibration calibration)
|
|
|
{
|
|
|
glViewport(0, 0, (int)dst_width, (int)dst_height);
|
|
|
check_gl();
|
|
@@ -142,11 +142,21 @@ gles2_debayer_configure(GLES2Debayer *self,
|
|
|
glUniform2f(self->uniform_pixel_size, pixel_size_x, pixel_size_y);
|
|
|
check_gl();
|
|
|
|
|
|
- if (colormatrix) {
|
|
|
+ float gamma = 1.0f;
|
|
|
+ for (int i = 0; i < calibration.tone_curve_length * 2; i += 2) {
|
|
|
+ float g = calibration.tone_curve[i + 1] / calibration.tone_curve[i];
|
|
|
+ if (g > gamma) {
|
|
|
+ gamma = g;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ glUniform1f(self->uniform_inv_gamma, 1.0f / gamma);
|
|
|
+
|
|
|
+ if (calibration.color_matrix_1[0]) {
|
|
|
GLfloat transposed[9];
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
for (int j = 0; j < 3; ++j)
|
|
|
- transposed[i + j * 3] = colormatrix[j + i * 3];
|
|
|
+ transposed[i + j * 3] =
|
|
|
+ calibration.color_matrix_1[j + i * 3];
|
|
|
|
|
|
glUniformMatrix3fv(
|
|
|
self->uniform_color_matrix, 1, GL_FALSE, transposed);
|