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.

115 lines
4.1KB

  1. /*
  2. * Common stuff for some Microsoft Screen codecs
  3. * Copyright (C) 2012 Konstantin Shishkov
  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. #include <stdint.h>
  22. #include "libavutil/common.h"
  23. #include "mss34dsp.h"
  24. static const uint8_t luma_quant[64] = {
  25. 16, 11, 10, 16, 24, 40, 51, 61,
  26. 12, 12, 14, 19, 26, 58, 60, 55,
  27. 14, 13, 16, 24, 40, 57, 69, 56,
  28. 14, 17, 22, 29, 51, 87, 80, 62,
  29. 18, 22, 37, 56, 68, 109, 103, 77,
  30. 24, 35, 55, 64, 81, 104, 113, 92,
  31. 49, 64, 78, 87, 103, 121, 120, 101,
  32. 72, 92, 95, 98, 112, 100, 103, 99
  33. };
  34. static const uint8_t chroma_quant[64] = {
  35. 17, 18, 24, 47, 99, 99, 99, 99,
  36. 18, 21, 26, 66, 99, 99, 99, 99,
  37. 24, 26, 56, 99, 99, 99, 99, 99,
  38. 47, 66, 99, 99, 99, 99, 99, 99,
  39. 99, 99, 99, 99, 99, 99, 99, 99,
  40. 99, 99, 99, 99, 99, 99, 99, 99,
  41. 99, 99, 99, 99, 99, 99, 99, 99,
  42. 99, 99, 99, 99, 99, 99, 99, 99
  43. };
  44. void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
  45. {
  46. int i;
  47. const uint8_t *qsrc = luma ? luma_quant : chroma_quant;
  48. if (quality >= 50) {
  49. int scale = 200 - 2 * quality;
  50. for (i = 0; i < 64; i++)
  51. qmat[i] = (qsrc[i] * scale + 50) / 100;
  52. } else {
  53. for (i = 0; i < 64; i++)
  54. qmat[i] = (5000 * qsrc[i] / quality + 50) / 100;
  55. }
  56. }
  57. #define DCT_TEMPLATE(blk, step, SOP, shift) \
  58. const int t0 = -39409 * blk[7 * step] - 58980 * blk[1 * step]; \
  59. const int t1 = 39410 * blk[1 * step] - 58980 * blk[7 * step]; \
  60. const int t2 = -33410 * blk[5 * step] - 167963 * blk[3 * step]; \
  61. const int t3 = 33410 * blk[3 * step] - 167963 * blk[5 * step]; \
  62. const int t4 = blk[3 * step] + blk[7 * step]; \
  63. const int t5 = blk[1 * step] + blk[5 * step]; \
  64. const int t6 = 77062 * t4 + 51491 * t5; \
  65. const int t7 = 77062 * t5 - 51491 * t4; \
  66. const int t8 = 35470 * blk[2 * step] - 85623 * blk[6 * step]; \
  67. const int t9 = 35470 * blk[6 * step] + 85623 * blk[2 * step]; \
  68. const int tA = SOP(blk[0 * step] - blk[4 * step]); \
  69. const int tB = SOP(blk[0 * step] + blk[4 * step]); \
  70. \
  71. blk[0 * step] = ( t1 + t6 + t9 + tB) >> shift; \
  72. blk[1 * step] = ( t3 + t7 + t8 + tA) >> shift; \
  73. blk[2 * step] = ( t2 + t6 - t8 + tA) >> shift; \
  74. blk[3 * step] = ( t0 + t7 - t9 + tB) >> shift; \
  75. blk[4 * step] = (-(t0 + t7) - t9 + tB) >> shift; \
  76. blk[5 * step] = (-(t2 + t6) - t8 + tA) >> shift; \
  77. blk[6 * step] = (-(t3 + t7) + t8 + tA) >> shift; \
  78. blk[7 * step] = (-(t1 + t6) + t9 + tB) >> shift; \
  79. #define SOP_ROW(a) ((a) << 16) + 0x2000
  80. #define SOP_COL(a) ((a + 32) << 16)
  81. void ff_mss34_dct_put(uint8_t *dst, ptrdiff_t stride, int *block)
  82. {
  83. int i, j;
  84. int *ptr;
  85. ptr = block;
  86. for (i = 0; i < 8; i++) {
  87. DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
  88. ptr += 8;
  89. }
  90. ptr = block;
  91. for (i = 0; i < 8; i++) {
  92. DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
  93. ptr++;
  94. }
  95. ptr = block;
  96. for (j = 0; j < 8; j++) {
  97. for (i = 0; i < 8; i++)
  98. dst[i] = av_clip_uint8(ptr[i] + 128);
  99. dst += stride;
  100. ptr += 8;
  101. }
  102. }