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.

195 lines
4.4KB

  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. #include "cfhddsp.h"
  29. enum CFHDParam {
  30. SampleType = 1,
  31. SampleIndexTable = 2,
  32. BitstreamMarker = 4,
  33. VersionMajor = 5,
  34. VersionMinor = 6,
  35. VersionRevision = 7,
  36. VersionEdit = 8,
  37. TransformType = 10,
  38. NumFrames = 11,
  39. ChannelCount = 12,
  40. WaveletCount = 13,
  41. SubbandCount = 14,
  42. NumSpatial = 15,
  43. FirstWavelet = 16,
  44. GroupTrailer = 18,
  45. FrameType = 19,
  46. ImageWidth = 20,
  47. ImageHeight = 21,
  48. FrameIndex = 23,
  49. LowpassSubband = 25,
  50. NumLevels = 26,
  51. LowpassWidth = 27,
  52. LowpassHeight = 28,
  53. PixelOffset = 33,
  54. LowpassQuantization=34,
  55. LowpassPrecision = 35,
  56. WaveletType = 37,
  57. WaveletNumber = 38,
  58. WaveletLevel = 39,
  59. NumBands = 40,
  60. HighpassWidth = 41,
  61. HighpassHeight = 42,
  62. LowpassBorder = 43,
  63. HighpassBorder = 44,
  64. LowpassScale = 45,
  65. LowpassDivisor = 46,
  66. SubbandNumber = 48,
  67. BandWidth = 49,
  68. BandHeight = 50,
  69. SubbandBand = 51,
  70. BandEncoding = 52,
  71. Quantization = 53,
  72. BandScale = 54,
  73. BandHeader = 55,
  74. BandTrailer = 56,
  75. ChannelNumber = 62,
  76. SampleFlags = 68,
  77. FrameNumber = 69,
  78. Precision = 70,
  79. InputFormat = 71,
  80. BandCodingFlags = 72,
  81. PeakLevel = 74,
  82. PeakOffsetLow = 75,
  83. PeakOffsetHigh = 76,
  84. Version = 79,
  85. BandSecondPass = 82,
  86. PrescaleTable = 83,
  87. EncodedFormat = 84,
  88. DisplayHeight = 85,
  89. ChannelWidth = 104,
  90. ChannelHeight = 105,
  91. };
  92. #define VLC_BITS 9
  93. #define SUBBAND_COUNT 10
  94. #define SUBBAND_COUNT_3D 17
  95. typedef struct CFHD_RL_VLC_ELEM {
  96. int16_t level;
  97. int8_t len;
  98. uint16_t run;
  99. } CFHD_RL_VLC_ELEM;
  100. #define DWT_LEVELS 3
  101. #define DWT_LEVELS_3D 6
  102. typedef struct SubBand {
  103. ptrdiff_t stride;
  104. int a_width;
  105. int width;
  106. int a_height;
  107. int height;
  108. int8_t read_ok;
  109. } SubBand;
  110. typedef struct Plane {
  111. int width;
  112. int height;
  113. ptrdiff_t stride;
  114. int16_t *idwt_buf;
  115. int16_t *idwt_tmp;
  116. int idwt_size;
  117. /* TODO: merge this into SubBand structure */
  118. int16_t *subband[SUBBAND_COUNT_3D];
  119. int16_t *l_h[10];
  120. SubBand band[DWT_LEVELS_3D][4];
  121. } Plane;
  122. typedef struct Peak {
  123. int level;
  124. int offset;
  125. GetByteContext base;
  126. } Peak;
  127. typedef struct CFHDContext {
  128. AVCodecContext *avctx;
  129. CFHD_RL_VLC_ELEM table_9_rl_vlc[2088];
  130. VLC vlc_9;
  131. CFHD_RL_VLC_ELEM table_18_rl_vlc[4572];
  132. VLC vlc_18;
  133. int lut[2][256];
  134. GetBitContext gb;
  135. int planes;
  136. int frame_type;
  137. int frame_index;
  138. int sample_type;
  139. int transform_type;
  140. int coded_width;
  141. int coded_height;
  142. int cropped_height;
  143. enum AVPixelFormat coded_format;
  144. int progressive;
  145. int a_width;
  146. int a_height;
  147. int a_format;
  148. int a_transform_type;
  149. int bpc; // bits per channel/component
  150. int channel_cnt;
  151. int subband_cnt;
  152. int band_encoding;
  153. int channel_num;
  154. uint8_t lowpass_precision;
  155. uint16_t quantisation;
  156. int codebook;
  157. int difference_coding;
  158. int subband_num;
  159. int level;
  160. int subband_num_actual;
  161. uint8_t prescale_table[8];
  162. Plane plane[4];
  163. Peak peak;
  164. CFHDDSPContext dsp;
  165. } CFHDContext;
  166. int ff_cfhd_init_vlcs(CFHDContext *s);
  167. #endif /* AVCODEC_CFHD_H */