-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh2v2_fancy_upsample.cl
66 lines (61 loc) · 1.97 KB
/
h2v2_fancy_upsample.cl
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
#include "upsample.clh"
__kernel
void my_upsample( __global JSAMPLE * input_buf,
__global JSAMPLE * output_buf)
{
__global JSAMPLE * inptr0;
__global JSAMPLE * inptr1;
__global JSAMPLE * input_ptr;
__global JSAMPLE * outptr;
int invalue;
int yoffset = get_global_id(0) ;
int height = get_global_size(0);
int col = get_global_id(1);
int width = get_global_size(1);
int input_offset = ( (yoffset >> 1 ) * width) + col ;
inptr0 = input_buf + input_offset;
if(yoffset == 0)
{
// the first row
inptr1 = inptr0;
}
else if (yoffset == (height - 1))
{
// the last row
inptr1 = inptr0;
}
else if( !(yoffset & 1 ))
{
inptr1 = inptr0 - width;
}
else
{
inptr1 = inptr0 + width;
}
outptr = output_buf + ( ( ( yoffset * width) + col ) << 1) ;
if(col == 0)
{
// first column
unsigned int thiscolsum = GETJSAMPLE(inptr0[0]) * 3 + GETJSAMPLE(inptr1[0]);
unsigned int nextcolsum = GETJSAMPLE(inptr0[1]) * 3 + GETJSAMPLE(inptr1[1]);
outptr[0] = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
outptr[1] = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
}
else if (col == (width - 1) )
{
// last column
unsigned int thiscolsum = GETJSAMPLE(inptr0[0]) * 3 + GETJSAMPLE(inptr1[0]);
unsigned int lastcolsum = GETJSAMPLE(inptr0[-1]) * 3 + GETJSAMPLE(inptr1[-1]);
outptr[0] = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
outptr[1] = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
}
else
{
// in the middle
unsigned int lastcolsum = GETJSAMPLE(inptr0[-1]) * 3 + GETJSAMPLE(inptr1[-1]);
unsigned int thiscolsum = GETJSAMPLE(inptr0[0]) * 3 + GETJSAMPLE(inptr1[0]);
unsigned int nextcolsum = GETJSAMPLE(inptr0[1]) * 3 + GETJSAMPLE(inptr1[1]);
outptr[0] = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
outptr[1] = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
}
}