Created
February 1, 2015 12:17
-
-
Save fador/91e04bec113181dddb26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__constant sampler_t sampler = | |
CLK_NORMALIZED_COORDS_FALSE | |
| CLK_ADDRESS_CLAMP_TO_EDGE | |
| CLK_FILTER_NEAREST; | |
const int BLOCKSIZE = 16; | |
const int ME_RANGE = 32; | |
const int ME_RANGE_x2 = 64; | |
__kernel void motion_est( | |
read_only image2d_t reference, | |
read_only image2d_t block, | |
global int *output) { | |
const int2 pos = { get_global_id(0), get_global_id(1) }; | |
const int2 blkpos = pos/ME_RANGE_x2; | |
const int2 searchpos = (pos%ME_RANGE_x2)-ME_RANGE; | |
unsigned int sum = 0; | |
for (int y = searchpos.s1; y < searchpos.s1+BLOCKSIZE; y++) { | |
for (int x = searchpos.s0; x <searchpos.s0+BLOCKSIZE; x++) { | |
int4 pixel_ref = convert_int4(read_imagef(reference, sampler, blkpos*BLOCKSIZE + (int2)(x, y))*255); | |
int4 pixel = convert_int4(read_imagef(block, sampler, blkpos*BLOCKSIZE + (int2)(x, y))*255); | |
sum += abs_diff(pixel_ref.x, pixel.x); | |
} | |
} | |
output[get_global_id(0) + get_global_id(1)*((832/BLOCKSIZE)*ME_RANGE_x2)] = sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment