| 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 "libavutil/imgutils.c" | ||
| 20 | #include "libavutil/crc.h" | ||
| 21 | #include "libavutil/mem.h" | ||
| 22 | |||
| 23 | 251 | static int check_image_fill(enum AVPixelFormat pix_fmt, int w, int h) { | |
| 24 | uint8_t *data[4]; | ||
| 25 | size_t sizes[4]; | ||
| 26 | 251 | ptrdiff_t linesizes1[4], offsets[3] = { 0 }; | |
| 27 | int i, total_size, linesizes[4]; | ||
| 28 | |||
| 29 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 251 times.
|
251 | if (av_image_fill_linesizes(linesizes, pix_fmt, w) < 0) |
| 30 | ✗ | return -1; | |
| 31 |
2/2✓ Branch 0 taken 1004 times.
✓ Branch 1 taken 251 times.
|
1255 | for (i = 0; i < 4; i++) |
| 32 | 1004 | linesizes1[i] = linesizes[i]; | |
| 33 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 251 times.
|
251 | if (av_image_fill_plane_sizes(sizes, pix_fmt, h, linesizes1) < 0) |
| 34 | ✗ | return -1; | |
| 35 | 251 | total_size = av_image_fill_pointers(data, pix_fmt, h, (void *)1, linesizes); | |
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 251 times.
|
251 | if (total_size < 0) |
| 37 | ✗ | return -1; | |
| 38 |
4/4✓ Branch 0 taken 744 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 533 times.
✓ Branch 3 taken 211 times.
|
784 | for (i = 0; i < 4 && data[i]; i++); |
| 39 | 251 | printf("planes: %d", i); | |
| 40 | // Test the output of av_image_fill_linesizes() | ||
| 41 | 251 | printf(", linesizes:"); | |
| 42 |
2/2✓ Branch 0 taken 1004 times.
✓ Branch 1 taken 251 times.
|
1255 | for (i = 0; i < 4; i++) |
| 43 | 1004 | printf(" %3d", linesizes[i]); | |
| 44 | // Test the output of av_image_fill_plane_sizes() | ||
| 45 | 251 | printf(", plane_sizes:"); | |
| 46 |
2/2✓ Branch 0 taken 1004 times.
✓ Branch 1 taken 251 times.
|
1255 | for (i = 0; i < 4; i++) |
| 47 | 1004 | printf(" %5zu", sizes[i]); | |
| 48 | // Test the output of av_image_fill_pointers() | ||
| 49 |
4/4✓ Branch 0 taken 493 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 211 times.
|
533 | for (i = 0; i < 3 && data[i + 1]; i++) |
| 50 | 282 | offsets[i] = data[i + 1] - data[i]; | |
| 51 | 251 | printf(", plane_offsets:"); | |
| 52 |
2/2✓ Branch 0 taken 753 times.
✓ Branch 1 taken 251 times.
|
1004 | for (i = 0; i < 3; i++) |
| 53 | 753 | printf(" %5td", offsets[i]); | |
| 54 | 251 | printf(", total_size: %d", total_size); | |
| 55 | |||
| 56 | 251 | return 0; | |
| 57 | } | ||
| 58 | |||
| 59 | 251 | static int check_image_fill_black(const AVPixFmtDescriptor *desc, enum AVPixelFormat pix_fmt, int w, int h) | |
| 60 | { | ||
| 61 | uint8_t *data[4]; | ||
| 62 | ptrdiff_t linesizes1[4]; | ||
| 63 | int ret, total_size, linesizes[4]; | ||
| 64 | |||
| 65 | 251 | ret = av_image_fill_linesizes(linesizes, pix_fmt, w); | |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 251 times.
|
251 | if (ret < 0) |
| 67 | ✗ | return ret; | |
| 68 | 251 | total_size = av_image_alloc(data, linesizes, w, h, pix_fmt, 4); | |
| 69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 251 times.
|
251 | if (total_size < 0) { |
| 70 | ✗ | printf("alloc failure"); | |
| 71 | ✗ | return total_size; | |
| 72 | } | ||
| 73 | 251 | printf("total_size: %6d", total_size); | |
| 74 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 250 times.
|
251 | if (desc->flags & AV_PIX_FMT_FLAG_PAL) |
| 75 | 1 | total_size -= 256 * 4; | |
| 76 | // Make it non-black by default... | ||
| 77 | 251 | memset(data[0], 0xA3, total_size); | |
| 78 |
2/2✓ Branch 0 taken 1004 times.
✓ Branch 1 taken 251 times.
|
1255 | for (int i = 0; i < 4; i++) |
| 79 | 1004 | linesizes1[i] = linesizes[i]; | |
| 80 |
2/2✓ Branch 0 taken 753 times.
✓ Branch 1 taken 251 times.
|
1004 | for (enum AVColorRange range = 0; range < AVCOL_RANGE_NB; range++) { |
| 81 | 753 | ret = av_image_fill_black(data, linesizes1, pix_fmt, range, w, h); | |
| 82 | 753 | printf(", black_%s_crc: ", av_color_range_name(range)); | |
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 753 times.
|
753 | if (ret < 0) { |
| 84 | ✗ | printf("----------"); | |
| 85 | } else { | ||
| 86 | 753 | const AVCRC *crc = av_crc_get_table(AV_CRC_32_IEEE_LE); | |
| 87 | 753 | printf("0x%08"PRIx32, av_crc(crc, 0, data[0], total_size)); | |
| 88 | } | ||
| 89 | } | ||
| 90 | 251 | av_freep(&data[0]); | |
| 91 | |||
| 92 | 251 | return 0; | |
| 93 | } | ||
| 94 | |||
| 95 | 1 | int main(void) | |
| 96 | { | ||
| 97 | int64_t x, y; | ||
| 98 | |||
| 99 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 1 times.
|
56 | for (y = -1; y<UINT_MAX; y+= y/2 + 1) { |
| 100 |
2/2✓ Branch 0 taken 3025 times.
✓ Branch 1 taken 55 times.
|
3080 | for (x = -1; x<UINT_MAX; x+= x/2 + 1) { |
| 101 | 3025 | int ret = av_image_check_size(x, y, 0, NULL); | |
| 102 | 3025 | printf("%d", ret >= 0); | |
| 103 | } | ||
| 104 | 55 | printf("\n"); | |
| 105 | } | ||
| 106 | 1 | printf("\n"); | |
| 107 | |||
| 108 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (int i = 0; i < 2; i++) { |
| 109 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | printf(i ? "\nimage_fill_black tests\n" : "image_fill tests\n"); |
| 110 |
2/2✓ Branch 1 taken 534 times.
✓ Branch 2 taken 2 times.
|
536 | for (const AVPixFmtDescriptor *desc = NULL; desc = av_pix_fmt_desc_next(desc);) { |
| 111 | 534 | int w = 64, h = 48; | |
| 112 | 534 | enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(desc); | |
| 113 | |||
| 114 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 502 times.
|
534 | if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) |
| 115 | 32 | continue; | |
| 116 | |||
| 117 | 502 | printf("%-16s", desc->name); | |
| 118 |
2/2✓ Branch 0 taken 251 times.
✓ Branch 1 taken 251 times.
|
502 | if (i == 0) |
| 119 | 251 | check_image_fill(pix_fmt, w, h); | |
| 120 | else | ||
| 121 | 251 | check_image_fill_black(desc, pix_fmt, w, h); | |
| 122 | 502 | printf("\n"); | |
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | 1 | return 0; | |
| 127 | } | ||
| 128 |