1/* 2 * Copyright (c) 2017 Jokyo Images 3 * 4 * This file is part of FFmpeg. 5 * 6 * FFmpeg is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (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 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with FFmpeg; if not, write to the Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 */ 20 21#include <string.h> 22 23#include "checkasm.h" 24#include "libavcodec/avcodec.h" 25#include "libavcodec/utvideodsp.h" 26#include "libavutil/intreadwrite.h" 27#include "libavutil/mem_internal.h" 28 29#define WIDTH 240 30#define HEIGHT 120 31#define WIDTH_PADDED (WIDTH + 16) /* padded to 32 */ 32#define BUFFER_SIZE (WIDTH_PADDED * HEIGHT) 33 34 35#define randomize_plane(buf, type) \ 36 do { \ 37 int w, h; \ 38 type * tmp = buf; \ 39 for (h = 0; h < HEIGHT; h++) { \ 40 for (w = 0; w < WIDTH; w++) \ 41 tmp[w] = rnd() & 0xFF; \ 42 tmp += WIDTH_PADDED; \ 43 } \ 44 } while (0) 45 46#define cmp_plane(buf0, buf1, s) \ 47 do { \ 48 int h; \ 49 for (h = 0; h < HEIGHT; h++) { \ 50 if (memcmp(buf0 + h*WIDTH_PADDED, \ 51 buf1 + h*WIDTH_PADDED, WIDTH *s)) \ 52 fail();\ 53 } \ 54 } while (0) 55 56 57#define CHECK_RESTORE(type)\ 58LOCAL_ALIGNED_32(type, src_r0, [BUFFER_SIZE]); \ 59LOCAL_ALIGNED_32(type, src_g0, [BUFFER_SIZE]); \ 60LOCAL_ALIGNED_32(type, src_b0, [BUFFER_SIZE]); \ 61LOCAL_ALIGNED_32(type, src_r1, [BUFFER_SIZE]); \ 62LOCAL_ALIGNED_32(type, src_g1, [BUFFER_SIZE]); \ 63LOCAL_ALIGNED_32(type, src_b1, [BUFFER_SIZE]); \ 64declare_func(void, type *src_r, type *src_g, type *src_b, \ 65 ptrdiff_t linesize_r, ptrdiff_t linesize_g, \ 66 ptrdiff_t linesize_b, int width, int height); \ 67memset(src_r0, 0, BUFFER_SIZE * sizeof(type)); \ 68memset(src_g0, 0, BUFFER_SIZE * sizeof(type)); \ 69memset(src_b0, 0, BUFFER_SIZE * sizeof(type)); \ 70randomize_plane(src_r0, type); \ 71randomize_plane(src_g0, type); \ 72randomize_plane(src_b0, type); \ 73memcpy(src_r1, src_r0, BUFFER_SIZE * sizeof(type)); \ 74memcpy(src_g1, src_g0, BUFFER_SIZE * sizeof(type)); \ 75memcpy(src_b1, src_b0, BUFFER_SIZE * sizeof(type)); \ 76call_ref(src_r0, src_g0, src_b0, WIDTH_PADDED, WIDTH_PADDED, WIDTH_PADDED, WIDTH, HEIGHT);\ 77call_new(src_r1, src_g1, src_b1, WIDTH_PADDED, WIDTH_PADDED, WIDTH_PADDED, WIDTH, HEIGHT);\ 78cmp_plane(src_r0, src_r1, sizeof(type)); \ 79cmp_plane(src_g0, src_g1, sizeof(type)); \ 80cmp_plane(src_b0, src_b1, sizeof(type)); \ 81bench_new(src_r1, src_g1, src_b1, WIDTH_PADDED, WIDTH_PADDED, WIDTH_PADDED, WIDTH, HEIGHT) 82 83static void check_restore_rgb_planes(void) { 84 CHECK_RESTORE(uint8_t); 85} 86 87static void check_restore_rgb_planes10(void) { 88 CHECK_RESTORE(uint16_t); 89} 90 91void checkasm_check_utvideodsp(void) 92{ 93 UTVideoDSPContext h; 94 95 ff_utvideodsp_init(&h); 96 97 if (check_func(h.restore_rgb_planes, "restore_rgb_planes")) 98 check_restore_rgb_planes(); 99 100 report("restore_rgb_planes"); 101 102 if (check_func(h.restore_rgb_planes10, "restore_rgb_planes10")) 103 check_restore_rgb_planes10(); 104 105 report("restore_rgb_planes10"); 106} 107