FFmpeg  4.0
huffyuvdsp.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
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  * 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 GNU
12  * 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 FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <stdint.h>
20 
21 #include "config.h"
22 #include "libavutil/attributes.h"
23 #include "mathops.h"
24 #include "huffyuvdsp.h"
25 
26 // 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
27 #define pw_1 (ULONG_MAX / UINT16_MAX)
28 
29 static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
30  long i;
31  unsigned long pw_lsb = (mask >> 1) * pw_1;
32  unsigned long pw_msb = pw_lsb + pw_1;
33  for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
34  long a = *(long*)(src+i);
35  long b = *(long*)(dst+i);
36  *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb);
37  }
38  for(; i<w; i++)
39  dst[i] = (dst[i] + src[i]) & mask;
40 }
41 
42 static void add_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top){
43  int i;
44  uint16_t l, lt;
45 
46  l = *left;
47  lt = *left_top;
48 
49  for(i=0; i<w; i++){
50  l = (mid_pred(l, src[i], (l + src[i] - lt) & mask) + diff[i]) & mask;
51  lt = src[i];
52  dst[i] = l;
53  }
54 
55  *left = l;
56  *left_top = lt;
57 }
58 
59 static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
60  intptr_t w, uint8_t *left)
61 {
62  int i;
63  uint8_t r = left[R], g = left[G], b = left[B], a = left[A];
64 
65  for (i = 0; i < w; i++) {
66  b += src[4 * i + B];
67  g += src[4 * i + G];
68  r += src[4 * i + R];
69  a += src[4 * i + A];
70 
71  dst[4 * i + B] = b;
72  dst[4 * i + G] = g;
73  dst[4 * i + R] = r;
74  dst[4 * i + A] = a;
75  }
76 
77  left[B] = b;
78  left[G] = g;
79  left[R] = r;
80  left[A] = a;
81 }
82 
84 {
88 
89  if (ARCH_X86)
90  ff_huffyuvdsp_init_x86(c, pix_fmt);
91 }
static enum AVPixelFormat pix_fmt
const char * g
Definition: vf_curves.c:112
const char * b
Definition: vf_curves.c:113
#define src
Definition: vp8dsp.c:254
Macro definitions for various function/variable attributes.
void(* add_int16)(uint16_t *dst, const uint16_t *src, unsigned mask, int w)
Definition: huffyuvdsp.h:39
#define pw_1
Definition: huffyuvdsp.c:27
uint8_t
#define av_cold
Definition: attributes.h:82
static void add_hfyu_median_pred_int16_c(uint16_t *dst, const uint16_t *src, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top)
Definition: huffyuvdsp.c:42
#define A(x)
Definition: vp56_arith.h:28
#define R
Definition: huffyuvdsp.h:34
static const uint16_t mask[17]
Definition: lzw.c:38
#define ARCH_X86
Definition: config.h:38
#define B
Definition: huffyuvdsp.h:32
const char * r
Definition: vf_curves.c:111
uint8_t w
Definition: llviddspenc.c:38
void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt)
av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c, enum AVPixelFormat pix_fmt)
Definition: huffyuvdsp.c:83
#define mid_pred
Definition: mathops.h:97
void(* add_hfyu_left_pred_bgr32)(uint8_t *dst, const uint8_t *src, intptr_t w, uint8_t *left)
Definition: huffyuvdsp.h:45
int
#define G
Definition: huffyuvdsp.h:33
void(* add_hfyu_median_pred_int16)(uint16_t *dst, const uint16_t *top, const uint16_t *diff, unsigned mask, int w, int *left, int *left_top)
Definition: huffyuvdsp.h:42
static double c[64]
static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src, intptr_t w, uint8_t *left)
Definition: huffyuvdsp.c:59
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w)
Definition: huffyuvdsp.c:29
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60