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