Fix QR-code/symbol not rendering on top of QR-code correctly

This commit is contained in:
Kristian Vos
2024-07-10 13:45:59 +02:00
parent 1a27c4b15b
commit 8b525210bc
3 changed files with 45 additions and 12 deletions

View File

@@ -422,6 +422,7 @@ preview_draw(GtkGLArea *area, GdkGLContext *ctx, gpointer data)
glViewport(
offset_x, state.preview_height - size_y - offset_y, size_x, size_y);
// This rotates the camera preview based on the phone rotation
if (current_preview_buffer) {
glUseProgram(blit_program);
@@ -469,20 +470,38 @@ preview_draw(GtkGLArea *area, GdkGLContext *ctx, gpointer data)
MPZBarCode *code = &zbar_result->codes[i];
GLfloat vertices[] = {
code->bounds_x[0], code->bounds_y[0],
code->bounds_x[1], code->bounds_y[1],
code->bounds_x[3], code->bounds_y[3],
code->bounds_x[2], code->bounds_y[2],
code->bounds_x[0], code->bounds_y[0], // Bottom left
code->bounds_x[1], code->bounds_y[1], // Bottom right
code->bounds_x[3], code->bounds_y[3], // Top left
code->bounds_x[2], code->bounds_y[2], // Top right
};
// Convert the pixel X/Y coordinates to OpenGL coordinates
// (-1 to 1)
for (int i = 0; i < 4; ++i) {
vertices[i * 2] =
2 * vertices[i * 2] /
state.preview_buffer_width -
1.0;
vertices[i * 2 + 1] =
1.0 - 2 * vertices[i * 2 + 1] /
state.preview_buffer_height;
// Width/height need to be swapped between portrait
// mode and landscape mode for symbols to render
// correctly
if (state.device_rotation == 0 ||
state.device_rotation == 180) {
vertices[i * 2] =
2 * vertices[i * 2] /
state.preview_buffer_width -
1.0;
vertices[i * 2 + 1] =
1.0 -
2 * vertices[i * 2 + 1] /
state.preview_buffer_height;
} else {
vertices[i * 2] =
2 * vertices[i * 2] /
state.preview_buffer_height -
1.0;
vertices[i * 2 + 1] =
1.0 -
2 * vertices[i * 2 + 1] /
state.preview_buffer_width;
}
}
if (gtk_gl_area_get_use_es(area)) {