• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/rectangle.h

Go to the documentation of this file.
00001 /*
00002  * rectangle filling function
00003  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #ifndef AVCODEC_RECTANGLE_H
00029 #define AVCODEC_RECTANGLE_H
00030 
00031 #include <assert.h>
00032 #include "config.h"
00033 #include "libavutil/common.h"
00034 #include "dsputil.h"
00035 
00042 static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){
00043     uint8_t *p= (uint8_t*)vp;
00044     assert(size==1 || size==2 || size==4);
00045     assert(w<=4);
00046 
00047     w      *= size;
00048     stride *= size;
00049 
00050     assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);
00051     assert((stride&(w-1))==0);
00052     if(w==2){
00053         const uint16_t v= size==4 ? val : val*0x0101;
00054         *(uint16_t*)(p + 0*stride)= v;
00055         if(h==1) return;
00056         *(uint16_t*)(p + 1*stride)= v;
00057         if(h==2) return;
00058         *(uint16_t*)(p + 2*stride)= v;
00059         *(uint16_t*)(p + 3*stride)= v;
00060     }else if(w==4){
00061         const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101;
00062         *(uint32_t*)(p + 0*stride)= v;
00063         if(h==1) return;
00064         *(uint32_t*)(p + 1*stride)= v;
00065         if(h==2) return;
00066         *(uint32_t*)(p + 2*stride)= v;
00067         *(uint32_t*)(p + 3*stride)= v;
00068     }else if(w==8){
00069     //gcc can't optimize 64bit math on x86_32
00070 #if HAVE_FAST_64BIT
00071         const uint64_t v=  size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL;
00072         *(uint64_t*)(p + 0*stride)= v;
00073         if(h==1) return;
00074         *(uint64_t*)(p + 1*stride)= v;
00075         if(h==2) return;
00076         *(uint64_t*)(p + 2*stride)= v;
00077         *(uint64_t*)(p + 3*stride)= v;
00078     }else if(w==16){
00079         const uint64_t v= val*0x0100000001ULL;
00080         *(uint64_t*)(p + 0+0*stride)= v;
00081         *(uint64_t*)(p + 8+0*stride)= v;
00082         *(uint64_t*)(p + 0+1*stride)= v;
00083         *(uint64_t*)(p + 8+1*stride)= v;
00084         if(h==2) return;
00085         *(uint64_t*)(p + 0+2*stride)= v;
00086         *(uint64_t*)(p + 8+2*stride)= v;
00087         *(uint64_t*)(p + 0+3*stride)= v;
00088         *(uint64_t*)(p + 8+3*stride)= v;
00089 #else
00090         const uint32_t v= size==2 ? val*0x00010001 : val;
00091         *(uint32_t*)(p + 0+0*stride)= v;
00092         *(uint32_t*)(p + 4+0*stride)= v;
00093         if(h==1) return;
00094         *(uint32_t*)(p + 0+1*stride)= v;
00095         *(uint32_t*)(p + 4+1*stride)= v;
00096         if(h==2) return;
00097         *(uint32_t*)(p + 0+2*stride)= v;
00098         *(uint32_t*)(p + 4+2*stride)= v;
00099         *(uint32_t*)(p + 0+3*stride)= v;
00100         *(uint32_t*)(p + 4+3*stride)= v;
00101     }else if(w==16){
00102         *(uint32_t*)(p + 0+0*stride)= val;
00103         *(uint32_t*)(p + 4+0*stride)= val;
00104         *(uint32_t*)(p + 8+0*stride)= val;
00105         *(uint32_t*)(p +12+0*stride)= val;
00106         *(uint32_t*)(p + 0+1*stride)= val;
00107         *(uint32_t*)(p + 4+1*stride)= val;
00108         *(uint32_t*)(p + 8+1*stride)= val;
00109         *(uint32_t*)(p +12+1*stride)= val;
00110         if(h==2) return;
00111         *(uint32_t*)(p + 0+2*stride)= val;
00112         *(uint32_t*)(p + 4+2*stride)= val;
00113         *(uint32_t*)(p + 8+2*stride)= val;
00114         *(uint32_t*)(p +12+2*stride)= val;
00115         *(uint32_t*)(p + 0+3*stride)= val;
00116         *(uint32_t*)(p + 4+3*stride)= val;
00117         *(uint32_t*)(p + 8+3*stride)= val;
00118         *(uint32_t*)(p +12+3*stride)= val;
00119 #endif
00120     }else
00121         assert(0);
00122     assert(h==4);
00123 }
00124 
00125 #endif /* AVCODEC_RECTANGLE_H */

Generated on Fri Sep 16 2011 17:17:42 for FFmpeg by  doxygen 1.7.1