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.

107 lines
3.1KB

  1. /*
  2. * RV30/40 decoder common dsp functions
  3. * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov
  4. * Copyright (c) 2011 Janne Grunau
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * RV30/40 decoder common dsp functions
  25. */
  26. #include "dsputil.h"
  27. #include "rv34dsp.h"
  28. /**
  29. * @name RV30/40 inverse transform functions
  30. * @{
  31. */
  32. static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block)
  33. {
  34. int i;
  35. for(i = 0; i < 4; i++){
  36. const int z0 = 13*(block[i+8*0] + block[i+8*2]);
  37. const int z1 = 13*(block[i+8*0] - block[i+8*2]);
  38. const int z2 = 7* block[i+8*1] - 17*block[i+8*3];
  39. const int z3 = 17* block[i+8*1] + 7*block[i+8*3];
  40. temp[4*i+0] = z0 + z3;
  41. temp[4*i+1] = z1 + z2;
  42. temp[4*i+2] = z1 - z2;
  43. temp[4*i+3] = z0 - z3;
  44. }
  45. }
  46. /**
  47. * Real Video 3.0/4.0 inverse transform
  48. * Code is almost the same as in SVQ3, only scaling is different.
  49. */
  50. static void rv34_inv_transform_c(DCTELEM *block){
  51. int temp[16];
  52. int i;
  53. rv34_row_transform(temp, block);
  54. for(i = 0; i < 4; i++){
  55. const int z0 = 13*(temp[4*0+i] + temp[4*2+i]) + 0x200;
  56. const int z1 = 13*(temp[4*0+i] - temp[4*2+i]) + 0x200;
  57. const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i];
  58. const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i];
  59. block[i*8+0] = (z0 + z3) >> 10;
  60. block[i*8+1] = (z1 + z2) >> 10;
  61. block[i*8+2] = (z1 - z2) >> 10;
  62. block[i*8+3] = (z0 - z3) >> 10;
  63. }
  64. }
  65. /**
  66. * RealVideo 3.0/4.0 inverse transform for DC block
  67. *
  68. * Code is almost the same as rv34_inv_transform()
  69. * but final coefficients are multiplied by 1.5 and have no rounding.
  70. */
  71. static void rv34_inv_transform_noround_c(DCTELEM *block){
  72. int temp[16];
  73. int i;
  74. rv34_row_transform(temp, block);
  75. for(i = 0; i < 4; i++){
  76. const int z0 = 13*(temp[4*0+i] + temp[4*2+i]);
  77. const int z1 = 13*(temp[4*0+i] - temp[4*2+i]);
  78. const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i];
  79. const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i];
  80. block[i*8+0] = ((z0 + z3) * 3) >> 11;
  81. block[i*8+1] = ((z1 + z2) * 3) >> 11;
  82. block[i*8+2] = ((z1 - z2) * 3) >> 11;
  83. block[i*8+3] = ((z0 - z3) * 3) >> 11;
  84. }
  85. }
  86. /** @} */ // transform
  87. av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) {
  88. c->rv34_inv_transform_tab[0] = rv34_inv_transform_c;
  89. c->rv34_inv_transform_tab[1] = rv34_inv_transform_noround_c;
  90. }