1/* 2 * This file is part of FFmpeg. 3 * 4 * FFmpeg is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * FFmpeg is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with FFmpeg; if not, write to the Free Software Foundation, Inc., 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 19#include <float.h> 20#include <string.h> 21#include "checkasm.h" 22#include "libavfilter/vf_gblur_init.h" 23 24#define WIDTH 256 25#define HEIGHT 256 26#define PIXELS (WIDTH * HEIGHT) 27#define BUF_SIZE (PIXELS * 4) 28 29#define randomize_buffers(buf, size) \ 30 do { \ 31 int j; \ 32 float *tmp_buf = (float *)buf; \ 33 for (j = 0; j < size; j++) \ 34 tmp_buf[j] = (float)(rnd() & 0xFF); \ 35 } while (0) 36 37static void check_horiz_slice(float *dst_ref, float *dst_new, float *localbuf) 38{ 39 int steps = 2; 40 float nu = 0.101f; 41 float bscale = 1.112f; 42 43 declare_func(void, float *dst, int w, int h, int steps, float nu, float bscale, float *localbuf); 44 call_ref(dst_ref, WIDTH, HEIGHT, steps, nu, bscale, localbuf); 45 call_new(dst_new, WIDTH, HEIGHT, steps, nu, bscale, localbuf); 46 if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) { 47 fail(); 48 } 49 bench_new(dst_new, WIDTH, HEIGHT, 1, nu, bscale, localbuf); 50} 51 52static void check_verti_slice(float *dst_ref, float *dst_new) 53{ 54 int steps = 2; 55 float nu = 0.101f; 56 float bscale = 1.112f; 57 58 declare_func(void, float *buffer, int width, int height, int column_begin, 59 int column_end, int steps, float nu, float bscale); 60 call_ref(dst_ref, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale); 61 call_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, steps, nu, bscale); 62 if (!float_near_abs_eps_array(dst_ref, dst_new, 0.01f, PIXELS)) { 63 fail(); 64 } 65 bench_new(dst_new, WIDTH, HEIGHT, 0, WIDTH, 1, nu, bscale); 66} 67 68static void check_postscale_slice(float *dst_ref, float *dst_new) 69{ 70 float postscale = 0.0603f; 71 72 declare_func(void, float *dst, int len, float postscale, float min, float max); 73 call_ref(dst_ref, PIXELS, postscale, -FLT_MAX, FLT_MAX); 74 call_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX); 75 if (!float_near_abs_eps_array(dst_ref, dst_new, FLT_EPSILON, PIXELS)) { 76 fail(); 77 } 78 bench_new(dst_new, PIXELS, postscale, -FLT_MAX, FLT_MAX); 79} 80 81void checkasm_check_vf_gblur(void) 82{ 83 float *dst_ref = av_malloc(BUF_SIZE); 84 float *dst_new = av_malloc(BUF_SIZE); 85 GBlurContext s; 86 87 randomize_buffers(dst_ref, PIXELS); 88 memcpy(dst_new, dst_ref, BUF_SIZE); 89 90 s.planewidth[0] = WIDTH; 91 s.planeheight[0] = HEIGHT; 92 ff_gblur_init(&s); 93 94 if (check_func(s.horiz_slice, "horiz_slice")) { 95 check_horiz_slice(dst_ref, dst_new, s.localbuf); 96 } 97 report("horiz_slice"); 98 99 randomize_buffers(dst_ref, PIXELS); 100 memcpy(dst_new, dst_ref, BUF_SIZE); 101 if (check_func(s.postscale_slice, "postscale_slice")) { 102 check_postscale_slice(dst_ref, dst_new); 103 } 104 report("postscale_slice"); 105 106 randomize_buffers(dst_ref, PIXELS); 107 memcpy(dst_new, dst_ref, BUF_SIZE); 108 if (check_func(s.verti_slice, "verti_slice")) { 109 check_verti_slice(dst_ref, dst_new); 110 } 111 report("verti_slice"); 112 113 if (s.localbuf) 114 av_free(s.localbuf); 115 116 av_freep(&dst_ref); 117 av_freep(&dst_new); 118} 119