From bc311cc486e45586959212cfae95787b7971f09e Mon Sep 17 00:00:00 2001 From: "jinhyung.jo" Date: Wed, 18 Mar 2015 14:43:50 +0900 Subject: [PATCH] maru-camera: Rename files Delete unnecessary postfix, like '_pci'. Integrate the format conversion utilities, separately implemented in Darwin & Win32. Change-Id: Ie71cc57c8ed7c9e74eb19afed2e55259b720151f Signed-off-by: Jinhyung Jo --- tizen/src/hw/pci/Makefile.objs | 9 +- ...maru_camera_common_pci.c => maru_camera.c} | 6 +- .../{maru_camera_common.h => maru_camera.h} | 10 +- tizen/src/hw/pci/maru_camera_convert.c | 663 ++++++++++++++++++ ..._camera_darwin.h => maru_camera_convert.h} | 50 +- ...mera_darwin_pci.m => maru_camera_darwin.m} | 45 +- .../src/hw/pci/maru_camera_darwin_converter.c | 385 ---------- ...camera_linux_pci.c => maru_camera_linux.c} | 6 +- ...camera_win32_pci.c => maru_camera_win32.c} | 314 +-------- ..._win32_interface.h => maru_camera_win32.h} | 10 +- tizen/src/util/check_cam.c | 4 +- 11 files changed, 740 insertions(+), 762 deletions(-) rename tizen/src/hw/pci/{maru_camera_common_pci.c => maru_camera.c} (98%) rename tizen/src/hw/pci/{maru_camera_common.h => maru_camera.h} (95%) create mode 100644 tizen/src/hw/pci/maru_camera_convert.c rename tizen/src/hw/pci/{maru_camera_darwin.h => maru_camera_convert.h} (68%) rename tizen/src/hw/pci/{maru_camera_darwin_pci.m => maru_camera_darwin.m} (95%) delete mode 100644 tizen/src/hw/pci/maru_camera_darwin_converter.c rename tizen/src/hw/pci/{maru_camera_linux_pci.c => maru_camera_linux.c} (99%) rename tizen/src/hw/pci/{maru_camera_win32_pci.c => maru_camera_win32.c} (87%) rename tizen/src/hw/pci/{maru_camera_win32_interface.h => maru_camera_win32.h} (99%) diff --git a/tizen/src/hw/pci/Makefile.objs b/tizen/src/hw/pci/Makefile.objs index 408a68c57b..506305e758 100644 --- a/tizen/src/hw/pci/Makefile.objs +++ b/tizen/src/hw/pci/Makefile.objs @@ -8,18 +8,17 @@ obj-$(CONFIG_VAAPI) += maru_brillcodec_vaapi.o obj-y += maru_brightness.o -obj-y += maru_camera_common_pci.o +obj-y += maru_camera.o ifdef CONFIG_LINUX -obj-y += maru_camera_linux_pci.o +obj-y += maru_camera_linux.o LIBS += -lv4l2 -lv4lconvert endif ifdef CONFIG_WIN32 -obj-y += maru_camera_win32_pci.o +obj-y += maru_camera_win32.o maru_camera_util.o LIBS += -lole32 -loleaut32 -luuid -lstrmiids endif ifdef CONFIG_DARWIN -obj-y += maru_camera_darwin_converter.o -obj-y += maru_camera_darwin_pci.o +obj-y += maru_camera_darwin.o maru_camera_util.o LIBS += -framework Foundation -framework SystemConfiguration LIBS += -framework Cocoa -framework QTKit -framework CoreVideo LIBS += -framework AppKit diff --git a/tizen/src/hw/pci/maru_camera_common_pci.c b/tizen/src/hw/pci/maru_camera.c similarity index 98% rename from tizen/src/hw/pci/maru_camera_common_pci.c rename to tizen/src/hw/pci/maru_camera.c index d44df52439..112c2866b4 100644 --- a/tizen/src/hw/pci/maru_camera_common_pci.c +++ b/tizen/src/hw/pci/maru_camera.c @@ -4,8 +4,8 @@ * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -39,7 +39,7 @@ #include "qemu/main-loop.h" #include "exec/cpu-common.h" -#include "maru_camera_common.h" +#include "maru_camera.h" #include "hw/maru_device_ids.h" #include "debug_ch.h" diff --git a/tizen/src/hw/pci/maru_camera_common.h b/tizen/src/hw/pci/maru_camera.h similarity index 95% rename from tizen/src/hw/pci/maru_camera_common.h rename to tizen/src/hw/pci/maru_camera.h index 45b1a38f15..429446023e 100644 --- a/tizen/src/hw/pci/maru_camera_common.h +++ b/tizen/src/hw/pci/maru_camera.h @@ -4,8 +4,8 @@ * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,8 +27,8 @@ * */ -#ifndef _MARU_CAMERA_COMMON_H_ -#define _MARU_CAMERA_COMMON_H_ +#ifndef _MARU_CAMERA_H_ +#define _MARU_CAMERA_H_ #include "hw/pci/pci.h" #include "qemu/thread.h" @@ -113,4 +113,4 @@ void marucam_device_enum_fintv(MaruCamState *state); int maru_camera_pci_init(PCIBus *bus); -#endif /* _MARU_CAMERA_COMMON_H_ */ +#endif /* _MARU_CAMERA_H_ */ diff --git a/tizen/src/hw/pci/maru_camera_convert.c b/tizen/src/hw/pci/maru_camera_convert.c new file mode 100644 index 0000000000..8be52ce9ba --- /dev/null +++ b/tizen/src/hw/pci/maru_camera_convert.c @@ -0,0 +1,663 @@ +/* + * Implementation of color conversion for MARU Virtual Camera device. + * + * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: + * Jun Tian + * Jinhyung Jo + * Sangho Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +#include "qemu-common.h" +#include "maru_camera_convert.h" +#include "debug_ch.h" + +MULTI_DEBUG_CHANNEL(tizen, camera); + +static void UYVYToYUV420(unsigned char *bufsrc, unsigned char *bufdest, + uint32_t width, uint32_t height); +static void YVU420ToYUV420(unsigned char *bufsrc, unsigned char *bufdest, + uint32_t width, uint32_t height); +static void YUYVToYUV420(unsigned char *bufsrc, unsigned char *bufdest, + uint32_t width, uint32_t height); + +static void yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height, uint32_t yvu); +static void rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height, uint32_t yvu); +static void rgb24_to_yuyv(unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height); +static void yuv420_to_yvu420(unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height); +static void yuv420_to_yuyv(unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height); + +/* Convert pixel format to YUV420 */ +uint8_t convert_frame(uint32_t src_format, uint32_t dst_format, + uint32_t width, uint32_t height, size_t frame_size, + void *src_buf, void *dst_buf) +{ + switch (src_format) { + case V4L2_PIX_FMT_YUV420: + switch (dst_format) { + case V4L2_PIX_FMT_YUV420: + memcpy(dst_buf, (void *)src_buf, (size_t)frame_size); + break; + case V4L2_PIX_FMT_YVU420: + yuv420_to_yvu420(src_buf, dst_buf, width, height); + break; + case V4L2_PIX_FMT_YUYV: + yuv420_to_yuyv(src_buf, dst_buf, width, height); + break; + default: + ERR("Cannot convert from the pixel format (%.4s)...\n", + (const char *)&src_format); + return 1; + } + break; + case V4L2_PIX_FMT_YVU420: + switch (dst_format) { + case V4L2_PIX_FMT_YUV420: + YVU420ToYUV420(src_buf, dst_buf, width, height); + break; + default: + ERR("Cannot convert from the pixel format (%.4s)...\n", + (const char *)&src_format); + return 1; + } + break; + case V4L2_PIX_FMT_YUYV: + switch (dst_format) { + case V4L2_PIX_FMT_YUV420: + //YUYVToYUV420(src_buf, dst_buf, width, height); + yuyv_to_yuv420(src_buf, dst_buf, width, height, 0); + break; + case V4L2_PIX_FMT_YVU420: + yuyv_to_yuv420(src_buf, dst_buf, width, height, 1); + break; + case V4L2_PIX_FMT_YUYV: + memcpy(dst_buf, (void *)src_buf, (size_t)frame_size); + break; + default: + ERR("Cannot convert from the pixel format (%.4s)...\n", + (const char *)&src_format); + return 1; + } + break; + case V4L2_PIX_FMT_UYVY: /* Mac default format */ + switch (dst_format) { + case V4L2_PIX_FMT_YUV420: + UYVYToYUV420(src_buf, dst_buf, width, height); + break; + default: + ERR("Cannot convert from the pixel format (%.4s)...\n", + (const char *)&src_format); + return 1; + } + break; + case V4L2_PIX_FMT_RGB24: + switch (dst_format) { + case V4L2_PIX_FMT_YUV420: + rgb24_to_yuv420(src_buf, dst_buf, width, height, 0); + break; + case V4L2_PIX_FMT_YVU420: + rgb24_to_yuv420(src_buf, dst_buf, width, height, 1); + break; + case V4L2_PIX_FMT_YUYV: + rgb24_to_yuyv(src_buf, dst_buf, width, height); + break; + default: + ERR("Cannot convert from the pixel format (%.4s)...\n", + (const char *)&src_format); + return 1; + } + break; + default: + ERR("Cannot convert from the pixel format (%.4s)...\n", + (const char *)&src_format); + return 1; + } + + return 0; +} + +static void UYVYToYUV420(unsigned char *bufsrc, unsigned char *bufdest, + uint32_t width, uint32_t height) +{ + uint32_t i, j; + + /* Source */ + unsigned char *ptrsrcy1, *ptrsrcy2; + unsigned char *ptrsrcy3, *ptrsrcy4; + unsigned char *ptrsrccb1; + unsigned char *ptrsrccb3; + unsigned char *ptrsrccr1; + unsigned char *ptrsrccr3; + uint32_t srcystride, srcccstride; + + ptrsrcy1 = bufsrc + 1; + ptrsrcy2 = bufsrc + (width << 1) + 1; + ptrsrcy3 = bufsrc + (width << 1) * 2 + 1; + ptrsrcy4 = bufsrc + (width << 1) * 3 + 1; + + ptrsrccb1 = bufsrc; + ptrsrccb3 = bufsrc + (width << 1) * 2; + + ptrsrccr1 = bufsrc + 2; + ptrsrccr3 = bufsrc + (width << 1) * 2 + 2; + + srcystride = (width << 1) * 3; + srcccstride = (width << 1) * 3; + + /* Destination */ + unsigned char *ptrdesty1, *ptrdesty2; + unsigned char *ptrdesty3, *ptrdesty4; + unsigned char *ptrdestcb1, *ptrdestcb2; + unsigned char *ptrdestcr1, *ptrdestcr2; + uint32_t destystride, destccstride; + + ptrdesty1 = bufdest; + ptrdesty2 = bufdest + width; + ptrdesty3 = bufdest + width * 2; + ptrdesty4 = bufdest + width * 3; + + ptrdestcb1 = bufdest + width * height; + ptrdestcb2 = bufdest + width * height + (width >> 1); + + ptrdestcr1 = bufdest + width * height + ((width*height) >> 2); + ptrdestcr2 = bufdest + width * height + ((width*height) >> 2) + + (width >> 1); + + destystride = (width)*3; + destccstride = (width>>1); + + for (j = 0; j < (height / 4); j++) { + for (i = 0; i < (width / 2); i++) { + (*ptrdesty1++) = (*ptrsrcy1); + (*ptrdesty2++) = (*ptrsrcy2); + (*ptrdesty3++) = (*ptrsrcy3); + (*ptrdesty4++) = (*ptrsrcy4); + + ptrsrcy1 += 2; + ptrsrcy2 += 2; + ptrsrcy3 += 2; + ptrsrcy4 += 2; + + (*ptrdesty1++) = (*ptrsrcy1); + (*ptrdesty2++) = (*ptrsrcy2); + (*ptrdesty3++) = (*ptrsrcy3); + (*ptrdesty4++) = (*ptrsrcy4); + + ptrsrcy1 += 2; + ptrsrcy2 += 2; + ptrsrcy3 += 2; + ptrsrcy4 += 2; + + (*ptrdestcb1++) = (*ptrsrccb1); + (*ptrdestcb2++) = (*ptrsrccb3); + + ptrsrccb1 += 4; + ptrsrccb3 += 4; + + (*ptrdestcr1++) = (*ptrsrccr1); + (*ptrdestcr2++) = (*ptrsrccr3); + + ptrsrccr1 += 4; + ptrsrccr3 += 4; + + } + + /* Update src pointers */ + ptrsrcy1 += srcystride; + ptrsrcy2 += srcystride; + ptrsrcy3 += srcystride; + ptrsrcy4 += srcystride; + + ptrsrccb1 += srcccstride; + ptrsrccb3 += srcccstride; + + ptrsrccr1 += srcccstride; + ptrsrccr3 += srcccstride; + + /* Update dest pointers */ + ptrdesty1 += destystride; + ptrdesty2 += destystride; + ptrdesty3 += destystride; + ptrdesty4 += destystride; + + ptrdestcb1 += destccstride; + ptrdestcb2 += destccstride; + + ptrdestcr1 += destccstride; + ptrdestcr2 += destccstride; + } +} + +static void YVU420ToYUV420(unsigned char *bufsrc, unsigned char *bufdest, + uint32_t width, uint32_t height) +{ + uint32_t i, j; + + /* Source*/ + unsigned char *ptrsrcy1, *ptrsrcy2; + unsigned char *ptrsrcy3, *ptrsrcy4; + unsigned char *ptrsrccb1, *ptrsrccb2; + unsigned char *ptrsrccr1, *ptrsrccr2; + uint32_t srcystride, srcccstride; + + ptrsrcy1 = bufsrc; + ptrsrcy2 = bufsrc + width; + ptrsrcy3 = bufsrc + width*2; + ptrsrcy4 = bufsrc + width*3; + + ptrsrccr1 = bufsrc + width*height; + ptrsrccr2 = bufsrc + width*height + (width>>1); + + ptrsrccb1 = bufsrc + width*height + ((width*height) >> 2); + ptrsrccb2 = bufsrc + width*height + ((width*height) >> 2) + (width>>1); + + srcystride = (width)*3; + srcccstride = (width>>1); + + /* Destination */ + unsigned char *ptrdesty1, *ptrdesty2; + unsigned char *ptrdesty3, *ptrdesty4; + unsigned char *ptrdestcb1, *ptrdestcb2; + unsigned char *ptrdestcr1, *ptrdestcr2; + uint32_t destystride, destccstride; + + ptrdesty1 = bufdest; + ptrdesty2 = bufdest + width; + ptrdesty3 = bufdest + width * 2; + ptrdesty4 = bufdest + width * 3; + + ptrdestcb1 = bufdest + width * height; + ptrdestcb2 = bufdest + width * height + (width >> 1); + + ptrdestcr1 = bufdest + width * height + ((width*height) >> 2); + ptrdestcr2 = bufdest + width * height + ((width*height) >> 2) + + (width >> 1); + + destystride = (width)*3; + destccstride = (width>>1); + + for (j = 0; j < (height / 4); j++) { + for (i = 0; i < (width / 2); i++) { + + (*ptrdesty1++) = (*ptrsrcy1++); + (*ptrdesty2++) = (*ptrsrcy2++); + (*ptrdesty3++) = (*ptrsrcy3++); + (*ptrdesty4++) = (*ptrsrcy4++); + (*ptrdesty1++) = (*ptrsrcy1++); + (*ptrdesty2++) = (*ptrsrcy2++); + (*ptrdesty3++) = (*ptrsrcy3++); + (*ptrdesty4++) = (*ptrsrcy4++); + + (*ptrdestcb1++) = (*ptrsrccb1++); + (*ptrdestcr1++) = (*ptrsrccr1++); + (*ptrdestcb2++) = (*ptrsrccb2++); + (*ptrdestcr2++) = (*ptrsrccr2++); + + } + + /* Update src pointers */ + ptrsrcy1 += srcystride; + ptrsrcy2 += srcystride; + ptrsrcy3 += srcystride; + ptrsrcy4 += srcystride; + + ptrsrccb1 += srcccstride; + ptrsrccb2 += srcccstride; + + ptrsrccr1 += srcccstride; + ptrsrccr2 += srcccstride; + + /* Update dest pointers */ + ptrdesty1 += destystride; + ptrdesty2 += destystride; + ptrdesty3 += destystride; + ptrdesty4 += destystride; + + ptrdestcb1 += destccstride; + ptrdestcb2 += destccstride; + + ptrdestcr1 += destccstride; + ptrdestcr2 += destccstride; + + } + +} + +static void YUYVToYUV420(unsigned char *bufsrc, unsigned char *bufdest, + uint32_t width, uint32_t height) +{ + uint32_t i, j; + + /* Source*/ + unsigned char *ptrsrcy1, *ptrsrcy2; + unsigned char *ptrsrcy3, *ptrsrcy4; + unsigned char *ptrsrccb1; + unsigned char *ptrsrccb3; + unsigned char *ptrsrccr1; + unsigned char *ptrsrccr3; + uint32_t srcystride, srcccstride; + + ptrsrcy1 = bufsrc ; + ptrsrcy2 = bufsrc + (width << 1); + ptrsrcy3 = bufsrc + (width << 1) * 2; + ptrsrcy4 = bufsrc + (width << 1) * 3; + + ptrsrccb1 = bufsrc + 1; + ptrsrccb3 = bufsrc + (width << 1) * 2 + 1; + + ptrsrccr1 = bufsrc + 3; + ptrsrccr3 = bufsrc + (width << 1) * 2 + 3; + + srcystride = (width << 1) * 3; + srcccstride = (width << 1) * 3; + + /* Destination */ + unsigned char *ptrdesty1, *ptrdesty2; + unsigned char *ptrdesty3, *ptrdesty4; + unsigned char *ptrdestcb1, *ptrdestcb2; + unsigned char *ptrdestcr1, *ptrdestcr2; + uint32_t destystride, destccstride; + + ptrdesty1 = bufdest; + ptrdesty2 = bufdest + width; + ptrdesty3 = bufdest + width * 2; + ptrdesty4 = bufdest + width * 3; + + ptrdestcb1 = bufdest + width * height; + ptrdestcb2 = bufdest + width * height + (width >> 1); + + ptrdestcr1 = bufdest + width * height + ((width * height) >> 2); + ptrdestcr2 = bufdest + width * height + ((width * height) >> 2) + + (width >> 1); + + destystride = width * 3; + destccstride = (width >> 1); + + for (j = 0; j < (height / 4); j++) { + for (i = 0; i < (width / 2); i++) { + (*ptrdesty1++) = (*ptrsrcy1); + (*ptrdesty2++) = (*ptrsrcy2); + (*ptrdesty3++) = (*ptrsrcy3); + (*ptrdesty4++) = (*ptrsrcy4); + + ptrsrcy1 += 2; + ptrsrcy2 += 2; + ptrsrcy3 += 2; + ptrsrcy4 += 2; + + (*ptrdesty1++) = (*ptrsrcy1); + (*ptrdesty2++) = (*ptrsrcy2); + (*ptrdesty3++) = (*ptrsrcy3); + (*ptrdesty4++) = (*ptrsrcy4); + + ptrsrcy1 += 2; + ptrsrcy2 += 2; + ptrsrcy3 += 2; + ptrsrcy4 += 2; + + (*ptrdestcb1++) = (*ptrsrccb1); + (*ptrdestcb2++) = (*ptrsrccb3); + + ptrsrccb1 += 4; + ptrsrccb3 += 4; + + (*ptrdestcr1++) = (*ptrsrccr1); + (*ptrdestcr2++) = (*ptrsrccr3); + + ptrsrccr1 += 4; + ptrsrccr3 += 4; + + } + + /* Update src pointers */ + ptrsrcy1 += srcystride; + ptrsrcy2 += srcystride; + ptrsrcy3 += srcystride; + ptrsrcy4 += srcystride; + + ptrsrccb1 += srcccstride; + ptrsrccb3 += srcccstride; + + ptrsrccr1 += srcccstride; + ptrsrccr3 += srcccstride; + + /* Update dest pointers */ + ptrdesty1 += destystride; + ptrdesty2 += destystride; + ptrdesty3 += destystride; + ptrdesty4 += destystride; + + ptrdestcb1 += destccstride; + ptrdestcb2 += destccstride; + + ptrdestcr1 += destccstride; + ptrdestcr2 += destccstride; + } +} + +static void yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height, uint32_t yvu) +{ + uint32_t i, j; + const unsigned char *src1; + unsigned char *udest, *vdest; + + /* copy the Y values */ + src1 = src; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j += 2) { + *dest++ = src1[0]; + *dest++ = src1[2]; + src1 += 4; + } + } + + /* copy the U and V values */ + src++; /* point to V */ + src1 = src + width * 2; /* next line */ + if (yvu) { + vdest = dest; + udest = dest + width * height / 4; + } else { + udest = dest; + vdest = dest + width * height / 4; + } + for (i = 0; i < height; i += 2) { + for (j = 0; j < width; j += 2) { + *udest++ = ((int) src[0] + src1[0]) / 2; /* U */ + *vdest++ = ((int) src[2] + src1[2]) / 2; /* V */ + src += 4; + src1 += 4; + } + src = src1; + src1 += width * 2; + } +} + +#define RGB2Y(r, g, b, y) \ + (y) = ((8453 * (r) + 16594 * (g) + 3223 * (b) + 524288) >> 15) + +#define RGB2UV(r, g, b, u, v) \ + do { \ + (u) = ((-4878 * (r) - 9578 * (g) + 14456 * (b) + 4210688) >> 15); \ + (v) = ((14456 * (r) - 12105 * (g) - 2351 * (b) + 4210688) >> 15); \ + } while (0) + +#define CLIP(color) \ + (unsigned char)(((color) > 0xFF) ? 0xff : (((color) < 0) ? 0 : (color))) + +static void rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height, uint32_t yvu) +{ + uint32_t x, y; + uint32_t halfWidth; + uint8_t *yplane, *uplane, *vplane; + uint8_t *yline, *uline, *vline; + const uint8_t *rgbIndex; + + halfWidth = width >> 1; + yplane = dest; + + if (yvu) { + vplane = dest + width * height; + uplane = vplane + ((width * height) >> 2); + } else { + uplane = dest + width * height; + vplane = uplane + ((width * height) >> 2); + } + + for (y = 0; y < height; y++) { + yline = yplane + (y * width); + uline = uplane + ((y >> 1) * halfWidth); + vline = vplane + ((y >> 1) * halfWidth); + + rgbIndex = src + (width * (height - 1 - y) * 3); + for (x = 0; x < (int)width; x+=2) { + RGB2Y(rgbIndex[2], rgbIndex[1], rgbIndex[0], *yline++); + rgbIndex += 3; + RGB2Y(rgbIndex[2], rgbIndex[1], rgbIndex[0], *yline++); + RGB2UV(rgbIndex[2], rgbIndex[1], rgbIndex[0], *uline++, *vline++); + rgbIndex += 3; + } + } +} + +static void rgb24_to_yuyv(unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height) +{ + uint32_t i, j; + uint8_t *ptr; + + for (i = 0; i < height; i++) { + ptr = src + (width * (height - 1 - i) * 3); + for (j = 0; j < width; j += 2) { + /* y */ + *dest++ = CLIP(0.299 * (ptr[2] - 128) + + 0.587 * (ptr[1] - 128) + + 0.114 * (ptr[0] - 128) + 128); + /* u */ + *dest++ = CLIP(((-0.147 * (ptr[2] - 128) - + 0.289 * (ptr[1] - 128) + + 0.436 * (ptr[0] - 128) + 128) + + (-0.147 * (ptr[5] - 128) - + 0.289 * (ptr[4] - 128) + + 0.436 * (ptr[3] - 128) + 128)) / 2); + /* y1 */ + *dest++ = CLIP(0.299 * (ptr[5] - 128) + + 0.587 * (ptr[4] - 128) + + 0.114 * (ptr[3] - 128) + 128); + /* v */ + *dest++ = CLIP(((0.615 * (ptr[2] - 128) - + 0.515 * (ptr[1] - 128) - + 0.100 * (ptr[0] - 128) + 128) + + (0.615 * (ptr[5] - 128) - + 0.515 * (ptr[4] - 128) - + 0.100 * (ptr[3] - 128) + 128)) / 2); + ptr += 6; + } + } +} + +static void yuv420_to_yvu420(unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height) +{ + unsigned char *psrc_y, *pdst_y; + unsigned char *psrc_u, *pdst_u; + unsigned char *psrc_v, *pdst_v; + + psrc_y = src; + psrc_u = psrc_y + (width * height); + psrc_v = psrc_u + (width * height / 4); + + pdst_y = dest; + pdst_v = pdst_y + (width * height); + pdst_u = pdst_v + (width * height / 4); + + memcpy(pdst_y, psrc_y, width * height); + memcpy(pdst_v, psrc_v, width * height / 4); + memcpy(pdst_u, psrc_u, width * height / 4); +} + +static void yuv420_to_yuyv(unsigned char *src, unsigned char *dest, + uint32_t width, uint32_t height) +{ + unsigned char *py; + unsigned char *pu; + unsigned char *pv; + + uint32_t linesize = width * 2; + uint32_t uvlinesize = width / 2; + uint32_t offset = 0; + uint32_t offset1 = 0; + uint32_t offsety = 0; + uint32_t offsety1 = 0; + uint32_t offsetuv = 0; + uint32_t h = 0; + uint32_t w = 0; + uint32_t wy = 0; + uint32_t huv = 0; + uint32_t wuv = 0; + + py = src; + pu = py + (width * height); + pv = pu + (width * height / 4); + + for (h = 0; h < height; h += 2) { + wy = 0; + wuv = 0; + offset = h * linesize; + offset1 = (h + 1) * linesize; + offsety = h * width; + offsety1 = (h + 1) * width; + offsetuv = huv * uvlinesize; + + for (w = 0; w < linesize; w += 4) { + /* y00 */ + dest[w + offset] = py[wy + offsety]; + /* u0 */ + dest[(w + 1) + offset] = pu[wuv + offsetuv]; + /* y01 */ + dest[(w + 2) + offset] = py[(wy + 1) + offsety]; + /* v0 */ + dest[(w + 3) + offset] = pv[wuv + offsetuv]; + + /* y10 */ + dest[w + offset1] = py[wy + offsety1]; + /* u0 */ + dest[(w + 1) + offset1] = pu[wuv + offsetuv]; + /* y11 */ + dest[(w + 2) + offset1] = py[(wy + 1) + offsety1]; + /* v0 */ + dest[(w + 3) + offset1] = pv[wuv + offsetuv]; + + wuv++; + wy += 2; + } + huv++; + } +} diff --git a/tizen/src/hw/pci/maru_camera_darwin.h b/tizen/src/hw/pci/maru_camera_convert.h similarity index 68% rename from tizen/src/hw/pci/maru_camera_darwin.h rename to tizen/src/hw/pci/maru_camera_convert.h index 2ac39f9172..8252d7db88 100644 --- a/tizen/src/hw/pci/maru_camera_darwin.h +++ b/tizen/src/hw/pci/maru_camera_convert.h @@ -1,12 +1,12 @@ /* - * Header of MARU Virtual Camera device for MacOS. + * Convert header of MARU Virtual Camera device. * * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: * Jun Tian - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,8 +28,8 @@ * */ -#ifndef _MARU_CAMERA_DARWIN_H_ -#define _MARU_CAMERA_DARWIN_H_ +#ifndef _MARU_CAMERA_CONVERT_H_ +#define _MARU_CAMERA_CONVERT_H_ #define MAKEFOURCC(a, b, c, d) \ (((uint32_t)(a) << 0) | \ @@ -82,7 +82,41 @@ /* 16 YUV 4:2:2 */ #define V4L2_PIX_FMT_YYUV MAKEFOURCC('Y', 'Y', 'U', 'V') -void convert_frame(uint32_t pixel_format, int frame_width, int frame_height, - size_t frame_size, void *frame_pixels, void *video_buf); +/* V4L2 defines copy from videodev2.h */ +#define V4L2_CTRL_FLAG_SLIDER 0x0020 -#endif /* _MARU_CAMERA_DARWIN_H_ */ +#define V4L2_CTRL_CLASS_USER 0x00980000 +#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) +#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE + 0) +#define V4L2_CID_CONTRAST (V4L2_CID_BASE + 1) +#define V4L2_CID_SATURATION (V4L2_CID_BASE + 2) +#define V4L2_CID_SHARPNESS (V4L2_CID_BASE + 27) + +inline uint32_t get_bytesperline(uint32_t pixfmt, uint32_t width) +{ + uint32_t bytesperline; + + switch (pixfmt) { + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + bytesperline = (width * 12) >> 3; + break; + case V4L2_PIX_FMT_YUYV: + default: + bytesperline = width * 2; + break; + } + + return bytesperline; +} + +inline uint32_t get_sizeimage(uint32_t pixfmt, uint32_t width, uint32_t height) +{ + return get_bytesperline(pixfmt, width) * height; +} + +uint8_t convert_frame(uint32_t src_format, uint32_t dst_format, + uint32_t width, uint32_t height, size_t frame_size, + void *src_buf, void *dst_buf) + +#endif /* _MARU_CAMERA_CONVERT_H_ */ diff --git a/tizen/src/hw/pci/maru_camera_darwin_pci.m b/tizen/src/hw/pci/maru_camera_darwin.m similarity index 95% rename from tizen/src/hw/pci/maru_camera_darwin_pci.m rename to tizen/src/hw/pci/maru_camera_darwin.m index b470da3662..26f29afb7a 100644 --- a/tizen/src/hw/pci/maru_camera_darwin_pci.m +++ b/tizen/src/hw/pci/maru_camera_darwin.m @@ -5,8 +5,8 @@ * * Contact: * Jun Tian - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -34,24 +34,14 @@ #include #include "qemu-common.h" -#include "maru_camera_common.h" -#include "maru_camera_darwin.h" +#include "maru_camera.h" +#include "maru_camera_convert.h" #include "debug_ch.h" MULTI_DEBUG_CHANNEL(tizen, camera); #define MARUCAM_THREAD_NAME "marucam_worker_thread" -/* V4L2 defines copy from videodev2.h */ -#define V4L2_CTRL_FLAG_SLIDER 0x0020 - -#define V4L2_CTRL_CLASS_USER 0x00980000 -#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) -#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE + 0) -#define V4L2_CID_CONTRAST (V4L2_CID_BASE + 1) -#define V4L2_CID_SATURATION (V4L2_CID_BASE + 2) -#define V4L2_CID_SHARPNESS (V4L2_CID_BASE + 27) - typedef struct tagMaruCamConvertPixfmt { uint32_t fmt; /* fourcc */ uint32_t bpp; /* bits per pixel, 0 for compressed formats */ @@ -144,30 +134,6 @@ static uint32_t corevideo_to_fourcc(uint32_t cv_pix_fmt) } } -static uint32_t get_bytesperline(uint32_t pixfmt, uint32_t width) -{ - uint32_t bytesperline; - - switch (pixfmt) { - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_YVU420: - bytesperline = (width * 12) >> 3; - break; - case V4L2_PIX_FMT_YUYV: - case V4L2_PIX_FMT_UYVY: - default: - bytesperline = width * 2; - break; - } - - return bytesperline; -} - -static uint32_t get_sizeimage(uint32_t pixfmt, uint32_t width, uint32_t height) -{ - return get_bytesperline(pixfmt, width) * height; -} - /****************************************************************** ** Maru Camera Implementation *****************************************************************/ @@ -307,6 +273,7 @@ static uint32_t get_sizeimage(uint32_t pixfmt, uint32_t width, uint32_t height) const int frame_height = CVPixelBufferGetHeight(mCurrentImageBuffer); const size_t frame_size = CVPixelBufferGetBytesPerRow(mCurrentImageBuffer) * frame_height; const void *frame_pixels = CVPixelBufferGetBaseAddress(mCurrentImageBuffer); + const uint32_t dst_format = supported_dst_pixfmts[cur_fmt_idx].fmt; TRACE("buffer(%p), pixel_format(%d,%.4s), frame_width(%d), " "frame_height(%d), frame_size(%d)\n", @@ -315,7 +282,7 @@ static uint32_t get_sizeimage(uint32_t pixfmt, uint32_t width, uint32_t height) frame_height, (int)frame_size); /* convert frame to v4l2 format */ - convert_frame(pixel_format, frame_width, frame_height, + convert_frame(pixel_format, dst_format, frame_width, frame_height, frame_size, (void *)frame_pixels, video_buf); CVPixelBufferUnlockBaseAddress(mCurrentImageBuffer, 0); [pool release]; diff --git a/tizen/src/hw/pci/maru_camera_darwin_converter.c b/tizen/src/hw/pci/maru_camera_darwin_converter.c deleted file mode 100644 index 3f9cec5f4f..0000000000 --- a/tizen/src/hw/pci/maru_camera_darwin_converter.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - * Implementation of color conversion for MARU Virtual Camera device on MacOS. - * - * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved - * - * Contact: - * Jun Tian - * JinHyung Jo - * YeongKyoon Lee - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * 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 General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -#include "qemu-common.h" -#include "maru_camera_darwin.h" -#include "debug_ch.h" - -MULTI_DEBUG_CHANNEL(tizen, camera); - -static void UYVYToYUV420(unsigned char *bufsrc, unsigned char *bufdest, - int width, int height); -static void YVU420ToYUV420(unsigned char *bufsrc, unsigned char *bufdest, - int width, int height); -static void YUYVToYUV420(unsigned char *bufsrc, unsigned char *bufdest, - int width, int height); - -/* Convert pixel format to YUV420 */ -void convert_frame(uint32_t pixel_format, int frame_width, int frame_height, - size_t frame_size, void *frame_pixels, void *video_buf) -{ - switch (pixel_format) { - case V4L2_PIX_FMT_YUV420: - memcpy(video_buf, (void *)frame_pixels, (size_t)frame_size); - break; - case V4L2_PIX_FMT_YVU420: - YVU420ToYUV420(frame_pixels, video_buf, frame_width, frame_height); - break; - case V4L2_PIX_FMT_YUYV: - YUYVToYUV420(frame_pixels, video_buf, frame_width, frame_height); - break; - case V4L2_PIX_FMT_UYVY: /* Mac default format */ - UYVYToYUV420(frame_pixels, video_buf, frame_width, frame_height); - break; - default: - ERR("Cannot convert the pixel format (%.4s)...\n", - (const char *)&pixel_format); - break; - } -} - -static void UYVYToYUV420(unsigned char *bufsrc, unsigned char *bufdest, - int width, int height) -{ - int i, j; - - /* Source */ - unsigned char *ptrsrcy1, *ptrsrcy2; - unsigned char *ptrsrcy3, *ptrsrcy4; - unsigned char *ptrsrccb1; - unsigned char *ptrsrccb3; - unsigned char *ptrsrccr1; - unsigned char *ptrsrccr3; - int srcystride, srcccstride; - - ptrsrcy1 = bufsrc + 1; - ptrsrcy2 = bufsrc + (width << 1) + 1; - ptrsrcy3 = bufsrc + (width << 1) * 2 + 1; - ptrsrcy4 = bufsrc + (width << 1) * 3 + 1; - - ptrsrccb1 = bufsrc; - ptrsrccb3 = bufsrc + (width << 1) * 2; - - ptrsrccr1 = bufsrc + 2; - ptrsrccr3 = bufsrc + (width << 1) * 2 + 2; - - srcystride = (width << 1) * 3; - srcccstride = (width << 1) * 3; - - /* Destination */ - unsigned char *ptrdesty1, *ptrdesty2; - unsigned char *ptrdesty3, *ptrdesty4; - unsigned char *ptrdestcb1, *ptrdestcb2; - unsigned char *ptrdestcr1, *ptrdestcr2; - int destystride, destccstride; - - ptrdesty1 = bufdest; - ptrdesty2 = bufdest + width; - ptrdesty3 = bufdest + width * 2; - ptrdesty4 = bufdest + width * 3; - - ptrdestcb1 = bufdest + width * height; - ptrdestcb2 = bufdest + width * height + (width >> 1); - - ptrdestcr1 = bufdest + width * height + ((width*height) >> 2); - ptrdestcr2 = bufdest + width * height + ((width*height) >> 2) - + (width >> 1); - - destystride = (width)*3; - destccstride = (width>>1); - - for (j = 0; j < (height / 4); j++) { - for (i = 0; i < (width / 2); i++) { - (*ptrdesty1++) = (*ptrsrcy1); - (*ptrdesty2++) = (*ptrsrcy2); - (*ptrdesty3++) = (*ptrsrcy3); - (*ptrdesty4++) = (*ptrsrcy4); - - ptrsrcy1 += 2; - ptrsrcy2 += 2; - ptrsrcy3 += 2; - ptrsrcy4 += 2; - - (*ptrdesty1++) = (*ptrsrcy1); - (*ptrdesty2++) = (*ptrsrcy2); - (*ptrdesty3++) = (*ptrsrcy3); - (*ptrdesty4++) = (*ptrsrcy4); - - ptrsrcy1 += 2; - ptrsrcy2 += 2; - ptrsrcy3 += 2; - ptrsrcy4 += 2; - - (*ptrdestcb1++) = (*ptrsrccb1); - (*ptrdestcb2++) = (*ptrsrccb3); - - ptrsrccb1 += 4; - ptrsrccb3 += 4; - - (*ptrdestcr1++) = (*ptrsrccr1); - (*ptrdestcr2++) = (*ptrsrccr3); - - ptrsrccr1 += 4; - ptrsrccr3 += 4; - - } - - /* Update src pointers */ - ptrsrcy1 += srcystride; - ptrsrcy2 += srcystride; - ptrsrcy3 += srcystride; - ptrsrcy4 += srcystride; - - ptrsrccb1 += srcccstride; - ptrsrccb3 += srcccstride; - - ptrsrccr1 += srcccstride; - ptrsrccr3 += srcccstride; - - /* Update dest pointers */ - ptrdesty1 += destystride; - ptrdesty2 += destystride; - ptrdesty3 += destystride; - ptrdesty4 += destystride; - - ptrdestcb1 += destccstride; - ptrdestcb2 += destccstride; - - ptrdestcr1 += destccstride; - ptrdestcr2 += destccstride; - } -} - -static void YVU420ToYUV420(unsigned char *bufsrc, unsigned char *bufdest, - int width, int height) -{ - int i, j; - - /* Source*/ - unsigned char *ptrsrcy1, *ptrsrcy2; - unsigned char *ptrsrcy3, *ptrsrcy4; - unsigned char *ptrsrccb1, *ptrsrccb2; - unsigned char *ptrsrccr1, *ptrsrccr2; - int srcystride, srcccstride; - - ptrsrcy1 = bufsrc; - ptrsrcy2 = bufsrc + width; - ptrsrcy3 = bufsrc + width*2; - ptrsrcy4 = bufsrc + width*3; - - ptrsrccr1 = bufsrc + width*height; - ptrsrccr2 = bufsrc + width*height + (width>>1); - - ptrsrccb1 = bufsrc + width*height + ((width*height) >> 2); - ptrsrccb2 = bufsrc + width*height + ((width*height) >> 2) + (width>>1); - - srcystride = (width)*3; - srcccstride = (width>>1); - - /* Destination */ - unsigned char *ptrdesty1, *ptrdesty2; - unsigned char *ptrdesty3, *ptrdesty4; - unsigned char *ptrdestcb1, *ptrdestcb2; - unsigned char *ptrdestcr1, *ptrdestcr2; - int destystride, destccstride; - - ptrdesty1 = bufdest; - ptrdesty2 = bufdest + width; - ptrdesty3 = bufdest + width * 2; - ptrdesty4 = bufdest + width * 3; - - ptrdestcb1 = bufdest + width * height; - ptrdestcb2 = bufdest + width * height + (width >> 1); - - ptrdestcr1 = bufdest + width * height + ((width*height) >> 2); - ptrdestcr2 = bufdest + width * height + ((width*height) >> 2) - + (width >> 1); - - destystride = (width)*3; - destccstride = (width>>1); - - for (j = 0; j < (height / 4); j++) { - for (i = 0; i < (width / 2); i++) { - - (*ptrdesty1++) = (*ptrsrcy1++); - (*ptrdesty2++) = (*ptrsrcy2++); - (*ptrdesty3++) = (*ptrsrcy3++); - (*ptrdesty4++) = (*ptrsrcy4++); - (*ptrdesty1++) = (*ptrsrcy1++); - (*ptrdesty2++) = (*ptrsrcy2++); - (*ptrdesty3++) = (*ptrsrcy3++); - (*ptrdesty4++) = (*ptrsrcy4++); - - (*ptrdestcb1++) = (*ptrsrccb1++); - (*ptrdestcr1++) = (*ptrsrccr1++); - (*ptrdestcb2++) = (*ptrsrccb2++); - (*ptrdestcr2++) = (*ptrsrccr2++); - - } - - /* Update src pointers */ - ptrsrcy1 += srcystride; - ptrsrcy2 += srcystride; - ptrsrcy3 += srcystride; - ptrsrcy4 += srcystride; - - ptrsrccb1 += srcccstride; - ptrsrccb2 += srcccstride; - - ptrsrccr1 += srcccstride; - ptrsrccr2 += srcccstride; - - /* Update dest pointers */ - ptrdesty1 += destystride; - ptrdesty2 += destystride; - ptrdesty3 += destystride; - ptrdesty4 += destystride; - - ptrdestcb1 += destccstride; - ptrdestcb2 += destccstride; - - ptrdestcr1 += destccstride; - ptrdestcr2 += destccstride; - - } - -} - -static void YUYVToYUV420(unsigned char *bufsrc, unsigned char *bufdest, - int width, int height) -{ - int i, j; - - /* Source*/ - unsigned char *ptrsrcy1, *ptrsrcy2; - unsigned char *ptrsrcy3, *ptrsrcy4; - unsigned char *ptrsrccb1; - unsigned char *ptrsrccb3; - unsigned char *ptrsrccr1; - unsigned char *ptrsrccr3; - int srcystride, srcccstride; - - ptrsrcy1 = bufsrc ; - ptrsrcy2 = bufsrc + (width << 1); - ptrsrcy3 = bufsrc + (width << 1) * 2; - ptrsrcy4 = bufsrc + (width << 1) * 3; - - ptrsrccb1 = bufsrc + 1; - ptrsrccb3 = bufsrc + (width << 1) * 2 + 1; - - ptrsrccr1 = bufsrc + 3; - ptrsrccr3 = bufsrc + (width << 1) * 2 + 3; - - srcystride = (width << 1) * 3; - srcccstride = (width << 1) * 3; - - /* Destination */ - unsigned char *ptrdesty1, *ptrdesty2; - unsigned char *ptrdesty3, *ptrdesty4; - unsigned char *ptrdestcb1, *ptrdestcb2; - unsigned char *ptrdestcr1, *ptrdestcr2; - int destystride, destccstride; - - ptrdesty1 = bufdest; - ptrdesty2 = bufdest + width; - ptrdesty3 = bufdest + width * 2; - ptrdesty4 = bufdest + width * 3; - - ptrdestcb1 = bufdest + width * height; - ptrdestcb2 = bufdest + width * height + (width >> 1); - - ptrdestcr1 = bufdest + width * height + ((width * height) >> 2); - ptrdestcr2 = bufdest + width * height + ((width * height) >> 2) - + (width >> 1); - - destystride = width * 3; - destccstride = (width >> 1); - - for (j = 0; j < (height / 4); j++) { - for (i = 0; i < (width / 2); i++) { - (*ptrdesty1++) = (*ptrsrcy1); - (*ptrdesty2++) = (*ptrsrcy2); - (*ptrdesty3++) = (*ptrsrcy3); - (*ptrdesty4++) = (*ptrsrcy4); - - ptrsrcy1 += 2; - ptrsrcy2 += 2; - ptrsrcy3 += 2; - ptrsrcy4 += 2; - - (*ptrdesty1++) = (*ptrsrcy1); - (*ptrdesty2++) = (*ptrsrcy2); - (*ptrdesty3++) = (*ptrsrcy3); - (*ptrdesty4++) = (*ptrsrcy4); - - ptrsrcy1 += 2; - ptrsrcy2 += 2; - ptrsrcy3 += 2; - ptrsrcy4 += 2; - - (*ptrdestcb1++) = (*ptrsrccb1); - (*ptrdestcb2++) = (*ptrsrccb3); - - ptrsrccb1 += 4; - ptrsrccb3 += 4; - - (*ptrdestcr1++) = (*ptrsrccr1); - (*ptrdestcr2++) = (*ptrsrccr3); - - ptrsrccr1 += 4; - ptrsrccr3 += 4; - - } - - /* Update src pointers */ - ptrsrcy1 += srcystride; - ptrsrcy2 += srcystride; - ptrsrcy3 += srcystride; - ptrsrcy4 += srcystride; - - ptrsrccb1 += srcccstride; - ptrsrccb3 += srcccstride; - - ptrsrccr1 += srcccstride; - ptrsrccr3 += srcccstride; - - /* Update dest pointers */ - ptrdesty1 += destystride; - ptrdesty2 += destystride; - ptrdesty3 += destystride; - ptrdesty4 += destystride; - - ptrdestcb1 += destccstride; - ptrdestcb2 += destccstride; - - ptrdestcr1 += destccstride; - ptrdestcr2 += destccstride; - } -} diff --git a/tizen/src/hw/pci/maru_camera_linux_pci.c b/tizen/src/hw/pci/maru_camera_linux.c similarity index 99% rename from tizen/src/hw/pci/maru_camera_linux_pci.c rename to tizen/src/hw/pci/maru_camera_linux.c index 406478b838..2a76c07ab1 100644 --- a/tizen/src/hw/pci/maru_camera_linux_pci.c +++ b/tizen/src/hw/pci/maru_camera_linux.c @@ -4,8 +4,8 @@ * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -29,7 +29,7 @@ #include "qemu-common.h" #include "sysemu/kvm.h" -#include "maru_camera_common.h" +#include "maru_camera.h" #include "debug_ch.h" #include diff --git a/tizen/src/hw/pci/maru_camera_win32_pci.c b/tizen/src/hw/pci/maru_camera_win32.c similarity index 87% rename from tizen/src/hw/pci/maru_camera_win32_pci.c rename to tizen/src/hw/pci/maru_camera_win32.c index 72bfbbb2ab..337c371ae0 100644 --- a/tizen/src/hw/pci/maru_camera_win32_pci.c +++ b/tizen/src/hw/pci/maru_camera_win32.c @@ -4,8 +4,8 @@ * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,7 +30,7 @@ #include "qemu-common.h" #include "sysemu/hax.h" -#include "maru_camera_common.h" +#include "maru_camera.h" #include "debug_ch.h" #define CINTERFACE @@ -38,7 +38,7 @@ #include "ocidl.h" #include "errors.h" /* for VFW_E_XXXX */ #include "mmsystem.h" /* for MAKEFOURCC macro */ -#include "maru_camera_win32_interface.h" +#include "maru_camera_win32.h" MULTI_DEBUG_CHANNEL(tizen, camera); @@ -1053,21 +1053,6 @@ IBaseFilter *g_pSrcFilter; IGrabCallback *g_pCallback; -/* V4L2 defines copy from videodev2.h */ -#define V4L2_CTRL_FLAG_SLIDER 0x0020 - -#define V4L2_CTRL_CLASS_USER 0x00980000 -#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) -#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0) -#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1) -#define V4L2_CID_SATURATION (V4L2_CID_BASE+2) -#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27) - -#define V4L2_PIX_FMT_YUYV MAKEFOURCC('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */ -#define V4L2_PIX_FMT_YUV420 MAKEFOURCC('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */ -#define V4L2_PIX_FMT_YVU420 MAKEFOURCC('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */ -#define V4L2_PIX_FMT_RGB24 MAKEFOURCC('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */ - typedef struct tagMaruCamConvertPixfmt { uint32_t fmt; /* fourcc */ uint32_t bpp; /* bits per pixel, 0 for compressed formats */ @@ -1124,43 +1109,9 @@ static uint32_t g_dwSrcFmt; /* - * Helper functions - converting image formats, converting values + * Helper functions - converting values */ -static uint32_t get_bytesperline(uint32_t pixfmt, uint32_t width) -{ - uint32_t bytesperline; - - switch (pixfmt) { - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_YVU420: - bytesperline = (width * 12) >> 3; - break; - case V4L2_PIX_FMT_YUYV: - default: - bytesperline = width * 2; - break; - } - - return bytesperline; -} - -static uint32_t get_sizeimage(uint32_t pixfmt, uint32_t width, uint32_t height) -{ - return get_bytesperline(pixfmt, width) * height; -} - -void yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height, uint32_t yvu); -void rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height, uint32_t yvu); -void rgb24_to_yuyv(unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height); -void yuv420_to_yvu420(unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height); -void yuv420_to_yuyv(unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height); - static long value_convert_from_guest(long min, long max, long value) { double rate = 0.0; @@ -1214,57 +1165,8 @@ static STDMETHODIMP marucam_device_callbackfn(ULONG dwSize, BYTE *pBuffer) return E_FAIL; } - switch (g_dwSrcFmt) { - case V4L2_PIX_FMT_YUYV: - switch (fmt) { - case V4L2_PIX_FMT_YUV420: - yuyv_to_yuv420(pBuffer, grab_buf, width, height, 0); - break; - case V4L2_PIX_FMT_YVU420: - yuyv_to_yuv420(pBuffer, grab_buf, width, height, 1); - break; - case V4L2_PIX_FMT_YUYV: - memcpy(grab_buf, (void *)pBuffer, (size_t)dwSize); - break; - default: - ERR("Invalid pixel format\n"); - return E_FAIL; - } - break; - case V4L2_PIX_FMT_RGB24: - switch (fmt) { - case V4L2_PIX_FMT_YUV420: - rgb24_to_yuv420(pBuffer, grab_buf, width, height, 0); - break; - case V4L2_PIX_FMT_YVU420: - rgb24_to_yuv420(pBuffer, grab_buf, width, height, 1); - break; - case V4L2_PIX_FMT_YUYV: - rgb24_to_yuyv(pBuffer, grab_buf, width, height); - break; - default: - ERR("Invalid pixel format\n"); - return E_FAIL; - } - break; - case V4L2_PIX_FMT_YUV420: - switch (fmt) { - case V4L2_PIX_FMT_YUV420: - memcpy(grab_buf, (void *)pBuffer, (size_t)dwSize); - break; - case V4L2_PIX_FMT_YVU420: - yuv420_to_yvu420(pBuffer, grab_buf, width, height); - break; - case V4L2_PIX_FMT_YUYV: - yuv420_to_yuyv(pBuffer, grab_buf, width, height); - break; - default: - ERR("Invalid pixel format\n"); - return E_FAIL; - } - break; - default: - ERR("Invalid pixel format\n"); + if (convert_frame(g_dwSrcFmt, fmt, width, height, + (size_t)dwSize, pBuffer, grab_buf) > 0) { return E_FAIL; } @@ -2595,205 +2497,3 @@ void marucam_device_enum_fintv(MaruCamState *state) } param->stack[0] = 1; /* numerator */ } - -void yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height, uint32_t yvu) -{ - uint32_t i, j; - const unsigned char *src1; - unsigned char *udest, *vdest; - - /* copy the Y values */ - src1 = src; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j += 2) { - *dest++ = src1[0]; - *dest++ = src1[2]; - src1 += 4; - } - } - - /* copy the U and V values */ - src++; /* point to V */ - src1 = src + width * 2; /* next line */ - if (yvu) { - vdest = dest; - udest = dest + width * height / 4; - } else { - udest = dest; - vdest = dest + width * height / 4; - } - for (i = 0; i < height; i += 2) { - for (j = 0; j < width; j += 2) { - *udest++ = ((int) src[0] + src1[0]) / 2; /* U */ - *vdest++ = ((int) src[2] + src1[2]) / 2; /* V */ - src += 4; - src1 += 4; - } - src = src1; - src1 += width * 2; - } -} - -#define RGB2Y(r, g, b, y) \ - (y) = ((8453 * (r) + 16594 * (g) + 3223 * (b) + 524288) >> 15) - -#define RGB2UV(r, g, b, u, v) \ - do { \ - (u) = ((-4878 * (r) - 9578 * (g) + 14456 * (b) + 4210688) >> 15); \ - (v) = ((14456 * (r) - 12105 * (g) - 2351 * (b) + 4210688) >> 15); \ - } while (0) - -#define CLIP(color) \ - (unsigned char)(((color) > 0xFF) ? 0xff : (((color) < 0) ? 0 : (color))) - -void rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height, uint32_t yvu) -{ - uint32_t x, y; - uint32_t halfWidth; - uint8_t *yplane, *uplane, *vplane; - uint8_t *yline, *uline, *vline; - const uint8_t *rgbIndex; - - halfWidth = width >> 1; - yplane = dest; - - if (yvu) { - vplane = dest + width * height; - uplane = vplane + ((width * height) >> 2); - } else { - uplane = dest + width * height; - vplane = uplane + ((width * height) >> 2); - } - - for (y = 0; y < height; y++) { - yline = yplane + (y * width); - uline = uplane + ((y >> 1) * halfWidth); - vline = vplane + ((y >> 1) * halfWidth); - - rgbIndex = src + (width * (height - 1 - y) * 3); - for (x = 0; x < (int)width; x+=2) { - RGB2Y(rgbIndex[2], rgbIndex[1], rgbIndex[0], *yline++); - rgbIndex += 3; - RGB2Y(rgbIndex[2], rgbIndex[1], rgbIndex[0], *yline++); - RGB2UV(rgbIndex[2], rgbIndex[1], rgbIndex[0], *uline++, *vline++); - rgbIndex += 3; - } - } -} - -void rgb24_to_yuyv(unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height) -{ - uint32_t i, j; - uint8_t *ptr; - - for (i = 0; i < height; i++) { - ptr = src + (width * (height - 1 - i) * 3); - for (j = 0; j < width; j += 2) { - /* y */ - *dest++ = CLIP(0.299 * (ptr[2] - 128) + - 0.587 * (ptr[1] - 128) + - 0.114 * (ptr[0] - 128) + 128); - /* u */ - *dest++ = CLIP(((-0.147 * (ptr[2] - 128) - - 0.289 * (ptr[1] - 128) + - 0.436 * (ptr[0] - 128) + 128) + - (-0.147 * (ptr[5] - 128) - - 0.289 * (ptr[4] - 128) + - 0.436 * (ptr[3] - 128) + 128)) / 2); - /* y1 */ - *dest++ = CLIP(0.299 * (ptr[5] - 128) + - 0.587 * (ptr[4] - 128) + - 0.114 * (ptr[3] - 128) + 128); - /* v */ - *dest++ = CLIP(((0.615 * (ptr[2] - 128) - - 0.515 * (ptr[1] - 128) - - 0.100 * (ptr[0] - 128) + 128) + - (0.615 * (ptr[5] - 128) - - 0.515 * (ptr[4] - 128) - - 0.100 * (ptr[3] - 128) + 128)) / 2); - ptr += 6; - } - } -} - -void yuv420_to_yvu420(unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height) -{ - unsigned char *psrc_y, *pdst_y; - unsigned char *psrc_u, *pdst_u; - unsigned char *psrc_v, *pdst_v; - - psrc_y = src; - psrc_u = psrc_y + (width * height); - psrc_v = psrc_u + (width * height / 4); - - pdst_y = dest; - pdst_v = pdst_y + (width * height); - pdst_u = pdst_v + (width * height / 4); - - memcpy(pdst_y, psrc_y, width * height); - memcpy(pdst_v, psrc_v, width * height / 4); - memcpy(pdst_u, psrc_u, width * height / 4); -} - -void yuv420_to_yuyv(unsigned char *src, unsigned char *dest, - uint32_t width, uint32_t height) -{ - unsigned char *py; - unsigned char *pu; - unsigned char *pv; - - uint32_t linesize = width * 2; - uint32_t uvlinesize = width / 2; - uint32_t offset = 0; - uint32_t offset1 = 0; - uint32_t offsety = 0; - uint32_t offsety1 = 0; - uint32_t offsetuv = 0; - uint32_t h = 0; - uint32_t w = 0; - uint32_t wy = 0; - uint32_t huv = 0; - uint32_t wuv = 0; - - py = src; - pu = py + (width * height); - pv = pu + (width * height / 4); - - for (h = 0; h < height; h += 2) { - wy = 0; - wuv = 0; - offset = h * linesize; - offset1 = (h + 1) * linesize; - offsety = h * width; - offsety1 = (h + 1) * width; - offsetuv = huv * uvlinesize; - - for (w = 0; w < linesize; w += 4) { - /* y00 */ - dest[w + offset] = py[wy + offsety]; - /* u0 */ - dest[(w + 1) + offset] = pu[wuv + offsetuv]; - /* y01 */ - dest[(w + 2) + offset] = py[(wy + 1) + offsety]; - /* v0 */ - dest[(w + 3) + offset] = pv[wuv + offsetuv]; - - /* y10 */ - dest[w + offset1] = py[wy + offsety1]; - /* u0 */ - dest[(w + 1) + offset1] = pu[wuv + offsetuv]; - /* y11 */ - dest[(w + 2) + offset1] = py[(wy + 1) + offsety1]; - /* v0 */ - dest[(w + 3) + offset1] = pv[wuv + offsetuv]; - - wuv++; - wy += 2; - } - huv++; - } -} diff --git a/tizen/src/hw/pci/maru_camera_win32_interface.h b/tizen/src/hw/pci/maru_camera_win32.h similarity index 99% rename from tizen/src/hw/pci/maru_camera_win32_interface.h rename to tizen/src/hw/pci/maru_camera_win32.h index c38a785d99..f1dcd8b212 100644 --- a/tizen/src/hw/pci/maru_camera_win32_interface.h +++ b/tizen/src/hw/pci/maru_camera_win32.h @@ -4,8 +4,8 @@ * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: - * JinHyung Jo - * YeongKyoon Lee + * Jinhyung Jo + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,8 +27,8 @@ * */ -#ifndef _MARU_CAMERA_INTERFACE_H_ -#define _MARU_CAMERA_INTERFACE_H_ +#ifndef _MARU_CAMERA_WIN32_H_ +#define _MARU_CAMERA_WIN32_H_ static const WCHAR HWCPinName[] = L"HWCInputPin\0"; static const WCHAR HWCFilterName[] = L"HWCFilter\0"; @@ -929,4 +929,4 @@ DECLARE_INTERFACE_(IMediaControl, IDispatch) ((This)->lpVtbl->FindPin(This,pSource,pindir,pCategory,pType,fUnconnected,num,ppPin)) #endif /* COBJMACROS */ -#endif /* _MARU_CAMERA_INTERFACE_H_ */ +#endif /* _MARU_CAMERA_WIN32_H_ */ diff --git a/tizen/src/util/check_cam.c b/tizen/src/util/check_cam.c index 8a0fc40602..3d2ec9953f 100644 --- a/tizen/src/util/check_cam.c +++ b/tizen/src/util/check_cam.c @@ -5,7 +5,7 @@ * * Contact: * Jinhyung Jo - * YeongKyoon Lee + * Sangho Park * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,7 +37,7 @@ #include "ocidl.h" #include "errors.h" /* for VFW_E_XXXX */ #include "mmsystem.h" /* for MAKEFOURCC macro */ -#include "hw/pci/maru_camera_win32_interface.h" +#include "hw/pci/maru_camera_win32.h" /* * COM Interface implementations -- 2.34.1