Skip to content

Commit b2dbbb7

Browse files
committed
testcamera: rotate acquired images as appropriate.
1 parent 4fb6224 commit b2dbbb7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/testcamera.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,17 @@ SDL_AppResult SDL_AppIterate(void *appstate)
360360
texture_updated = true;
361361
}
362362

363+
// the image might be coming from a mobile device that provides images in only one orientation, but the
364+
// device might be rotated to a different one (like an iPhone providing portrait images even if you hold
365+
// the phone in landscape mode). The rotation is how far to rotate the image clockwise to put it right-side
366+
// up, for how the user would expect it to be for how they are holding the device.
367+
const int rotation = (int) SDL_GetNumberProperty(SDL_GetSurfaceProperties(frame_current), SDL_PROP_SURFACE_ROTATION_NUMBER, 0);
363368
SDL_GetRenderOutputSize(renderer, &win_w, &win_h);
364369
d.x = ((win_w - texture->w) / 2.0f);
365370
d.y = ((win_h - texture->h) / 2.0f);
366371
d.w = (float)texture->w;
367372
d.h = (float)texture->h;
368-
SDL_RenderTexture(renderer, texture, NULL, &d);
373+
SDL_RenderTextureRotated(renderer, texture, NULL, &d, rotation, NULL, SDL_FLIP_NONE);
369374
}
370375

371376
/* !!! FIXME: Render a "flip" icon if front_camera and back_camera are both != 0. */

0 commit comments

Comments
 (0)