Skip to content

Commit 08dddee

Browse files
danielmyhisak-jakobssonStiv-work
authored andcommitted
axoverlay: take stream rotation into account
Co-authored-by: Isak Jakobsson <[email protected]> Co-authored-by: Stiv Abdullwahed <[email protected]>
1 parent 90f695a commit 08dddee

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

axoverlay/app/axoverlay.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,23 @@ static void adjustment_cb(gint id,
212212
(void)overlay_y;
213213
(void)user_data;
214214

215-
syslog(LOG_INFO, "Adjust callback for overlay: %i x %i", *overlay_width, *overlay_height);
216-
syslog(LOG_INFO, "Adjust callback for stream: %i x %i", stream->width, stream->height);
217-
215+
/* Set overlay resolution in case of rotation */
218216
*overlay_width = stream->width;
219217
*overlay_height = stream->height;
218+
if (stream->rotation == 90 || stream->rotation == 270) {
219+
*overlay_width = stream->height;
220+
*overlay_height = stream->width;
221+
}
222+
223+
syslog(LOG_INFO,
224+
"Stream or rotation changed, overlay resolution is now: %i x %i",
225+
*overlay_width,
226+
*overlay_height);
227+
syslog(LOG_INFO,
228+
"Stream or rotation changed, stream resolution is now: %i x %i",
229+
stream->width,
230+
stream->height);
231+
syslog(LOG_INFO, "Stream or rotation changed, rotation angle is now: %i", stream->rotation);
220232
}
221233

222234
/**
@@ -256,29 +268,30 @@ static void render_overlay_cb(gpointer rendering_context,
256268
syslog(LOG_INFO, "Render callback for camera: %i", stream->camera);
257269
syslog(LOG_INFO, "Render callback for overlay: %i x %i", overlay_width, overlay_height);
258270
syslog(LOG_INFO, "Render callback for stream: %i x %i", stream->width, stream->height);
271+
syslog(LOG_INFO, "Render callback for rotation: %i", stream->rotation);
259272

260273
if (id == overlay_id) {
261274
// Clear background by drawing a "filled" rectangle
262275
val = index2cairo(0);
263276
cairo_set_source_rgba(rendering_context, val, val, val, val);
264277
cairo_set_operator(rendering_context, CAIRO_OPERATOR_SOURCE);
265-
cairo_rectangle(rendering_context, 0, 0, stream->width, stream->height);
278+
cairo_rectangle(rendering_context, 0, 0, overlay_width, overlay_height);
266279
cairo_fill(rendering_context);
267280

268281
// Draw a top rectangle in toggling color
269-
draw_rectangle(rendering_context, 0, 0, stream->width, stream->height / 4, top_color, 9.6);
282+
draw_rectangle(rendering_context, 0, 0, overlay_width, overlay_height / 4, top_color, 9.6);
270283

271284
// Draw a bottom rectangle in toggling color
272285
draw_rectangle(rendering_context,
273286
0,
274-
stream->height * 3 / 4,
275-
stream->width,
276-
stream->height,
287+
overlay_height * 3 / 4,
288+
overlay_width,
289+
overlay_height,
277290
bottom_color,
278291
2.0);
279292
} else if (id == overlay_id_text) {
280293
// Show text in black
281-
draw_text(rendering_context, stream->width / 2, stream->height / 2);
294+
draw_text(rendering_context, overlay_width / 2, overlay_height / 2);
282295
} else {
283296
syslog(LOG_INFO, "Unknown overlay id!");
284297
}

0 commit comments

Comments
 (0)