| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * rectangle filling function | ||
| 3 | * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * useful rectangle filling function | ||
| 25 | * @author Michael Niedermayer <michaelni@gmx.at> | ||
| 26 | */ | ||
| 27 | |||
| 28 | #ifndef AVCODEC_RECTANGLE_H | ||
| 29 | #define AVCODEC_RECTANGLE_H | ||
| 30 | |||
| 31 | #include "config.h" | ||
| 32 | #include "libavutil/common.h" | ||
| 33 | #include "libavutil/avassert.h" | ||
| 34 | |||
| 35 | /** | ||
| 36 | * fill a rectangle. | ||
| 37 | * @param h height of the rectangle, should be a constant | ||
| 38 | * @param w width of the rectangle, should be a constant | ||
| 39 | * @param size the size of val (1, 2 or 4), should be a constant | ||
| 40 | */ | ||
| 41 | 88123599 | static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ | |
| 42 | 88123599 | uint8_t *p= (uint8_t*)vp; | |
| 43 | av_assert2(size==1 || size==2 || size==4); | ||
| 44 | av_assert2(w<=4); | ||
| 45 | |||
| 46 | 88123599 | w *= size; | |
| 47 | 88123599 | stride *= size; | |
| 48 | |||
| 49 | av_assert2((((uintptr_t)vp)&(FFMIN(w, 8<<(HAVE_NEON|ARCH_PPC|HAVE_MMX))-1)) == 0); | ||
| 50 | av_assert2((stride&(w-1))==0); | ||
| 51 |
2/2✓ Branch 0 taken 24758556 times.
✓ Branch 1 taken 63365043 times.
|
88123599 | if(w==2){ |
| 52 |
1/2✓ Branch 0 taken 24758556 times.
✗ Branch 1 not taken.
|
24758556 | const uint16_t v= size==4 ? val : val*0x0101; |
| 53 | 24758556 | *(uint16_t*)(p + 0*stride)= v; | |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24758556 times.
|
24758556 | if(h==1) return; |
| 55 | 24758556 | *(uint16_t*)(p + 1*stride)= v; | |
| 56 |
2/2✓ Branch 0 taken 23046874 times.
✓ Branch 1 taken 1711682 times.
|
24758556 | if(h==2) return; |
| 57 | 1711682 | *(uint16_t*)(p + 2*stride)= v; | |
| 58 | 1711682 | *(uint16_t*)(p + 3*stride)= v; | |
| 59 |
2/2✓ Branch 0 taken 38090816 times.
✓ Branch 1 taken 25274227 times.
|
63365043 | }else if(w==4){ |
| 60 |
4/4✓ Branch 0 taken 37175014 times.
✓ Branch 1 taken 915802 times.
✓ Branch 2 taken 1840690 times.
✓ Branch 3 taken 35334324 times.
|
38090816 | const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101; |
| 61 | 38090816 | *(uint32_t*)(p + 0*stride)= v; | |
| 62 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 38090768 times.
|
38090816 | if(h==1) return; |
| 63 | 38090768 | *(uint32_t*)(p + 1*stride)= v; | |
| 64 |
2/2✓ Branch 0 taken 3613002 times.
✓ Branch 1 taken 34477766 times.
|
38090768 | if(h==2) return; |
| 65 | 34477766 | *(uint32_t*)(p + 2*stride)= v; | |
| 66 | 34477766 | *(uint32_t*)(p + 3*stride)= v; | |
| 67 |
2/2✓ Branch 0 taken 10093980 times.
✓ Branch 1 taken 15180247 times.
|
25274227 | }else if(w==8){ |
| 68 | // gcc cannot optimize 64-bit math on x86_32 | ||
| 69 | #if HAVE_FAST_64BIT | ||
| 70 |
2/2✓ Branch 0 taken 4914727 times.
✓ Branch 1 taken 5179253 times.
|
10093980 | const uint64_t v= size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL; |
| 71 | 10093980 | *(uint64_t*)(p + 0*stride)= v; | |
| 72 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 10093916 times.
|
10093980 | if(h==1) return; |
| 73 | 10093916 | *(uint64_t*)(p + 1*stride)= v; | |
| 74 |
2/2✓ Branch 0 taken 4677889 times.
✓ Branch 1 taken 5416027 times.
|
10093916 | if(h==2) return; |
| 75 | 5416027 | *(uint64_t*)(p + 2*stride)= v; | |
| 76 | 5416027 | *(uint64_t*)(p + 3*stride)= v; | |
| 77 |
1/2✓ Branch 0 taken 15180247 times.
✗ Branch 1 not taken.
|
15180247 | }else if(w==16){ |
| 78 | 15180247 | const uint64_t v= val*0x0100000001ULL; | |
| 79 | 15180247 | *(uint64_t*)(p + 0+0*stride)= v; | |
| 80 | 15180247 | *(uint64_t*)(p + 8+0*stride)= v; | |
| 81 | 15180247 | *(uint64_t*)(p + 0+1*stride)= v; | |
| 82 | 15180247 | *(uint64_t*)(p + 8+1*stride)= v; | |
| 83 |
2/2✓ Branch 0 taken 1937932 times.
✓ Branch 1 taken 13242315 times.
|
15180247 | if(h==2) return; |
| 84 | 13242315 | *(uint64_t*)(p + 0+2*stride)= v; | |
| 85 | 13242315 | *(uint64_t*)(p + 8+2*stride)= v; | |
| 86 | 13242315 | *(uint64_t*)(p + 0+3*stride)= v; | |
| 87 | 13242315 | *(uint64_t*)(p + 8+3*stride)= v; | |
| 88 | #else | ||
| 89 | const uint32_t v= size==2 ? val*0x00010001 : val; | ||
| 90 | *(uint32_t*)(p + 0+0*stride)= v; | ||
| 91 | *(uint32_t*)(p + 4+0*stride)= v; | ||
| 92 | if(h==1) return; | ||
| 93 | *(uint32_t*)(p + 0+1*stride)= v; | ||
| 94 | *(uint32_t*)(p + 4+1*stride)= v; | ||
| 95 | if(h==2) return; | ||
| 96 | *(uint32_t*)(p + 0+2*stride)= v; | ||
| 97 | *(uint32_t*)(p + 4+2*stride)= v; | ||
| 98 | *(uint32_t*)(p + 0+3*stride)= v; | ||
| 99 | *(uint32_t*)(p + 4+3*stride)= v; | ||
| 100 | }else if(w==16){ | ||
| 101 | *(uint32_t*)(p + 0+0*stride)= val; | ||
| 102 | *(uint32_t*)(p + 4+0*stride)= val; | ||
| 103 | *(uint32_t*)(p + 8+0*stride)= val; | ||
| 104 | *(uint32_t*)(p +12+0*stride)= val; | ||
| 105 | *(uint32_t*)(p + 0+1*stride)= val; | ||
| 106 | *(uint32_t*)(p + 4+1*stride)= val; | ||
| 107 | *(uint32_t*)(p + 8+1*stride)= val; | ||
| 108 | *(uint32_t*)(p +12+1*stride)= val; | ||
| 109 | if(h==2) return; | ||
| 110 | *(uint32_t*)(p + 0+2*stride)= val; | ||
| 111 | *(uint32_t*)(p + 4+2*stride)= val; | ||
| 112 | *(uint32_t*)(p + 8+2*stride)= val; | ||
| 113 | *(uint32_t*)(p +12+2*stride)= val; | ||
| 114 | *(uint32_t*)(p + 0+3*stride)= val; | ||
| 115 | *(uint32_t*)(p + 4+3*stride)= val; | ||
| 116 | *(uint32_t*)(p + 8+3*stride)= val; | ||
| 117 | *(uint32_t*)(p +12+3*stride)= val; | ||
| 118 | #endif | ||
| 119 | }else | ||
| 120 | av_assert2(0); | ||
| 121 | av_assert2(h==4); | ||
| 122 | } | ||
| 123 | |||
| 124 | #endif /* AVCODEC_RECTANGLE_H */ | ||
| 125 |