Refactor and optimize --scale and --rotation-offset

pull/4658/head
Willy A. Kuster 4 months ago
parent de7d21d369
commit 16f93ac5fd

@ -845,28 +845,30 @@ static const struct sc_option options[] = {
.longopt_id = OPT_ROTATION_OFFSET,
.longopt = "rotation-offset",
.argdesc = "value",
.text = "Set the initial display rotation offset.\n"
.text = "Set the display rotation offset in degrees.\n"
"Positive values rotate clockwise, negative values "
"rotate counter-clockwise.\n"
"Default is 0 (automatic).",
},
{
.longopt_id = OPT_SCALE,
.longopt = "scale",
.argdesc = "value",
.text = "Set the initial display scale.\n"
.text = "Set the display scale in integer percentage.\n"
"Default is 100 (automatic).",
},
{
.longopt_id = OPT_POSITION_X_OFFSET,
.longopt = "position-x-offset",
.argdesc = "value",
.text = "Set the initial display horizontal position offset.\n"
.text = "Set the display horizontal position offset.\n"
"Default is 0 (automatic).",
},
{
.longopt_id = OPT_POSITION_Y_OFFSET,
.longopt = "position-y-offset",
.argdesc = "value",
.text = "Set the initial display vertical position offset.\n"
.text = "Set the display vertical position offset.\n"
"Default is 0 (automatic).",
},
};

@ -262,8 +262,8 @@ sc_display_render(struct sc_display *display, const SDL_Rect *geometry,
rect.y = geometry->y + transform_offsets->position.y;
if (transform_offsets->scale != 100) {
rect.w = (int)(geometry->w * (float32_t)transform_offsets->scale / 100);
rect.h = (int)(geometry->h * (float32_t)transform_offsets->scale / 100);
rect.w = geometry->w * transform_offsets->scale / 100;
rect.h = geometry->h * transform_offsets->scale / 100;
} else {
rect.w = geometry->w;
rect.h = geometry->h;

@ -850,7 +850,8 @@ static void
sc_rotate_point(struct sc_point *point,
struct sc_point *pivot,
int16_t angle_in_degrees) {
float32_t angle_in_radians = (float32_t)angle_in_degrees * M_PI / 180.0;
const double deg_to_rad = M_PI / 180.0;
float32_t angle_in_radians = (float32_t)angle_in_degrees * deg_to_rad;
float32_t cosine = (float32_t)cos(angle_in_radians);
float32_t sine = (float32_t)sin(angle_in_radians);
@ -870,20 +871,20 @@ sc_screen_convert_drawable_to_frame_coords(struct sc_screen *screen,
int32_t w = screen->content_size.width;
int32_t h = screen->content_size.height;
int32_t w_half = (int32_t) w * 0.5;
int32_t h_half = (int32_t) h * 0.5;
int32_t w_half = w >> 1;
int32_t h_half = h >> 1;
struct sc_point pivot = {
.x = w_half,
.y = h_half,
};
int8_t flip_factor = -1;
float32_t scale_factor = 100 / (float32_t)screen->transform_offsets.scale;
float32_t scale_factor = 100.0 / screen->transform_offsets.scale;
// screen->rect must be initialized to avoid a division by zero
assert(screen->rect.w && screen->rect.h);
float32_t w_factor = (float32_t)w / screen->rect.w;
float32_t h_factor = (float32_t)h / screen->rect.h;
float32_t w_factor = w / (float32_t)screen->rect.w;
float32_t h_factor = h / (float32_t)screen->rect.h;
x = (int64_t) (x - screen->rect.x) * w_factor;
y = (int64_t) (y - screen->rect.y) * h_factor;
int32_t x_offset = screen->transform_offsets.position.x * w_factor;

@ -143,7 +143,8 @@ values are allowed when recording.
## Rotation offset
Rotation offset to be applied (positive values will rotate clockwise):
Rotation offset in degrees to be applied (positive values rotate clockwise,
negative values rotate counter-clockwise):
```bash
scrcpy --rotation-offset=45
@ -152,18 +153,23 @@ scrcpy --rotation-offset=45
This is useful for Meta Quest 3 tilted screen setup:
```bash
scrcpy --crop=2064:2208:0:0 --rotation-offset=21
scrcpy --crop=2064:2208:0:0 --rotation-offset=22
```
This is not supported when recording.
## Scale
Scale to be applied (default is 100):
Scale in integer percentage to be applied (default is 100):
```bash
scrcpy --scale=150 # 150% scale
```
This is not supported when recording.
## Position offset
Position offset to be applied both horizontally and/or vertically
@ -174,6 +180,9 @@ scrcpy --position-x-offset=150
scrcpy --position-y-offset=150
```
This is not supported when recording.
## Crop
The device screen may be cropped to mirror only part of the screen.

Loading…
Cancel
Save