FFmpeg
vf_threshold.c
Go to the documentation of this file.
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 <string.h>
20 #include "checkasm.h"
21 #include "libavfilter/threshold.h"
22 #include "libavutil/intreadwrite.h"
23 
24 #define WIDTH 256
25 #define WIDTH_PADDED 256 + 32
26 
27 #define randomize_buffers(buf, size) \
28  do { \
29  int j; \
30  uint8_t *tmp_buf = (uint8_t *)buf;\
31  for (j = 0; j < size; j++) \
32  tmp_buf[j] = rnd() & 0xFF; \
33  } while (0)
34 
35 static void check_threshold(int depth){
37  LOCAL_ALIGNED_32(uint8_t, threshold, [WIDTH_PADDED]);
42  ptrdiff_t line_size = WIDTH_PADDED;
43  int w = WIDTH;
44 
45  declare_func(void, const uint8_t *in, const uint8_t *threshold,
46  const uint8_t *min, const uint8_t *max, uint8_t *out,
47  ptrdiff_t ilinesize, ptrdiff_t tlinesize,
48  ptrdiff_t flinesize, ptrdiff_t slinesize,
49  ptrdiff_t olinesize, int w, int h);
50 
52  s.depth = depth;
54 
55  memset(in, 0, WIDTH_PADDED);
56  memset(threshold, 0, WIDTH_PADDED);
57  memset(min, 0, WIDTH_PADDED);
58  memset(max, 0, WIDTH_PADDED);
59  memset(out_ref, 0, WIDTH_PADDED);
60  memset(out_new, 0, WIDTH_PADDED);
62  randomize_buffers(threshold, WIDTH);
65 
66  if (depth == 16)
67  w /= 2;
68 
69  if (check_func(s.threshold, "threshold%d", depth)) {
70  call_ref(in, threshold, min, max, out_ref, line_size, line_size, line_size, line_size, line_size, w, 1);
71  call_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1);
72  if (memcmp(out_ref, out_new, WIDTH))
73  fail();
74  bench_new(in, threshold, min, max, out_new, line_size, line_size, line_size, line_size, line_size, w, 1);
75  }
76 }
77 
79 {
80  check_threshold(8);
81  report("threshold8");
82 
83  check_threshold(16);
84  report("threshold16");
85 }
WIDTH
#define WIDTH
Definition: vf_threshold.c:24
out
FILE * out
Definition: movenc.c:54
ff_threshold_init
void ff_threshold_init(ThresholdContext *s)
Definition: vf_threshold.c:229
threshold.h
w
uint8_t w
Definition: llviddspenc.c:38
checkasm_check_vf_threshold
void checkasm_check_vf_threshold(void)
Definition: vf_threshold.c:78
check_func
#define check_func(func,...)
Definition: checkasm.h:111
max
#define max(a, b)
Definition: cuda_runtime.h:33
call_ref
#define call_ref(...)
Definition: checkasm.h:126
fail
#define fail()
Definition: checkasm.h:120
checkasm.h
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
call_new
#define call_new(...)
Definition: checkasm.h:193
randomize_buffers
#define randomize_buffers(buf, size)
Definition: vf_threshold.c:27
ThresholdContext
Definition: threshold.h:27
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
report
#define report
Definition: checkasm.h:123
bench_new
#define bench_new(...)
Definition: checkasm.h:253
check_threshold
static void check_threshold(int depth)
Definition: vf_threshold.c:35
uint8_t
uint8_t
Definition: audio_convert.c:194
WIDTH_PADDED
#define WIDTH_PADDED
Definition: vf_threshold.c:25
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:115
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: internal.h:137
h
h
Definition: vp9dsp_template.c:2038
min
float min
Definition: vorbis_enc_data.h:456