FFmpeg
cfhddsp.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 "cfhddsp.h"
26 
27 static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride,
28  const int16_t *low, ptrdiff_t low_stride,
29  const int16_t *high, ptrdiff_t high_stride,
30  int len, int clip)
31 {
32  int16_t tmp;
33  int i;
34 
35  tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3;
36  output[(2*0+0)*out_stride] = (tmp + high[0*high_stride]) >> 1;
37  if (clip)
38  output[(2*0+0)*out_stride] = av_clip_uintp2_c(output[(2*0+0)*out_stride], clip);
39 
40  tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3;
41  output[(2*0+1)*out_stride] = (tmp - high[0*high_stride]) >> 1;
42  if (clip)
43  output[(2*0+1)*out_stride] = av_clip_uintp2_c(output[(2*0+1)*out_stride], clip);
44 
45  for (i = 1; i < len - 1; i++) {
46  tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3;
47  output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1;
48  if (clip)
49  output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip);
50 
51  tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3;
52  output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1;
53  if (clip)
54  output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip);
55  }
56 
57  tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3;
58  output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1;
59  if (clip)
60  output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip);
61 
62  tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3;
63  output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1;
64  if (clip)
65  output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip);
66 }
67 
68 static void vert_filter(int16_t *output, ptrdiff_t out_stride,
69  const int16_t *low, ptrdiff_t low_stride,
70  const int16_t *high, ptrdiff_t high_stride,
71  int width, int height)
72 {
73  for (int i = 0; i < width; i++) {
74  filter(output, out_stride, low, low_stride, high, high_stride, height, 0);
75  low++;
76  high++;
77  output++;
78  }
79 }
80 
81 static void horiz_filter(int16_t *output, ptrdiff_t ostride,
82  const int16_t *low, ptrdiff_t lstride,
83  const int16_t *high, ptrdiff_t hstride,
84  int width, int height)
85 {
86  for (int i = 0; i < height; i++) {
87  filter(output, 1, low, 1, high, 1, width, 0);
88  low += lstride;
89  high += hstride;
90  output += ostride * 2;
91  }
92 }
93 
94 static void horiz_filter_clip(int16_t *output, const int16_t *low, const int16_t *high,
95  int width, int clip)
96 {
97  filter(output, 1, low, 1, high, 1, width, clip);
98 }
99 
100 static void horiz_filter_clip_bayer(int16_t *output, const int16_t *low, const int16_t *high,
101  int width, int clip)
102 {
103  filter(output, 2, low, 1, high, 1, width, clip);
104 }
105 
106 av_cold void ff_cfhddsp_init(CFHDDSPContext *c, int depth, int bayer)
107 {
108  c->horiz_filter = horiz_filter;
109  c->vert_filter = vert_filter;
110 
111  if (bayer)
112  c->horiz_filter_clip = horiz_filter_clip_bayer;
113  else
114  c->horiz_filter_clip = horiz_filter_clip;
115 
116  if (ARCH_X86)
117  ff_cfhddsp_init_x86(c, depth, bayer);
118 }
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:27
av_clip_uintp2_c
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.
Definition: common.h:302
CFHDDSPContext
Definition: cfhddsp.h:25
horiz_filter_clip
static void horiz_filter_clip(int16_t *output, const int16_t *low, const int16_t *high, int width, int clip)
Definition: cfhddsp.c:94
vert_filter
static void vert_filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int width, int height)
Definition: cfhddsp.c:68
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
width
#define width
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
height
#define height
attributes.h
i
int i
Definition: input.c:407
horiz_filter_clip_bayer
static void horiz_filter_clip_bayer(int16_t *output, const int16_t *low, const int16_t *high, int width, int clip)
Definition: cfhddsp.c:100
common.h
cfhddsp.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
horiz_filter
static void horiz_filter(int16_t *output, ptrdiff_t ostride, const int16_t *low, ptrdiff_t lstride, const int16_t *high, ptrdiff_t hstride, int width, int height)
Definition: cfhddsp.c:81
len
int len
Definition: vorbis_enc_data.h:452
filter
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
Definition: cfhddsp.c:27
ff_cfhddsp_init
av_cold void ff_cfhddsp_init(CFHDDSPContext *c, int depth, int bayer)
Definition: cfhddsp.c:106
ff_cfhddsp_init_x86
void ff_cfhddsp_init_x86(CFHDDSPContext *c, int format, int bayer)
Definition: cfhddsp_init.c:40
clip
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
Definition: vf_lut.c:162