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.

154 lines
5.6KB

  1. /*
  2. * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * Microsoft Screen 2 (aka Windows Media Video V9 Screen) decoder DSP routines
  23. */
  24. #include "mss2dsp.h"
  25. #include "libavutil/common.h"
  26. static av_always_inline void mss2_blit_wmv9_template(uint8_t *dst,
  27. ptrdiff_t dst_stride,
  28. int gray,
  29. int use_mask,
  30. int maskcolor,
  31. const uint8_t *mask,
  32. ptrdiff_t mask_stride,
  33. const uint8_t *srcy,
  34. ptrdiff_t srcy_stride,
  35. const uint8_t *srcu,
  36. const uint8_t *srcv,
  37. ptrdiff_t srcuv_stride,
  38. int w, int h)
  39. {
  40. int i, j, k, r = -1;
  41. while (++r < h) {
  42. for (i = 0, j = 0, k = 0; i < w; j += (i & 1), i++, k += 3) {
  43. if (!use_mask || mask[i] == maskcolor) {
  44. if (gray) {
  45. dst[k] = dst[k + 1] = dst[k + 2] = 0x80;
  46. } else {
  47. int y = srcy[i];
  48. int u = srcu[j] - 128;
  49. int v = srcv[j] - 128;
  50. dst[k] = av_clip_uint8(y + ( 91881 * v + 32768 >> 16));
  51. dst[k + 1] = av_clip_uint8(y + (-22554 * u - 46802 * v + 32768 >> 16));
  52. dst[k + 2] = av_clip_uint8(y + (116130 * u + 32768 >> 16));
  53. }
  54. }
  55. }
  56. mask += mask_stride;
  57. dst += dst_stride;
  58. srcy += srcy_stride;
  59. srcu += srcuv_stride * (r & 1);
  60. srcv += srcuv_stride * (r & 1);
  61. }
  62. }
  63. static void mss2_blit_wmv9_c(uint8_t *dst, ptrdiff_t dst_stride,
  64. const uint8_t *srcy, ptrdiff_t srcy_stride,
  65. const uint8_t *srcu, const uint8_t *srcv,
  66. ptrdiff_t srcuv_stride, int w, int h)
  67. {
  68. mss2_blit_wmv9_template(dst, dst_stride, 0, 0,
  69. 0, NULL, 0,
  70. srcy, srcy_stride,
  71. srcu, srcv, srcuv_stride,
  72. w, h);
  73. }
  74. static void mss2_blit_wmv9_masked_c(uint8_t *dst, ptrdiff_t dst_stride,
  75. int maskcolor, const uint8_t *mask,
  76. ptrdiff_t mask_stride,
  77. const uint8_t *srcy, ptrdiff_t srcy_stride,
  78. const uint8_t *srcu, const uint8_t *srcv,
  79. ptrdiff_t srcuv_stride, int w, int h)
  80. {
  81. mss2_blit_wmv9_template(dst, dst_stride, 0, 1,
  82. maskcolor, mask, mask_stride,
  83. srcy, srcy_stride,
  84. srcu, srcv, srcuv_stride,
  85. w, h);
  86. }
  87. static void mss2_gray_fill_masked_c(uint8_t *dst, ptrdiff_t dst_stride,
  88. int maskcolor, const uint8_t *mask,
  89. ptrdiff_t mask_stride, int w, int h)
  90. {
  91. mss2_blit_wmv9_template(dst, dst_stride, 1, 1,
  92. maskcolor, mask, mask_stride,
  93. NULL, 0,
  94. NULL, NULL, 0,
  95. w, h);
  96. }
  97. static void upsample_plane_c(uint8_t *plane, ptrdiff_t plane_stride, int w, int h)
  98. {
  99. uint8_t *src1, *src2, *dst1, *dst2, *p, a, b;
  100. int i, j;
  101. w += (w & 1);
  102. h += (h & 1);
  103. j = h - 1;
  104. memcpy(plane + plane_stride * j,
  105. plane + plane_stride * (j >> 1),
  106. w);
  107. while ((j -= 2) > 0) {
  108. dst1 = plane + plane_stride * (j + 1);
  109. dst2 = plane + plane_stride * j;
  110. src1 = plane + plane_stride * ((j + 1) >> 1);
  111. src2 = plane + plane_stride * ( j >> 1);
  112. for (i = (w - 1) >> 1; i >= 0; i--) {
  113. a = src1[i];
  114. b = src2[i];
  115. dst1[i] = (3 * a + b + 2) >> 2;
  116. dst2[i] = (a + 3 * b + 2) >> 2;
  117. }
  118. }
  119. for (j = h - 1; j >= 0; j--) {
  120. p = plane + plane_stride * j;
  121. i = w - 1;
  122. p[i] = p[i >> 1];
  123. while ((i -= 2) > 0) {
  124. a = p[ i >> 1];
  125. b = p[(i + 1) >> 1];
  126. p[i] = (3 * a + b + 1) >> 2;
  127. p[i + 1] = (a + 3 * b + 1) >> 2;
  128. }
  129. }
  130. }
  131. av_cold void ff_mss2dsp_init(MSS2DSPContext* dsp)
  132. {
  133. dsp->mss2_blit_wmv9 = mss2_blit_wmv9_c;
  134. dsp->mss2_blit_wmv9_masked = mss2_blit_wmv9_masked_c;
  135. dsp->mss2_gray_fill_masked = mss2_gray_fill_masked_c;
  136. dsp->upsample_plane = upsample_plane_c;
  137. }