]> git.sesse.net Git - ffmpeg/blob - libavcodec/cfhd.h
avcodec/cfhd: read prescale table tag
[ffmpeg] / libavcodec / cfhd.h
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
33 enum CFHDParam {
34     SampleType       =   1,
35     SampleIndexTable =   2,
36     BitstreamMarker  =   4,
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     BandSecondPass   =  82,
82     PrescaleTable    =  83,
83     EncodedFormat    =  84,
84     ChannelWidth     = 104,
85     ChannelHeight    = 105,
86 };
87
88 #define VLC_BITS       9
89 #define SUBBAND_COUNT 10
90 #define SUBBAND_COUNT_3D 17
91
92 typedef struct CFHD_RL_VLC_ELEM {
93     int16_t level;
94     int8_t len;
95     uint16_t run;
96 } CFHD_RL_VLC_ELEM;
97
98 #define DWT_LEVELS 3
99 #define DWT_LEVELS_3D 6
100
101 typedef struct SubBand {
102     ptrdiff_t stride;
103     int a_width;
104     int width;
105     int a_height;
106     int height;
107 } SubBand;
108
109 typedef struct Plane {
110     int width;
111     int height;
112     ptrdiff_t stride;
113
114     int16_t *idwt_buf;
115     int16_t *idwt_tmp;
116     int      idwt_size;
117
118     /* TODO: merge this into SubBand structure */
119     int16_t *subband[SUBBAND_COUNT_3D];
120     int16_t *l_h[10];
121
122     SubBand band[DWT_LEVELS_3D][4];
123 } Plane;
124
125 typedef struct Peak {
126     int level;
127     int offset;
128     GetByteContext base;
129 } Peak;
130
131 typedef struct CFHDContext {
132     AVCodecContext *avctx;
133
134     CFHD_RL_VLC_ELEM table_9_rl_vlc[2088];
135     VLC vlc_9;
136
137     CFHD_RL_VLC_ELEM table_18_rl_vlc[4572];
138     VLC vlc_18;
139
140     int lut[2][256];
141
142     GetBitContext gb;
143
144     int planes;
145     int frame_type;
146     int frame_index;
147     int sample_type;
148     int transform_type;
149     int coded_width;
150     int coded_height;
151     int cropped_height;
152     enum AVPixelFormat coded_format;
153     int progressive;
154
155     int a_width;
156     int a_height;
157     int a_format;
158
159     int bpc; // bits per channel/component
160     int channel_cnt;
161     int subband_cnt;
162     int band_encoding;
163     int channel_num;
164     uint8_t lowpass_precision;
165     uint16_t quantisation;
166
167     int codebook;
168     int difference_coding;
169     int subband_num;
170     int level;
171     int subband_num_actual;
172
173     uint8_t prescale_table[8];
174     Plane plane[4];
175     Peak peak;
176 } CFHDContext;
177
178 int ff_cfhd_init_vlcs(CFHDContext *s);
179
180 #endif /* AVCODEC_CFHD_H */