Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Header file for hardcoded motion pixels RGB to YUV table | ||
3 | * | ||
4 | * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de> | ||
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 | #ifndef AVCODEC_MOTIONPIXELS_TABLEGEN_H | ||
24 | #define AVCODEC_MOTIONPIXELS_TABLEGEN_H | ||
25 | |||
26 | #include <stdint.h> | ||
27 | #include "libavutil/attributes.h" | ||
28 | |||
29 | typedef struct YuvPixel { | ||
30 | int8_t y, v, u; | ||
31 | } YuvPixel; | ||
32 | |||
33 | 5832515 | static int mp_yuv_to_rgb(int y, int v, int u, int clip_rgb) { | |
34 | 5832515 | const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP; | |
35 | int r, g, b; | ||
36 | |||
37 | 5832515 | r = (1000 * y + 701 * v) / 1000; | |
38 | 5832515 | g = (1000 * y - 357 * v - 172 * u) / 1000; | |
39 | 5832515 | b = (1000 * y + 886 * u) / 1000; | |
40 |
2/2✓ Branch 0 taken 5705507 times.
✓ Branch 1 taken 127008 times.
|
5832515 | if (clip_rgb) |
41 | 5705507 | return ((cm[r * 8] & 0xF8) << 7) | ((cm[g * 8] & 0xF8) << 2) | (cm[b * 8] >> 3); | |
42 |
6/6✓ Branch 0 taken 85050 times.
✓ Branch 1 taken 41958 times.
✓ Branch 2 taken 63670 times.
✓ Branch 3 taken 21380 times.
✓ Branch 4 taken 33922 times.
✓ Branch 5 taken 29748 times.
|
127008 | if ((unsigned)r < 32 && (unsigned)g < 32 && (unsigned)b < 32) |
43 | 33922 | return (r << 10) | (g << 5) | b; | |
44 | 93086 | return 1 << 15; | |
45 | } | ||
46 | |||
47 | #if CONFIG_HARDCODED_TABLES | ||
48 | #define motionpixels_tableinit() | ||
49 | #include "libavcodec/motionpixels_tables.h" | ||
50 | #else | ||
51 | static YuvPixel mp_rgb_yuv_table[1 << 15]; | ||
52 | |||
53 | 1024 | static av_cold void mp_set_zero_yuv(YuvPixel *p) | |
54 | { | ||
55 | int i, j; | ||
56 | |||
57 |
2/2✓ Branch 0 taken 31744 times.
✓ Branch 1 taken 1024 times.
|
32768 | for (i = 0; i < 31; ++i) { |
58 |
2/2✓ Branch 0 taken 507904 times.
✓ Branch 1 taken 31744 times.
|
539648 | for (j = 31; j > i; --j) |
59 |
2/2✓ Branch 0 taken 11975 times.
✓ Branch 1 taken 495929 times.
|
507904 | if (!(p[j].u | p[j].v | p[j].y)) |
60 | 11975 | p[j] = p[j - 1]; | |
61 |
2/2✓ Branch 0 taken 507904 times.
✓ Branch 1 taken 31744 times.
|
539648 | for (j = 0; j < 31 - i; ++j) |
62 |
2/2✓ Branch 0 taken 6066 times.
✓ Branch 1 taken 501838 times.
|
507904 | if (!(p[j].u | p[j].v | p[j].y)) |
63 | 6066 | p[j] = p[j + 1]; | |
64 | } | ||
65 | 1024 | } | |
66 | |||
67 | 1 | static av_cold void mp_build_rgb_yuv_table(YuvPixel *p) | |
68 | { | ||
69 | int y, v, u, i; | ||
70 | |||
71 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1 times.
|
33 | for (y = 0; y <= 31; ++y) |
72 |
2/2✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 32 times.
|
2048 | for (v = -31; v <= 31; ++v) |
73 |
2/2✓ Branch 0 taken 127008 times.
✓ Branch 1 taken 2016 times.
|
129024 | for (u = -31; u <= 31; ++u) { |
74 | 127008 | i = mp_yuv_to_rgb(y, v, u, 0); | |
75 |
4/4✓ Branch 0 taken 33922 times.
✓ Branch 1 taken 93086 times.
✓ Branch 2 taken 23226 times.
✓ Branch 3 taken 10696 times.
|
127008 | if (i < (1 << 15) && !(p[i].u | p[i].v | p[i].y)) { |
76 | 23226 | p[i].y = y; | |
77 | 23226 | p[i].v = v; | |
78 | 23226 | p[i].u = u; | |
79 | } | ||
80 | } | ||
81 |
2/2✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 1 times.
|
1025 | for (i = 0; i < 1024; ++i) |
82 | 1024 | mp_set_zero_yuv(p + i * 32); | |
83 | 1 | } | |
84 | |||
85 | 1 | static av_cold void motionpixels_tableinit(void) | |
86 | { | ||
87 | 1 | mp_build_rgb_yuv_table(mp_rgb_yuv_table); | |
88 | 1 | } | |
89 | #endif /* CONFIG_HARDCODED_TABLES */ | ||
90 | |||
91 | #endif /* AVCODEC_MOTIONPIXELS_TABLEGEN_H */ | ||
92 |