?? dc1394_conversions.c
字號:
/* * 1394-Based Digital Camera Control Library * Color conversion functions, including Bayer pattern decoding * Copyright (C) Damien Douxchamps <ddouxchamps@users.sf.net> * * Written by Damien Douxchamps and Frederic Devernay * * This library 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 library 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 library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "dc1394_conversions.h"// this should disappear...extern void swab();/********************************************************************** * * CONVERSION FUNCTIONS TO UYVY * **********************************************************************/voiddc1394_YUV422_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order){ switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: swab(src, dest, (width*height) << 1); break; case DC1394_BYTE_ORDER_UYVY: memcpy(dest,src, (width*height)<<1); break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; }}voiddc1394_YUV411_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order){ register int i=(width*height) + ((width*height) >> 1) -1; register int j=((width*height) << 1)-1; register int y0, y1, y2, y3, u, v; switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: while (i >= 0) { y3 = src[i--]; y2 = src[i--]; v = src[i--]; y1 = src[i--]; y0 = src[i--]; u = src[i--]; dest[j--] = v; dest[j--] = y3; dest[j--] = u; dest[j--] = y2; dest[j--] = v; dest[j--] = y1; dest[j--] = u; dest[j--] = y0; } break; case DC1394_BYTE_ORDER_UYVY: while (i >= 0) { y3 = src[i--]; y2 = src[i--]; v = src[i--]; y1 = src[i--]; y0 = src[i--]; u = src[i--]; dest[j--] = y3; dest[j--] = v; dest[j--] = y2; dest[j--] = u; dest[j--] = y1; dest[j--] = v; dest[j--] = y0; dest[j--] = u; } break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; }}voiddc1394_YUV444_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order){ register int i = (width*height) + ((width*height) << 1)-1; register int j = ((width*height) << 1)-1; register int y0, y1, u0, u1, v0, v1; switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: while (i >= 0) { v1 = src[i--]; y1 = src[i--]; u1 = src[i--]; v0 = src[i--]; y0 = src[i--]; u0 = src[i--]; dest[j--] = (v0+v1) >> 1; dest[j--] = y1; dest[j--] = (u0+u1) >> 1; dest[j--] = y0; } break; case DC1394_BYTE_ORDER_UYVY: while (i >= 0) { v1 = src[i--]; y1 = src[i--]; u1 = src[i--]; v0 = src[i--]; y0 = src[i--]; u0 = src[i--]; dest[j--] = y1; dest[j--] = (v0+v1) >> 1; dest[j--] = y0; dest[j--] = (u0+u1) >> 1; } break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; }}voiddc1394_MONO8_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order){ if ((width%2)==0) { // do it the quick way register int i = width*height - 1; register int j = (width*height << 1) - 1; register int y0, y1; switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: while (i >= 0) { y1 = src[i--]; y0 = src[i--]; dest[j--] = 128; dest[j--] = y1; dest[j--] = 128; dest[j--] = y0; } break; case DC1394_BYTE_ORDER_UYVY: while (i >= 0) { y1 = src[i--]; y0 = src[i--]; dest[j--] = y1; dest[j--] = 128; dest[j--] = y0; dest[j--] = 128; } break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; } } else { // width*2 != dest_pitch register int x, y; //assert ((dest_pitch - 2*width)==1); switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: y=height; while (y--) { x=width; while (x--) { *dest++ = *src++; *dest++ = 128; } // padding required, duplicate last column *dest++ = *(src-1); *dest++ = 128; } break; case DC1394_BYTE_ORDER_UYVY: y=height; while (y--) { x=width; while (x--) { *dest++ = 128; *dest++ = *src++; } // padding required, duplicate last column *dest++ = 128; *dest++ = *(src-1); } break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; } }}voiddc1394_MONO16_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order, uint_t bits){ register int i = ((width*height) << 1)-1; register int j = ((width*height) << 1)-1; register int y0, y1; switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: while (i >= 0) { y1 = src[i--]; y1 = (y1 + (((int)src[i--])<<8))>>(bits-8); y0 = src[i--]; y0 = (y0 + (((int)src[i--])<<8))>>(bits-8); dest[j--] = 128; dest[j--] = y1; dest[j--] = 128; dest[j--] = y0; } break; case DC1394_BYTE_ORDER_UYVY: while (i >= 0) { y1 = src[i--]; y1 = (y1 + (((int)src[i--])<<8))>>(bits-8); y0 = src[i--]; y0 = (y0 + (((int)src[i--])<<8))>>(bits-8); dest[j--] = y1; dest[j--] = 128; dest[j--] = y0; dest[j--] = 128; } break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; }}voiddc1394_MONO16_to_MONO8(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t bits){ register int i = ((width*height)<<1)-1; register int j = (width*height)-1; register int y; while (i >= 0) { y = src[i--]; dest[j--] = (y + (src[i--]<<8))>>(bits-8); }}voiddc1394_RGB8_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order){ register int i = (width*height) + ( (width*height) << 1 )-1; register int j = ((width*height) << 1)-1; register int y0, y1, u0, u1, v0, v1 ; register int r, g, b; switch (byte_order) { case DC1394_BYTE_ORDER_YUYV: while (i >= 0) { b = (uchar_t) src[i--]; g = (uchar_t) src[i--]; r = (uchar_t) src[i--]; RGB2YUV (r, g, b, y0, u0 , v0); b = (uchar_t) src[i--]; g = (uchar_t) src[i--]; r = (uchar_t) src[i--]; RGB2YUV (r, g, b, y1, u1 , v1); dest[j--] = (v0+v1) >> 1; dest[j--] = y0; dest[j--] = (u0+u1) >> 1; dest[j--] = y1; } break; case DC1394_BYTE_ORDER_UYVY: while (i >= 0) { b = (uchar_t) src[i--]; g = (uchar_t) src[i--]; r = (uchar_t) src[i--]; RGB2YUV (r, g, b, y0, u0 , v0); b = (uchar_t) src[i--]; g = (uchar_t) src[i--]; r = (uchar_t) src[i--]; RGB2YUV (r, g, b, y1, u1 , v1); dest[j--] = y0; dest[j--] = (v0+v1) >> 1; dest[j--] = y1; dest[j--] = (u0+u1) >> 1; } break; default: fprintf(stderr,"Invalid overlay byte order\n"); break; }}voiddc1394_RGB16_to_YUV422(uchar_t *restrict src, uchar_t *restrict dest, uint_t width, uint_t height, uint_t byte_order, uint_t bits)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -