color.c
Go to the documentation of this file.
1 /****************************************************************************
2 # GspcaGui: Gspca/Spca5xx Grabber #
3 # Copyright (C) 2004 2005 2006 Michel Xhaard #
4 # #
5 # This program is free software; you can redistribute it and/or modify #
6 # it under the terms of the GNU General Public License as published by #
7 # the Free Software Foundation; either version 2 of the License, or #
8 # (at your option) any later version. #
9 # #
10 # This program is distributed in the hope that it will be useful, #
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
13 # GNU General Public License for more details. #
14 # #
15 # You should have received a copy of the GNU General Public License #
16 # along with this program; if not, write to the Free Software #
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
18 # #
19 ****************************************************************************/
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include "luvcview/color.h"
24 
25 static int *LutYr = NULL;
26 static int *LutYg = NULL;;
27 static int *LutYb = NULL;;
28 static int *LutVr = NULL;;
29 static int *LutVrY = NULL;;
30 static int *LutUb = NULL;;
31 static int *LutUbY = NULL;;
32 static int *LutRv = NULL;
33 static int *LutGu = NULL;
34 static int *LutGv = NULL;
35 static int *LutBu = NULL;
36 
37 #if 0
38 #define RGB24_TO_Y(r,g,b) LutYr[(r)] + LutYg[(g)] + LutYb[(b)]
39 #define YR_TO_V(r,y) LutVr[(r)] + LutVrY[(y)]
40 #define YB_TO_U(b,y) LutUb[(b)] + LutUbY[(y)]
41 
42 #define R_FROMYV(y,v) CLIP((y) + LutRv[(v)])
43 #define G_FROMYUV(y,u,v) CLIP((y) + LutGu[(u)] + LutGv[(v)])
44 #define B_FROMYU(y,u) CLIP((y) + LutBu[(u)])
45 #endif
46 
47 unsigned char
48 RGB24_TO_Y(unsigned char r, unsigned char g, unsigned char b)
49 {
50 return (LutYr[(r)] + LutYg[(g)] + LutYb[(b)]);
51 }
52 unsigned char
53 YR_TO_V(unsigned char r, unsigned char y)
54 {
55 return (LutVr[(r)] + LutVrY[(y)]);
56 }
57 unsigned char
58 YB_TO_U(unsigned char b, unsigned char y)
59 {
60 return (LutUb[(b)] + LutUbY[(y)]);
61 }
62 unsigned char
63 R_FROMYV(unsigned char y, unsigned char v)
64 {
65 return CLIP((y) + LutRv[(v)]);
66 }
67 unsigned char
68 G_FROMYUV(unsigned char y, unsigned char u, unsigned char v)
69 {
70 return CLIP((y) + LutGu[(u)] + LutGv[(v)]);
71 }
72 unsigned char
73 B_FROMYU(unsigned char y, unsigned char u)
74 {
75 return CLIP((y) + LutBu[(u)]);
76 }
77 
78 void initLut(void)
79 {
80  int i;
81  #define Rcoef 299
82  #define Gcoef 587
83  #define Bcoef 114
84  #define Vrcoef 711 //656 //877
85  #define Ubcoef 560 //500 //493 564
86 
87  #define CoefRv 1402
88  #define CoefGu 714 // 344
89  #define CoefGv 344 // 714
90  #define CoefBu 1772
91 
92  LutYr = malloc(256*sizeof(int));
93  LutYg = malloc(256*sizeof(int));
94  LutYb = malloc(256*sizeof(int));
95  LutVr = malloc(256*sizeof(int));
96  LutVrY = malloc(256*sizeof(int));
97  LutUb = malloc(256*sizeof(int));
98  LutUbY = malloc(256*sizeof(int));
99 
100  LutRv = malloc(256*sizeof(int));
101  LutGu = malloc(256*sizeof(int));
102  LutGv = malloc(256*sizeof(int));
103  LutBu = malloc(256*sizeof(int));
104  for (i= 0;i < 256;i++){
105  LutYr[i] = i*Rcoef/1000 ;
106  LutYg[i] = i*Gcoef/1000 ;
107  LutYb[i] = i*Bcoef/1000 ;
108  LutVr[i] = i*Vrcoef/1000;
109  LutUb[i] = i*Ubcoef/1000;
110  LutVrY[i] = 128 -(i*Vrcoef/1000);
111  LutUbY[i] = 128 -(i*Ubcoef/1000);
112  LutRv[i] = (i-128)*CoefRv/1000;
113  LutBu[i] = (i-128)*CoefBu/1000;
114  LutGu[i] = (128-i)*CoefGu/1000;
115  LutGv[i] = (128-i)*CoefGv/1000;
116  }
117 }
118 
119 
120 void freeLut(void){
121  free(LutYr);
122  free(LutYg);
123  free(LutYb);
124  free(LutVr);
125  free(LutVrY);
126  free(LutUb);
127  free(LutUbY);
128 
129  free(LutRv);
130  free(LutGu);
131  free(LutGv);
132  free(LutBu);
133 }
134 
static int * LutVr
Definition: color.c:28
#define CoefBu
static int * LutGu
Definition: color.c:33
void initLut(void)
Definition: color.c:78
unsigned char B_FROMYU(unsigned char y, unsigned char u)
Definition: color.c:73
static int * LutRv
Definition: color.c:32
#define Ubcoef
#define Rcoef
unsigned char YB_TO_U(unsigned char b, unsigned char y)
Definition: color.c:58
static int * LutYg
Definition: color.c:26
static int * LutUbY
Definition: color.c:31
static int * LutVrY
Definition: color.c:29
void freeLut(void)
Definition: color.c:120
static int * LutGv
Definition: color.c:34
static int * LutUb
Definition: color.c:30
#define Bcoef
#define CLIP(color)
Definition: color.h:50
#define CoefGu
static int * LutBu
Definition: color.c:35
static int * LutYb
Definition: color.c:27
#define CoefGv
#define Vrcoef
#define CoefRv
#define Gcoef
static int * LutYr
Definition: color.c:25
unsigned char YR_TO_V(unsigned char r, unsigned char y)
Definition: color.c:53
unsigned char RGB24_TO_Y(unsigned char r, unsigned char g, unsigned char b)
Definition: color.c:48
unsigned char G_FROMYUV(unsigned char y, unsigned char u, unsigned char v)
Definition: color.c:68
unsigned char R_FROMYV(unsigned char y, unsigned char v)
Definition: color.c:63


tuw_uvc
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:39:24