From a63e58c8101caacfc5f82b66de79e794adf0ca3a Mon Sep 17 00:00:00 2001 From: "hans@localhost.localdomain" Date: Thu, 7 Aug 2008 19:34:10 +0200 Subject: libv4l: add support for fixing upside down images to libv4lconvert From: Hans de Goede Add support to libv4lconvert to flipping the image for upside down mounted sensors, libv4lconvert will do this automatically if the webcam sets a flag in its query_fmt reply indicating that this is necessary, this fixes the upside down image on Philips SPC200NC images Priority: normal Signed-off-by: Hans de Goede --- v4l2-apps/lib/libv4l/libv4lconvert/flip.c | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 v4l2-apps/lib/libv4l/libv4lconvert/flip.c (limited to 'v4l2-apps/lib/libv4l/libv4lconvert/flip.c') diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/flip.c b/v4l2-apps/lib/libv4l/libv4lconvert/flip.c new file mode 100644 index 000000000..de76ecc9a --- /dev/null +++ b/v4l2-apps/lib/libv4l/libv4lconvert/flip.c @@ -0,0 +1,60 @@ +/* + +# RGB / YUV flip routines + +# (C) 2008 Hans de Goede + +# 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 Lesser 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 + +*/ + +#include "libv4lconvert-priv.h" + +void v4lconvert_flip_rgbbgr24(const unsigned char *src, unsigned char *dst, + int width, int height) +{ + int i; + + src += 3 * width * height - 3; + + for (i = 0; i < width * height; i++) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst += 3; + src -= 3; + } +} + +void v4lconvert_flip_yuv420(const unsigned char *src, unsigned char *dst, + int width, int height) +{ + int i; + + /* First flip x and y of the Y plane */ + src += width * height - 1; + for (i = 0; i < width * height; i++) + *dst++ = *src--; + + /* Now flip the U plane */ + src += width * height * 5 / 4; + for (i = 0; i < width * height / 4; i++) + *dst++ = *src--; + + /* Last flip the V plane */ + src += width * height / 2; + for (i = 0; i < width * height / 4; i++) + *dst++ = *src--; +} -- cgit v1.2.3 From a15825844ed72e4b0f13e10de4b7dd0ce31846ac Mon Sep 17 00:00:00 2001 From: "hans@localhost.localdomain" Date: Fri, 22 Aug 2008 23:23:50 +0200 Subject: libv4l: add support for Pixart custom JPEG format From: Hans de Goede libv4l: add support for Pixart custom JPEG format Priority: normal Signed-off-by: Hans de Goede --- v4l2-apps/lib/libv4l/libv4lconvert/flip.c | 53 +++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'v4l2-apps/lib/libv4l/libv4lconvert/flip.c') diff --git a/v4l2-apps/lib/libv4l/libv4lconvert/flip.c b/v4l2-apps/lib/libv4l/libv4lconvert/flip.c index de76ecc9a..cd3468a89 100644 --- a/v4l2-apps/lib/libv4l/libv4lconvert/flip.c +++ b/v4l2-apps/lib/libv4l/libv4lconvert/flip.c @@ -1,6 +1,6 @@ /* -# RGB / YUV flip routines +# RGB / YUV flip/rotate routines # (C) 2008 Hans de Goede @@ -22,7 +22,7 @@ #include "libv4lconvert-priv.h" -void v4lconvert_flip_rgbbgr24(const unsigned char *src, unsigned char *dst, +void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, unsigned char *dst, int width, int height) { int i; @@ -38,7 +38,7 @@ void v4lconvert_flip_rgbbgr24(const unsigned char *src, unsigned char *dst, } } -void v4lconvert_flip_yuv420(const unsigned char *src, unsigned char *dst, +void v4lconvert_rotate180_yuv420(const unsigned char *src, unsigned char *dst, int width, int height) { int i; @@ -58,3 +58,50 @@ void v4lconvert_flip_yuv420(const unsigned char *src, unsigned char *dst, for (i = 0; i < width * height / 4; i++) *dst++ = *src--; } + +void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, unsigned char *dst, + int destwidth, int destheight) +{ + int x, y; +#define srcwidth destheight +#define srcheight destwidth + + for (y = 0; y < destheight; y++) + for (x = 0; x < destwidth; x++) { + int offset = ((srcheight - x - 1) * srcwidth + y) * 3; + *dst++ = src[offset++]; + *dst++ = src[offset++]; + *dst++ = src[offset]; + } +} + +void v4lconvert_rotate90_yuv420(const unsigned char *src, unsigned char *dst, + int destwidth, int destheight) +{ + int x, y; + + /* Y-plane */ + for (y = 0; y < destheight; y++) + for (x = 0; x < destwidth; x++) { + int offset = (srcheight - x - 1) * srcwidth + y; + *dst++ = src[offset]; + } + + /* U-plane */ + src += srcwidth * srcheight; + destwidth /= 2; + destheight /= 2; + for (y = 0; y < destheight; y++) + for (x = 0; x < destwidth; x++) { + int offset = (srcheight - x - 1) * srcwidth + y; + *dst++ = src[offset]; + } + + /* V-plane */ + src += srcwidth * srcheight; + for (y = 0; y < destheight; y++) + for (x = 0; x < destwidth; x++) { + int offset = (srcheight - x - 1) * srcwidth + y; + *dst++ = src[offset]; + } +} -- cgit v1.2.3