cmake macro to set less strict flags per file - remove_strict_flags_file(file, file...)
[blender.git] / extern / libredcode / debayer.c
1 #include "debayer.h"
2
3 /* pretty simple but astonishingly very effective "debayer" function 
4  */
5
6 void redcode_ycbcr2rgb_fullscale(
7         int ** planes, int width, int height, float * out)
8 {
9         int x,y;
10         int pix_max = 4096;
11         int mask = pix_max - 1;
12         float *o;
13
14         for (y = 0; y < height; y++) {
15                 for (x = 0; x < width; x++) {
16                         int i = x + y*width;
17                         int i_p = (y > 0) ? i-width : i;
18                         int i_n = (y < (height-1)) ? i + width : i;
19                         float y1n = planes[0][i_n] & mask;
20                         float y1  = planes[0][i] & mask;
21                         float cb  = (planes[1][i] & mask)   - pix_max/2;
22                         float cr  = (planes[2][i] & mask)   - pix_max/2;
23                         float y2  = (planes[3][i] & mask);
24                         float y2p = (planes[3][i_p] & mask);
25
26                         float b_ = cb /(pix_max/2);
27                         float r_ = cr /(pix_max/2);
28                         float g_ = 0.0;
29                 
30                         float y_[4] = {y1 / pix_max, 
31                                        (y2 + y2p)/2 / pix_max, 
32                                        (y1 + y1n)/2 / pix_max, 
33                                        y2 / pix_max};
34
35                         int j;
36                         int yc = 0;
37
38                         o = out + (2*height-1-2*y)*2*4*width 
39                                 + x*2*4;
40
41                         for (j = 0; j < 8; j += 4) {
42                                 o[j+0] = r_ + y_[yc];
43                                 o[j+1] = g_ + y_[yc];
44                                 o[j+2] = b_ + y_[yc];
45                                 o[j+3] = 1.0;
46                                 yc++;
47                         }
48                         
49                         o = out + (2*height-1-2*y)*2*4*width 
50                                 + x*2*4 - 2*4*width;
51
52                         for (j = 0; j < 8; j += 4) {
53                                 o[j+0] = r_ + y_[yc];
54                                 o[j+1] = g_ + y_[yc];
55                                 o[j+2] = b_ + y_[yc];
56                                 o[j+3] = 1.0;
57                                 yc++;
58                         }
59                 }
60         }
61 }
62
63 void redcode_ycbcr2rgb_halfscale(
64         int ** planes, int width, int height, float * out)
65 {
66         int x,y;
67         int pix_max = 4096;
68         int mask = pix_max - 1;
69
70         for (y = 0; y < height; y++) {
71                 float *o = out + width * (height - y - 1);
72                 for (x = 0; x < width; x++) {
73                         int i = y*height + x;
74                         float y1  = (planes[0][i] & mask);
75                         float cb  = (planes[1][i] & mask)  - pix_max/2;
76                         float cr  = (planes[2][i] & mask)  - pix_max/2;
77                         float y2  = (planes[3][i] & mask);
78
79                         float b_ = cb /(pix_max/2);
80                         float r_ = cr /(pix_max/2);
81                         float g_ = 0.0;
82                         
83                         float y = (y1 + y2)/2 / pix_max;
84
85                         *o++ = r_ + y;
86                         *o++ = g_ + y;
87                         *o++ = b_ + y;
88                         *o++ = 1.0;
89                 }
90         }
91 }
92
93
94 void redcode_ycbcr2rgb_quarterscale(
95         int ** planes, int width, int height, float * out)
96 {
97         int x,y;
98         int pix_max = 4096;
99         int mask = pix_max - 1;
100
101         for (y = 0; y < height; y += 2) {
102                 float *o = out + (width/2) * (height/2 - y/2 - 1);
103                 for (x = 0; x < width; x += 2) {
104                         int i = y * width + x;
105                         float y1  = planes[0][i] & mask;
106                         float cb  = (planes[1][i] & mask)  - pix_max/2;
107                         float cr  = (planes[2][i] & mask)  - pix_max/2;
108                         float y2  = planes[3][i] & mask;
109
110                         float b_ = cb /(pix_max/2);
111                         float r_ = cr /(pix_max/2);
112                         float g_ = 0.0;
113                         
114                         float y = (y1 + y2)/2 / pix_max;
115                         
116                         *o++ = r_ + y;
117                         *o++ = g_ + y;
118                         *o++ = b_ + y;
119                         *o++ = 1.0;
120                 }
121         }
122 }
123