mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Markus Rechberger" <mrechberger@gmail.com>
To: "Greg KH" <greg@kroah.com>
Cc: mchehab@infradead.org, v4l-dvb-maintainer@linuxtv.org,
	video4linux-list@redhat.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [v4l-dvb-maintainer] [PATCH] USB: add Sensoray 2255 v4l driver
Date: Thu, 15 May 2008 03:17:42 +0200	[thread overview]
Message-ID: <d9def9db0805141817n4182deedp780791b0a51fb7be@mail.gmail.com> (raw)
In-Reply-To: <20080514205927.GA13134@kroah.com>

Hi Dean, Greg,

On 5/14/08, Greg KH <greg@kroah.com> wrote:
> From: Dean Anderson <dean@sensoray.com>
>
> +static int norm_maxw(struct video_device *vdev)
> +{
> +	return (vdev->current_norm != V4L2_STD_PAL_B) ?
> +	    LINE_SZ_4CIFS_NTSC : LINE_SZ_4CIFS_PAL;
> +}
> +
> +static int norm_maxh(struct video_device *vdev)
> +{
> +	return (vdev->current_norm != V4L2_STD_PAL_B) ?
> +	    (NUM_LINES_1CIFS_NTSC * 2) : (NUM_LINES_1CIFS_PAL * 2);
> +}
> +
> +static int norm_minw(struct video_device *vdev)
> +{
> +	return (vdev->current_norm != V4L2_STD_PAL_B) ?
> +	    LINE_SZ_1CIFS_NTSC : LINE_SZ_1CIFS_PAL;
> +}
> +
> +static int norm_minh(struct video_device *vdev)
> +{
> +	return (vdev->current_norm != V4L2_STD_PAL_B) ?
> +	    (NUM_LINES_1CIFS_NTSC) : (NUM_LINES_1CIFS_PAL);
> +}
> +
> +/*
> + * convert from YUV(YCrCb) to RGB
> + * 65536 R = 76533(Y-16) + 104936 * (Cr-128)
> + * 65536 G = 76533(Y-16) - 53451(Cr-128) - 25703(Cb -128)
> + * 65536 B = 76533(Y-16) + 132677(Cb-128)
> + */
> +static void YCrCb2RGB(int Y, int Cr, int Cb, unsigned char *pR,
> +		      unsigned char *pG, unsigned char *pB)
> +{
> +	int R, G, B;
> +
> +	Y = Y - 16;
> +	Cr = Cr - 128;
> +	Cb = Cb - 128;
> +
> +	R = (76533 * Y + 104936 * Cr) >> 16;
> +	G = ((76533 * Y) - (53451 * Cr) - (25703 * Cb)) >> 16;
> +	B = ((76533 * Y) + (132677 * Cb)) >> 16;
> +	/* even with proper conversion, some values still need clipping. */
> +	if (R > 255)
> +		R = 255;
> +	if (G > 255)
> +		G = 255;
> +	if (B > 255)
> +		B = 255;
> +	if (R < 0)
> +		R = 0;
> +	if (G < 0)
> +		G = 0;
> +	if (B < 0)
> +		B = 0;
> +	*pR = R;
> +	*pG = G;
> +	*pB = B;
> +	return;
> +}
> +
> +/* converts 2255 planar format to yuyv */
> +static void planar422p_to_yuy2(const unsigned char *in, unsigned char *out,
> +			       int width, int height)
> +{
> +	unsigned char *pY;
> +	unsigned char *pCb;
> +	unsigned char *pCr;
> +	unsigned long size = height * width;
> +	unsigned int i;
> +	pY = (unsigned char *)in;
> +	pCr = (unsigned char *)in + height * width;
> +	pCb = (unsigned char *)in + height * width + (height * width / 2);
> +	for (i = 0; i < size * 2; i += 4) {
> +		out[i] = *pY++;
> +		out[i + 1] = *pCr++;
> +		out[i + 2] = *pY++;
> +		out[i + 3] = *pCb++;
> +	}
> +	return;
> +}
> +
> +/*
> + * basic 422 planar to RGB24 or BGR24 software conversion.
> + * This is best done with MMX. Update to kernel function
> + * when image conversion functions added to kernel.
> + */
> +static void planar422p_to_rgb24(const unsigned char *in,
> +				unsigned char *out, int width,
> +				int height, int rev_order)
> +{
> +	unsigned char *pY;
> +	unsigned char *pYEND;
> +	unsigned char *pCb;
> +	unsigned char *pCr;
> +	unsigned char Cr, Cb, Y, r, g, b;
> +	unsigned long k = 0;
> +	pY = (unsigned char *)in;
> +	pCb = (unsigned char *)in + (height * width);
> +	pCr = (unsigned char *)in + (height * width) + (height * width / 2);
> +	pYEND = pCb;
> +	while (pY < pYEND) {
> +		Y = *pY++;
> +		Cr = *pCr;
> +		Cb = *pCb;
> +		YCrCb2RGB(Y, Cr, Cb, &r, &g, &b);
> +		out[k++] = !rev_order ? b : r;
> +		out[k++] = g;
> +		out[k++] = !rev_order ? r : b;
> +		if (pY >= pYEND)
> +			break;
> +		Y = *pY++;
> +		Cr = *pCr++;
> +		Cb = *pCb++;
> +		YCrCb2RGB(Y, Cr, Cb, &r, &g, &b);
> +		out[k++] = !rev_order ? b : r;
> +		out[k++] = g;
> +		out[k++] = !rev_order ? r : b;
> +	}
> +	return;
> +}
> +
> +static void planar422p_to_rgb32(const unsigned char *in, unsigned char
> *out,
> +				int width, int height, int rev_order)
> +{
> +	unsigned char *pY;
> +	unsigned char *pYEND;
> +	unsigned char *pCb;
> +	unsigned char *pCr;
> +	unsigned char Cr, Cb, Y, r, g, b;
> +	unsigned long k = 0;
> +	pY = (unsigned char *)in;
> +	pCb = (unsigned char *)in + (height * width);
> +	pCr = (unsigned char *)in + (height * width) + (height * width / 2);
> +	pYEND = pCb;
> +	while (pY < pYEND) {
> +		Y = *pY++;
> +		Cr = *pCr;
> +		Cb = *pCb;
> +		YCrCb2RGB(Y, Cr, Cb, &r, &g, &b);
> +		out[k++] = rev_order ? b : r;
> +		out[k++] = g;
> +		out[k++] = rev_order ? r : b;
> +		out[k++] = 0;
> +		if (pY >= pYEND)
> +			break;
> +		Y = *pY++;
> +		Cr = *pCr++;
> +		Cb = *pCb++;
> +		YCrCb2RGB(Y, Cr, Cb, &r, &g, &b);
> +		out[k++] = rev_order ? b : r;
> +		out[k++] = g;
> +		out[k++] = rev_order ? r : b;
> +		out[k++] = 0;
> +	}
> +
> +	return;
> +}
> +
> +static void planar422p_to_rgb565(unsigned char const *in, unsigned char
> *out,
> +				 int width, int height, int rev_order)
> +{
> +	unsigned char *pY;
> +	unsigned char *pYEND;
> +	unsigned char *pCb;
> +	unsigned char *pCr;
> +	unsigned char Cr, Cb, Y, r, g, b;
> +	unsigned long k = 0;
> +	unsigned short rgbbytes;
> +	pY = (unsigned char *)in;
> +	pCb = (unsigned char *)in + (height * width);
> +	pCr = (unsigned char *)in + (height * width) + (height * width / 2);
> +	pYEND = pCb;
> +	while (pY < pYEND) {
> +		Y = *pY++;
> +		Cr = *pCr;
> +		Cb = *pCb;
> +		YCrCb2RGB(Y, Cr, Cb, &r, &g, &b);
> +		r = r >> 3;
> +		g = g >> 2;
> +		b = b >> 3;
> +		if (rev_order)
> +			rgbbytes = b + (g << 5) + (r << (5 + 6));
> +		else
> +			rgbbytes = r + (g << 5) + (b << (5 + 6));
> +		out[k++] = rgbbytes & 0xff;
> +		out[k++] = (rgbbytes >> 8) & 0xff;
> +		Y = *pY++;
> +		Cr = *pCr++;
> +		Cb = *pCb++;
> +		YCrCb2RGB(Y, Cr, Cb, &r, &g, &b);
> +		r = r >> 3;
> +		g = g >> 2;
> +		b = b >> 3;
> +		if (rev_order)
> +			rgbbytes = b + (g << 5) + (r << (5 + 6));
> +		else
> +			rgbbytes = r + (g << 5) + (b << (5 + 6));
> +		out[k++] = rgbbytes & 0xff;
> +		out[k++] = (rgbbytes >> 8) & 0xff;
> +	}
> +	return;
> +}
> +


