From patchwork Fri Mar 1 12:52:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D910417EF for ; Fri, 1 Mar 2019 12:52:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C658E2F57E for ; Fri, 1 Mar 2019 12:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAD8F2F607; Fri, 1 Mar 2019 12:52:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A022A2F601 for ; Fri, 1 Mar 2019 12:52:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728221AbfCAMwZ (ORCPT ); Fri, 1 Mar 2019 07:52:25 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:40528 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727697AbfCAMwZ (ORCPT ); Fri, 1 Mar 2019 07:52:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DBRD7UTN1XhladlTOP+IXaVBu2F0f0sqVvhVFqagqm0=; b=NunbF/DH43IfQGjsFeTx6BAeq p1bs9T36+mIuBA+KuFAG/iK62fRvz1Le2M+sfL8crLOurRTfDlB8JczOVy08DSn++tg1D3Pw1g8Lm acHc6fh0r0shEmBzwmhxCvaIQSy0fYodDfbiaxvx56yaKITGtXaNYCrZ4T42uvvYGTOGyRc6qY7bb MB83dOLCjmcJFh5BWAZxGmqSHPySnZ0wnpadidoVQau1VzLqNJy5EqcX802e0nnGcVvrrNPIhrSch xKJnaUshBiqJ6YC78Xsh0ZueVjmH9WGBwheKAjB9EhMM4wPd4DDDaWwVfYKZhlSi717R+To8boKjA SRuvi7PhQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzheK-0001Ad-G0; Fri, 01 Mar 2019 12:52:24 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzheH-0001pv-4o; Fri, 01 Mar 2019 09:52:21 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 1/3] media: vim2m: add vertical linear scaler Date: Fri, 1 Mar 2019 09:52:18 -0300 Message-Id: <8d53fe1c2d8305dda9a360ace275c63dfacc3b1f.1551444730.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When resolutions are different, the expected behavior is to scale the image. Implement a vertical scaler as the first step. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 65 +++++++++++++++++----------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index ec177de144b6..1708becbaa9d 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -267,23 +267,17 @@ static const char *type_name(enum v4l2_buf_type type) #define CLIP(__color) \ (u8)(((__color) > 0xff) ? 0xff : (((__color) < 0) ? 0 : (__color))) -static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, +static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, struct vim2m_q_data *q_data_out, - u8 **src, u8 **dst, int ypos, bool reverse) + u8 **src, u8 **dst, bool reverse) { int depth = q_data_out->fmt->depth >> 3; - /* Only do fast copy when format and resolution are identical */ - if (q_data_in->fmt->fourcc != q_data_out->fmt->fourcc || - q_data_in->width != q_data_out->width || - q_data_in->height != q_data_out->height) - return 0; - if (!reverse) { memcpy(*dst, *src, depth << 1); *src += depth << 1; *dst += depth << 1; - return 1; + return; } /* Copy line at reverse order - YUYV format */ @@ -303,7 +297,7 @@ static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, *(*dst)++ = u; *(*dst)++ = y1; *(*dst)++ = v; - return 1; + return; } /* copy RGB formats in reverse order */ @@ -311,7 +305,7 @@ static int fast_copy_two_pixels(struct vim2m_q_data *q_data_in, memcpy(*dst + depth, *src - depth, depth); *src -= depth << 1; *dst += depth << 1; - return 1; + return; } static void copy_two_pixels(struct vim2m_q_data *q_data_in, @@ -323,11 +317,6 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, u8 _r[2], _g[2], _b[2], *r, *g, *b; int i, step; - // If format is the same just copy the data, respecting the width - if (fast_copy_two_pixels(q_data_in, q_data_out, - src, dst, ypos, reverse)) - return; - /* Step 1: read two consecutive pixels from src pointer */ r = _r; @@ -527,25 +516,25 @@ static int device_process(struct vim2m_ctx *ctx, struct vim2m_q_data *q_data_in, *q_data_out; u8 *p_in, *p, *p_out; unsigned int width, height, bytesperline, bytesperline_out; - unsigned int x, y, y_out; + unsigned int x, y, y_in, y_out; int start, end, step; struct vim2m_fmt *in, *out; q_data_in = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in = q_data_in->fmt; - width = q_data_in->width; - height = q_data_in->height; bytesperline = (q_data_in->width * q_data_in->fmt->depth) >> 3; q_data_out = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); bytesperline_out = (q_data_out->width * q_data_out->fmt->depth) >> 3; out = q_data_out->fmt; + /* As we're doing vertical scaling use the out height here */ + height = q_data_out->height; + /* Crop to the limits of the destination image */ + width = q_data_in->width; if (width > q_data_out->width) width = q_data_out->width; - if (height > q_data_out->height) - height = q_data_out->height; p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); @@ -555,17 +544,6 @@ static int device_process(struct vim2m_ctx *ctx, return -EFAULT; } - /* - * FIXME: instead of cropping the image and zeroing any - * extra data, the proper behavior is to either scale the - * data or report that scale is not supported (with depends - * on some API for such purpose). - */ - - /* Image size is different. Zero buffer first */ - if (q_data_in->width != q_data_out->width || - q_data_in->height != q_data_out->height) - memset(p_out, 0, q_data_out->sizeimage); out_vb->sequence = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE)->sequence++; in_vb->sequence = q_data_in->sequence++; @@ -581,8 +559,29 @@ static int device_process(struct vim2m_ctx *ctx, step = 1; } y_out = 0; + + /* Faster copy logic, when format and resolution are identical */ + if (q_data_in->fmt->fourcc == q_data_out->fmt->fourcc && + q_data_in->width == q_data_out->width && + q_data_in->height == q_data_out->height) { + for (y = start; y != end; y += step, y_out++) { + p = p_in + (y * bytesperline); + if (ctx->mode & MEM2MEM_HFLIP) + p += bytesperline - (q_data_in->fmt->depth >> 3); + + for (x = 0; x < width >> 1; x++) + fast_copy_two_pixels(q_data_in, q_data_out, + &p, &p_out, + ctx->mode & MEM2MEM_HFLIP); + } + return 0; + } + + /* Slower algorithm with format conversion and scaler */ for (y = start; y != end; y += step, y_out++) { - p = p_in + (y * bytesperline); + y_in = (y * q_data_in->height) / q_data_out->height; + + p = p_in + (y_in * bytesperline); if (ctx->mode & MEM2MEM_HFLIP) p += bytesperline - (q_data_in->fmt->depth >> 3); From patchwork Fri Mar 1 12:52:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6331A1515 for ; Fri, 1 Mar 2019 12:52:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 512E02F573 for ; Fri, 1 Mar 2019 12:52:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4528E2F5FE; Fri, 1 Mar 2019 12:52:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DF542F5D9 for ; Fri, 1 Mar 2019 12:52:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728212AbfCAMwZ (ORCPT ); Fri, 1 Mar 2019 07:52:25 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:40532 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728161AbfCAMwZ (ORCPT ); Fri, 1 Mar 2019 07:52:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7q+FhjWdYXA1o+3VwsL572UHQ/YkxZUbnx9oC112dvQ=; b=E9BtiHc+b9BFzgt8ljPcjxyErG mZpvZif6xI3D4N2B7qVnVw5LG/Sf5u8Qi7a3YoAR6frPJrBnkUhxw5UrWL3SPuvjp7M6BDZk3Z0Kt 6F9297nruD25rHA6sB9DNep5270rQ91wvvW3rl2sbnxhTGBKSp6uTBQD9Ihqoj5SsR1b+lOfmQr47 X9AWVnJbTBgLRWWpHo+q6BDiBhNIZeqdkbRKu0HBlMVkEYk2YqSZNAEGjwbOFHGExArdDpk4Izedc schb569vR39+zHNBYLHpguXKDeQBl99JJ9apVIP6HTjpCNWVmjq9sqO6DpJ22sOBsu8kYn+h8YHro nt9RBI9Q==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzheK-0001Ac-Ee; Fri, 01 Mar 2019 12:52:24 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzheH-0001py-5o; Fri, 01 Mar 2019 09:52:21 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 2/3] media: vim2m: don't accept YUYV anymore as output format Date: Fri, 1 Mar 2019 09:52:19 -0300 Message-Id: <906312367485f0e67e16bc4fb12c239885b61dbc.1551444730.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <8d53fe1c2d8305dda9a360ace275c63dfacc3b1f.1551444730.git.mchehab+samsung@kernel.org> References: <8d53fe1c2d8305dda9a360ace275c63dfacc3b1f.1551444730.git.mchehab+samsung@kernel.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Handling any Y,Cr,Cb formats require some extra logic, as it handles a group of two pixels. That's easy while we don't do horizontal scaling. However, doing horizontal scaling with such formats would require a lot more code, in order to avoid distortions, as, if it scales to two non-consecutive points, the logic would need to read 4 points in order to properly convert to RGB. As this is just a test driver, and we want fast algorithms, let's just get rid of this format as an output one. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 57 ++-------------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index 1708becbaa9d..a0e52eb205e3 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -113,7 +113,7 @@ static struct vim2m_fmt formats[] = { }, { .fourcc = V4L2_PIX_FMT_YUYV, .depth = 16, - .types = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT, + .types = MEM2MEM_CAPTURE, }, { .fourcc = V4L2_PIX_FMT_SBGGR8, .depth = 8, @@ -280,26 +280,6 @@ static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, return; } - /* Copy line at reverse order - YUYV format */ - if (q_data_in->fmt->fourcc == V4L2_PIX_FMT_YUYV) { - int u, v, y, y1; - - *src -= 2; - - y1 = (*src)[0]; /* copy as second point */ - u = (*src)[1]; - y = (*src)[2]; /* copy as first point */ - v = (*src)[3]; - - *src -= 2; - - *(*dst)++ = y; - *(*dst)++ = u; - *(*dst)++ = y1; - *(*dst)++ = v; - return; - } - /* copy RGB formats in reverse order */ memcpy(*dst, *src, depth); memcpy(*dst + depth, *src - depth, depth); @@ -352,6 +332,7 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, *src += step << 1; } break; + default: case V4L2_PIX_FMT_RGB24: for (i = 0; i < 2; i++) { *r++ = (*src)[0]; @@ -370,40 +351,6 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, *src += step * 3; } break; - default: /* V4L2_PIX_FMT_YUYV */ - { - int u, v, y, y1, u1, v1, tmp; - - if (reverse) { - *src -= 2; - - y1 = (*src)[0]; /* copy as second point */ - u = (*src)[1]; - y = (*src)[2]; /* copy as first point */ - v = (*src)[3]; - - *src -= 2; - } else { - y = *(*src)++; - u = *(*src)++; - y1 = *(*src)++; - v = *(*src)++; - } - - u1 = (((u - 128) << 7) + (u - 128)) >> 6; - tmp = (((u - 128) << 1) + (u - 128) + - ((v - 128) << 2) + ((v - 128) << 1)) >> 3; - v1 = (((v - 128) << 1) + (v - 128)) >> 1; - - *r++ = CLIP(y + v1); - *g++ = CLIP(y - tmp); - *b++ = CLIP(y + u1); - - *r = CLIP(y1 + v1); - *g = CLIP(y1 - tmp); - *b = CLIP(y1 + u1); - break; - } } /* Step 2: store two consecutive points, reversing them if needed */ From patchwork Fri Mar 1 12:52:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10835199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 860191515 for ; Fri, 1 Mar 2019 12:52:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 718632F4C3 for ; Fri, 1 Mar 2019 12:52:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65E372F619; Fri, 1 Mar 2019 12:52:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5ED22F4C3 for ; Fri, 1 Mar 2019 12:52:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728300AbfCAMw0 (ORCPT ); Fri, 1 Mar 2019 07:52:26 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:40524 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727920AbfCAMwZ (ORCPT ); Fri, 1 Mar 2019 07:52:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZQL9nvcw/a6aK+gKT6rbweNSeFBeJyzcGcYPj7/uASk=; b=C8i2SH2xonyzVFuYE6LyKJTXbU otexaGJuXyMAWpdcGcWFrsqp5+4c7eVewoV/vsy0flMJXix4V4UI1wX6eomY9PA3WHyTmOt9X7cK2 OawWpfQIU5t85JrDAoh8pOoNMCFDFE+xVVctdkehpziciCj3Xb/r+oasr1ECdYrEW6klafZ20EBmI icesyhSZ6yRipl0E3q81wJwQq0W8Kx8Qale9H4+B2iC8yUyHy9BMLfj7y9/fZ3QVtNTO7KLOibNZ0 pituAsc7ivhdVy4FuVf3CmwizG3W9KNjq++PXMQLJLIQ64SpGgMUbcKnm9fe2P6gRv052zHmzk99p XbL9dEhQ==; Received: from 177.41.113.159.dynamic.adsl.gvt.net.br ([177.41.113.159] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzheK-0001Ae-Ek; Fri, 01 Mar 2019 12:52:24 +0000 Received: from mchehab by bombadil.infradead.org with local (Exim 4.92) (envelope-from ) id 1gzheH-0001q2-6d; Fri, 01 Mar 2019 09:52:21 -0300 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Hans Verkuil , Ezequiel Garcia Subject: [PATCH 3/3] media: vim2m: add an horizontal scaler Date: Fri, 1 Mar 2019 09:52:20 -0300 Message-Id: <4f7af5730361937a48557822050005d707a3762c.1551444730.git.mchehab+samsung@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <8d53fe1c2d8305dda9a360ace275c63dfacc3b1f.1551444730.git.mchehab+samsung@kernel.org> References: <8d53fe1c2d8305dda9a360ace275c63dfacc3b1f.1551444730.git.mchehab+samsung@kernel.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an horizontal linear scaler using Breseham algorithm in order to speep up its calculus. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/vim2m.c | 95 ++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c index a0e52eb205e3..6bcc0c9f9910 100644 --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -290,12 +290,12 @@ static void fast_copy_two_pixels(struct vim2m_q_data *q_data_in, static void copy_two_pixels(struct vim2m_q_data *q_data_in, struct vim2m_q_data *q_data_out, - u8 **src, u8 **dst, int ypos, bool reverse) + u8 *src[2], u8 **dst, int ypos, bool reverse) { struct vim2m_fmt *out = q_data_out->fmt; struct vim2m_fmt *in = q_data_in->fmt; u8 _r[2], _g[2], _b[2], *r, *g, *b; - int i, step; + int i; /* Step 1: read two consecutive pixels from src pointer */ @@ -303,52 +303,39 @@ static void copy_two_pixels(struct vim2m_q_data *q_data_in, g = _g; b = _b; - if (reverse) - step = -1; - else - step = 1; - switch (in->fourcc) { case V4L2_PIX_FMT_RGB565: /* rrrrrggg gggbbbbb */ for (i = 0; i < 2; i++) { - u16 pix = *(u16 *)*src; + u16 pix = *(u16 *)(src[i]); *r++ = (u8)(((pix & 0xf800) >> 11) << 3) | 0x07; *g++ = (u8)((((pix & 0x07e0) >> 5)) << 2) | 0x03; *b++ = (u8)((pix & 0x1f) << 3) | 0x07; - - *src += step << 1; } break; case V4L2_PIX_FMT_RGB565X: /* gggbbbbb rrrrrggg */ for (i = 0; i < 2; i++) { - u16 pix = *(u16 *)*src; + u16 pix = *(u16 *)(src[i]); *r++ = (u8)(((0x00f8 & pix) >> 3) << 3) | 0x07; *g++ = (u8)(((pix & 0x7) << 2) | ((pix & 0xe000) >> 5)) | 0x03; *b++ = (u8)(((pix & 0x1f00) >> 8) << 3) | 0x07; - - *src += step << 1; } break; default: case V4L2_PIX_FMT_RGB24: for (i = 0; i < 2; i++) { - *r++ = (*src)[0]; - *g++ = (*src)[1]; - *b++ = (*src)[2]; - - *src += step * 3; + *r++ = src[i][0]; + *g++ = src[i][1]; + *b++ = src[i][2]; } break; case V4L2_PIX_FMT_BGR24: for (i = 0; i < 2; i++) { - *b++ = (*src)[0]; - *g++ = (*src)[1]; - *r++ = (*src)[2]; - - *src += step * 3; + *b++ = src[i][0]; + *g++ = src[i][1]; + *r++ = src[i][2]; } break; } @@ -461,27 +448,24 @@ static int device_process(struct vim2m_ctx *ctx, { struct vim2m_dev *dev = ctx->dev; struct vim2m_q_data *q_data_in, *q_data_out; - u8 *p_in, *p, *p_out; - unsigned int width, height, bytesperline, bytesperline_out; - unsigned int x, y, y_in, y_out; + u8 *p_in, *p_line, *p_in_x[2], *p, *p_out; + unsigned int width, height, bytesperline, bytesperline_out, bytes_per_pixel; + unsigned int x, y, y_in, y_out, x_int, x_fract, x_err, x_offset; int start, end, step; struct vim2m_fmt *in, *out; q_data_in = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); in = q_data_in->fmt; bytesperline = (q_data_in->width * q_data_in->fmt->depth) >> 3; + bytes_per_pixel = q_data_in->fmt->depth >> 3; q_data_out = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); bytesperline_out = (q_data_out->width * q_data_out->fmt->depth) >> 3; out = q_data_out->fmt; - /* As we're doing vertical scaling use the out height here */ + /* As we're doing scaling, use the output dimensions here */ height = q_data_out->height; - - /* Crop to the limits of the destination image */ - width = q_data_in->width; - if (width > q_data_out->width) - width = q_data_out->width; + width = q_data_out->width; p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); @@ -525,21 +509,52 @@ static int device_process(struct vim2m_ctx *ctx, } /* Slower algorithm with format conversion and scaler */ + + /* To speed scaler up, use Bresenham for X dimension */ + x_int = q_data_in->width / q_data_out->width; + x_fract = q_data_in->width % q_data_out->width; + for (y = start; y != end; y += step, y_out++) { y_in = (y * q_data_in->height) / q_data_out->height; + x_offset = 0; + x_err = 0; - p = p_in + (y_in * bytesperline); + p_line = p_in + (y_in * bytesperline); if (ctx->mode & MEM2MEM_HFLIP) - p += bytesperline - (q_data_in->fmt->depth >> 3); + p_line += bytesperline - (q_data_in->fmt->depth >> 3); + p_in_x[0] = p_line; - for (x = 0; x < width >> 1; x++) - copy_two_pixels(q_data_in, q_data_out, &p, &p_out, y_out, + for (x = 0; x < width >> 1; x++) { + x_offset += x_int; + x_err += x_fract; + if (x_err > width) { + x_offset++; + x_err -= width; + } + + if (ctx->mode & MEM2MEM_HFLIP) + p_in_x[1] = p_line - x_offset * bytes_per_pixel; + else + p_in_x[1] = p_line + x_offset * bytes_per_pixel; + + copy_two_pixels(q_data_in, q_data_out, + p_in_x, &p_out, y_out, ctx->mode & MEM2MEM_HFLIP); - /* Go to the next line at the out buffer */ - if (width < q_data_out->width) - p_out += ((q_data_out->width - width) - * q_data_out->fmt->depth) >> 3; + /* Calculate the next p_in_x0 */ + x_offset += x_int; + x_err += x_fract; + if (x_err > width) { + x_offset++; + x_err -= width; + } + + if (ctx->mode & MEM2MEM_HFLIP) + p_in_x[0] = p_line - x_offset * bytes_per_pixel; + else + p_in_x[0] = p_line + x_offset * bytes_per_pixel; + } + } return 0;