]> git.sesse.net Git - ffmpeg/blob - libavcodec/cfhd.h
avcodec/cfhd: use LUT for 9 and 18 codebook decompanding
[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     ImageWidth       =  20,
46     ImageHeight      =  21,
47     LowpassSubband   =  25,
48     NumLevels        =  26,
49     LowpassWidth     =  27,
50     LowpassHeight    =  28,
51     PixelOffset      =  33,
52     LowpassQuantization=34,
53     LowpassPrecision =  35,
54     WaveletType      =  37,
55     WaveletNumber    =  38,
56     WaveletLevel     =  39,
57     NumBands         =  40,
58     HighpassWidth    =  41,
59     HighpassHeight   =  42,
60     LowpassBorder    =  43,
61     HighpassBorder   =  44,
62     LowpassScale     =  45,
63     LowpassDivisor   =  46,
64     SubbandNumber    =  48,
65     BandWidth        =  49,
66     BandHeight       =  50,
67     SubbandBand      =  51,
68     BandEncoding     =  52,
69     Quantization     =  53,
70     BandScale        =  54,
71     BandHeader       =  55,
72     BandTrailer      =  56,
73     ChannelNumber    =  62,
74     SampleFlags      =  68,
75     Precision        =  70,
76     BandCodingFlags  =  72,
77     PrescaleTable    =  83,
78     EncodedFormat    =  84,
79     BitsPerComponent = 101,
80     ChannelWidth     = 104,
81     ChannelHeight    = 105,
82     PrescaleShift    = 109,
83 };
84
85 #define VLC_BITS       9
86 #define SUBBAND_COUNT 10
87
88 typedef struct CFHD_RL_VLC_ELEM {
89     int16_t level;
90     int8_t len;
91     uint16_t run;
92 } CFHD_RL_VLC_ELEM;
93
94 #define DWT_LEVELS 3
95
96 typedef struct SubBand {
97     int level;
98     int orientation;
99     ptrdiff_t stride;
100     int a_width;
101     int width;
102     int a_height;
103     int height;
104     int pshift;
105     int quant;
106     uint8_t *ibuf;
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
117     /* TODO: merge this into SubBand structure */
118     int16_t *subband[SUBBAND_COUNT];
119     int16_t *l_h[8];
120
121     SubBand band[DWT_LEVELS][4];
122 } Plane;
123
124 typedef struct Peak {
125     int level;
126     int offset;
127     GetByteContext base;
128 } Peak;
129
130 typedef struct CFHDContext {
131     AVCodecContext *avctx;
132
133     CFHD_RL_VLC_ELEM table_9_rl_vlc[2088];
134     VLC vlc_9;
135
136     CFHD_RL_VLC_ELEM table_18_rl_vlc[4572];
137     VLC vlc_18;
138
139     int lut[2][256];
140
141     GetBitContext gb;
142
143     int coded_width;
144     int coded_height;
145     int cropped_height;
146     enum AVPixelFormat coded_format;
147     int progressive;
148
149     int a_width;
150     int a_height;
151     int a_format;
152
153     int bpc; // bits per channel/component
154     int channel_cnt;
155     int subband_cnt;
156     int channel_num;
157     uint8_t lowpass_precision;
158     uint16_t quantisation;
159     int wavelet_depth;
160     int pshift;
161
162     int codebook;
163     int difference_coding;
164     int subband_num;
165     int level;
166     int subband_num_actual;
167
168     uint8_t prescale_shift[3];
169     Plane plane[4];
170     Peak peak;
171 } CFHDContext;
172
173 int ff_cfhd_init_vlcs(CFHDContext *s);
174
175 #endif /* AVCODEC_CFHD_H */