26 void CfaFlatten(
float *Flat,
const float *Input,
int Width,
int Height,
29 const float *InputRed = Input;
30 const float *InputGreen = Input + Width*Height;
31 const float *InputBlue = Input + 2*Width*Height;
32 const int Green = 1 - ((RedX + RedY) & 1);
36 for(y = 0, i = 0; y < Height; y++)
37 for(x = 0; x < Width; x++, i++)
39 if(((x + y) & 1) == Green)
40 Flat[i] = InputGreen[i];
41 else if((y & 1) == RedY)
42 Flat[i] = InputRed[i];
44 Flat[i] = InputBlue[i];
75 int Width,
int Height,
int RedX,
int RedY)
77 const int NumPixels = Width*Height;
78 const int Green = 1 - ((RedX + RedY) & 1);
79 float *OutputRed = Output;
80 float *OutputGreen = Output + NumPixels;
81 float *OutputBlue = Output + 2*NumPixels;
82 float AverageH, AverageV, AverageX;
86 for(y = 0, i = 0; y < Height; y++)
88 for(x = 0; x < Width; x++, i++)
102 AverageV = Diff[i + Width];
106 AverageH = Diff[i + 1];
107 AverageX = Diff[i + 1 + Width];
109 else if(x < Width - 1)
111 AverageH = (Diff[i - 1] + Diff[i + 1]) / 2;
112 AverageX = (Diff[i - 1 + Width] + Diff[i + 1 + Width]) / 2;
116 AverageH = Diff[i - 1];
117 AverageX = Diff[i - 1 + Width];
121 else if(y < Height - 1)
123 AverageV = (Diff[i - Width] + Diff[i + Width]) / 2;
127 AverageH = Diff[i + 1];
128 AverageX = (Diff[i + 1 - Width] + Diff[i + 1 + Width]) / 2;
130 else if(x < Width - 1)
132 AverageH = (Diff[i - 1] + Diff[i + 1]) / 2;
133 AverageX = (Diff[i - 1 - Width] + Diff[i + 1 - Width]
134 + Diff[i - 1 + Width] + Diff[i + 1 + Width]) / 4;
138 AverageH = Diff[i - 1];
139 AverageX = (Diff[i - 1 - Width] + Diff[i - 1 + Width]) / 2;
144 AverageV = Diff[i - Width];
148 AverageH = Diff[i + 1];
149 AverageX = Diff[i + 1 - Width];
151 else if(x < Width - 1)
153 AverageH = (Diff[i - 1] + Diff[i + 1]) / 2;
154 AverageX = (Diff[i - 1 - Width] + Diff[i + 1 - Width]) / 2;
158 AverageH = Diff[i - 1];
159 AverageX = Diff[i - 1 - Width];
163 if(((x + y) & 1) == Green)
168 OutputRed[i] = OutputGreen[i] + AverageH;
169 OutputBlue[i] = OutputGreen[i] + AverageV;
174 OutputRed[i] = OutputGreen[i] + AverageV;
175 OutputBlue[i] = OutputGreen[i] + AverageH;
183 OutputRed[i] = OutputGreen[i] + Diff[i];
184 OutputBlue[i] = OutputGreen[i] + AverageX;
189 OutputRed[i] = OutputGreen[i] + AverageX;
190 OutputBlue[i] = OutputGreen[i] + Diff[i];
215 float *OutputRed = Output;
216 float *OutputGreen = Output + Width*Height;
217 float *OutputBlue = Output + 2*Width*Height;
218 const int Green = 1 - ((RedX + RedY) & 1);
219 float AverageH, AverageV, AverageC, AverageX;
223 for(y = 0, i = 0; y < Height; y++)
225 for(x = 0; x < Width; x++, i++)
240 AverageV = Input[i + Width];
244 AverageH = Input[i + 1];
245 AverageC = (Input[i + 1] + Input[i + Width])/2;
246 AverageX = Input[i + 1 + Width];
248 else if(x < Width - 1)
250 AverageH = (Input[i - 1] + Input[i + 1]) / 2;
251 AverageC = (Input[i - 1] + Input[i + 1]
252 + Input[i + Width])/3;
253 AverageX = (Input[i - 1 + Width]
254 + Input[i + 1 + Width]) / 2;
258 AverageH = Input[i - 1];
259 AverageC = (Input[i - 1] + Input[i + Width])/2;
260 AverageX = Input[i - 1 + Width];
263 else if(y < Height - 1)
265 AverageV = (Input[i - Width] + Input[i + Width]) / 2;
269 AverageH = Input[i + 1];
270 AverageC = (Input[i + 1] +
271 Input[i - Width] + Input[i + Width]) / 3;
272 AverageX = (Input[i + 1 - Width]
273 + Input[i + 1 + Width]) / 2;
275 else if(x < Width - 1)
277 AverageH = (Input[i - 1] + Input[i + 1]) / 2;
278 AverageC = (AverageH + AverageV) / 2;
279 AverageX = (Input[i - 1 - Width] + Input[i + 1 - Width]
280 + Input[i - 1 + Width] + Input[i + 1 + Width]) / 4;
284 AverageH = Input[i - 1];
285 AverageC = (Input[i - 1] +
286 Input[i - Width] + Input[i + Width]) / 3;
287 AverageX = (Input[i - 1 - Width]
288 + Input[i - 1 + Width]) / 2;
293 AverageV = Input[i - Width];
297 AverageH = Input[i + 1];
298 AverageC = (Input[i + 1] + Input[i - Width]) / 2;
299 AverageX = Input[i + 1 - Width];
301 else if(x < Width - 1)
303 AverageH = (Input[i - 1] + Input[i + 1]) / 2;
304 AverageC = (Input[i - 1]
305 + Input[i + 1] + Input[i - Width]) / 3;
306 AverageX = (Input[i - 1 - Width]
307 + Input[i + 1 - Width]) / 2;
311 AverageH = Input[i - 1];
312 AverageC = (Input[i - 1] + Input[i - Width]) / 2;
313 AverageX = Input[i - 1 - Width];
317 if(((x + y) & 1) == Green)
320 OutputGreen[i] = Input[i];
325 OutputRed[i] = AverageH;
326 OutputBlue[i] = AverageV;
331 OutputRed[i] = AverageV;
332 OutputBlue[i] = AverageH;
337 OutputGreen[i] = AverageC;
342 OutputRed[i] = Input[i];
343 OutputBlue[i] = AverageX;
348 OutputRed[i] = AverageX;
349 OutputBlue[i] = Input[i];