-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbilinear.cpp
More file actions
executable file
·68 lines (57 loc) · 2.18 KB
/
Copy pathbilinear.cpp
File metadata and controls
executable file
·68 lines (57 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* bilinear.cpp
*
* Created on: 22 Apr 2010
* Author: sjf
*/
#include "base.h"
#include "image.h"
#include "bayer.h"
#include "sys/times.h"
#include "util.h"
void host_bilinear(img *image){
Info("Performing bilinear interpolation");
for (uint y = 0; y < image->height; y++) {
for (uint x = 0; x < image->width; x++) {
pixel *pix = get_pixel(image,x,y);
int filter_color = get_filter_color(x,y);
double sum = 0;
if (filter_color == R || filter_color == B) {
/* Red/Blue only pixels */
/* Green channel */
sum = get_pixel(image,x-1,y)[G] +
get_pixel(image,x+1,y)[G] +
get_pixel(image,x,y-1)[G] +
get_pixel(image,x,y+1)[G];
pix[G] = clampc(sum / 4);
int dest_color = (filter_color == R) ? B : R;
/* Red/Blue channel */
sum = get_pixel(image,x-1,y-1)[dest_color] +
get_pixel(image,x-1,y+1)[dest_color] +
get_pixel(image,x+1,y-1)[dest_color] +
get_pixel(image,x+1,y+1)[dest_color];
pix[dest_color] = clampc(sum / 4);
} else {
/* Green only pixels */
/* Red/Green rows */
int bayer = settings->bayer_type;
if ((even(y) && (bayer == RGGB || bayer == GRBG)) ||
( odd(y) && (bayer == GBRG || bayer == BGGR))) {
sum = get_pixel(image,x-1,y)[R] +
get_pixel(image,x+1,y)[R];
pix[R] = clampc(sum / 2);
sum = get_pixel(image,x,y-1)[B] +
get_pixel(image,x,y+1)[B];
pix[B] = clampc(sum / 2);
} else {
sum = get_pixel(image,x,y-1)[R] +
get_pixel(image,x,y+1)[R];
pix[R] = clampc(sum / 2);
sum = get_pixel(image,x-1,y)[B] +
get_pixel(image,x+1,y)[B];
pix[B] = clampc(sum / 2);
}
}
}
}
}