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.

132 lines
3.8KB

  1. /*
  2. * HQX DSP routines
  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. #include <stdint.h>
  21. #include "libavutil/common.h"
  22. #include "hqxdsp.h"
  23. static inline void idct_col(int16_t *blk, const uint8_t *quant)
  24. {
  25. int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;
  26. int t10, t11, t12, t13;
  27. int s0, s1, s2, s3, s4, s5, s6, s7;
  28. s0 = (int) blk[0 * 8] * quant[0 * 8];
  29. s1 = (int) blk[1 * 8] * quant[1 * 8];
  30. s2 = (int) blk[2 * 8] * quant[2 * 8];
  31. s3 = (int) blk[3 * 8] * quant[3 * 8];
  32. s4 = (int) blk[4 * 8] * quant[4 * 8];
  33. s5 = (int) blk[5 * 8] * quant[5 * 8];
  34. s6 = (int) blk[6 * 8] * quant[6 * 8];
  35. s7 = (int) blk[7 * 8] * quant[7 * 8];
  36. t0 = (s3 * 19266 + s5 * 12873) >> 15;
  37. t1 = (s5 * 19266 - s3 * 12873) >> 15;
  38. t2 = ((s7 * 4520 + s1 * 22725) >> 15) - t0;
  39. t3 = ((s1 * 4520 - s7 * 22725) >> 15) - t1;
  40. t4 = t0 * 2 + t2;
  41. t5 = t1 * 2 + t3;
  42. t6 = t2 - t3;
  43. t7 = t3 * 2 + t6;
  44. t8 = (t6 * 11585) >> 14;
  45. t9 = (t7 * 11585) >> 14;
  46. tA = (s2 * 8867 - s6 * 21407) >> 14;
  47. tB = (s6 * 8867 + s2 * 21407) >> 14;
  48. tC = (s0 >> 1) - (s4 >> 1);
  49. tD = (s4 >> 1) * 2 + tC;
  50. tE = tC - (tA >> 1);
  51. tF = tD - (tB >> 1);
  52. t10 = tF - t5;
  53. t11 = tE - t8;
  54. t12 = tE + (tA >> 1) * 2 - t9;
  55. t13 = tF + (tB >> 1) * 2 - t4;
  56. blk[0 * 8] = t13 + t4 * 2;
  57. blk[1 * 8] = t12 + t9 * 2;
  58. blk[2 * 8] = t11 + t8 * 2;
  59. blk[3 * 8] = t10 + t5 * 2;
  60. blk[4 * 8] = t10;
  61. blk[5 * 8] = t11;
  62. blk[6 * 8] = t12;
  63. blk[7 * 8] = t13;
  64. }
  65. static inline void idct_row(int16_t *blk)
  66. {
  67. int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;
  68. int t10, t11, t12, t13;
  69. t0 = (blk[3] * 19266 + blk[5] * 12873) >> 14;
  70. t1 = (blk[5] * 19266 - blk[3] * 12873) >> 14;
  71. t2 = ((blk[7] * 4520 + blk[1] * 22725) >> 14) - t0;
  72. t3 = ((blk[1] * 4520 - blk[7] * 22725) >> 14) - t1;
  73. t4 = t0 * 2 + t2;
  74. t5 = t1 * 2 + t3;
  75. t6 = t2 - t3;
  76. t7 = t3 * 2 + t6;
  77. t8 = (t6 * 11585) >> 14;
  78. t9 = (t7 * 11585) >> 14;
  79. tA = (blk[2] * 8867 - blk[6] * 21407) >> 14;
  80. tB = (blk[6] * 8867 + blk[2] * 21407) >> 14;
  81. tC = blk[0] - blk[4];
  82. tD = blk[4] * 2 + tC;
  83. tE = tC - tA;
  84. tF = tD - tB;
  85. t10 = tF - t5;
  86. t11 = tE - t8;
  87. t12 = tE + tA * 2 - t9;
  88. t13 = tF + tB * 2 - t4;
  89. blk[0] = (t13 + t4 * 2 + 4) >> 3;
  90. blk[1] = (t12 + t9 * 2 + 4) >> 3;
  91. blk[2] = (t11 + t8 * 2 + 4) >> 3;
  92. blk[3] = (t10 + t5 * 2 + 4) >> 3;
  93. blk[4] = (t10 + 4) >> 3;
  94. blk[5] = (t11 + 4) >> 3;
  95. blk[6] = (t12 + 4) >> 3;
  96. blk[7] = (t13 + 4) >> 3;
  97. }
  98. static void hqx_idct_put(uint16_t *dst, ptrdiff_t stride,
  99. int16_t *block, const uint8_t *quant)
  100. {
  101. int i, j;
  102. for (i = 0; i < 8; i++)
  103. idct_col(block + i, quant + i);
  104. for (i = 0; i < 8; i++)
  105. idct_row(block + i * 8);
  106. for (i = 0; i < 8; i++) {
  107. for (j = 0; j < 8; j++) {
  108. int v = av_clip(block[j + i * 8] + 0x800, 0, 0xFFF);
  109. dst[j] = (v << 4) | (v >> 8);
  110. }
  111. dst += stride >> 1;
  112. }
  113. }
  114. av_cold void ff_hqxdsp_init(HQXDSPContext *c)
  115. {
  116. c->idct_put = hqx_idct_put;
  117. }