1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (C) 2016 foo86
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14cabdff1aSopenharmony_ci * Lesser General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#ifndef AVCODEC_DCAMATH_H
22cabdff1aSopenharmony_ci#define AVCODEC_DCAMATH_H
23cabdff1aSopenharmony_ci
24cabdff1aSopenharmony_ci#include "libavutil/common.h"
25cabdff1aSopenharmony_ci#include "libavutil/intmath.h"
26cabdff1aSopenharmony_ci
27cabdff1aSopenharmony_cistatic inline int32_t norm__(int64_t a, int bits)
28cabdff1aSopenharmony_ci{
29cabdff1aSopenharmony_ci    if (bits > 0)
30cabdff1aSopenharmony_ci        return (int32_t)((a + (INT64_C(1) << (bits - 1))) >> bits);
31cabdff1aSopenharmony_ci    else
32cabdff1aSopenharmony_ci        return (int32_t)a;
33cabdff1aSopenharmony_ci}
34cabdff1aSopenharmony_ci
35cabdff1aSopenharmony_cistatic inline int32_t mul__(int32_t a, int32_t b, int bits)
36cabdff1aSopenharmony_ci{
37cabdff1aSopenharmony_ci    return norm__((int64_t)a * b, bits);
38cabdff1aSopenharmony_ci}
39cabdff1aSopenharmony_ci
40cabdff1aSopenharmony_cistatic inline int32_t norm13(int64_t a) { return norm__(a, 13); }
41cabdff1aSopenharmony_cistatic inline int32_t norm16(int64_t a) { return norm__(a, 16); }
42cabdff1aSopenharmony_cistatic inline int32_t norm20(int64_t a) { return norm__(a, 20); }
43cabdff1aSopenharmony_cistatic inline int32_t norm21(int64_t a) { return norm__(a, 21); }
44cabdff1aSopenharmony_cistatic inline int32_t norm23(int64_t a) { return norm__(a, 23); }
45cabdff1aSopenharmony_ci
46cabdff1aSopenharmony_cistatic inline int32_t mul15(int32_t a, int32_t b) { return mul__(a, b, 15); }
47cabdff1aSopenharmony_cistatic inline int32_t mul16(int32_t a, int32_t b) { return mul__(a, b, 16); }
48cabdff1aSopenharmony_cistatic inline int32_t mul17(int32_t a, int32_t b) { return mul__(a, b, 17); }
49cabdff1aSopenharmony_cistatic inline int32_t mul22(int32_t a, int32_t b) { return mul__(a, b, 22); }
50cabdff1aSopenharmony_cistatic inline int32_t mul23(int32_t a, int32_t b) { return mul__(a, b, 23); }
51cabdff1aSopenharmony_cistatic inline int32_t mul31(int32_t a, int32_t b) { return mul__(a, b, 31); }
52cabdff1aSopenharmony_cistatic inline int32_t mul32(int32_t a, int32_t b) { return mul__(a, b, 32); }
53cabdff1aSopenharmony_ci
54cabdff1aSopenharmony_cistatic inline int32_t clip23(int32_t a) { return av_clip_intp2(a, 23); }
55cabdff1aSopenharmony_ci
56cabdff1aSopenharmony_ci#endif
57