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