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