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.

99 lines
2.8KB

  1. /*
  2. * JPEG 2000 DSP functions
  3. * Copyright (c) 2007 Kamil Nowosad
  4. * Copyright (c) 2013 Nicolas Bertrand <nicoinattendu@gmail.com>
  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. #include "config.h"
  23. #include "libavutil/attributes.h"
  24. #include "jpeg2000dsp.h"
  25. /* Inverse ICT parameters in float and integer.
  26. * int value = (float value) * (1<<16) */
  27. static const float f_ict_params[4] = {
  28. 1.402f,
  29. 0.34413f,
  30. 0.71414f,
  31. 1.772f
  32. };
  33. static const int i_ict_params[4] = {
  34. 91881,
  35. 22553,
  36. 46802,
  37. 116130
  38. };
  39. static void ict_float(void *_src0, void *_src1, void *_src2, int csize)
  40. {
  41. float *src0 = _src0, *src1 = _src1, *src2 = _src2;
  42. float i0f, i1f, i2f;
  43. int i;
  44. for (i = 0; i < csize; i++) {
  45. i0f = *src0 + (f_ict_params[0] * *src2);
  46. i1f = *src0 - (f_ict_params[1] * *src1)
  47. - (f_ict_params[2] * *src2);
  48. i2f = *src0 + (f_ict_params[3] * *src1);
  49. *src0++ = i0f;
  50. *src1++ = i1f;
  51. *src2++ = i2f;
  52. }
  53. }
  54. static void ict_int(void *_src0, void *_src1, void *_src2, int csize)
  55. {
  56. int32_t *src0 = _src0, *src1 = _src1, *src2 = _src2;
  57. int32_t i0, i1, i2;
  58. int i;
  59. for (i = 0; i < csize; i++) {
  60. i0 = *src0 + (((i_ict_params[0] * *src2) + (1 << 15)) >> 16);
  61. i1 = *src0 - (((i_ict_params[1] * *src1) + (1 << 15)) >> 16)
  62. - (((i_ict_params[2] * *src2) + (1 << 15)) >> 16);
  63. i2 = *src0 + (((i_ict_params[3] * *src1) + (1 << 15)) >> 16);
  64. *src0++ = i0;
  65. *src1++ = i1;
  66. *src2++ = i2;
  67. }
  68. }
  69. static void rct_int(void *_src0, void *_src1, void *_src2, int csize)
  70. {
  71. int32_t *src0 = _src0, *src1 = _src1, *src2 = _src2;
  72. int32_t i0, i1, i2;
  73. int i;
  74. for (i = 0; i < csize; i++) {
  75. i1 = *src0 - (*src2 + *src1 >> 2);
  76. i0 = i1 + *src2;
  77. i2 = i1 + *src1;
  78. *src0++ = i0;
  79. *src1++ = i1;
  80. *src2++ = i2;
  81. }
  82. }
  83. av_cold void ff_jpeg2000dsp_init(Jpeg2000DSPContext *c)
  84. {
  85. c->mct_decode[FF_DWT97] = ict_float;
  86. c->mct_decode[FF_DWT53] = rct_int;
  87. c->mct_decode[FF_DWT97_INT] = ict_int;
  88. }