diff options
Diffstat (limited to 'apps/codecs/libtremor/ffmpeg_render_line.h')
-rw-r--r-- | apps/codecs/libtremor/ffmpeg_render_line.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/apps/codecs/libtremor/ffmpeg_render_line.h b/apps/codecs/libtremor/ffmpeg_render_line.h new file mode 100644 index 0000000000..c429c274e6 --- /dev/null +++ b/apps/codecs/libtremor/ffmpeg_render_line.h | |||
@@ -0,0 +1,73 @@ | |||
1 | /** | ||
2 | * @file | ||
3 | * Common code for Vorbis I encoder and decoder | ||
4 | * @author Denes Balatoni ( dbalatoni programozo hu ) | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /* render_line and friend taken from ffmpeg (libavcodec/vorbis.c) */ | ||
24 | static inline void render_line_unrolled(int x, int y, int x1, | ||
25 | int sy, int ady, int adx, | ||
26 | ogg_int32_t *buf) | ||
27 | { | ||
28 | int err = -adx; | ||
29 | x -= x1 - 1; | ||
30 | buf += x1 - 1; | ||
31 | while (++x < 0) { | ||
32 | err += ady; | ||
33 | if (err >= 0) { | ||
34 | err += ady - adx; | ||
35 | y += sy; | ||
36 | buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]); | ||
37 | x++; | ||
38 | } | ||
39 | buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]); | ||
40 | } | ||
41 | if (x <= 0) { | ||
42 | if (err + ady >= 0) | ||
43 | y += sy; | ||
44 | buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | static void render_line(int x0, int y0, int x1, int y1, ogg_int32_t *buf) | ||
49 | { | ||
50 | int dy = y1 - y0; | ||
51 | int adx = x1 - x0; | ||
52 | int ady = abs(dy); | ||
53 | int sy = dy < 0 ? -1 : 1; | ||
54 | buf[x0] = MULT31_SHIFT15(buf[x0],FLOOR_fromdB_LOOKUP[y0]); | ||
55 | if (ady*2 <= adx) { // optimized common case | ||
56 | render_line_unrolled(x0, y0, x1, sy, ady, adx, buf); | ||
57 | } else { | ||
58 | int base = dy / adx; | ||
59 | int x = x0; | ||
60 | int y = y0; | ||
61 | int err = -adx; | ||
62 | ady -= abs(base) * adx; | ||
63 | while (++x < x1) { | ||
64 | y += base; | ||
65 | err += ady; | ||
66 | if (err >= 0) { | ||
67 | err -= adx; | ||
68 | y += sy; | ||
69 | } | ||
70 | buf[x] = MULT31_SHIFT15(buf[x],FLOOR_fromdB_LOOKUP[y]); | ||
71 | } | ||
72 | } | ||
73 | } | ||