2 * rectangle filling function
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of FFmpeg.
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.
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.
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
24 * useful rectangle filling function
25 * @author Michael Niedermayer <michaelni@gmx.at>
28 #ifndef FFMPEG_RECTANGLE_H
29 #define FFMPEG_RECTANGLE_H
31 #include "libavutil/common.h"
35 * @param h height of the rectangle, should be a constant
36 * @param w width of the rectangle, should be a constant
37 * @param size the size of val (1 or 4), should be a constant
39 static av_always_inline
void fill_rectangle(void *vp
, int w
, int h
, int stride
, uint32_t val
, int size
){
40 uint8_t *p
= (uint8_t*)vp
;
41 assert(size
==1 || size
==4);
47 assert((((long)vp
)&(FFMIN(w
, STRIDE_ALIGN
)-1)) == 0);
48 assert((stride
&(w
-1))==0);
50 const uint16_t v
= size
==4 ? val
: val
*0x0101;
51 *(uint16_t*)(p
+ 0*stride
)= v
;
53 *(uint16_t*)(p
+ 1*stride
)= v
;
55 *(uint16_t*)(p
+ 2*stride
)= v
;
56 *(uint16_t*)(p
+ 3*stride
)= v
;
58 const uint32_t v
= size
==4 ? val
: val
*0x01010101;
59 *(uint32_t*)(p
+ 0*stride
)= v
;
61 *(uint32_t*)(p
+ 1*stride
)= v
;
63 *(uint32_t*)(p
+ 2*stride
)= v
;
64 *(uint32_t*)(p
+ 3*stride
)= v
;
66 //gcc can't optimize 64bit math on x86_32
67 #ifdef HAVE_FAST_64BIT
68 const uint64_t v
= val
*0x0100000001ULL
;
69 *(uint64_t*)(p
+ 0*stride
)= v
;
71 *(uint64_t*)(p
+ 1*stride
)= v
;
73 *(uint64_t*)(p
+ 2*stride
)= v
;
74 *(uint64_t*)(p
+ 3*stride
)= v
;
76 const uint64_t v
= val
*0x0100000001ULL
;
77 *(uint64_t*)(p
+ 0+0*stride
)= v
;
78 *(uint64_t*)(p
+ 8+0*stride
)= v
;
79 *(uint64_t*)(p
+ 0+1*stride
)= v
;
80 *(uint64_t*)(p
+ 8+1*stride
)= v
;
82 *(uint64_t*)(p
+ 0+2*stride
)= v
;
83 *(uint64_t*)(p
+ 8+2*stride
)= v
;
84 *(uint64_t*)(p
+ 0+3*stride
)= v
;
85 *(uint64_t*)(p
+ 8+3*stride
)= v
;
87 *(uint32_t*)(p
+ 0+0*stride
)= val
;
88 *(uint32_t*)(p
+ 4+0*stride
)= val
;
90 *(uint32_t*)(p
+ 0+1*stride
)= val
;
91 *(uint32_t*)(p
+ 4+1*stride
)= val
;
93 *(uint32_t*)(p
+ 0+2*stride
)= val
;
94 *(uint32_t*)(p
+ 4+2*stride
)= val
;
95 *(uint32_t*)(p
+ 0+3*stride
)= val
;
96 *(uint32_t*)(p
+ 4+3*stride
)= val
;
98 *(uint32_t*)(p
+ 0+0*stride
)= val
;
99 *(uint32_t*)(p
+ 4+0*stride
)= val
;
100 *(uint32_t*)(p
+ 8+0*stride
)= val
;
101 *(uint32_t*)(p
+12+0*stride
)= val
;
102 *(uint32_t*)(p
+ 0+1*stride
)= val
;
103 *(uint32_t*)(p
+ 4+1*stride
)= val
;
104 *(uint32_t*)(p
+ 8+1*stride
)= val
;
105 *(uint32_t*)(p
+12+1*stride
)= val
;
107 *(uint32_t*)(p
+ 0+2*stride
)= val
;
108 *(uint32_t*)(p
+ 4+2*stride
)= val
;
109 *(uint32_t*)(p
+ 8+2*stride
)= val
;
110 *(uint32_t*)(p
+12+2*stride
)= val
;
111 *(uint32_t*)(p
+ 0+3*stride
)= val
;
112 *(uint32_t*)(p
+ 4+3*stride
)= val
;
113 *(uint32_t*)(p
+ 8+3*stride
)= val
;
114 *(uint32_t*)(p
+12+3*stride
)= val
;
121 #endif /* FFMPEG_RECTANGLE_H */