m_option: make m_rect_apply center based

This makes it easier to apply crops without need to manually calc the
offset. I wanted for it to be top-left corner based, but maybe it was
not that good idea in retrospect.

Also rename scrw/scrh, since they don't refer to screen. It was copied
form m_geometry apply.
This commit is contained in:
Kacper Michajłow 2023-08-31 22:39:04 +02:00 committed by Dudemanguy
parent b47a58516a
commit fef4481bfe
3 changed files with 7 additions and 11 deletions

View File

@ -1571,7 +1571,7 @@ Video
applied to the source video rectangle (before anamorphic stretch) by the VO.
A crop rectangle that is not within the video rectangle will be ignored.
This works with hwdec, unlike the equivalent 'lavfi-crop'. Setting the crop
to '0x0' disables it.
to '0' disables it. When offset is omitted, the central area will be cropped.
``--video-zoom=<value>``
Adjust the video display scale factor by the given value. The parameter is

View File

@ -2381,20 +2381,16 @@ const m_option_type_t m_option_type_size_box = {
.equal = geometry_equal,
};
void m_rect_apply(struct mp_rect *rc, int scrw, int scrh, struct m_geometry *gm)
void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm)
{
*rc = (struct mp_rect){0};
m_geometry_apply(&rc->x0, &rc->y0, &rc->x1, &rc->y1, scrw, scrh, gm);
*rc = (struct mp_rect){0, 0, w, h};
m_geometry_apply(&rc->x0, &rc->y0, &rc->x1, &rc->y1, w, h, gm);
if (!gm->xy_valid && gm->wh_valid && rc->x1 == 0 && rc->y1 == 0)
return;
if (!gm->xy_valid) {
rc->x0 = 0;
rc->y0 = 0;
}
if (!gm->wh_valid || rc->x1 == 0 || rc->x1 == INT_MIN)
rc->x1 = scrw - rc->x0;
rc->x1 = w - rc->x0;
if (!gm->wh_valid || rc->y1 == 0 || rc->y1 == INT_MIN)
rc->y1 = scrh - rc->y0;
rc->y1 = h - rc->y0;
rc->x1 += rc->x0;
rc->y1 += rc->y0;
}

View File

@ -105,7 +105,7 @@ struct m_geometry {
void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh,
int scrw, int scrh, struct m_geometry *gm);
void m_rect_apply(struct mp_rect *rc, int scrw, int scrh, struct m_geometry *gm);
void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm);
struct m_channels {
bool set : 1;