int gsc_set_scaler_info(struct gsc_ctx *ctx) { struct gsc_scaler *sc = &ctx->scaler; struct gsc_frame *s_frame = &ctx->s_frame; struct gsc_frame *d_frame = &ctx->d_frame; struct gsc_variant *variant = ctx->gsc_dev->variant; int tx, ty; int ret; ret = gsc_check_scaler_ratio(variant, s_frame->crop.width, s_frame->crop.height, d_frame->crop.width, d_frame->crop.height, ctx->gsc_ctrls.rotate->val, ctx->out_path); if (ret) { gsc_err("out of scaler range"); return ret; } if (ctx->gsc_ctrls.rotate->val == 90 || ctx->gsc_ctrls.rotate->val == 270) { ty = d_frame->crop.width; tx = d_frame->crop.height; } else { tx = d_frame->crop.width; ty = d_frame->crop.height; } ret = gsc_cal_prescaler_ratio(variant, s_frame->crop.width, tx, &sc->pre_hratio); if (ret) { gsc_err("Horizontal scale ratio is out of range"); return ret; } ret = gsc_cal_prescaler_ratio(variant, s_frame->crop.height, ty, &sc->pre_vratio); if (ret) { gsc_err("Vertical scale ratio is out of range"); return ret; } gsc_check_src_scale_info(variant, s_frame, &sc->pre_hratio, tx, ty, &sc->pre_vratio); gsc_get_prescaler_shfactor(sc->pre_hratio, sc->pre_vratio, &sc->pre_shfactor); sc->main_hratio = (s_frame->crop.width << 16) / tx; sc->main_vratio = (s_frame->crop.height << 16) / ty; gsc_dbg("scaler input/output size : sx = %d, sy = %d, tx = %d, ty = %d", s_frame->crop.width, s_frame->crop.height, tx, ty); gsc_dbg("scaler ratio info : pre_shfactor : %d, pre_h : %d, pre_v :%d,\ main_h : %ld, main_v : %ld", sc->pre_shfactor, sc->pre_hratio, sc->pre_vratio, sc->main_hratio, sc->main_vratio); return 0; }
static int gsc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) { struct gsc_ctx *ctx = fh_to_ctx(fh); struct gsc_variant *variant = ctx->gsc_dev->variant; struct gsc_frame *f; int ret; ret = gsc_try_crop(ctx, cr); if (ret) return ret; f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ? &ctx->s_frame : &ctx->d_frame; /* Default is input rotator */ ctx->scaler.is_scaled_down = false; /* Check to see if scaling ratio is within supported range */ if (gsc_ctx_state_is_set(GSC_DST_FMT | GSC_SRC_FMT, ctx)) { if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { ret = gsc_check_scaler_ratio(ctx, variant, cr->c.width, cr->c.height, ctx->d_frame.crop.width,ctx->d_frame.crop.height, ctx->gsc_ctrls.rotate->val, ctx->out_path); } else { ret = gsc_check_scaler_ratio(ctx, variant, ctx->s_frame.crop.width, ctx->s_frame.crop.height, cr->c.width, cr->c.height, ctx->gsc_ctrls.rotate->val, ctx->out_path); } if (ret) { gsc_err("Out of scaler range"); return -EINVAL; } } f->crop.left = cr->c.left; f->crop.top = cr->c.top; f->crop.width = cr->c.width; f->crop.height = cr->c.height; gsc_ctx_state_lock_set(GSC_PARAMS, ctx); return 0; }
static int __gsc_s_ctrl(struct gsc_ctx *ctx, struct v4l2_ctrl *ctrl) { struct gsc_dev *gsc = ctx->gsc_dev; struct gsc_variant *variant = gsc->variant; unsigned int flags = GSC_DST_FMT | GSC_SRC_FMT; int ret = 0; if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) return 0; switch (ctrl->id) { case V4L2_CID_HFLIP: ctx->hflip = ctrl->val; break; case V4L2_CID_VFLIP: ctx->vflip = ctrl->val; break; case V4L2_CID_ROTATE: if ((ctx->state & flags) == flags) { ret = gsc_check_scaler_ratio(variant, ctx->s_frame.crop.width, ctx->s_frame.crop.height, ctx->d_frame.crop.width, ctx->d_frame.crop.height, ctx->gsc_ctrls.rotate->val, ctx->out_path); if (ret) return -EINVAL; } ctx->rotation = ctrl->val; break; case V4L2_CID_ALPHA_COMPONENT: ctx->d_frame.alpha = ctrl->val; break; } ctx->state |= GSC_PARAMS; return 0; }
static int gsc_m2m_s_selection(struct file *file, void *fh, struct v4l2_selection *s) { struct gsc_frame *frame; struct gsc_ctx *ctx = fh_to_ctx(fh); struct gsc_variant *variant = ctx->gsc_dev->variant; struct v4l2_selection sel = *s; int ret; if ((s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)) return -EINVAL; ret = gsc_try_selection(ctx, &sel); if (ret) return ret; if (s->flags & V4L2_SEL_FLAG_LE && !is_rectangle_enclosed(&sel.r, &s->r)) return -ERANGE; if (s->flags & V4L2_SEL_FLAG_GE && !is_rectangle_enclosed(&s->r, &sel.r)) return -ERANGE; s->r = sel.r; switch (s->target) { case V4L2_SEL_TGT_COMPOSE_BOUNDS: case V4L2_SEL_TGT_COMPOSE_DEFAULT: case V4L2_SEL_TGT_COMPOSE: frame = &ctx->s_frame; break; case V4L2_SEL_TGT_CROP_BOUNDS: case V4L2_SEL_TGT_CROP: case V4L2_SEL_TGT_CROP_DEFAULT: frame = &ctx->d_frame; break; default: return -EINVAL; } /* Check to see if scaling ratio is within supported range */ if (gsc_ctx_state_is_set(GSC_DST_FMT | GSC_SRC_FMT, ctx)) { if (s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { ret = gsc_check_scaler_ratio(variant, sel.r.width, sel.r.height, ctx->d_frame.crop.width, ctx->d_frame.crop.height, ctx->gsc_ctrls.rotate->val, ctx->out_path); } else { ret = gsc_check_scaler_ratio(variant, ctx->s_frame.crop.width, ctx->s_frame.crop.height, sel.r.width, sel.r.height, ctx->gsc_ctrls.rotate->val, ctx->out_path); } if (ret) { pr_err("Out of scaler range"); return -EINVAL; } } frame->crop = sel.r; gsc_ctx_state_lock_set(GSC_PARAMS, ctx); return 0; }