vf_eq.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. *
  3. * Original MPlayer filters by Richard Felker.
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (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
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/mem.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavfilter/vf_eq.h"
  26. #if HAVE_MMX_INLINE && HAVE_6REGS
  27. static void process_MMX(EQParameters *param, uint8_t *dst, int dst_stride,
  28. const uint8_t *src, int src_stride, int w, int h)
  29. {
  30. int i;
  31. int pel;
  32. int dstep = dst_stride - w;
  33. int sstep = src_stride - w;
  34. short brvec[4];
  35. short contvec[4];
  36. int contrast = (int) (param->contrast * 256 * 16);
  37. int brightness = ((int) (100.0 * param->brightness + 100.0) * 511) / 200 - 128 - contrast / 32;
  38. brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness;
  39. contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast;
  40. while (h--) {
  41. __asm__ volatile (
  42. "movq (%5), %%mm3 \n\t"
  43. "movq (%6), %%mm4 \n\t"
  44. "pxor %%mm0, %%mm0 \n\t"
  45. "movl %4, %%eax \n\t"
  46. ".p2align 4 \n\t"
  47. "1: \n\t"
  48. "movq (%0), %%mm1 \n\t"
  49. "movq (%0), %%mm2 \n\t"
  50. "punpcklbw %%mm0, %%mm1\n\t"
  51. "punpckhbw %%mm0, %%mm2\n\t"
  52. "psllw $4, %%mm1 \n\t"
  53. "psllw $4, %%mm2 \n\t"
  54. "pmulhw %%mm4, %%mm1 \n\t"
  55. "pmulhw %%mm4, %%mm2 \n\t"
  56. "paddw %%mm3, %%mm1 \n\t"
  57. "paddw %%mm3, %%mm2 \n\t"
  58. "packuswb %%mm2, %%mm1 \n\t"
  59. "add $8, %0 \n\t"
  60. "movq %%mm1, (%1) \n\t"
  61. "add $8, %1 \n\t"
  62. "decl %%eax \n\t"
  63. "jnz 1b \n\t"
  64. : "=r" (src), "=r" (dst)
  65. : "0" (src), "1" (dst), "r" (w>>3), "r" (brvec), "r" (contvec)
  66. : "%eax"
  67. );
  68. for (i = w&7; i; i--) {
  69. pel = ((*src++ * contrast) >> 12) + brightness;
  70. if (pel & ~255)
  71. pel = (-pel) >> 31;
  72. *dst++ = pel;
  73. }
  74. src += sstep;
  75. dst += dstep;
  76. }
  77. __asm__ volatile ( "emms \n\t" ::: "memory" );
  78. }
  79. #endif
  80. av_cold void ff_eq_init_x86(EQContext *eq)
  81. {
  82. #if HAVE_MMX_INLINE && HAVE_6REGS
  83. int cpu_flags = av_get_cpu_flags();
  84. if (cpu_flags & AV_CPU_FLAG_MMX) {
  85. eq->process = process_MMX;
  86. }
  87. #endif
  88. }