FFmpeg
Loading...
Searching...
No Matches
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"
23#include "mathops.h"
24#include "huffyuv.h"
25#include "huffyuvdsp.h"
26
27// 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
28#define pw_1 (ULONG_MAX / UINT16_MAX)
29
30static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
31 long i;
32 unsigned long pw_lsb = (mask >> 1) * pw_1;
33 unsigned long pw_msb = pw_lsb + pw_1;
34 for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
35 long a = *(long*)(src+i);
36 long b = *(long*)(dst+i);
37 *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb);
38 }
39 for(; i<w; i++)
40 dst[i] = (dst[i] + src[i]) & mask;
41}
42
43static 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){
44 int i;
45 uint16_t l, lt;
46
47 l = *left;
48 lt = *left_top;
49
50 for(i=0; i<w; i++){
51 l = (mid_pred(l, src[i], (l + src[i] - lt) & mask) + diff[i]) & mask;
52 lt = src[i];
53 dst[i] = l;
54 }
55
56 *left = l;
57 *left_top = lt;
58}
59
60static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src,
61 intptr_t w, uint8_t *left)
62{
63 int i;
64 uint8_t r = left[R], g = left[G], b = left[B], a = left[A];
65
66 for (i = 0; i < w; i++) {
67 b += src[4 * i + B];
68 g += src[4 * i + G];
69 r += src[4 * i + R];
70 a += src[4 * i + A];
71
72 dst[4 * i + B] = b;
73 dst[4 * i + G] = g;
74 dst[4 * i + R] = r;
75 dst[4 * i + A] = a;
76 }
77
78 left[B] = b;
79 left[G] = g;
80 left[R] = r;
81 left[A] = a;
82}
83
85{
86 c->add_int16 = add_int16_c;
87 c->add_hfyu_median_pred_int16 = add_hfyu_median_pred_int16_c;
88 c->add_hfyu_left_pred_bgr32 = add_hfyu_left_pred_bgr32_c;
89
90#if ARCH_AARCH64
92#elif ARCH_RISCV
94#elif ARCH_X86 && HAVE_X86ASM
96#endif
97}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define A(x)
Definition vpx_arith.h:28
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
int a
huffyuv codec for libavcodec.
#define B
Definition huffyuv.h:42
#define R
Definition huffyuv.h:44
#define G
Definition huffyuv.h:43
void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c)
void ff_huffyuvdsp_init_riscv(HuffYUVDSPContext *c)
av_cold void ff_huffyuvdsp_init_aarch64(HuffYUVDSPContext *c)
#define r
Definition input.c:42
#define b
Definition input.c:43
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:43
av_cold void ff_huffyuvdsp_init(HuffYUVDSPContext *c)
Definition huffyuvdsp.c:84
static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w)
Definition huffyuvdsp.c:30
#define pw_1
Definition huffyuvdsp.c:28
static void add_hfyu_left_pred_bgr32_c(uint8_t *dst, const uint8_t *src, intptr_t w, uint8_t *left)
Definition huffyuvdsp.c:60
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
uint8_t w
Definition llvidencdsp.c:39
static const uint16_t mask[17]
Definition lzw.c:38
#define mid_pred
Definition mathops.h:115
#define src
Definition vp8dsp.c:248
const char * g
Definition vf_curves.c:128
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static double c[64]