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.

177 lines
3.9KB

  1. /*
  2. * Copyright (c) 2015 Kieran Kunhya
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_CFHD_H
  21. #define AVCODEC_CFHD_H
  22. #include <stdint.h>
  23. #include "libavutil/avassert.h"
  24. #include "avcodec.h"
  25. #include "bytestream.h"
  26. #include "get_bits.h"
  27. #include "vlc.h"
  28. enum CFHDParam {
  29. SampleType = 1,
  30. SampleIndexTable = 2,
  31. BitstreamMarker = 4,
  32. TransformType = 10,
  33. NumFrames = 11,
  34. ChannelCount = 12,
  35. WaveletCount = 13,
  36. SubbandCount = 14,
  37. NumSpatial = 15,
  38. FirstWavelet = 16,
  39. GroupTrailer = 18,
  40. ImageWidth = 20,
  41. ImageHeight = 21,
  42. LowpassSubband = 25,
  43. NumLevels = 26,
  44. LowpassWidth = 27,
  45. LowpassHeight = 28,
  46. PixelOffset = 33,
  47. LowpassQuantization=34,
  48. LowpassPrecision = 35,
  49. WaveletType = 37,
  50. WaveletNumber = 38,
  51. WaveletLevel = 39,
  52. NumBands = 40,
  53. HighpassWidth = 41,
  54. HighpassHeight = 42,
  55. LowpassBorder = 43,
  56. HighpassBorder = 44,
  57. LowpassScale = 45,
  58. LowpassDivisor = 46,
  59. SubbandNumber = 48,
  60. BandWidth = 49,
  61. BandHeight = 50,
  62. SubbandBand = 51,
  63. BandEncoding = 52,
  64. Quantization = 53,
  65. BandScale = 54,
  66. BandHeader = 55,
  67. BandTrailer = 56,
  68. ChannelNumber = 62,
  69. SampleFlags = 68,
  70. Precision = 70,
  71. InputFormat = 71,
  72. BandCodingFlags = 72,
  73. PrescaleTable = 83,
  74. EncodedFormat = 84,
  75. BitsPerComponent = 101,
  76. ChannelWidth = 104,
  77. ChannelHeight = 105,
  78. PrescaleShift = 109,
  79. };
  80. #define VLC_BITS 9
  81. #define SUBBAND_COUNT 10
  82. typedef struct CFHD_RL_VLC_ELEM {
  83. int16_t level;
  84. int8_t len;
  85. uint16_t run;
  86. } CFHD_RL_VLC_ELEM;
  87. #define DWT_LEVELS 3
  88. typedef struct SubBand {
  89. int level;
  90. int orientation;
  91. ptrdiff_t stride;
  92. int a_width;
  93. int width;
  94. int a_height;
  95. int height;
  96. int pshift;
  97. int quant;
  98. uint8_t *ibuf;
  99. } SubBand;
  100. typedef struct Plane {
  101. int width;
  102. int height;
  103. ptrdiff_t stride;
  104. int16_t *idwt_buf;
  105. int16_t *idwt_tmp;
  106. /* TODO: merge this into SubBand structure */
  107. int16_t *subband[SUBBAND_COUNT];
  108. int16_t *l_h[8];
  109. SubBand band[DWT_LEVELS][4];
  110. } Plane;
  111. typedef struct Peak {
  112. int level;
  113. int offset;
  114. GetByteContext base;
  115. } Peak;
  116. typedef struct CFHDContext {
  117. AVCodecContext *avctx;
  118. CFHD_RL_VLC_ELEM table_9_rl_vlc[2088];
  119. VLC vlc_9;
  120. CFHD_RL_VLC_ELEM table_18_rl_vlc[4572];
  121. VLC vlc_18;
  122. int lut[2][256];
  123. GetBitContext gb;
  124. int coded_width;
  125. int coded_height;
  126. int cropped_height;
  127. enum AVPixelFormat coded_format;
  128. int progressive;
  129. int a_width;
  130. int a_height;
  131. int a_format;
  132. int bpc; // bits per channel/component
  133. int channel_cnt;
  134. int subband_cnt;
  135. int channel_num;
  136. uint8_t lowpass_precision;
  137. uint16_t quantisation;
  138. int wavelet_depth;
  139. int pshift;
  140. int codebook;
  141. int difference_coding;
  142. int subband_num;
  143. int level;
  144. int subband_num_actual;
  145. uint8_t prescale_shift[3];
  146. Plane plane[4];
  147. Peak peak;
  148. } CFHDContext;
  149. int ff_cfhd_init_vlcs(CFHDContext *s);
  150. #endif /* AVCODEC_CFHD_H */