blob: df7c18a4e2fe920b720c765f4056c58bfbcdd2fa [file] [log] [blame]
Kostya Shishkov626464f2007-12-15 06:06:161/*
2 * rectangle filling function
3 * Copyright (c) 2003 Michael Niedermayer <[email protected]>
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/**
Diego Biurrunba87f082010-04-20 14:45:3423 * @file
Kostya Shishkov626464f2007-12-15 06:06:1624 * useful rectangle filling function
25 * @author Michael Niedermayer <[email protected]>
26 */
27
Stefano Sabatini98790382008-08-31 07:39:4728#ifndef AVCODEC_RECTANGLE_H
29#define AVCODEC_RECTANGLE_H
Kostya Shishkov626464f2007-12-15 06:06:1630
Diego Biurrun175da7d2009-01-24 14:46:0031#include "config.h"
Diego Biurrun245976d2008-05-09 11:56:3632#include "libavutil/common.h"
Michael Niedermayer3422e7c2012-06-07 18:51:0733#include "libavutil/avassert.h"
Kostya Shishkov626464f2007-12-15 06:06:1634
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
Michael Niedermayer3393bff2010-02-24 22:05:5139 * @param size the size of val (1, 2 or 4), should be a constant
Kostya Shishkov626464f2007-12-15 06:06:1640 */
41static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){
42 uint8_t *p= (uint8_t*)vp;
Michael Niedermayer3422e7c2012-06-07 18:51:0743 av_assert2(size==1 || size==2 || size==4);
44 av_assert2(w<=4);
Kostya Shishkov626464f2007-12-15 06:06:1645
46 w *= size;
47 stride *= size;
48
Michael Niedermayer8bbb4872013-02-14 10:00:2249 av_assert2((((long)vp)&(FFMIN(w, 8<<(HAVE_NEON|ARCH_PPC|HAVE_MMX))-1)) == 0);
Michael Niedermayer3422e7c2012-06-07 18:51:0750 av_assert2((stride&(w-1))==0);
Kostya Shishkov626464f2007-12-15 06:06:1651 if(w==2){
52 const uint16_t v= size==4 ? val : val*0x0101;
53 *(uint16_t*)(p + 0*stride)= v;
54 if(h==1) return;
55 *(uint16_t*)(p + 1*stride)= v;
56 if(h==2) return;
57 *(uint16_t*)(p + 2*stride)= v;
58 *(uint16_t*)(p + 3*stride)= v;
59 }else if(w==4){
Michael Niedermayerf3ea29b2010-02-24 20:37:5860 const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101;
Kostya Shishkov626464f2007-12-15 06:06:1661 *(uint32_t*)(p + 0*stride)= v;
62 if(h==1) return;
63 *(uint32_t*)(p + 1*stride)= v;
64 if(h==2) return;
65 *(uint32_t*)(p + 2*stride)= v;
66 *(uint32_t*)(p + 3*stride)= v;
67 }else if(w==8){
Vittorio Giovara41ed7ab2016-04-27 17:45:2368 // gcc cannot optimize 64-bit math on x86_32
Aurelien Jacobsb250f9c2009-01-13 23:44:1669#if HAVE_FAST_64BIT
Michael Niedermayerf3ea29b2010-02-24 20:37:5870 const uint64_t v= size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL;
Kostya Shishkov626464f2007-12-15 06:06:1671 *(uint64_t*)(p + 0*stride)= v;
72 if(h==1) return;
73 *(uint64_t*)(p + 1*stride)= v;
74 if(h==2) return;
75 *(uint64_t*)(p + 2*stride)= v;
76 *(uint64_t*)(p + 3*stride)= v;
77 }else if(w==16){
78 const uint64_t v= val*0x0100000001ULL;
79 *(uint64_t*)(p + 0+0*stride)= v;
80 *(uint64_t*)(p + 8+0*stride)= v;
81 *(uint64_t*)(p + 0+1*stride)= v;
82 *(uint64_t*)(p + 8+1*stride)= v;
83 if(h==2) return;
84 *(uint64_t*)(p + 0+2*stride)= v;
85 *(uint64_t*)(p + 8+2*stride)= v;
86 *(uint64_t*)(p + 0+3*stride)= v;
87 *(uint64_t*)(p + 8+3*stride)= v;
88#else
Michael Niedermayer09ef1ac2010-02-24 22:13:2089 const uint32_t v= size==2 ? val*0x00010001 : val;
Michael Niedermayerf3ea29b2010-02-24 20:37:5890 *(uint32_t*)(p + 0+0*stride)= v;
91 *(uint32_t*)(p + 4+0*stride)= v;
Kostya Shishkov626464f2007-12-15 06:06:1692 if(h==1) return;
Michael Niedermayerf3ea29b2010-02-24 20:37:5893 *(uint32_t*)(p + 0+1*stride)= v;
94 *(uint32_t*)(p + 4+1*stride)= v;
Kostya Shishkov626464f2007-12-15 06:06:1695 if(h==2) return;
Michael Niedermayerf3ea29b2010-02-24 20:37:5896 *(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;
Kostya Shishkov626464f2007-12-15 06:06:16100 }else if(w==16){
Michael Niedermayer377fc382010-02-24 21:55:55101 *(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;
Kostya Shishkov626464f2007-12-15 06:06:16109 if(h==2) return;
Michael Niedermayer377fc382010-02-24 21:55:55110 *(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;
Kostya Shishkov626464f2007-12-15 06:06:16118#endif
119 }else
Michael Niedermayer3422e7c2012-06-07 18:51:07120 av_assert2(0);
121 av_assert2(h==4);
Kostya Shishkov626464f2007-12-15 06:06:16122}
123
Stefano Sabatini98790382008-08-31 07:39:47124#endif /* AVCODEC_RECTANGLE_H */