static int fimc_m2m_s_crop(struct file *file, void *fh, const struct v4l2_crop *crop) { struct fimc_ctx *ctx = fh_to_ctx(fh); struct fimc_dev *fimc = ctx->fimc_dev; struct v4l2_crop cr = *crop; struct fimc_frame *f; int ret; ret = fimc_m2m_try_crop(ctx, &cr); if (ret) return ret; f = (cr.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) ? &ctx->s_frame : &ctx->d_frame; /* Check to see if scaling ratio is within supported range */ if (fimc_ctx_state_is_set(FIMC_DST_FMT | FIMC_SRC_FMT, ctx)) { if (cr.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { ret = fimc_check_scaler_ratio(ctx, cr.c.width, cr.c.height, ctx->d_frame.width, ctx->d_frame.height, ctx->rotation); } else { ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width, ctx->s_frame.height, cr.c.width, cr.c.height, ctx->rotation); } if (ret) { v4l2_err(&fimc->m2m.vfd, "Out of scaler range\n"); return -EINVAL; } } f->offs_h = cr.c.left; f->offs_v = cr.c.top; f->width = cr.c.width; f->height = cr.c.height; fimc_ctx_state_set(FIMC_PARAMS, ctx); return 0; }
static int fimc_cap_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) { struct fimc_frame *f; struct fimc_ctx *ctx = file->private_data; struct fimc_dev *fimc = ctx->fimc_dev; int ret = -EINVAL; if (fimc_capture_active(fimc)) return -EBUSY; ret = fimc_try_crop(ctx, cr); if (ret) return ret; if (mutex_lock_interruptible(&fimc->lock)) return -ERESTARTSYS; if (!(ctx->state & FIMC_DST_FMT)) { v4l2_err(&fimc->vid_cap.v4l2_dev, "Capture color format not set\n"); goto sc_unlock; } f = &ctx->s_frame; /* Check for the pixel scaling ratio when cropping input image. */ ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame); if (ret) { v4l2_err(&fimc->vid_cap.v4l2_dev, "Out of the scaler range"); } else { ret = 0; f->offs_h = cr->c.left; f->offs_v = cr->c.top; f->width = cr->c.width; f->height = cr->c.height; } sc_unlock: mutex_unlock(&fimc->lock); return ret; }
static int fimc_cap_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) { struct fimc_frame *f; struct fimc_ctx *ctx = file->private_data; struct fimc_dev *fimc = ctx->fimc_dev; int ret = -EINVAL; if (fimc_capture_active(fimc)) return -EBUSY; ret = fimc_try_crop(ctx, cr); if (ret) return ret; if (!(ctx->state & FIMC_DST_FMT)) { v4l2_err(&fimc->vid_cap.v4l2_dev, "Capture color format not set\n"); return -EINVAL; /* TODO: make sure this is the right value */ } f = &ctx->s_frame; /* Check for the pixel scaling ratio when cropping input image. */ ret = fimc_check_scaler_ratio(cr->c.width, cr->c.height, ctx->d_frame.width, ctx->d_frame.height, ctx->rotation); if (ret) { v4l2_err(&fimc->vid_cap.v4l2_dev, "Out of the scaler range\n"); return ret; } f->offs_h = cr->c.left; f->offs_v = cr->c.top; f->width = cr->c.width; f->height = cr->c.height; return 0; }