|
@@ -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)) {
|