Spaces:
Paused
Paused
from OpenGL.GL import * | |
from ColorMatrix import ColorMatrix | |
def set_uniform(uniform_name, value, type, shader_program): | |
uniform_location = glGetUniformLocation( | |
shader_program, f"u_{uniform_name}") | |
if type == '1f': | |
glUniform1f(uniform_location, value) | |
elif type == '2fv': | |
glUniform2fv(uniform_location, 1, (GLfloat * len(value))(*value)) | |
elif type == '4fv': | |
glUniform4fv(uniform_location, 1, (GLfloat * len(value))(*value)) | |
elif type == 'mat4': | |
glUniformMatrix4fv(uniform_location, 1, GL_FALSE, | |
(GLfloat * len(value))(*value)) | |
def set_color_matrix_uniform(color_matrix, val_name, shader_program): | |
t = color_matrix | |
set_uniform( | |
f"{val_name}Matrix", | |
[t.a, t.b, t.c, t.d, t.f, t.g, t.h, t.i, | |
t.k, t.l, t.m, t.n, t.p, t.q, t.r, t.s], | |
'mat4', | |
shader_program | |
) | |
set_uniform(f"{val_name}Matrix_vec", [ | |
t.e, t.j, t.o, t.t], '4fv', shader_program) | |
set_uniform(f"{val_name}Offset", color_matrix.get_offsets(), | |
'4fv', shader_program) | |
def set_options(exposure, saturation, contrast, brightness, gamma, shadows, highlights, whites, blacks, | |
clarity, temperature, sharpness, shader_program, canvas_width, canvas_height): | |
if not shader_program: | |
print('Shader program not initialized') | |
return | |
set_uniform('gamma', gamma, '1f', shader_program) | |
set_uniform('shadows', shadows, '1f', shader_program) | |
set_uniform('highlights', highlights, '1f', shader_program) | |
set_uniform('whites', whites, '1f', shader_program) | |
set_uniform('blacks', blacks, '1f', shader_program) | |
set_uniform('clarity', clarity, '1f', shader_program) | |
set_uniform('temperature', temperature, '1f', shader_program) | |
set_uniform('sharpness', sharpness, '1f', shader_program) | |
color_matrix = ColorMatrix() | |
color_matrix.multiply(ColorMatrix.create_exposure_matrix(exposure)) | |
print(vars(color_matrix)) | |
color_matrix.multiply(ColorMatrix.create_saturation_matrix(saturation + 1)) | |
print(vars(color_matrix)) | |
if contrast > 0: | |
contrast = contrast * 2 | |
color_matrix.multiply(ColorMatrix.create_contrast_matrix( | |
contrast + 1)) | |
print(vars(color_matrix)) | |
color_matrix.multiply(ColorMatrix.create_brightness_matrix(brightness)) | |
print(vars(color_matrix)) | |
set_color_matrix_uniform(color_matrix, 'color', shader_program) | |
clarity_matrix = ColorMatrix() | |
clarity_matrix.multiply( | |
ColorMatrix.create_saturation_matrix(-0.3 * clarity + 1)) | |
clarity_matrix.multiply( | |
ColorMatrix.create_contrast_matrix(0.1 * clarity + 1)) | |
set_color_matrix_uniform(clarity_matrix, 'clarity', shader_program) | |
print('pixelDimension', [ | |
1 / canvas_width, 1 / canvas_height]) | |
set_uniform('pixelDimension', [ | |
1 / canvas_width, 1 / canvas_height], '2fv', shader_program) | |