static int reconfig(struct vf_instance *vf, struct mp_image_params *p, int flags) { if (vf->priv->direction & 4) { if (p->w < p->h) vf->priv->direction &= 3; } if (vf->priv->direction & 4) return vf_next_reconfig(vf, p, flags); struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(p->imgfmt); int a_w = MP_ALIGN_DOWN(p->w, desc.align_x); int a_h = MP_ALIGN_DOWN(p->h, desc.align_y); vf_rescale_dsize(&p->d_w, &p->d_h, p->w, p->h, a_w, a_h); p->w = a_h; p->h = a_w; int t = p->d_w; p->d_w = p->d_h; p->d_h = t; return vf_next_reconfig(vf, p, flags); }
static int reconfig(struct vf_instance *vf, struct mp_image_params *p, int flags) { int width = p->w, height = p->h, d_width = p->d_w, d_height = p->d_h; unsigned int outfmt = p->imgfmt; unsigned int best = find_best_out(vf, outfmt); int round_w = 0, round_h = 0; struct mp_image_params input = *p; if (!best) { mp_msg(MSGT_VFILTER, MSGL_WARN, "SwScale: no supported outfmt found :(\n"); return -1; } vf->next->query_format(vf->next, best); vf->priv->w = vf->priv->cfg_w; vf->priv->h = vf->priv->cfg_h; if (vf->priv->w <= -8) { vf->priv->w += 8; round_w = 1; } if (vf->priv->h <= -8) { vf->priv->h += 8; round_h = 1; } if (vf->priv->w < -3 || vf->priv->h < -3 || (vf->priv->w < -1 && vf->priv->h < -1)) { // TODO: establish a direct connection to the user's brain // and find out what the heck he thinks MPlayer should do // with this nonsense. mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n"); return -1; } if (vf->priv->w == -1) vf->priv->w = width; if (vf->priv->w == 0) vf->priv->w = d_width; if (vf->priv->h == -1) vf->priv->h = height; if (vf->priv->h == 0) vf->priv->h = d_height; if (vf->priv->w == -3) vf->priv->w = vf->priv->h * width / height; if (vf->priv->w == -2) vf->priv->w = vf->priv->h * d_width / d_height; if (vf->priv->h == -3) vf->priv->h = vf->priv->w * height / width; if (vf->priv->h == -2) vf->priv->h = vf->priv->w * d_height / d_width; if (round_w) vf->priv->w = ((vf->priv->w + 8) / 16) * 16; if (round_h) vf->priv->h = ((vf->priv->h + 8) / 16) * 16; // check for upscaling, now that all parameters had been applied if (vf->priv->noup) { if ((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup) { vf->priv->w = width; vf->priv->h = height; } } mp_msg(MSGT_VFILTER, MSGL_DBG2, "SwScale: scaling %dx%d %s to %dx%d %s \n", width, height, vo_format_name(outfmt), vf->priv->w, vf->priv->h, vo_format_name(best)); // Compute new d_width and d_height, preserving aspect // while ensuring that both are >= output size in pixels. if (vf->priv->h * d_width > vf->priv->w * d_height) { d_width = vf->priv->h * d_width / d_height; d_height = vf->priv->h; } else { d_height = vf->priv->w * d_height / d_width; d_width = vf->priv->w; } //d_width=d_width*vf->priv->w/width; //d_height=d_height*vf->priv->h/height; p->w = vf->priv->w; p->h = vf->priv->h; p->d_w = d_width; p->d_h = d_height; p->imgfmt = best; // Second-guess what libswscale is going to output and what not. // It depends what libswscale supports for in/output, and what makes sense. struct mp_imgfmt_desc s_fmt = mp_imgfmt_get_desc(input.imgfmt); struct mp_imgfmt_desc d_fmt = mp_imgfmt_get_desc(p->imgfmt); // keep colorspace settings if the data stays in yuv if (!(s_fmt.flags & MP_IMGFLAG_YUV) || !(d_fmt.flags & MP_IMGFLAG_YUV)) { p->colorspace = MP_CSP_AUTO; p->colorlevels = MP_CSP_LEVELS_AUTO; } mp_image_params_guess_csp(p); mp_sws_set_from_cmdline(vf->priv->sws); vf->priv->sws->flags |= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT; vf->priv->sws->flags |= vf->priv->accurate_rnd * SWS_ACCURATE_RND; vf->priv->sws->src = input; vf->priv->sws->dst = *p; if (mp_sws_reinit(vf->priv->sws) < 0) { // error... mp_msg(MSGT_VFILTER, MSGL_WARN, "Couldn't init libswscale for this setup\n"); return -1; } // In particular, fix up colorspace/levels if YUV<->RGB conversion is // performed. return vf_next_reconfig(vf, p, flags); }