color.c
Go to the documentation of this file.
00001 /****************************************************************************
00002 #               GspcaGui:  Gspca/Spca5xx Grabber                            #
00003 #               Copyright (C) 2004 2005 2006 Michel Xhaard                  #
00004 #                                                                           #
00005 # This program is free software; you can redistribute it and/or modify      #
00006 # it under the terms of the GNU General Public License as published by      #
00007 # the Free Software Foundation; either version 2 of the License, or         #
00008 # (at your option) any later version.                                       #
00009 #                                                                           #
00010 # This program is distributed in the hope that it will be useful,           #
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of            #
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
00013 # GNU General Public License for more details.                              #
00014 #                                                                           #
00015 # You should have received a copy of the GNU General Public License         #
00016 # along with this program; if not, write to the Free Software               #
00017 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA #
00018 #                                                                           #
00019 ****************************************************************************/ 
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <unistd.h> 
00023 #include "luvcview/color.h"
00024 
00025 static int *LutYr = NULL;
00026 static int *LutYg = NULL;;
00027 static int *LutYb = NULL;;
00028 static int *LutVr = NULL;;
00029 static int *LutVrY = NULL;;
00030 static int *LutUb = NULL;;
00031 static int *LutUbY = NULL;;
00032 static int *LutRv = NULL;
00033 static int *LutGu = NULL;
00034 static int *LutGv = NULL;
00035 static int *LutBu = NULL;
00036 
00037 #if 0
00038 #define RGB24_TO_Y(r,g,b) LutYr[(r)] + LutYg[(g)] + LutYb[(b)]
00039 #define YR_TO_V(r,y) LutVr[(r)] + LutVrY[(y)]
00040 #define YB_TO_U(b,y) LutUb[(b)] + LutUbY[(y)]
00041 
00042 #define R_FROMYV(y,v)  CLIP((y) + LutRv[(v)])
00043 #define G_FROMYUV(y,u,v) CLIP((y) + LutGu[(u)] + LutGv[(v)])
00044 #define B_FROMYU(y,u) CLIP((y) + LutBu[(u)])
00045 #endif
00046 
00047 unsigned char
00048 RGB24_TO_Y(unsigned char r, unsigned char g, unsigned char b)
00049 {
00050 return (LutYr[(r)] + LutYg[(g)] + LutYb[(b)]);
00051 }
00052 unsigned char
00053 YR_TO_V(unsigned char r, unsigned char y)
00054 {
00055 return (LutVr[(r)] + LutVrY[(y)]);
00056 }
00057 unsigned char
00058 YB_TO_U(unsigned char b, unsigned char y)
00059 {
00060 return (LutUb[(b)] + LutUbY[(y)]);
00061 }
00062 unsigned char
00063 R_FROMYV(unsigned char y, unsigned char v)
00064 {
00065 return CLIP((y) + LutRv[(v)]);
00066 }
00067 unsigned char
00068 G_FROMYUV(unsigned char y, unsigned char u, unsigned char v)
00069 {
00070 return CLIP((y) + LutGu[(u)] + LutGv[(v)]);
00071 }
00072 unsigned char
00073 B_FROMYU(unsigned char y, unsigned char u)
00074 {
00075 return CLIP((y) + LutBu[(u)]);
00076 }
00077 
00078 void initLut(void)
00079 {
00080         int i;
00081         #define Rcoef 299 
00082         #define Gcoef 587 
00083         #define Bcoef 114 
00084         #define Vrcoef 711 //656 //877 
00085         #define Ubcoef 560 //500 //493 564
00086         
00087         #define CoefRv 1402
00088         #define CoefGu 714 // 344
00089         #define CoefGv 344 // 714
00090         #define CoefBu 1772
00091         
00092         LutYr = malloc(256*sizeof(int));
00093         LutYg = malloc(256*sizeof(int));
00094         LutYb = malloc(256*sizeof(int));
00095         LutVr = malloc(256*sizeof(int));
00096         LutVrY = malloc(256*sizeof(int));
00097         LutUb = malloc(256*sizeof(int));
00098         LutUbY = malloc(256*sizeof(int));
00099         
00100         LutRv = malloc(256*sizeof(int));
00101         LutGu = malloc(256*sizeof(int));
00102         LutGv = malloc(256*sizeof(int));
00103         LutBu = malloc(256*sizeof(int));
00104         for (i= 0;i < 256;i++){
00105             LutYr[i] = i*Rcoef/1000 ;
00106             LutYg[i] = i*Gcoef/1000 ;
00107             LutYb[i] = i*Bcoef/1000 ;
00108             LutVr[i] = i*Vrcoef/1000;
00109             LutUb[i] = i*Ubcoef/1000;
00110             LutVrY[i] = 128 -(i*Vrcoef/1000);
00111             LutUbY[i] = 128 -(i*Ubcoef/1000);
00112             LutRv[i] = (i-128)*CoefRv/1000;
00113             LutBu[i] = (i-128)*CoefBu/1000;
00114             LutGu[i] = (128-i)*CoefGu/1000;
00115             LutGv[i] = (128-i)*CoefGv/1000;
00116         }       
00117 }
00118 
00119 
00120 void freeLut(void){
00121         free(LutYr);
00122         free(LutYg);
00123         free(LutYb);
00124         free(LutVr);
00125         free(LutVrY);
00126         free(LutUb);
00127         free(LutUbY);
00128         
00129         free(LutRv);
00130         free(LutGu);
00131         free(LutGv);
00132         free(LutBu);
00133 }
00134 


tuw_uvc
Author(s):
autogenerated on Sun May 29 2016 02:50:28