Skip to content

Commit 334d36e

Browse files
committed
surface: Surface rotation property should be float, not int.
Adjusted camera internals to work in floats, too. Reference Issue #14616.
1 parent 7773157 commit 334d36e

File tree

13 files changed

+23
-23
lines changed

13 files changed

+23
-23
lines changed

WhatsNew.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ General:
3737
* Added SDL_FLIP_HORIZONTAL_AND_VERTICAL to flip a surface both horizontally and vertically
3838
* Added SDL_LoadPNG(), SDL_LoadPNG_IO(), SDL_SavePNG(), and SDL_SavePNG_IO() to load and save PNG images
3939
* Added SDL_LoadSurface() and SDL_LoadSurface_IO() to detect BMP and PNG formats and load them as surfaces
40-
* Added SDL_PROP_SURFACE_ROTATION_NUMBER to indicate the rotation needed to display camera images upright
40+
* Added SDL_PROP_SURFACE_ROTATION_FLOAT to indicate the rotation needed to display camera images upright
4141
* Added SDL_RotateSurface() to create a rotated copy of a surface
4242
* SDL_EVENT_WINDOW_EXPOSED now sets data1 to true if it is sent during live resizing
4343
* Added SDL_EVENT_DISPLAY_USABLE_BOUNDS_CHANGED, which is sent when the usable desktop bounds change

include/SDL3/SDL_surface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
241241
* left edge of the image, if this surface is being used as a cursor.
242242
* - `SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`: the hotspot pixel offset from the
243243
* top edge of the image, if this surface is being used as a cursor.
244-
* - `SDL_PROP_SURFACE_ROTATION_NUMBER`: the number of degrees a surface's
244+
* - `SDL_PROP_SURFACE_ROTATION_FLOAT`: the number of degrees a surface's
245245
* data is meant to be rotated clockwise to make the image right-side up.
246246
* Default 0. This is used by the camera API, if a mobile device is oriented
247247
* differently than what its camera provides (i.e. - the camera always
@@ -263,7 +263,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surfac
263263
#define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING "SDL.surface.tonemap"
264264
#define SDL_PROP_SURFACE_HOTSPOT_X_NUMBER "SDL.surface.hotspot.x"
265265
#define SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER "SDL.surface.hotspot.y"
266-
#define SDL_PROP_SURFACE_ROTATION_NUMBER "SDL.surface.rotation"
266+
#define SDL_PROP_SURFACE_ROTATION_FLOAT "SDL.surface.rotation"
267267

268268
/**
269269
* Set the colorspace used by a surface.

src/camera/SDL_camera.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static size_t GetFrameBufLen(const SDL_CameraSpec *spec)
150150
return wxh * SDL_BYTESPERPIXEL(fmt);
151151
}
152152

153-
static SDL_CameraFrameResult ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
153+
static SDL_CameraFrameResult ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
154154
{
155155
const SDL_CameraSpec *spec = &device->actual_spec;
156156

@@ -832,7 +832,7 @@ bool SDL_CameraThreadIterate(SDL_Camera *device)
832832
SDL_Surface *output_surface = NULL;
833833
SurfaceList *slist = NULL;
834834
Uint64 timestampNS = 0;
835-
int rotation = 0;
835+
float rotation = 0.0f;
836836

837837
// AcquireFrame SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice instead!
838838
const SDL_CameraFrameResult rc = device->AcquireFrame(device, device->acquire_surface, &timestampNS, &rotation);
@@ -929,7 +929,7 @@ bool SDL_CameraThreadIterate(SDL_Camera *device)
929929
acquired->pixels = NULL;
930930
acquired->pitch = 0;
931931

932-
SDL_SetNumberProperty(SDL_GetSurfaceProperties(output_surface), SDL_PROP_SURFACE_ROTATION_NUMBER, rotation);
932+
SDL_SetFloatProperty(SDL_GetSurfaceProperties(output_surface), SDL_PROP_SURFACE_ROTATION_FLOAT, rotation);
933933

934934
// make the filled output surface available to the app.
935935
SDL_LockMutex(device->lock);

src/camera/SDL_syscamera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct SDL_Camera
9999

100100
// These are, initially, set from camera_driver, but we might swap them out with Zombie versions on disconnect/failure.
101101
bool (*WaitDevice)(SDL_Camera *device);
102-
SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation);
102+
SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation);
103103
void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame);
104104

105105
// All supported formats/dimensions for this device.
@@ -178,7 +178,7 @@ typedef struct SDL_CameraDriverImpl
178178
bool (*OpenDevice)(SDL_Camera *device, const SDL_CameraSpec *spec);
179179
void (*CloseDevice)(SDL_Camera *device);
180180
bool (*WaitDevice)(SDL_Camera *device);
181-
SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation); // set frame->pixels, frame->pitch, *timestampNS, and *rotation!
181+
SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation); // set frame->pixels, frame->pitch, *timestampNS, and *rotation!
182182
void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame); // Reclaim frame->pixels and frame->pitch!
183183
void (*FreeDeviceHandle)(SDL_Camera *device); // SDL is done with this device; free the handle from SDL_AddCamera()
184184
void (*Deinitialize)(void);

src/camera/android/SDL_camera_android.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static bool ANDROIDCAMERA_WaitDevice(SDL_Camera *device)
296296
return true; // this isn't used atm, since we run our own thread via onImageAvailable callbacks.
297297
}
298298

299-
static SDL_CameraFrameResult ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
299+
static SDL_CameraFrameResult ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
300300
{
301301
SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY;
302302
media_status_t res;
@@ -380,7 +380,7 @@ static SDL_CameraFrameResult ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_
380380
dev_rotation = -dev_rotation; // we want to subtract this value, instead of add, if back-facing.
381381
}
382382

383-
*rotation = dev_rotation + device->hidden->rotation; // current phone orientation, static camera orientation in relation to phone.
383+
*rotation = (float) (dev_rotation + device->hidden->rotation); // current phone orientation, static camera orientation in relation to phone.
384384

385385
return result;
386386
}

src/camera/coremedia/SDL_camera_coremedia.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static bool COREMEDIA_WaitDevice(SDL_Camera *device)
157157
return true; // this isn't used atm, since we run our own thread out of Grand Central Dispatch.
158158
}
159159

160-
static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
160+
static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
161161
{
162162
SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY;
163163
SDLPrivateCameraData *hidden = (__bridge SDLPrivateCameraData *) device->hidden;
@@ -243,21 +243,21 @@ static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surf
243243
// there is probably math for this, but this is easy to slap into a table.
244244
// rotation = rotations[uiorientation-1][devorientation-1];
245245
if (device->position == SDL_CAMERA_POSITION_BACK_FACING) {
246-
static const int back_rotations[4][4] = {
246+
static const Uint16 back_rotations[4][4] = {
247247
{ 90, 90, 90, 90 }, // ui portrait
248248
{ 270, 270, 270, 270 }, // ui portait upside down
249249
{ 0, 0, 0, 0 }, // ui landscape left
250250
{ 180, 180, 180, 180 } // ui landscape right
251251
};
252-
*rotation = back_rotations[ui_orientation - 1][device_orientation - 1];
252+
*rotation = (float) back_rotations[ui_orientation - 1][device_orientation - 1];
253253
} else {
254-
static const int front_rotations[4][4] = {
254+
static const Uint16 front_rotations[4][4] = {
255255
{ 90, 90, 270, 270 }, // ui portrait
256256
{ 270, 270, 90, 90 }, // ui portait upside down
257257
{ 0, 0, 180, 180 }, // ui landscape left
258258
{ 180, 180, 0, 0 } // ui landscape right
259259
};
260-
*rotation = front_rotations[ui_orientation - 1][device_orientation - 1];
260+
*rotation = (float) front_rotations[ui_orientation - 1][device_orientation - 1];
261261
}
262262
#endif
263263

src/camera/dummy/SDL_camera_dummy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static bool DUMMYCAMERA_WaitDevice(SDL_Camera *device)
3838
return SDL_Unsupported();
3939
}
4040

41-
static SDL_CameraFrameResult DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
41+
static SDL_CameraFrameResult DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
4242
{
4343
SDL_Unsupported();
4444
return SDL_CAMERA_FRAME_ERROR;

src/camera/emscripten/SDL_camera_emscripten.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static bool EMSCRIPTENCAMERA_WaitDevice(SDL_Camera *device)
3939
return false;
4040
}
4141

42-
static SDL_CameraFrameResult EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
42+
static SDL_CameraFrameResult EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
4343
{
4444
void *rgba = SDL_malloc(device->actual_spec.width * device->actual_spec.height * 4);
4545
if (!rgba) {

src/camera/mediafoundation/SDL_camera_mediafoundation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ static void SDLCALL CleanupIMFMediaBuffer(void *userdata, void *value)
430430
SDL_free(objs);
431431
}
432432

433-
static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
433+
static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
434434
{
435435
SDL_assert(device->hidden->current_sample != NULL);
436436

@@ -562,7 +562,7 @@ static SDL_CameraFrameResult MEDIAFOUNDATION_CopyFrame(SDL_Surface *frame, const
562562
return SDL_CAMERA_FRAME_READY;
563563
}
564564

565-
static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
565+
static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
566566
{
567567
SDL_assert(device->hidden->current_sample != NULL);
568568

src/camera/pipewire/SDL_camera_pipewire.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static bool PIPEWIRECAMERA_WaitDevice(SDL_Camera *device)
577577
return true;
578578
}
579579

580-
static SDL_CameraFrameResult PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, int *rotation)
580+
static SDL_CameraFrameResult PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS, float *rotation)
581581
{
582582
struct pw_buffer *b;
583583

0 commit comments

Comments
 (0)