/src/ffmpeg/libavcodec/v210enc_init.h
Line | Count | Source |
1 | | /* |
2 | | * V210 encoder DSP init |
3 | | * |
4 | | * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at> |
5 | | * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com> |
6 | | * |
7 | | * This file is part of FFmpeg. |
8 | | * |
9 | | * FFmpeg is free software; you can redistribute it and/or |
10 | | * modify it under the terms of the GNU Lesser General Public |
11 | | * License as published by the Free Software Foundation; either |
12 | | * version 2.1 of the License, or (at your option) any later version. |
13 | | * |
14 | | * FFmpeg is distributed in the hope that it will be useful, |
15 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | | * Lesser General Public License for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public |
20 | | * License along with FFmpeg; if not, write to the Free Software |
21 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | | */ |
23 | | |
24 | | #ifndef AVCODEC_V210ENC_INIT_H |
25 | | #define AVCODEC_V210ENC_INIT_H |
26 | | |
27 | | #include <stddef.h> |
28 | | #include <stdint.h> |
29 | | |
30 | | #include "config.h" |
31 | | #include "libavutil/attributes.h" |
32 | | #include "libavutil/common.h" |
33 | | #include "libavutil/intreadwrite.h" |
34 | | #include "v210enc.h" |
35 | | |
36 | 39.8M | #define CLIP(v, depth) av_clip(v, 1<<(depth-8), ((1<<depth)-(1<<(depth-8))-1)) |
37 | | #define WRITE_PIXELS(a, b, c, depth) \ |
38 | 10.7M | do { \ |
39 | 10.7M | val = CLIP(*a++, depth) << (10-depth); \ |
40 | 10.7M | val |= (CLIP(*b++, depth) << (20-depth)) | \ |
41 | 10.7M | (CLIP(*c++, depth) << (30-depth)); \ |
42 | 10.7M | AV_WL32(dst, val); \ |
43 | 10.7M | dst += 4; \ |
44 | 10.7M | } while (0) |
45 | | |
46 | | static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u, |
47 | | const uint8_t *v, uint8_t *dst, |
48 | | ptrdiff_t width) |
49 | 1.11M | { |
50 | 1.11M | uint32_t val; |
51 | | |
52 | | /* unroll this to match the assembly */ |
53 | 1.47M | for (int i = 0; i < width - 11; i += 12) { |
54 | 358k | WRITE_PIXELS(u, y, v, 8); |
55 | 358k | WRITE_PIXELS(y, u, y, 8); |
56 | 358k | WRITE_PIXELS(v, y, u, 8); |
57 | 358k | WRITE_PIXELS(y, v, y, 8); |
58 | 358k | WRITE_PIXELS(u, y, v, 8); |
59 | 358k | WRITE_PIXELS(y, u, y, 8); |
60 | 358k | WRITE_PIXELS(v, y, u, 8); |
61 | 358k | WRITE_PIXELS(y, v, y, 8); |
62 | 358k | } |
63 | 1.11M | } |
64 | | |
65 | | static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u, |
66 | | const uint16_t *v, uint8_t *dst, |
67 | | ptrdiff_t width) |
68 | 1.18M | { |
69 | 1.18M | uint32_t val; |
70 | | |
71 | 2.23M | for (int i = 0; i < width - 5; i += 6) { |
72 | 1.04M | WRITE_PIXELS(u, y, v, 10); |
73 | 1.04M | WRITE_PIXELS(y, u, y, 10); |
74 | 1.04M | WRITE_PIXELS(v, y, u, 10); |
75 | 1.04M | WRITE_PIXELS(y, v, y, 10); |
76 | 1.04M | } |
77 | 1.18M | } |
78 | | |
79 | | av_unused av_cold static void ff_v210enc_init(V210EncContext *s) |
80 | 1.03k | { |
81 | 1.03k | s->pack_line_8 = v210_planar_pack_8_c; |
82 | 1.03k | s->pack_line_10 = v210_planar_pack_10_c; |
83 | 1.03k | s->sample_factor_8 = 2; |
84 | 1.03k | s->sample_factor_10 = 1; |
85 | | |
86 | | #if ARCH_X86 && HAVE_X86ASM |
87 | | ff_v210enc_init_x86(s); |
88 | | #endif |
89 | 1.03k | } |
90 | | |
91 | | #endif /* AVCODEC_V210ENC_INIT_H */ |