From patchwork Mon Mar 3 07:33:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archit Taneja X-Patchwork-Id: 22672 X-Patchwork-Delegate: kamil@wypas.org Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1WKNOe-0004sY-31; Mon, 03 Mar 2014 08:34:44 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-5) with esmtp id 1WKNOb-0005tC-8N; Mon, 03 Mar 2014 08:34:43 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753631AbaCCHeg (ORCPT + 1 other); Mon, 3 Mar 2014 02:34:36 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:51413 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751756AbaCCHef (ORCPT ); Mon, 3 Mar 2014 02:34:35 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s237YV7k016862; Mon, 3 Mar 2014 01:34:31 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s237YV2R018627; Mon, 3 Mar 2014 01:34:31 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Mon, 3 Mar 2014 01:34:30 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s237YUJh012875; Mon, 3 Mar 2014 01:34:31 -0600 Received: from localhost (a0393947pc.apr.dhcp.ti.com [172.24.145.166] (may be forged)) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id s237YSt11062; Mon, 3 Mar 2014 01:34:29 -0600 (CST) From: Archit Taneja To: CC: , , , , Archit Taneja Subject: [PATCH 7/7] v4l: ti-vpe: Add crop support in VPE driver Date: Mon, 3 Mar 2014 13:03:28 +0530 Message-ID: <1393832008-22174-8-git-send-email-archit@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1393832008-22174-1-git-send-email-archit@ti.com> References: <1393832008-22174-1-git-send-email-archit@ti.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.3.3.72115 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, MSGID_ADDED_BY_MTA 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __CT 0, __CT_TEXT_PLAIN 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SXL_SIG_ERROR_SERVFAIL , __SXL_URI_ERROR_SERVFAIL , __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' Add crop ioctl ops. For VPE, cropping only makes sense with the input to VPE, or the V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE buffer type. For the CAPTURE type, a S_CROP ioctl results in setting the crop region as the whole image itself, hence making crop dimensions same as the pix dimensions. Setting the crop successfully should result in re-configuration of those registers which are affected when either source or destination dimensions change, set_srcdst_params() is called for this purpose. Some standard crop parameter checks are done in __vpe_try_crop(). Signed-off-by: Archit Taneja --- drivers/media/platform/ti-vpe/vpe.c | 96 +++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c index 6acdcd8..c6778f4 100644 --- a/drivers/media/platform/ti-vpe/vpe.c +++ b/drivers/media/platform/ti-vpe/vpe.c @@ -1585,6 +1585,98 @@ static int vpe_s_fmt(struct file *file, void *priv, struct v4l2_format *f) return set_srcdst_params(ctx); } +static int __vpe_try_crop(struct vpe_ctx *ctx, struct v4l2_crop *cr) +{ + struct vpe_q_data *q_data; + + q_data = get_q_data(ctx, cr->type); + if (!q_data) + return -EINVAL; + + /* we don't support crop on capture plane */ + if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { + cr->c.top = cr->c.left = 0; + cr->c.width = q_data->width; + cr->c.height = q_data->height; + return 0; + } + + if (cr->c.top < 0 || cr->c.left < 0) { + vpe_err(ctx->dev, "negative values for top and left\n"); + cr->c.top = cr->c.left = 0; + } + + v4l_bound_align_image(&cr->c.width, MIN_W, q_data->width, 1, + &cr->c.height, MIN_H, q_data->height, H_ALIGN, S_ALIGN); + + /* adjust left/top if cropping rectangle is out of bounds */ + if (cr->c.left + cr->c.width > q_data->width) + cr->c.left = q_data->width - cr->c.width; + if (cr->c.top + cr->c.height > q_data->height) + cr->c.top = q_data->height - cr->c.height; + + return 0; +} + +static int vpe_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cr) +{ + struct vpe_ctx *ctx = file2ctx(file); + struct vpe_q_data *q_data; + + q_data = get_q_data(ctx, cr->type); + if (!q_data) + return -EINVAL; + + cr->bounds.left = 0; + cr->bounds.top = 0; + cr->bounds.width = q_data->width; + cr->bounds.height = q_data->height; + cr->defrect = cr->bounds; + + return 0; +} + +static int vpe_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) +{ + struct vpe_ctx *ctx = file2ctx(file); + struct vpe_q_data *q_data; + + q_data = get_q_data(ctx, cr->type); + if (!q_data) + return -EINVAL; + + cr->c = q_data->c_rect; + + return 0; +} + +static int vpe_s_crop(struct file *file, void *priv, + const struct v4l2_crop *crop) +{ + struct vpe_ctx *ctx = file2ctx(file); + struct vpe_q_data *q_data; + struct v4l2_crop cr = *crop; + int ret; + + ret = __vpe_try_crop(ctx, &cr); + if (ret) + return ret; + + q_data = get_q_data(ctx, cr.type); + + if ((q_data->c_rect.left == cr.c.left) && + (q_data->c_rect.top == cr.c.top) && + (q_data->c_rect.width == cr.c.width) && + (q_data->c_rect.height == cr.c.height)) { + vpe_dbg(ctx->dev, "requested crop values are already set\n"); + return 0; + } + + q_data->c_rect = cr.c; + + return set_srcdst_params(ctx); +} + static int vpe_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *reqbufs) { @@ -1672,6 +1764,10 @@ static const struct v4l2_ioctl_ops vpe_ioctl_ops = { .vidioc_try_fmt_vid_out_mplane = vpe_try_fmt, .vidioc_s_fmt_vid_out_mplane = vpe_s_fmt, + .vidioc_cropcap = vpe_cropcap, + .vidioc_g_crop = vpe_g_crop, + .vidioc_s_crop = vpe_s_crop, + .vidioc_reqbufs = vpe_reqbufs, .vidioc_querybuf = vpe_querybuf,