mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] v4l: mem2mem_testdev: Add horizontal and vertical flip.
@ 2012-06-10 19:18 Tomasz Moń
  2012-06-12  7:01 ` Marek Szyprowski
  0 siblings, 1 reply; 2+ messages in thread
From: Tomasz Moń @ 2012-06-10 19:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Guennadi Liakhovetski, Hans Verkuil,
	Marek Szyprowski, Hans de Goede, linux-media
  Cc: linux-kernel, Tomasz Moń


Signed-off-by: Tomasz Moń <desowin@gmail.com>
---
 drivers/media/video/mem2mem_testdev.c |  135 ++++++++++++++++++++++++++++++---
 1 file changed, 124 insertions(+), 11 deletions(-)

diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
index d2dec58..e1b66e9 100644
--- a/drivers/media/video/mem2mem_testdev.c
+++ b/drivers/media/video/mem2mem_testdev.c
@@ -60,6 +60,10 @@ MODULE_VERSION("0.1.1");
 #define MEM2MEM_COLOR_STEP	(0xff >> 4)
 #define MEM2MEM_NUM_TILES	8
 
+/* Flags that indicate processing mode */
+#define MEM2MEM_HFLIP	(1 << 0)
+#define MEM2MEM_VFLIP	(1 << 1)
+
 #define dprintk(dev, fmt, arg...) \
 	v4l2_dbg(1, 1, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
 
@@ -131,6 +135,24 @@ static struct m2mtest_q_data *get_q_data(enum v4l2_buf_type type)
 
 static struct v4l2_queryctrl m2mtest_ctrls[] = {
 	{
+		.id		= V4L2_CID_HFLIP,
+		.type		= V4L2_CTRL_TYPE_BOOLEAN,
+		.name		= "Mirror",
+		.minimum	= 0,
+		.maximum	= 1,
+		.step		= 1,
+		.default_value	= 0,
+		.flags		= 0,
+	}, {
+		.id		= V4L2_CID_VFLIP,
+		.type		= V4L2_CTRL_TYPE_BOOLEAN,
+		.name		= "Vertical Mirror",
+		.minimum	= 0,
+		.maximum	= 1,
+		.step		= 1,
+		.default_value	= 0,
+		.flags		= 0,
+	}, {
 		.id		= V4L2_CID_TRANS_TIME_MSEC,
 		.type		= V4L2_CTRL_TYPE_INTEGER,
 		.name		= "Transaction time (msec)",
@@ -197,6 +219,9 @@ struct m2mtest_ctx {
 	/* Abort requested by m2m */
 	int			aborting;
 
+	/* Processing mode */
+	int			mode;
+
 	struct v4l2_m2m_ctx	*m2m_ctx;
 };
 
@@ -247,19 +272,84 @@ static int device_process(struct m2mtest_ctx *ctx,
 	bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES;
 	w = 0;
 
-	for (y = 0; y < height; ++y) {
-		for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
-			if (w & 0x1) {
-				for (x = 0; x < tile_w; ++x)
-					*p_out++ = *p_in++ + MEM2MEM_COLOR_STEP;
-			} else {
-				for (x = 0; x < tile_w; ++x)
-					*p_out++ = *p_in++ - MEM2MEM_COLOR_STEP;
+	switch (ctx->mode) {
+	case MEM2MEM_HFLIP | MEM2MEM_VFLIP:
+		p_out += bytesperline * height - bytes_left;
+		for (y = 0; y < height; ++y) {
+			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
+				if (w & 0x1) {
+					for (x = 0; x < tile_w; ++x)
+						*--p_out = *p_in++ +
+							MEM2MEM_COLOR_STEP;
+				} else {
+					for (x = 0; x < tile_w; ++x)
+						*--p_out = *p_in++ -
+							MEM2MEM_COLOR_STEP;
+				}
+				++w;
 			}
-			++w;
+			p_in += bytes_left;
+			p_out -= bytes_left;
+		}
+		break;
+
+	case MEM2MEM_HFLIP:
+		for (y = 0; y < height; ++y) {
+			p_out += MEM2MEM_NUM_TILES * tile_w;
+			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
+				if (w & 0x01) {
+					for (x = 0; x < tile_w; ++x)
+						*--p_out = *p_in++ +
+							MEM2MEM_COLOR_STEP;
+				} else {
+					for (x = 0; x < tile_w; ++x)
+						*--p_out = *p_in++ -
+							MEM2MEM_COLOR_STEP;
+				}
+				++w;
+			}
+			p_in += bytes_left;
+			p_out += bytesperline;
+		}
+		break;
+
+	case MEM2MEM_VFLIP:
+		p_out += bytesperline * (height - 1);
+		for (y = 0; y < height; ++y) {
+			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
+				if (w & 0x1) {
+					for (x = 0; x < tile_w; ++x)
+						*p_out++ = *p_in++ +
+							MEM2MEM_COLOR_STEP;
+				} else {
+					for (x = 0; x < tile_w; ++x)
+						*p_out++ = *p_in++ -
+							MEM2MEM_COLOR_STEP;
+				}
+				++w;
+			}
+			p_in += bytes_left;
+			p_out += bytes_left - 2 * bytesperline;
+		}
+		break;
+
+	default:
+		for (y = 0; y < height; ++y) {
+			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
+				if (w & 0x1) {
+					for (x = 0; x < tile_w; ++x)
+						*p_out++ = *p_in++ +
+							MEM2MEM_COLOR_STEP;
+				} else {
+					for (x = 0; x < tile_w; ++x)
+						*p_out++ = *p_in++ -
+							MEM2MEM_COLOR_STEP;
+				}
+				++w;
+			}
+			p_in += bytes_left;
+			p_out += bytes_left;
 		}
-		p_in += bytes_left;
-		p_out += bytes_left;
 	}
 
 	return 0;
@@ -646,6 +736,14 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 	struct m2mtest_ctx *ctx = priv;
 
 	switch (ctrl->id) {
+	case V4L2_CID_HFLIP:
+		ctrl->value = (ctx->mode & MEM2MEM_HFLIP) ? 1 : 0;
+		break;
+
+	case V4L2_CID_VFLIP:
+		ctrl->value = (ctx->mode & MEM2MEM_VFLIP) ? 1 : 0;
+		break;
+
 	case V4L2_CID_TRANS_TIME_MSEC:
 		ctrl->value = ctx->transtime;
 		break;
@@ -689,6 +787,20 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
 		return ret;
 
 	switch (ctrl->id) {
+	case V4L2_CID_HFLIP:
+		if (ctrl->value)
+			ctx->mode |= MEM2MEM_HFLIP;
+		else
+			ctx->mode &= ~MEM2MEM_HFLIP;
+		break;
+
+	case V4L2_CID_VFLIP:
+		if (ctrl->value)
+			ctx->mode |= MEM2MEM_VFLIP;
+		else
+			ctx->mode &= ~MEM2MEM_VFLIP;
+		break;
+
 	case V4L2_CID_TRANS_TIME_MSEC:
 		ctx->transtime = ctrl->value;
 		break;
@@ -859,6 +971,7 @@ static int m2mtest_open(struct file *file)
 	ctx->translen = MEM2MEM_DEF_TRANSLEN;
 	ctx->transtime = MEM2MEM_DEF_TRANSTIME;
 	ctx->num_processed = 0;
+	ctx->mode = 0;
 
 	ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
 
-- 
1.7.10


^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH 1/1] v4l: mem2mem_testdev: Add horizontal and vertical flip.
  2012-06-10 19:18 [PATCH 1/1] v4l: mem2mem_testdev: Add horizontal and vertical flip Tomasz Moń
@ 2012-06-12  7:01 ` Marek Szyprowski
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Szyprowski @ 2012-06-12  7:01 UTC (permalink / raw)
  To: 'Tomasz Moń', 'Mauro Carvalho Chehab',
	'Guennadi Liakhovetski', 'Hans Verkuil',
	'Hans de Goede',
	linux-media
  Cc: linux-kernel

