9/10-bit: simplify clipping macros
[libav.git] / libavcodec / bit_depth_template.c
1 /*
2 * This file is part of Libav.
3 *
4 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "dsputil.h"
20
21 #ifndef BIT_DEPTH
22 #define BIT_DEPTH 8
23 #endif
24
25 #ifdef AVCODEC_H264_HIGH_DEPTH_H
26 # undef pixel
27 # undef pixel2
28 # undef pixel4
29 # undef dctcoef
30 # undef INIT_CLIP
31 # undef no_rnd_avg_pixel4
32 # undef rnd_avg_pixel4
33 # undef AV_RN2P
34 # undef AV_RN4P
35 # undef AV_RN4PA
36 # undef AV_WN2P
37 # undef AV_WN4P
38 # undef AV_WN4PA
39 # undef CLIP
40 # undef FUNC
41 # undef FUNCC
42 # undef av_clip_pixel
43 # undef PIXEL_SPLAT_X4
44 #else
45 # define AVCODEC_H264_HIGH_DEPTH_H
46 #endif
47
48 #if BIT_DEPTH > 8
49 # define pixel uint16_t
50 # define pixel2 uint32_t
51 # define pixel4 uint64_t
52 # define dctcoef int32_t
53
54 # define INIT_CLIP
55 # define no_rnd_avg_pixel4 no_rnd_avg64
56 # define rnd_avg_pixel4 rnd_avg64
57 # define AV_RN2P AV_RN32
58 # define AV_RN4P AV_RN64
59 # define AV_RN4PA AV_RN64A
60 # define AV_WN2P AV_WN32
61 # define AV_WN4P AV_WN64
62 # define AV_WN4PA AV_WN64A
63 # define PIXEL_SPLAT_X4(x) ((x)*0x0001000100010001ULL)
64
65 # define av_clip_pixel(a) av_clip_uintp2(a, BIT_DEPTH)
66 # define CLIP(a) av_clip_uintp2(a, BIT_DEPTH)
67 #else
68 # define pixel uint8_t
69 # define pixel2 uint16_t
70 # define pixel4 uint32_t
71 # define dctcoef int16_t
72
73 # define INIT_CLIP uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
74 # define no_rnd_avg_pixel4 no_rnd_avg32
75 # define rnd_avg_pixel4 rnd_avg32
76 # define AV_RN2P AV_RN16
77 # define AV_RN4P AV_RN32
78 # define AV_RN4PA AV_RN32A
79 # define AV_WN2P AV_WN16
80 # define AV_WN4P AV_WN32
81 # define AV_WN4PA AV_WN32A
82 # define PIXEL_SPLAT_X4(x) ((x)*0x01010101U)
83
84 # define av_clip_pixel(a) av_clip_uint8(a)
85 # define CLIP(a) cm[a]
86 #endif
87
88 #if BIT_DEPTH == 8
89 # define FUNC(a) a ## _8
90 # define FUNCC(a) a ## _8_c
91 #elif BIT_DEPTH == 9
92 # define FUNC(a) a ## _9
93 # define FUNCC(a) a ## _9_c
94 #elif BIT_DEPTH == 10
95 # define FUNC(a) a ## _10
96 # define FUNCC(a) a ## _10_c
97 #endif