Branch data Line data Source code
1 : : /* 2 : : * This file is part of libplacebo. 3 : : * 4 : : * libplacebo is free software; you can redistribute it and/or 5 : : * modify it under the terms of the GNU Lesser General Public 6 : : * License as published by the Free Software Foundation; either 7 : : * version 2.1 of the License, or (at your option) any later version. 8 : : * 9 : : * libplacebo 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 Lesser General Public License for more details. 13 : : * 14 : : * You should have received a copy of the GNU Lesser General Public 15 : : * License along with libplacebo. If not, see <http://www.gnu.org/licenses/>. 16 : : */ 17 : : 18 : : #include "shaders.h" 19 : : #include "shaders/film_grain.h" 20 : : 21 : 799 : bool pl_needs_film_grain(const struct pl_film_grain_params *params) 22 : : { 23 [ + + - + ]: 799 : switch (params->data.type) { 24 : : case PL_FILM_GRAIN_NONE: return false; 25 : 16 : case PL_FILM_GRAIN_AV1: return pl_needs_fg_av1(params); 26 : 14 : case PL_FILM_GRAIN_H274: return pl_needs_fg_h274(params); 27 : 0 : default: pl_unreachable(); 28 : : } 29 : : } 30 : : 31 : : struct sh_grain_obj { 32 : : pl_shader_obj av1; 33 : : pl_shader_obj h274; 34 : : }; 35 : : 36 : 6 : static void sh_grain_uninit(pl_gpu gpu, void *ptr) 37 : : { 38 : : struct sh_grain_obj *obj = ptr; 39 : 6 : pl_shader_obj_destroy(&obj->av1); 40 : 6 : pl_shader_obj_destroy(&obj->h274); 41 : 6 : } 42 : : 43 : 14 : bool pl_shader_film_grain(pl_shader sh, pl_shader_obj *grain_state, 44 : : const struct pl_film_grain_params *params) 45 : : { 46 [ - + ]: 14 : if (!pl_needs_film_grain(params)) { 47 : : // FIXME: Instead of erroring, sample directly 48 : 0 : SH_FAIL(sh, "pl_shader_film_grain called but no film grain needs to be " 49 : : "applied, test with `pl_needs_film_grain` first!"); 50 : 0 : return false; 51 : : } 52 : : 53 : : struct sh_grain_obj *obj; 54 : 14 : obj = SH_OBJ(sh, grain_state, PL_SHADER_OBJ_FILM_GRAIN, 55 : : struct sh_grain_obj, sh_grain_uninit); 56 [ + - ]: 14 : if (!obj) 57 : : return false; 58 : : 59 [ + + - - ]: 14 : switch (params->data.type) { 60 : : case PL_FILM_GRAIN_NONE: return false; 61 : 8 : case PL_FILM_GRAIN_AV1: return pl_shader_fg_av1(sh, &obj->av1, params); 62 : 6 : case PL_FILM_GRAIN_H274: return pl_shader_fg_h274(sh, &obj->h274, params); 63 : 0 : default: pl_unreachable(); 64 : : } 65 : : }