| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg 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 | * FFmpeg 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 FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "edge_common.h" | ||
| 20 | |||
| 21 | // Internal helper for ff_sobel() | ||
| 22 | 34924828 | static int get_rounded_direction(int gx, int gy) | |
| 23 | { | ||
| 24 | /* reference angles: | ||
| 25 | * tan( pi/8) = sqrt(2)-1 | ||
| 26 | * tan(3pi/8) = sqrt(2)+1 | ||
| 27 | * Gy/Gx is the tangent of the angle (theta), so Gy/Gx is compared against | ||
| 28 | * <ref-angle>, or more simply Gy against <ref-angle>*Gx | ||
| 29 | * | ||
| 30 | * Gx and Gy bounds = [-1020;1020], using 16-bit arithmetic: | ||
| 31 | * round((sqrt(2)-1) * (1<<16)) = 27146 | ||
| 32 | * round((sqrt(2)+1) * (1<<16)) = 158218 | ||
| 33 | */ | ||
| 34 |
2/2✓ Branch 0 taken 19561364 times.
✓ Branch 1 taken 15363464 times.
|
34924828 | if (gx) { |
| 35 | int tanpi8gx, tan3pi8gx; | ||
| 36 | |||
| 37 |
2/2✓ Branch 0 taken 8194174 times.
✓ Branch 1 taken 11367190 times.
|
19561364 | if (gx < 0) |
| 38 | 8194174 | gx = -gx, gy = -gy; | |
| 39 | 19561364 | gy *= (1 << 16); | |
| 40 | 19561364 | tanpi8gx = 27146 * gx; | |
| 41 | 19561364 | tan3pi8gx = 158218 * gx; | |
| 42 |
4/4✓ Branch 0 taken 16808375 times.
✓ Branch 1 taken 2752989 times.
✓ Branch 2 taken 3368807 times.
✓ Branch 3 taken 13439568 times.
|
19561364 | if (gy > -tan3pi8gx && gy < -tanpi8gx) return DIRECTION_45UP; |
| 43 |
4/4✓ Branch 0 taken 13439568 times.
✓ Branch 1 taken 2752989 times.
✓ Branch 2 taken 4840797 times.
✓ Branch 3 taken 8598771 times.
|
16192557 | if (gy > -tanpi8gx && gy < tanpi8gx) return DIRECTION_HORIZONTAL; |
| 44 |
4/4✓ Branch 0 taken 8598771 times.
✓ Branch 1 taken 2752989 times.
✓ Branch 2 taken 5679341 times.
✓ Branch 3 taken 2919430 times.
|
11351760 | if (gy > tanpi8gx && gy < tan3pi8gx) return DIRECTION_45DOWN; |
| 45 | } | ||
| 46 | 21035883 | return DIRECTION_VERTICAL; | |
| 47 | } | ||
| 48 | |||
| 49 | #undef DEPTH | ||
| 50 | #define DEPTH 8 | ||
| 51 | #include "edge_template.c" | ||
| 52 | |||
| 53 | #undef DEPTH | ||
| 54 | #define DEPTH 16 | ||
| 55 | #include "edge_template.c" | ||
| 56 | |||
| 57 | // Filters rounded gradients to drop all non-maxima | ||
| 58 | // Expects gradients generated by ff_sobel() | ||
| 59 | // Expects zero's destination buffer | ||
| 60 | 105 | void ff_non_maximum_suppression(int w, int h, | |
| 61 | uint8_t *dst, int dst_linesize, | ||
| 62 | const int8_t *dir, int dir_linesize, | ||
| 63 | const uint16_t *src, int src_linesize) | ||
| 64 | { | ||
| 65 | int i, j; | ||
| 66 | |||
| 67 | #define COPY_MAXIMA(ay, ax, by, bx) do { \ | ||
| 68 | if (src[i] > src[(ay)*src_linesize + i+(ax)] && \ | ||
| 69 | src[i] > src[(by)*src_linesize + i+(bx)]) \ | ||
| 70 | dst[i] = av_clip_uint8(src[i]); \ | ||
| 71 | } while (0) | ||
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 50262 times.
✓ Branch 1 taken 105 times.
|
50367 | for (j = 1; j < h - 1; j++) { |
| 74 | 50262 | dst += dst_linesize; | |
| 75 | 50262 | dir += dir_linesize; | |
| 76 | 50262 | src += src_linesize; | |
| 77 |
2/2✓ Branch 0 taken 34924828 times.
✓ Branch 1 taken 50262 times.
|
34975090 | for (i = 1; i < w - 1; i++) { |
| 78 |
4/5✓ Branch 0 taken 3368807 times.
✓ Branch 1 taken 5679341 times.
✓ Branch 2 taken 4840797 times.
✓ Branch 3 taken 21035883 times.
✗ Branch 4 not taken.
|
34924828 | switch (dir[i]) { |
| 79 |
4/4✓ Branch 0 taken 1742326 times.
✓ Branch 1 taken 1626481 times.
✓ Branch 2 taken 831109 times.
✓ Branch 3 taken 911217 times.
|
3368807 | case DIRECTION_45UP: COPY_MAXIMA( 1, -1, -1, 1); break; |
| 80 |
4/4✓ Branch 0 taken 2820907 times.
✓ Branch 1 taken 2858434 times.
✓ Branch 2 taken 1411973 times.
✓ Branch 3 taken 1408934 times.
|
5679341 | case DIRECTION_45DOWN: COPY_MAXIMA(-1, -1, 1, 1); break; |
| 81 |
4/4✓ Branch 0 taken 2231850 times.
✓ Branch 1 taken 2608947 times.
✓ Branch 2 taken 707101 times.
✓ Branch 3 taken 1524749 times.
|
4840797 | case DIRECTION_HORIZONTAL: COPY_MAXIMA( 0, -1, 0, 1); break; |
| 82 |
4/4✓ Branch 0 taken 4046332 times.
✓ Branch 1 taken 16989551 times.
✓ Branch 2 taken 1182003 times.
✓ Branch 3 taken 2864329 times.
|
21035883 | case DIRECTION_VERTICAL: COPY_MAXIMA(-1, 0, 1, 0); break; |
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | 105 | } | |
| 87 | |||
| 88 | // Filter to keep all pixels > high, and keep all pixels > low where all surrounding pixels > high | ||
| 89 | 105 | void ff_double_threshold(int low, int high, int w, int h, | |
| 90 | uint8_t *dst, int dst_linesize, | ||
| 91 | const uint8_t *src, int src_linesize) | ||
| 92 | { | ||
| 93 | int i, j; | ||
| 94 | |||
| 95 |
2/2✓ Branch 0 taken 50472 times.
✓ Branch 1 taken 105 times.
|
50577 | for (j = 0; j < h; j++) { |
| 96 |
2/2✓ Branch 0 taken 35122144 times.
✓ Branch 1 taken 50472 times.
|
35172616 | for (i = 0; i < w; i++) { |
| 97 |
2/2✓ Branch 0 taken 2864525 times.
✓ Branch 1 taken 32257619 times.
|
35122144 | if (src[i] > high) { |
| 98 | 2864525 | dst[i] = src[i]; | |
| 99 | 2864525 | continue; | |
| 100 | } | ||
| 101 | |||
| 102 |
8/8✓ Branch 0 taken 32207147 times.
✓ Branch 1 taken 50472 times.
✓ Branch 2 taken 32156675 times.
✓ Branch 3 taken 50472 times.
✓ Branch 4 taken 32108489 times.
✓ Branch 5 taken 48186 times.
✓ Branch 6 taken 32060303 times.
✓ Branch 7 taken 48186 times.
|
32257619 | if (!(!i || i == w - 1 || !j || j == h - 1) && |
| 103 |
2/2✓ Branch 0 taken 493857 times.
✓ Branch 1 taken 31566446 times.
|
32060303 | src[i] > low && |
| 104 |
2/2✓ Branch 0 taken 483827 times.
✓ Branch 1 taken 10030 times.
|
493857 | (src[-src_linesize + i-1] > high || |
| 105 |
2/2✓ Branch 0 taken 473979 times.
✓ Branch 1 taken 9848 times.
|
483827 | src[-src_linesize + i ] > high || |
| 106 |
2/2✓ Branch 0 taken 467464 times.
✓ Branch 1 taken 6515 times.
|
473979 | src[-src_linesize + i+1] > high || |
| 107 |
2/2✓ Branch 0 taken 458354 times.
✓ Branch 1 taken 9110 times.
|
467464 | src[ i-1] > high || |
| 108 |
2/2✓ Branch 0 taken 450784 times.
✓ Branch 1 taken 7570 times.
|
458354 | src[ i+1] > high || |
| 109 |
2/2✓ Branch 0 taken 445139 times.
✓ Branch 1 taken 5645 times.
|
450784 | src[ src_linesize + i-1] > high || |
| 110 |
2/2✓ Branch 0 taken 437813 times.
✓ Branch 1 taken 7326 times.
|
445139 | src[ src_linesize + i ] > high || |
| 111 |
2/2✓ Branch 0 taken 6116 times.
✓ Branch 1 taken 431697 times.
|
437813 | src[ src_linesize + i+1] > high)) |
| 112 | 62160 | dst[i] = src[i]; | |
| 113 | else | ||
| 114 | 32195459 | dst[i] = 0; | |
| 115 | } | ||
| 116 | 50472 | dst += dst_linesize; | |
| 117 | 50472 | src += src_linesize; | |
| 118 | } | ||
| 119 | 105 | } | |
| 120 |