Why do you do those conversions in kernelspace?
ffmpeg/libswscale has optimized code for colourspace conversions.
I know a few drivers do that in kernelspace but it's way more flexible
in userspace and depending on the optimization requires less CPU
power.

Markus

  reply	other threads:[~2008-05-15  1:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-14 20:59 Greg KH
2008-05-15  1:17 ` Markus Rechberger [this message]
2008-05-15  2:41   ` [v4l-dvb-maintainer] " Greg KH
2008-05-15  3:12     ` Trent Piepho
2008-05-15 15:34       ` Dean Anderson
2008-05-15 16:57         ` Markus Rechberger
2008-05-16  2:59         ` Mauro Carvalho Chehab
2008-05-15 11:38 ` Oliver Neukum
2008-05-15 12:03   ` Oliver Neukum
2008-05-15 18:44     ` Greg KH
2008-05-15 19:54       ` Oliver Neukum
2008-05-15 20:10         ` Greg KH
2008-05-15 20:13           ` Oliver Neukum
2008-05-16  2:51 ` Mauro Carvalho Chehab
2008-05-16  6:28   ` Oliver Neukum
2008-05-16 15:57     ` dean
2008-05-16 16:04       ` Oliver Neukum
2008-05-16 18:17       ` Mauro Carvalho Chehab
2008-05-16 14:53   ` dean
2008-05-16 15:34     ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9def9db0805141817n4182deedp780791b0a51fb7be@mail.gmail.com \
    --to=mrechberger@gmail.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=v4l-dvb-maintainer@linuxtv.org \
    --cc=video4linux-list@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®