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.

131 lines
3.8KB

  1. /*
  2. * Canopus HQ/HQA 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. #include <stdint.h>
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/common.h"
  23. #include "hq_hqadsp.h"
  24. #define FIX_1_082 17734
  25. #define FIX_1_847 30274
  26. #define FIX_1_414 23170
  27. #define FIX_2_613 21407 // divided by two to fit the range
  28. #define IDCTMUL(a, b) ((a) * (b) >> 16)
  29. static inline void idct_row(int16_t *blk)
  30. {
  31. int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmpA;
  32. int tmpB, tmpC, tmpD, tmpE, tmpF, tmp10, tmp11, tmp12, tmp13, tmp14;
  33. tmp0 = blk[5] - blk[3];
  34. tmp1 = blk[5] + blk[3];
  35. tmp2 = blk[1] - blk[7];
  36. tmp3 = blk[1] + blk[7];
  37. tmp4 = tmp3 - tmp1;
  38. tmp5 = IDCTMUL(tmp0 + tmp2, FIX_1_847);
  39. tmp6 = IDCTMUL(tmp2, FIX_1_082) - tmp5;
  40. tmp7 = tmp5 - IDCTMUL(tmp0, FIX_2_613) * 2;
  41. tmp8 = tmp3 + tmp1;
  42. tmp9 = tmp7 * 4 - tmp8;
  43. tmpA = IDCTMUL(tmp4, FIX_1_414) * 4 - tmp9;
  44. tmpB = tmp6 * 4 + tmpA;
  45. tmpC = blk[2] + blk[6];
  46. tmpD = blk[2] - blk[6];
  47. tmpE = blk[0] - blk[4];
  48. tmpF = blk[0] + blk[4];
  49. tmp10 = IDCTMUL(tmpD, FIX_1_414) * 4 - tmpC;
  50. tmp11 = tmpE - tmp10;
  51. tmp12 = tmpF - tmpC;
  52. tmp13 = tmpE + tmp10;
  53. tmp14 = tmpF + tmpC;
  54. blk[0] = tmp14 + tmp8;
  55. blk[1] = tmp13 + tmp9;
  56. blk[2] = tmp11 + tmpA;
  57. blk[3] = tmp12 - tmpB;
  58. blk[4] = tmp12 + tmpB;
  59. blk[5] = tmp11 - tmpA;
  60. blk[6] = tmp13 - tmp9;
  61. blk[7] = tmp14 - tmp8;
  62. }
  63. static inline void idct_col(int16_t *blk)
  64. {
  65. int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmpA;
  66. int tmpB, tmpC, tmpD, tmpE, tmpF, tmp10, tmp11, tmp12, tmp13, tmp14;
  67. tmp0 = blk[5 * 8] - blk[3 * 8];
  68. tmp1 = blk[5 * 8] + blk[3 * 8];
  69. tmp2 = blk[1 * 8] * 2 - (blk[7 * 8] >> 2);
  70. tmp3 = blk[1 * 8] * 2 + (blk[7 * 8] >> 2);
  71. tmp4 = tmp3 - tmp1;
  72. tmp5 = IDCTMUL(tmp0 + tmp2, FIX_1_847);
  73. tmp6 = IDCTMUL(tmp2, FIX_1_082) - tmp5;
  74. tmp7 = tmp5 - IDCTMUL(tmp0, FIX_2_613) * 2;
  75. tmp8 = (tmp3 + tmp1) >> 1;
  76. tmp9 = tmp7 * 2 - tmp8;
  77. tmpA = IDCTMUL(tmp4, FIX_1_414) * 2 - tmp9;
  78. tmpB = tmp6 * 2 + tmpA;
  79. tmpC = blk[2 * 8] + (blk[6 * 8] >> 1) >> 1;
  80. tmpD = blk[2 * 8] - (blk[6 * 8] >> 1);
  81. tmpE = (blk[0 * 8] >> 1) - (blk[4 * 8] >> 1) + 0x2020;
  82. tmpF = (blk[0 * 8] >> 1) + (blk[4 * 8] >> 1) + 0x2020;
  83. tmp10 = IDCTMUL(tmpD, FIX_1_414) * 2 - tmpC;
  84. tmp11 = tmpE - tmp10;
  85. tmp12 = tmpF - tmpC;
  86. tmp13 = tmpE + tmp10;
  87. tmp14 = tmpF + tmpC;
  88. blk[0 * 8] = (tmp14 + tmp8) >> 6;
  89. blk[1 * 8] = (tmp13 + tmp9) >> 6;
  90. blk[2 * 8] = (tmp11 + tmpA) >> 6;
  91. blk[3 * 8] = (tmp12 - tmpB) >> 6;
  92. blk[4 * 8] = (tmp12 + tmpB) >> 6;
  93. blk[5 * 8] = (tmp11 - tmpA) >> 6;
  94. blk[6 * 8] = (tmp13 - tmp9) >> 6;
  95. blk[7 * 8] = (tmp14 - tmp8) >> 6;
  96. }
  97. static void hq_idct_put(uint8_t *dst, int stride, int16_t *block)
  98. {
  99. int i, j;
  100. for (i = 0; i < 8; i++)
  101. idct_row(block + i * 8);
  102. for (i = 0; i < 8; i++)
  103. idct_col(block + i);
  104. for (i = 0; i < 8; i++) {
  105. for (j = 0; j < 8; j++)
  106. dst[j] = av_clip_uint8(block[j + i * 8]);
  107. dst += stride;
  108. }
  109. }
  110. av_cold void ff_hqdsp_init(HQDSPContext *c)
  111. {
  112. c->idct_put = hq_idct_put;
  113. }