FFmpeg
cfhdencdsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016 Kieran Kunhya <kieran@kunhya.com>
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 #include "libavutil/attributes.h"
22 #include "libavutil/common.h"
23 #include "libavutil/avassert.h"
24 
25 #include "cfhdencdsp.h"
26 
27 static av_always_inline void filter(int16_t *input, ptrdiff_t in_stride,
28  int16_t *low, ptrdiff_t low_stride,
29  int16_t *high, ptrdiff_t high_stride,
30  int len)
31 {
32  low[(0>>1) * low_stride] = av_clip_int16(input[0*in_stride] + input[1*in_stride]);
33  high[(0>>1) * high_stride] = av_clip_int16((5 * input[0*in_stride] - 11 * input[1*in_stride] +
34  4 * input[2*in_stride] + 4 * input[3*in_stride] -
35  1 * input[4*in_stride] - 1 * input[5*in_stride] + 4) >> 3);
36 
37  for (int i = 2; i < len - 2; i += 2) {
38  low[(i>>1) * low_stride] = av_clip_int16(input[i*in_stride] + input[(i+1)*in_stride]);
39  high[(i>>1) * high_stride] = av_clip_int16(((-input[(i-2)*in_stride] - input[(i-1)*in_stride] +
40  input[(i+2)*in_stride] + input[(i+3)*in_stride] + 4) >> 3) +
41  input[(i+0)*in_stride] - input[(i+1)*in_stride]);
42  }
43 
44  low[((len-2)>>1) * low_stride] = av_clip_int16(input[((len-2)+0)*in_stride] + input[((len-2)+1)*in_stride]);
45  high[((len-2)>>1) * high_stride] = av_clip_int16((11* input[((len-2)+0)*in_stride] - 5 * input[((len-2)+1)*in_stride] -
46  4 * input[((len-2)-1)*in_stride] - 4 * input[((len-2)-2)*in_stride] +
47  1 * input[((len-2)-3)*in_stride] + 1 * input[((len-2)-4)*in_stride] + 4) >> 3);
48 }
49 
50 static void horiz_filter(int16_t *input, int16_t *low, int16_t *high,
51  ptrdiff_t in_stride, ptrdiff_t low_stride,
52  ptrdiff_t high_stride,
53  int width, int height)
54 {
55  for (int i = 0; i < height; i++) {
56  filter(input, 1, low, 1, high, 1, width);
57  input += in_stride;
58  low += low_stride;
59  high += high_stride;
60  }
61 }
62 
63 static void vert_filter(int16_t *input, int16_t *low, int16_t *high,
64  ptrdiff_t in_stride, ptrdiff_t low_stride,
65  ptrdiff_t high_stride,
66  int width, int height)
67 {
68  for (int i = 0; i < width; i++)
69  filter(&input[i], in_stride, &low[i], low_stride, &high[i], high_stride, height);
70 }
71 
73 {
74  c->horiz_filter = horiz_filter;
75  c->vert_filter = vert_filter;
76 
77  if (ARCH_X86)
79 }
vert_filter
static void vert_filter(int16_t *input, int16_t *low, int16_t *high, ptrdiff_t in_stride, ptrdiff_t low_stride, ptrdiff_t high_stride, int width, int height)
Definition: cfhdencdsp.c:63
ff_cfhdencdsp_init_x86
void ff_cfhdencdsp_init_x86(CFHDEncDSPContext *c)
Definition: cfhdencdsp_init.c:38
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
width
#define width
av_clip_int16
#define av_clip_int16
Definition: common.h:137
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
cfhdencdsp.h
height
#define height
attributes.h
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
i
int i
Definition: input.c:407
common.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
len
int len
Definition: vorbis_enc_data.h:452
ff_cfhdencdsp_init
av_cold void ff_cfhdencdsp_init(CFHDEncDSPContext *c)
Definition: cfhdencdsp.c:72
horiz_filter
static void horiz_filter(int16_t *input, int16_t *low, int16_t *high, ptrdiff_t in_stride, ptrdiff_t low_stride, ptrdiff_t high_stride, int width, int height)
Definition: cfhdencdsp.c:50
CFHDEncDSPContext
Definition: cfhdencdsp.h:25
filter
static av_always_inline void filter(int16_t *input, ptrdiff_t in_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len)
Definition: cfhdencdsp.c:27