Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Side by Side Diff: third_party/libwebp/vp8i.h

Issue 3614010: Add WebP library to Chromium... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libwebp/vp8.c ('k') | third_party/libwebp/webp.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 Google Inc.
2 //
3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 // VP8 decoder: internal header.
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11
12 #ifndef WEBP_DECODE_VP8I_H_
13 #define WEBP_DECODE_VP8I_H_
14
15 #include <string.h> // for memcpy()
16 #include "bits.h"
17
18 #if defined(__cplusplus) || defined(c_plusplus)
19 extern "C" {
20 #endif
21
22 //-----------------------------------------------------------------------------
23 // Various defines and enums
24
25 #define ONLY_KEYFRAME_CODE // to remove any code related to P-Frames
26
27 // intra prediction modes
28 enum { B_DC_PRED = 0, // 4x4 modes
29 B_TM_PRED,
30 B_VE_PRED,
31 B_HE_PRED,
32 B_LD_PRED,
33 B_RD_PRED,
34 B_VR_PRED,
35 B_VL_PRED,
36 B_HD_PRED,
37 B_HU_PRED,
38 NUM_BMODES = B_HU_PRED + 1 - B_DC_PRED, // = 10
39
40 // Luma16 or UV modes
41 DC_PRED = B_DC_PRED, V_PRED = B_VE_PRED,
42 H_PRED = B_HE_PRED, TM_PRED = B_TM_PRED,
43 B_PRED = NUM_BMODES, // refined I4x4 mode
44
45 // special modes
46 B_DC_PRED_NOTOP = 4,
47 B_DC_PRED_NOLEFT = 5,
48 B_DC_PRED_NOTOPLEFT = 6 };
49
50 #ifndef ONLY_KEYFRAME_CODE
51 // inter prediction modes
52 enum {
53 LEFT4 = 0, ABOVE4 = 1, ZERO4 = 2, NEW4 = 3,
54 NEARESTMV, NEARMV, ZEROMV, NEWMV, SPLITMV };
55 #endif
56
57 enum { MB_FEATURE_TREE_PROBS = 3,
58 NUM_MB_SEGMENTS = 4,
59 NUM_REF_LF_DELTAS = 4,
60 NUM_MODE_LF_DELTAS = 4, // I4x4, ZERO, *, SPLIT
61 MAX_NUM_PARTITIONS = 8,
62 // Probabilities
63 NUM_TYPES = 4,
64 NUM_BANDS = 8,
65 NUM_CTX = 3,
66 NUM_PROBAS = 11,
67 NUM_MV_PROBAS = 19 };
68
69 // YUV-cache parameters.
70 // Constraints are: We need to store one 16x16 block of luma samples (y),
71 // and two 8x8 chroma blocks (u/v). These are better be 16-bytes aligned,
72 // in order to be SIMD-friendly. We also need to store the top, left and
73 // top-left samples (from previously decoded blocks), along with four
74 // extra top-right samples for luma (intra4x4 prediction only).
75 // One possible layout is, using 32 * (17 + 9) bytes:
76 //
77 // .+------ <- only 1 pixel high
78 // .|yyyyt.
79 // .|yyyyt.
80 // .|yyyyt.
81 // .|yyyy..
82 // .+--.+-- <- only 1 pixel high
83 // .|uu.|vv
84 // .|uu.|vv
85 //
86 // Every character is a 4x4 block, with legend:
87 // '.' = unused
88 // 'y' = y-samples 'u' = u-samples 'v' = u-samples
89 // '|' = left sample, '-' = top sample, '+' = top-left sample
90 // 't' = extra top-right sample for 4x4 modes
91 // With this layout, BPS (=Bytes Per Scan-line) is one cacheline size.
92 #define BPS 32 // this is the common stride used by yuv[]
93 #define YUV_SIZE (BPS * 17 + BPS * 9)
94 #define Y_SIZE (BPS * 17)
95 #define Y_OFF (BPS * 1 + 8)
96 #define U_OFF (Y_OFF + BPS * 16 + BPS)
97 #define V_OFF (U_OFF + 16)
98
99 //-----------------------------------------------------------------------------
100 // Headers
101
102 typedef struct {
103 uint8_t key_frame_;
104 uint8_t profile_;
105 uint8_t show_;
106 uint32_t partition_length_;
107 } VP8FrameHeader;
108
109 typedef struct {
110 uint16_t width_;
111 uint16_t height_;
112 uint8_t xscale_;
113 uint8_t yscale_;
114 uint8_t colorspace_; // 0 = YCbCr
115 uint8_t clamp_type_;
116 } VP8PictureHeader;
117
118 // segment features
119 typedef struct {
120 int use_segment_;
121 int update_map_; // whether to update the segment map or not
122 int absolute_delta_; // absolute or delta values for quantizer and filter
123 int8_t quantizer_[NUM_MB_SEGMENTS]; // quantization changes
124 int8_t filter_strength_[NUM_MB_SEGMENTS]; // filter strength for segments
125 } VP8SegmentHeader;
126
127 // Struct collecting all frame-persistent probabilities.
128 typedef struct {
129 uint8_t segments_[MB_FEATURE_TREE_PROBS];
130 // Type: 0:Intra16-AC 1:Intra16-DC 2:Chroma 3:Intra4
131 uint8_t coeffs_[NUM_TYPES][NUM_BANDS][NUM_CTX][NUM_PROBAS];
132 #ifndef ONLY_KEYFRAME_CODE
133 uint8_t ymode_[4], uvmode_[3];
134 uint8_t mv_[2][NUM_MV_PROBAS];
135 #endif
136 } VP8Proba;
137
138 // Filter parameters
139 typedef struct {
140 int simple_; // 0=complex, 1=simple
141 int level_; // [0..63]
142 int sharpness_; // [0..7]
143 int use_lf_delta_;
144 int ref_lf_delta_[NUM_REF_LF_DELTAS];
145 int mode_lf_delta_[NUM_MODE_LF_DELTAS];
146 } VP8FilterHeader;
147
148 //-----------------------------------------------------------------------------
149 // Informations about the macroblocks.
150
151 typedef struct {
152 // block type
153 uint8_t skip_:1;
154 // filter specs
155 uint8_t f_level_:6; // filter strength: 0..63
156 uint8_t f_ilevel_:6; // inner limit: 1..63
157 uint8_t f_inner_:1; // do inner filtering?
158 // cbp
159 uint8_t nz_; // non-zero AC/DC coeffs
160 uint8_t dc_nz_; // non-zero DC coeffs
161 } VP8MB;
162
163 // Dequantization matrices
164 typedef struct {
165 uint16_t y1_mat_[2], y2_mat_[2], uv_mat_[2]; // [DC / AC]
166 } VP8QuantMatrix;
167
168 //-----------------------------------------------------------------------------
169 // VP8Decoder: the main opaque structure handed over to user
170
171 struct VP8Decoder {
172 int status_; // 0 = OK
173 int ready_; // true if ready to decode a picture with VP8Decode()
174 const char* error_msg_; // set when status_ is not OK.
175
176 // Main data source
177 VP8BitReader br_;
178
179 // headers
180 VP8FrameHeader frm_hdr_;
181 VP8PictureHeader pic_hdr_;
182 VP8FilterHeader filter_hdr_;
183 VP8SegmentHeader segment_hdr_;
184
185 // dimension, in macroblock units.
186 int mb_w_, mb_h_;
187
188 // number of partitions.
189 int num_parts_;
190 // per-partition boolean decoders.
191 VP8BitReader parts_[MAX_NUM_PARTITIONS];
192
193 // buffer refresh flags
194 // bit 0: refresh Gold, bit 1: refresh Alt
195 // bit 2-3: copy to Gold, bit 4-5: copy to Alt
196 // bit 6: Gold sign bias, bit 7: Alt sign bias
197 // bit 8: refresh last frame
198 uint32_t buffer_flags_;
199
200 // dequantization (one set of DC/AC dequant factor per segment)
201 VP8QuantMatrix dqm_[NUM_MB_SEGMENTS];
202
203 // probabilities
204 VP8Proba proba_, proba_saved_;
205 int update_proba_;
206 int use_skip_proba_;
207 uint8_t skip_p_, intra_p_, last_p_, golden_p_;
208
209 // Boundary data cache and persistent buffers.
210 uint8_t* intra_t_; // top intra modes values: 4 * mb_w_
211 uint8_t intra_l_[4]; // left intra modes values
212 uint8_t *y_t_; // top luma samples: 16 * mb_w_
213 uint8_t *u_t_, *v_t_; // top u/v samples: 8 * mb_w_ each
214
215 VP8MB* mb_info_; // contextual macroblock infos (mb_w_ + 1)
216 uint8_t* yuv_b_; // main block for Y/U/V (size = YUV_SIZE)
217 int16_t* coeffs_; // 384 coeffs = (16+8+8) * 4*4
218
219 uint8_t* cache_y_; // macroblock row for storing unfiltered samples
220 uint8_t* cache_u_;
221 uint8_t* cache_v_;
222 int cache_y_stride_;
223 int cache_uv_stride_;
224
225 // main memory chunk for the above data. Persistent.
226 void* mem_;
227 int mem_size_;
228
229 // Per macroblock non-persistent infos.
230 int mb_x_, mb_y_; // current position, in macroblock units
231 uint8_t is_i4x4_; // true if intra4x4
232 uint8_t imodes_[16]; // one 16x16 mode (#0) or sixteen 4x4 modes
233 uint8_t uvmode_; // chroma prediction mode
234 uint8_t segment_; // block's segment
235
236 // bit-wise info about the content of each sub-4x4 blocks: there are 16 bits
237 // for luma (bits #0->#15), then 4 bits for chroma-u (#16->#19) and 4 bits for
238 // chroma-v (#20->#23), each corresponding to one 4x4 block in decoding order.
239 // If the bit is set, the 4x4 block contains some non-zero coefficients.
240 uint32_t non_zero_;
241 uint32_t non_zero_ac_;
242
243 // Filtering side-info
244 int filter_type_; // 0=off, 1=simple, 2=complex
245 uint8_t filter_levels_[NUM_MB_SEGMENTS]; // precalculated per-segment
246 };
247
248 //-----------------------------------------------------------------------------
249 // internal functions. Not public.
250
251 // in vp8.c
252 int VP8SetError(VP8Decoder* const dec, int error, const char *msg);
253
254 // in tree.c
255 void VP8ResetProba(VP8Proba* const proba);
256 void VP8ParseProba(VP8BitReader* const br, VP8Decoder* const dec);
257 void VP8ParseIntraMode(VP8BitReader* const br, VP8Decoder* const dec);
258
259 // in quant.c
260 void VP8ParseQuant(VP8Decoder* const dec);
261
262 // in frame.c
263 int VP8InitFrame(VP8Decoder* const dec, VP8Io* io);
264 // Predict a block and add residual
265 void VP8ReconstructBlock(VP8Decoder* const dec);
266 // Filtering
267 void VP8StoreBlock(VP8Decoder* const dec);
268 void VP8FilterRow(VP8Decoder* const dec, VP8Io* io);
269
270 // in dsp.c
271 typedef void (*VP8Idct)(const int16_t* coeffs, uint8_t* dst);
272 extern VP8Idct VP8Transform;
273 extern VP8Idct VP8TransformUV;
274 extern VP8Idct VP8TransformDC;
275 extern VP8Idct VP8TransformDCUV;
276 extern void (*VP8TransformWHT)(const int16_t* in, int16_t* out);
277
278 // *dst is the destination block, with stride BPS. Boundary samples are
279 // assumed accessible when needed.
280 typedef void (*VP8PredFunc)(uint8_t *dst);
281 extern VP8PredFunc VP8PredLuma16[7];
282 extern VP8PredFunc VP8PredChroma8[7];
283 extern VP8PredFunc VP8PredLuma4[11];
284
285 void VP8DspInit(); // must be called before anything using the above
286 void VP8DspInitTables(); // needs to be called no matter what.
287
288 // simple filter (only for luma)
289 typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
290 extern VP8SimpleFilterFunc VP8SimpleVFilter16;
291 extern VP8SimpleFilterFunc VP8SimpleHFilter16;
292 extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges
293 extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
294
295 // regular filter (on both macroblock edges and inner edges)
296 typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
297 int thresh, int ithresh, int hev_t);
298 typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
299 int thresh, int ithresh, int hev_t);
300 // on outter edge
301 extern VP8LumaFilterFunc VP8VFilter16;
302 extern VP8LumaFilterFunc VP8HFilter16;
303 extern VP8ChromaFilterFunc VP8VFilter8;
304 extern VP8ChromaFilterFunc VP8HFilter8;
305
306 // on inner edge
307 extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether
308 extern VP8LumaFilterFunc VP8HFilter16i;
309 extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether
310 extern VP8ChromaFilterFunc VP8HFilter8i;
311
312 //-----------------------------------------------------------------------------
313
314 #if defined(__cplusplus) || defined(c_plusplus)
315 } // extern "C"
316 #endif
317
318 #endif // WEBP_DECODE_VP8I_H_
OLDNEW
« no previous file with comments | « third_party/libwebp/vp8.c ('k') | third_party/libwebp/webp.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698