1/* 2 * Copyright (c) 2018 Dylan Fernando 3 * 4 * This file is part of FFmpeg. 5 * 6 * FFmpeg is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * FFmpeg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with FFmpeg; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 22__kernel void avgblur_horiz(__write_only image2d_t dst, 23 __read_only image2d_t src, 24 int rad) 25{ 26 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE | 27 CLK_FILTER_NEAREST); 28 int2 loc = (int2)(get_global_id(0), get_global_id(1)); 29 int2 size = (int2)(get_global_size(0), get_global_size(1)); 30 31 int count = 0; 32 float4 acc = (float4)(0,0,0,0); 33 34 for (int xx = max(0, loc.x - rad); xx < min(loc.x + rad + 1, size.x); xx++) { 35 count++; 36 acc += read_imagef(src, sampler, (int2)(xx, loc.y)); 37 } 38 39 write_imagef(dst, loc, acc / count); 40} 41 42__kernel void avgblur_vert(__write_only image2d_t dst, 43 __read_only image2d_t src, 44 int radv) 45{ 46 const sampler_t sampler = (CLK_NORMALIZED_COORDS_FALSE | 47 CLK_FILTER_NEAREST); 48 int2 loc = (int2)(get_global_id(0), get_global_id(1)); 49 int2 size = (int2)(get_global_size(0), get_global_size(1)); 50 51 int count = 0; 52 float4 acc = (float4)(0,0,0,0); 53 54 for (int yy = max(0, loc.y - radv); yy < min(loc.y + radv + 1, size.y); yy++) { 55 count++; 56 acc += read_imagef(src, sampler, (int2)(loc.x, yy)); 57 } 58 59 write_imagef(dst, loc, acc / count); 60} 61