Hi Tomasz,

On Sunday, June 10, 2012 9:18 PM Tomasz Moń wrote:

> Signed-off-by: Tomasz Moń <desowin@gmail.com>

Please add some commit description, even if it is as simple as repeating the subject with one
additional line of comment.

> ---
>  drivers/media/video/mem2mem_testdev.c |  135 ++++++++++++++++++++++++++++++---
>  1 file changed, 124 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
> index d2dec58..e1b66e9 100644
> --- a/drivers/media/video/mem2mem_testdev.c
> +++ b/drivers/media/video/mem2mem_testdev.c
> @@ -60,6 +60,10 @@ MODULE_VERSION("0.1.1");
>  #define MEM2MEM_COLOR_STEP	(0xff >> 4)
>  #define MEM2MEM_NUM_TILES	8
> 
> +/* Flags that indicate processing mode */
> +#define MEM2MEM_HFLIP	(1 << 0)
> +#define MEM2MEM_VFLIP	(1 << 1)
> +
>  #define dprintk(dev, fmt, arg...) \
>  	v4l2_dbg(1, 1, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
> 
> @@ -131,6 +135,24 @@ static struct m2mtest_q_data *get_q_data(enum v4l2_buf_type type)
> 
>  static struct v4l2_queryctrl m2mtest_ctrls[] = {
>  	{
> +		.id		= V4L2_CID_HFLIP,
> +		.type		= V4L2_CTRL_TYPE_BOOLEAN,
> +		.name		= "Mirror",
> +		.minimum	= 0,
> +		.maximum	= 1,
> +		.step		= 1,
> +		.default_value	= 0,
> +		.flags		= 0,
> +	}, {
> +		.id		= V4L2_CID_VFLIP,
> +		.type		= V4L2_CTRL_TYPE_BOOLEAN,
> +		.name		= "Vertical Mirror",
> +		.minimum	= 0,
> +		.maximum	= 1,
> +		.step		= 1,
> +		.default_value	= 0,
> +		.flags		= 0,
> +	}, {
>  		.id		= V4L2_CID_TRANS_TIME_MSEC,
>  		.type		= V4L2_CTRL_TYPE_INTEGER,
>  		.name		= "Transaction time (msec)",
> @@ -197,6 +219,9 @@ struct m2mtest_ctx {
>  	/* Abort requested by m2m */
>  	int			aborting;
> 
> +	/* Processing mode */
> +	int			mode;
> +
>  	struct v4l2_m2m_ctx	*m2m_ctx;
>  };
> 
> @@ -247,19 +272,84 @@ static int device_process(struct m2mtest_ctx *ctx,
>  	bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES;
>  	w = 0;
> 
> -	for (y = 0; y < height; ++y) {
> -		for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
> -			if (w & 0x1) {
> -				for (x = 0; x < tile_w; ++x)
> -					*p_out++ = *p_in++ + MEM2MEM_COLOR_STEP;
> -			} else {
> -				for (x = 0; x < tile_w; ++x)
> -					*p_out++ = *p_in++ - MEM2MEM_COLOR_STEP;
> +	switch (ctx->mode) {
> +	case MEM2MEM_HFLIP | MEM2MEM_VFLIP:
> +		p_out += bytesperline * height - bytes_left;
> +		for (y = 0; y < height; ++y) {
> +			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
> +				if (w & 0x1) {
> +					for (x = 0; x < tile_w; ++x)
> +						*--p_out = *p_in++ +
> +							MEM2MEM_COLOR_STEP;
> +				} else {
> +					for (x = 0; x < tile_w; ++x)
> +						*--p_out = *p_in++ -
> +							MEM2MEM_COLOR_STEP;
> +				}
> +				++w;
>  			}
> -			++w;
> +			p_in += bytes_left;
> +			p_out -= bytes_left;
> +		}
> +		break;
> +
> +	case MEM2MEM_HFLIP:
> +		for (y = 0; y < height; ++y) {
> +			p_out += MEM2MEM_NUM_TILES * tile_w;
> +			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
> +				if (w & 0x01) {
> +					for (x = 0; x < tile_w; ++x)
> +						*--p_out = *p_in++ +
> +							MEM2MEM_COLOR_STEP;
> +				} else {
> +					for (x = 0; x < tile_w; ++x)
> +						*--p_out = *p_in++ -
> +							MEM2MEM_COLOR_STEP;
> +				}
> +				++w;
> +			}
> +			p_in += bytes_left;
> +			p_out += bytesperline;
> +		}
> +		break;
> +
> +	case MEM2MEM_VFLIP:
> +		p_out += bytesperline * (height - 1);
> +		for (y = 0; y < height; ++y) {
> +			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
> +				if (w & 0x1) {
> +					for (x = 0; x < tile_w; ++x)
> +						*p_out++ = *p_in++ +
> +							MEM2MEM_COLOR_STEP;
> +				} else {
> +					for (x = 0; x < tile_w; ++x)
> +						*p_out++ = *p_in++ -
> +							MEM2MEM_COLOR_STEP;
> +				}
> +				++w;
> +			}
> +			p_in += bytes_left;
> +			p_out += bytes_left - 2 * bytesperline;
> +		}
> +		break;
> +
> +	default:
> +		for (y = 0; y < height; ++y) {
> +			for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
> +				if (w & 0x1) {
> +					for (x = 0; x < tile_w; ++x)
> +						*p_out++ = *p_in++ +
> +							MEM2MEM_COLOR_STEP;
> +				} else {
> +					for (x = 0; x < tile_w; ++x)
> +						*p_out++ = *p_in++ -
> +							MEM2MEM_COLOR_STEP;
> +				}
> +				++w;
> +			}
> +			p_in += bytes_left;
> +			p_out += bytes_left;
>  		}
> -		p_in += bytes_left;
> -		p_out += bytes_left;
>  	}
> 
>  	return 0;
> @@ -646,6 +736,14 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
>  	struct m2mtest_ctx *ctx = priv;
> 
>  	switch (ctrl->id) {
> +	case V4L2_CID_HFLIP:
> +		ctrl->value = (ctx->mode & MEM2MEM_HFLIP) ? 1 : 0;
> +		break;
> +
> +	case V4L2_CID_VFLIP:
> +		ctrl->value = (ctx->mode & MEM2MEM_VFLIP) ? 1 : 0;
> +		break;
> +
>  	case V4L2_CID_TRANS_TIME_MSEC:
>  		ctrl->value = ctx->transtime;
>  		break;
> @@ -689,6 +787,20 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
>  		return ret;
> 
>  	switch (ctrl->id) {
> +	case V4L2_CID_HFLIP:
> +		if (ctrl->value)
> +			ctx->mode |= MEM2MEM_HFLIP;
> +		else
> +			ctx->mode &= ~MEM2MEM_HFLIP;
> +		break;
> +
> +	case V4L2_CID_VFLIP:
> +		if (ctrl->value)
> +			ctx->mode |= MEM2MEM_VFLIP;
> +		else
> +			ctx->mode &= ~MEM2MEM_VFLIP;
> +		break;
> +
>  	case V4L2_CID_TRANS_TIME_MSEC:
>  		ctx->transtime = ctrl->value;
>  		break;
> @@ -859,6 +971,7 @@ static int m2mtest_open(struct file *file)
>  	ctx->translen = MEM2MEM_DEF_TRANSLEN;
>  	ctx->transtime = MEM2MEM_DEF_TRANSTIME;
>  	ctx->num_processed = 0;
> +	ctx->mode = 0;
> 
>  	ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
> 
> --
> 1.7.10


Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-12  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-10 19:18 [PATCH 1/1] v4l: mem2mem_testdev: Add horizontal and vertical flip Tomasz Moń
2012-06-12  7:01 ` Marek Szyprowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®