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.

98 lines
3.2KB

  1. /*
  2. * Apple ProRes compatible decoder
  3. *
  4. * Copyright (c) 2010-2011 Maxim Poliakovski
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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 "libavutil/common.h"
  25. #include "idctdsp.h"
  26. #include "proresdsp.h"
  27. #include "simple_idct.h"
  28. #define CLIP_MIN (1 << 2) ///< minimum value for clipping resulting pixels
  29. #define CLIP_MAX_10 (1 << 10) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels
  30. #define CLIP_MAX_12 (1 << 12) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels
  31. #define CLIP_10(x) (av_clip((x), CLIP_MIN, CLIP_MAX_10))
  32. #define CLIP_12(x) (av_clip((x), CLIP_MIN, CLIP_MAX_12))
  33. /**
  34. * Add bias value, clamp and output pixels of a slice
  35. */
  36. static inline void put_pixel(uint16_t *dst, ptrdiff_t linesize, const int16_t *in, int bits_per_raw_sample) {
  37. int x, y, src_offset, dst_offset;
  38. for (y = 0, dst_offset = 0; y < 8; y++, dst_offset += linesize) {
  39. for (x = 0; x < 8; x++) {
  40. src_offset = (y << 3) + x;
  41. if (bits_per_raw_sample == 10) {
  42. dst[dst_offset + x] = CLIP_10(in[src_offset]);
  43. } else {//12b
  44. dst[dst_offset + x] = CLIP_12(in[src_offset]);
  45. }
  46. }
  47. }
  48. }
  49. static void put_pixels_10(uint16_t *dst, ptrdiff_t linesize, const int16_t *in)
  50. {
  51. put_pixel(dst, linesize, in, 10);
  52. }
  53. static void put_pixels_12(uint16_t *dst, ptrdiff_t linesize, const int16_t *in)
  54. {
  55. put_pixel(dst, linesize, in, 12);
  56. }
  57. static void prores_idct_put_10_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat)
  58. {
  59. ff_prores_idct_10(block, qmat);
  60. put_pixels_10(out, linesize >> 1, block);
  61. }
  62. static void prores_idct_put_12_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat)
  63. {
  64. ff_prores_idct_12(block, qmat);
  65. put_pixels_12(out, linesize >> 1, block);
  66. }
  67. av_cold int ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx)
  68. {
  69. if (avctx->bits_per_raw_sample == 10) {
  70. dsp->idct_put = prores_idct_put_10_c;
  71. dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
  72. } else if (avctx->bits_per_raw_sample == 12) {
  73. dsp->idct_put = prores_idct_put_12_c;
  74. dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
  75. } else {
  76. return AVERROR_BUG;
  77. }
  78. if (ARCH_X86)
  79. ff_proresdsp_init_x86(dsp, avctx);
  80. ff_init_scantable_permutation(dsp->idct_permutation,
  81. dsp->idct_permutation_type);
  82. return 0;
  83. }