You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.1KB

  1. /*
  2. * rectangle filling function
  3. * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * useful rectangle filling function
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #ifndef AVCODEC_RECTANGLE_H
  27. #define AVCODEC_RECTANGLE_H
  28. #include <assert.h>
  29. #include "config.h"
  30. #include "libavutil/common.h"
  31. /**
  32. * fill a rectangle.
  33. * @param h height of the rectangle, should be a constant
  34. * @param w width of the rectangle, should be a constant
  35. * @param size the size of val (1, 2 or 4), should be a constant
  36. */
  37. static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){
  38. uint8_t *p= (uint8_t*)vp;
  39. assert(size==1 || size==2 || size==4);
  40. assert(w<=4);
  41. w *= size;
  42. stride *= size;
  43. assert((stride&(w-1))==0);
  44. if(w==2){
  45. const uint16_t v= size==4 ? val : val*0x0101;
  46. *(uint16_t*)(p + 0*stride)= v;
  47. if(h==1) return;
  48. *(uint16_t*)(p + 1*stride)= v;
  49. if(h==2) return;
  50. *(uint16_t*)(p + 2*stride)= v;
  51. *(uint16_t*)(p + 3*stride)= v;
  52. }else if(w==4){
  53. const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101;
  54. *(uint32_t*)(p + 0*stride)= v;
  55. if(h==1) return;
  56. *(uint32_t*)(p + 1*stride)= v;
  57. if(h==2) return;
  58. *(uint32_t*)(p + 2*stride)= v;
  59. *(uint32_t*)(p + 3*stride)= v;
  60. }else if(w==8){
  61. // gcc cannot optimize 64-bit math on x86_32
  62. #if HAVE_FAST_64BIT
  63. const uint64_t v= size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL;
  64. *(uint64_t*)(p + 0*stride)= v;
  65. if(h==1) return;
  66. *(uint64_t*)(p + 1*stride)= v;
  67. if(h==2) return;
  68. *(uint64_t*)(p + 2*stride)= v;
  69. *(uint64_t*)(p + 3*stride)= v;
  70. }else if(w==16){
  71. const uint64_t v= val*0x0100000001ULL;
  72. *(uint64_t*)(p + 0+0*stride)= v;
  73. *(uint64_t*)(p + 8+0*stride)= v;
  74. *(uint64_t*)(p + 0+1*stride)= v;
  75. *(uint64_t*)(p + 8+1*stride)= v;
  76. if(h==2) return;
  77. *(uint64_t*)(p + 0+2*stride)= v;
  78. *(uint64_t*)(p + 8+2*stride)= v;
  79. *(uint64_t*)(p + 0+3*stride)= v;
  80. *(uint64_t*)(p + 8+3*stride)= v;
  81. #else
  82. const uint32_t v= size==2 ? val*0x00010001 : val;
  83. *(uint32_t*)(p + 0+0*stride)= v;
  84. *(uint32_t*)(p + 4+0*stride)= v;
  85. if(h==1) return;
  86. *(uint32_t*)(p + 0+1*stride)= v;
  87. *(uint32_t*)(p + 4+1*stride)= v;
  88. if(h==2) return;
  89. *(uint32_t*)(p + 0+2*stride)= v;
  90. *(uint32_t*)(p + 4+2*stride)= v;
  91. *(uint32_t*)(p + 0+3*stride)= v;
  92. *(uint32_t*)(p + 4+3*stride)= v;
  93. }else if(w==16){
  94. *(uint32_t*)(p + 0+0*stride)= val;
  95. *(uint32_t*)(p + 4+0*stride)= val;
  96. *(uint32_t*)(p + 8+0*stride)= val;
  97. *(uint32_t*)(p +12+0*stride)= val;
  98. *(uint32_t*)(p + 0+1*stride)= val;
  99. *(uint32_t*)(p + 4+1*stride)= val;
  100. *(uint32_t*)(p + 8+1*stride)= val;
  101. *(uint32_t*)(p +12+1*stride)= val;
  102. if(h==2) return;
  103. *(uint32_t*)(p + 0+2*stride)= val;
  104. *(uint32_t*)(p + 4+2*stride)= val;
  105. *(uint32_t*)(p + 8+2*stride)= val;
  106. *(uint32_t*)(p +12+2*stride)= val;
  107. *(uint32_t*)(p + 0+3*stride)= val;
  108. *(uint32_t*)(p + 4+3*stride)= val;
  109. *(uint32_t*)(p + 8+3*stride)= val;
  110. *(uint32_t*)(p +12+3*stride)= val;
  111. #endif
  112. }else
  113. assert(0);
  114. assert(h==4);
  115. }
  116. #endif /* AVCODEC_RECTANGLE_H */