diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-07-08 07:25:08 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-07-08 07:25:08 -0300 |
commit | c13f70467621e2c352f93b336b382e70ea24d218 (patch) | |
tree | 582367340fe7529eb3fec3c514ec9d4b2f68ff71 /v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c | |
parent | a953cf4edb8db13f8b7d20c793696a13ffcd3333 (diff) | |
parent | 9380e197397e3f8404fa2d2effe5c84b6f56735b (diff) | |
download | mediapointer-dvb-s2-c13f70467621e2c352f93b336b382e70ea24d218.tar.gz mediapointer-dvb-s2-c13f70467621e2c352f93b336b382e70ea24d218.tar.bz2 |
merge: http://linuxtv.org/hg/~jfrancois/gspca/
From: Mauro Carvalho Chehab <mchehab@infradead.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c')
-rw-r--r-- | v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c b/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c new file mode 100644 index 000000000..79c8ecb35 --- /dev/null +++ b/v4l2-apps/lib/libv4l/libv4lconvert/rgbyuv.c @@ -0,0 +1,82 @@ +/* + +# RGB <-> YUV conversion routines + +# (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl> + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#define RGB2YUV(r,g,b,y,u,v) \ + (y) = (( 8453*(r) + 16594*(g) + 3223*(b) + 524288) >> 15); \ + (u) = (( -4878*(r) - 9578*(g) + 14456*(b) + 4210688) >> 15); \ + (v) = (( 14456*(r) - 12105*(g) - 2351*(b) + 4210688) >> 15) + +#define YUV2R(y, u, v) ({ \ + int r = (y) + ((((v)-128)*1436) >> 10); r > 255 ? 255 : r < 0 ? 0 : r; }) +#define YUV2G(y, u, v) ({ \ + int g = (y) - ((((u)-128)*352 + ((v)-128)*731) >> 10); g > 255 ? 255 : g < 0 ? 0 : g; }) +#define YUV2B(y, u, v) ({ \ + int b = (y) + ((((u)-128)*1814) >> 10); b > 255 ? 255 : b < 0 ? 0 : b; }) + +#define CLIP(color) (unsigned char)(((color)>0xFF)?0xff:(((color)<0)?0:(color))) + +void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest, + int width, int height) +{ + int i,j; + + const unsigned char *ysrc = src; + const unsigned char *usrc = src + width * height; + const unsigned char *vsrc = usrc + (width * height) / 4; + + for (i = 0; i < height; i++) { + for (j = 0; j < width; j += 2) { +#if 1 /* fast slightly less accurate multiplication free code */ + int u1 = (((*usrc - 128) << 7) + (*usrc - 128)) >> 6; + int rg = (((*usrc - 128) << 1) + (*usrc - 128) + + ((*vsrc - 128) << 2) + ((*vsrc - 128) << 1)) >> 3; + int v1 = (((*vsrc - 128) << 1) + (*vsrc - 128)) >> 1; + + *dest++ = CLIP(*ysrc + u1); + *dest++ = CLIP(*ysrc - rg); + *dest++ = CLIP(*ysrc + v1); + ysrc++; + + *dest++ = CLIP(*ysrc + u1); + *dest++ = CLIP(*ysrc - rg); + *dest++ = CLIP(*ysrc + v1); +#else + *dest++ = YUV2B(*ysrc, *usrc, *vsrc); + *dest++ = YUV2G(*ysrc, *usrc, *vsrc); + *dest++ = YUV2R(*ysrc, *usrc, *vsrc); + ysrc++; + + *dest++ = YUV2B(*ysrc, *usrc, *vsrc); + *dest++ = YUV2G(*ysrc, *usrc, *vsrc); + *dest++ = YUV2R(*ysrc, *usrc, *vsrc); +#endif + ysrc++; + usrc++; + vsrc++; + } + /* Rewind u and v for next line */ + if (i&1) { + usrc -= width / 2; + vsrc -= width / 2; + } + } +} |