]> git.nihav.org Git - nihav.git/blame_incremental - nihav-realmedia/src/codecs/rv10.rs
add README.md and license
[nihav.git] / nihav-realmedia / src / codecs / rv10.rs
... / ...
CommitLineData
1use nihav_core::io::bitreader::*;
2use nihav_core::io::codebook::*;
3use nihav_core::formats;
4use nihav_core::frame::*;
5use nihav_core::codecs::*;
6use nihav_codec_support::codecs::{MV, ZIGZAG};
7use nihav_codec_support::codecs::h263::*;
8use nihav_codec_support::codecs::h263::code::H263BlockDSP;
9use nihav_codec_support::codecs::h263::decoder::*;
10use nihav_codec_support::codecs::h263::data::*;
11
12#[allow(dead_code)]
13struct Tables {
14 intra_mcbpc_cb: Codebook<u8>,
15 inter_mcbpc_cb: Codebook<u8>,
16 cbpy_cb: Codebook<u8>,
17 rl_cb: Codebook<H263RLSym>,
18 aic_rl_cb: Codebook<H263RLSym>,
19 mv_cb: Codebook<u8>,
20 luma_dc_cb: Codebook<u8>,
21 chroma_dc_cb: Codebook<u8>,
22}
23
24struct RealVideo10Decoder {
25 info: NACodecInfoRef,
26 dec: H263BaseDecoder,
27 tables: Tables,
28 w: usize,
29 h: usize,
30 new_ver: bool,
31 bdsp: H263BlockDSP,
32 mvmode: MVMode,
33}
34
35struct RealVideo10BR<'a> {
36 br: BitReader<'a>,
37 tables: &'a Tables,
38 num_slices: usize,
39 slice_no: usize,
40 slice_off: Vec<u32>,
41 w: usize,
42 h: usize,
43 mb_w: usize,
44 mb_h: usize,
45 new_ver: bool,
46 dc_coded: [bool; 3],
47 last_dc: [i16; 3],
48 mvmode: MVMode,
49}
50
51struct RV10SliceInfo {
52 is_p: bool,
53 qscale: u8,
54 mb_x: usize,
55 mb_y: usize,
56 mb_c: usize,
57}
58
59impl RV10SliceInfo {
60 fn new(is_p: bool, qscale: u8, mb_x: usize, mb_y: usize, mb_c: usize) -> Self {
61 RV10SliceInfo { is_p, qscale, mb_x, mb_y, mb_c }
62 }
63}
64
65impl<'a> RealVideo10BR<'a> {
66 fn new(src: &'a [u8], tables: &'a Tables, width: usize, height: usize, new_ver: bool, mvmode: MVMode) -> Self {
67 let nslices = (src[0] as usize) + 1;
68 let mut slice_offs = Vec::with_capacity(nslices);
69 {
70 let offs = &src[1..][..nslices * 8];
71 let mut br = BitReader::new(offs, BitReaderMode::BE);
72 for _ in 0..nslices {
73 br.skip(32).unwrap();
74 let off = br.read(32).unwrap();
75 slice_offs.push(off);
76 }
77 }
78 let soff = nslices * 8 + 1;
79 RealVideo10BR {
80 br: BitReader::new(&src[soff..], BitReaderMode::BE),
81 tables,
82 num_slices: nslices,
83 slice_no: 0,
84 slice_off: slice_offs,
85 w: width,
86 h: height,
87 mb_w: (width + 15) >> 4,
88 mb_h: (height + 15) >> 4,
89 new_ver,
90 dc_coded: [false; 3],
91 last_dc: [0; 3],
92 mvmode,
93 }
94 }
95
96#[allow(unused_variables)]
97 fn decode_block(&mut self, sstate: &SliceState, quant: u8, intra: bool, coded: bool, blk: &mut [i16; 64], plane_no: usize) -> DecoderResult<()> {
98 let br = &mut self.br;
99 let mut idx = 0;
100 if intra {
101 let mut dc;
102 if !self.new_ver || !sstate.is_iframe {
103 dc = br.read(8)? as i16;
104 if dc == 255 { dc = 128; }
105 } else {
106 if self.dc_coded[plane_no] {
107 let diff;
108 let bits = br.peek(14);
109 let ret = if plane_no == 0 {
110 br.read_cb(&self.tables.luma_dc_cb)
111 } else {
112 br.read_cb(&self.tables.chroma_dc_cb)
113 };
114 if ret.is_err() {
115 println!("Illegal {} code {:X}", if plane_no==0{"luma"}else{"chroma"},bits);
116 }
117 let val = ret.unwrap() as i16;
118
119 if val != 0 {
120 diff = val - 128;
121 } else {
122 let code = br.read(2)?;
123 match code {
124 0x0 => { diff = ((br.read(7)? + 1) as i8) as i16; },
125 0x1 => { diff = (br.read(7)? as i16) - 128; },
126 0x2 => {
127 if plane_no == 0 {
128 if br.read_bool()? {
129 diff = ((br.read(8)? + 1) as i8) as i16;
130 } else {
131 diff = (br.read(8)? as i8) as i16;
132 }
133 } else {
134 br.skip(9)?;
135 diff = 1;
136 }
137 },
138 _ => {
139 if plane_no == 0 {
140 br.skip(4)?;
141 diff = 1;
142 } else {
143 return Err(DecoderError::InvalidData);
144 }
145 },
146 };
147 }
148 dc = (self.last_dc[plane_no] - diff) & 0xFF;
149 self.last_dc[plane_no] = dc;
150 } else {
151 self.dc_coded[plane_no] = true;
152 dc = self.last_dc[plane_no];
153 }
154 }
155 blk[0] = dc << 3;
156 idx = 1;
157 }
158 if !coded { return Ok(()); }
159
160 let rl_cb = &self.tables.rl_cb; // could be aic too
161 let q_add = if quant == 0 { 0i16 } else { ((quant - 1) | 1) as i16 };
162 let q = (quant * 2) as i16;
163 while idx < 64 {
164 let code = br.read_cb(rl_cb)?;
165 let run;
166 let mut level;
167 let last;
168 if !code.is_escape() {
169 run = code.get_run();
170 level = code.get_level();
171 last = code.is_last();
172 if br.read_bool()? { level = -level; }
173 if level >= 0 {
174 level = (level * q) + q_add;
175 } else {
176 level = (level * q) - q_add;
177 }
178 } else {
179 last = br.read_bool()?;
180 run = br.read(6)? as u8;
181 level = br.read_s(8)? as i16;
182 if level == -128 {
183 let low = br.read(5)? as i16;
184 let top = br.read_s(6)? as i16;
185 level = (top << 5) | low;
186 }
187 if level >= 0 {
188 level = (level * q) + q_add;
189 } else {
190 level = (level * q) - q_add;
191 }
192 if level < -2048 { level = -2048; }
193 if level > 2047 { level = 2047; }
194 }
195 idx += run;
196 validate!(idx < 64);
197 let oidx = ZIGZAG[idx as usize];
198 blk[oidx] = level;
199 idx += 1;
200 if last { break; }
201 }
202 Ok(())
203 }
204}
205
206fn decode_mv_component(br: &mut BitReader, mv_cb: &Codebook<u8>) -> DecoderResult<i16> {
207 let code = br.read_cb(mv_cb)? as i16;
208 if code == 0 { return Ok(0) }
209 if !br.read_bool()? {
210 Ok(code)
211 } else {
212 Ok(-code)
213 }
214}
215
216fn decode_mv(br: &mut BitReader, mv_cb: &Codebook<u8>) -> DecoderResult<MV> {
217 let xval = decode_mv_component(br, mv_cb)?;
218 let yval = decode_mv_component(br, mv_cb)?;
219 Ok(MV::new(xval, yval))
220}
221
222impl<'a> BlockDecoder for RealVideo10BR<'a> {
223
224#[allow(unused_variables)]
225 fn decode_pichdr(&mut self) -> DecoderResult<PicInfo> {
226 self.slice_no = 0;
227 let shdr = self.read_slice_header()?;
228 validate!((shdr.mb_x == 0) && (shdr.mb_y == 0));
229
230 let mb_end = shdr.mb_x + shdr.mb_y * self.mb_w + shdr.mb_c;
231
232 let ftype = if !shdr.is_p { Type::I } else { Type::P };
233 let picinfo = PicInfo::new(self.w, self.h, ftype, self.mvmode, false, false, shdr.qscale, 0, None, None);
234 Ok(picinfo)
235 }
236
237 #[allow(unused_variables)]
238 fn decode_slice_header(&mut self, info: &PicInfo) -> DecoderResult<SliceInfo> {
239 let shdr = self.read_slice_header()?;
240 self.slice_no += 1;
241 let mb_end = shdr.mb_x + shdr.mb_y * self.mb_w + shdr.mb_c;
242 let ret = SliceInfo::new(shdr.mb_x, shdr.mb_y, mb_end, shdr.qscale);
243
244 Ok(ret)
245 }
246
247 fn decode_block_header(&mut self, info: &PicInfo, slice: &SliceInfo, _sstate: &SliceState) -> DecoderResult<BlockInfo> {
248 let br = &mut self.br;
249 let mut q = slice.get_quant();
250 match info.get_mode() {
251 Type::I => {
252 let mut cbpc = br.read_cb(&self.tables.intra_mcbpc_cb)?;
253 while cbpc == 8 { cbpc = br.read_cb(&self.tables.intra_mcbpc_cb)?; }
254 let cbpy = br.read_cb(&self.tables.cbpy_cb)?;
255 let cbp = (cbpy << 2) | (cbpc & 3);
256 let dquant = (cbpc & 4) != 0;
257 if dquant {
258 let idx = br.read(2)? as usize;
259 q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8;
260 validate!(q < 32);
261 }
262 Ok(BlockInfo::new(Type::I, cbp, q))
263 },
264 Type::P => {
265 if br.read_bool()? {
266 return Ok(BlockInfo::new(Type::Skip, 0, info.get_quant()));
267 }
268 let mut cbpc = br.read_cb(&self.tables.inter_mcbpc_cb)?;
269 while cbpc == 20 { cbpc = br.read_cb(&self.tables.inter_mcbpc_cb)?; }
270 let is_intra = (cbpc & 0x04) != 0;
271 let dquant = (cbpc & 0x08) != 0;
272 let is_4x4 = (cbpc & 0x10) != 0;
273 if is_intra {
274 let cbpy = br.read_cb(&self.tables.cbpy_cb)?;
275 let cbp = (cbpy << 2) | (cbpc & 3);
276 if dquant {
277 let idx = br.read(2)? as usize;
278 q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8;
279 validate!(q < 32);
280 }
281 let binfo = BlockInfo::new(Type::I, cbp, q);
282 return Ok(binfo);
283 }
284
285 let mut cbpy = br.read_cb(&self.tables.cbpy_cb)?;
286// if /* !aiv && */(cbpc & 3) != 3 {
287 cbpy ^= 0xF;
288// }
289 let cbp = (cbpy << 2) | (cbpc & 3);
290 if dquant {
291 let idx = br.read(2)? as usize;
292 q = ((q as i16) + (H263_DQUANT_TAB[idx] as i16)) as u8;
293 validate!(q < 32);
294 }
295 let mut binfo = BlockInfo::new(Type::P, cbp, q);
296 if !is_4x4 {
297 let mvec: [MV; 1] = [decode_mv(br, &self.tables.mv_cb)?];
298 binfo.set_mv(&mvec);
299 } else {
300 let mvec: [MV; 4] = [
301 decode_mv(br, &self.tables.mv_cb)?,
302 decode_mv(br, &self.tables.mv_cb)?,
303 decode_mv(br, &self.tables.mv_cb)?,
304 decode_mv(br, &self.tables.mv_cb)?
305 ];
306 binfo.set_mv(&mvec);
307 }
308 Ok(binfo)
309 },
310 _ => { println!("wrong info mode"); Err(DecoderError::InvalidData) },
311 }
312 }
313
314 #[allow(unused_variables)]
315 fn decode_block_intra(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> {
316 self.decode_block(sstate, quant, true, coded, blk, if no < 4 { 0 } else { no - 3 })
317 }
318
319 #[allow(unused_variables)]
320 fn decode_block_inter(&mut self, info: &BlockInfo, sstate: &SliceState, quant: u8, no: usize, coded: bool, blk: &mut [i16; 64]) -> DecoderResult<()> {
321 self.decode_block(sstate, quant, false, coded, blk, if no < 4 { 0 } else { no - 3 })
322 }
323
324 fn is_slice_end(&mut self) -> bool { false }
325}
326
327impl<'a> RealVideo10BR<'a> {
328 fn read_slice_header(&mut self) -> DecoderResult<RV10SliceInfo> {
329 validate!(self.slice_no < self.num_slices);
330
331 let br = &mut self.br;
332 br.seek(self.slice_off[self.slice_no] * 8)?;
333
334 let marker = br.read(1)?;
335 validate!(marker == 1);
336 let is_p = br.read_bool()?;
337 let pb_frame = br.read_bool()?;
338 validate!(!pb_frame);
339 let qscale = br.read(5)? as u8;
340 validate!(qscale > 0);
341
342 if !is_p && self.new_ver {
343 self.last_dc[0] = br.read(8)? as i16;
344 self.last_dc[1] = br.read(8)? as i16;
345 self.last_dc[2] = br.read(8)? as i16;
346 } else {
347 self.last_dc[0] = 0;
348 self.last_dc[1] = 0;
349 self.last_dc[2] = 0;
350 }
351 self.dc_coded[0] = false;
352 self.dc_coded[1] = false;
353 self.dc_coded[2] = false;
354
355 let mb_x;
356 let mb_y;
357 let mb_count;
358 if (br.peek(12) == 0) || (self.slice_no > 0) {
359 mb_x = br.read(6)? as usize;
360 mb_y = br.read(6)? as usize;
361 mb_count = br.read(12)? as usize;
362 } else {
363 mb_x = 0;
364 mb_y = 0;
365 mb_count = self.mb_w * self.mb_h;
366 }
367 br.skip(3)?;
368 validate!(mb_x + mb_y * self.mb_w + mb_count <= self.mb_w * self.mb_h);
369
370 Ok(RV10SliceInfo::new(is_p, qscale, mb_x, mb_y, mb_count))
371 }
372}
373
374impl RealVideo10Decoder {
375 fn new() -> Self {
376 let mut coderead = H263ShortCodeReader::new(H263_INTRA_MCBPC);
377 let intra_mcbpc_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
378 let mut coderead = H263ShortCodeReader::new(H263_INTER_MCBPC);
379 let inter_mcbpc_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
380 let mut coderead = H263ShortCodeReader::new(H263_CBPY);
381 let cbpy_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
382 let mut coderead = H263RLCodeReader::new(H263_RL_CODES);
383 let rl_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
384 let mut coderead = H263RLCodeReader::new(H263_RL_CODES_AIC);
385 let aic_rl_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
386 let mut coderead = H263ShortCodeReader::new(H263_MV);
387 let mv_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
388 let mut coderead = CodeReader::new(RV10_LUMA_DC_CODES, RV10_LUMA_DC_BITS);
389 let luma_dc_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
390 let mut coderead = CodeReader::new(RV10_CHROMA_DC_CODES, RV10_CHROMA_DC_BITS);
391 let chroma_dc_cb = Codebook::new(&mut coderead, CodebookMode::MSB).unwrap();
392
393 let tables = Tables {
394 intra_mcbpc_cb,
395 inter_mcbpc_cb,
396 cbpy_cb,
397 rl_cb,
398 aic_rl_cb,
399 mv_cb,
400 luma_dc_cb,
401 chroma_dc_cb,
402 };
403
404 RealVideo10Decoder{
405 info: NACodecInfoRef::default(),
406 dec: H263BaseDecoder::new_with_opts(0),
407 tables,
408 w: 0,
409 h: 0,
410 new_ver: false,
411 bdsp: H263BlockDSP::new(),
412 mvmode: MVMode::Long,
413 }
414 }
415}
416
417impl NADecoder for RealVideo10Decoder {
418 fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
419 if let NACodecTypeInfo::Video(vinfo) = info.get_properties() {
420 let w = vinfo.get_width();
421 let h = vinfo.get_height();
422 let fmt = formats::YUV420_FORMAT;
423 let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(w, h, false, fmt));
424 self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
425 self.w = w;
426 self.h = h;
427
428 let edata = info.get_extradata().unwrap();
429 let src: &[u8] = &edata;
430 let ver = ((src[4] as u32) << 12) | ((src[5] as u32) << 4) | ((src[6] as u32) >> 4);
431 let maj_ver = ver >> 16;
432 let mic_ver = ver & 0xFF;
433 validate!(maj_ver == 1);
434 self.new_ver = mic_ver > 0;
435 if mic_ver == 2 {
436 self.dec = H263BaseDecoder::new_with_opts(H263DEC_OPT_HAS_OBMC);
437 }
438 if (src[3] & 1) != 0 {
439 self.mvmode = MVMode::UMV;
440 }
441 Ok(())
442 } else {
443 Err(DecoderError::InvalidData)
444 }
445 }
446 fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
447 let src = pkt.get_buffer();
448
449 let mut ibr = RealVideo10BR::new(&src, &self.tables, self.w, self.h, self.new_ver, self.mvmode);
450
451 let bufinfo = self.dec.parse_frame(&mut ibr, &self.bdsp)?;
452
453 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);
454 frm.set_keyframe(self.dec.is_intra());
455 frm.set_frame_type(if self.dec.is_intra() { FrameType::I } else { FrameType::P });
456 Ok(frm.into_ref())
457 }
458 fn flush(&mut self) {
459 self.dec.flush();
460 }
461}
462
463impl NAOptionHandler for RealVideo10Decoder {
464 fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
465 fn set_options(&mut self, _options: &[NAOption]) { }
466 fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
467}
468
469
470pub fn get_decoder() -> Box<dyn NADecoder + Send> {
471 Box::new(RealVideo10Decoder::new())
472}
473
474#[cfg(test)]
475mod test {
476 use nihav_core::codecs::RegisteredDecoders;
477 use nihav_core::demuxers::RegisteredDemuxers;
478 use nihav_codec_support::test::dec_video::*;
479 use crate::realmedia_register_all_decoders;
480 use crate::realmedia_register_all_demuxers;
481 #[test]
482 fn test_rv10_old() {
483 let mut dmx_reg = RegisteredDemuxers::new();
484 realmedia_register_all_demuxers(&mut dmx_reg);
485 let mut dec_reg = RegisteredDecoders::new();
486 realmedia_register_all_decoders(&mut dec_reg);
487
488 test_decoding("realmedia", "realvideo1", "assets/RV/thankyou.rm",
489 Some(1000), &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![
490 [0x8bba459c, 0xe6e8e01c, 0x36f90595, 0xb268adee],
491 [0x32ca9567, 0xedc13b6f, 0xbee77cfd, 0xc7ebe24b],
492 [0xcf1865b6, 0xea7cf1b2, 0x30a5a622, 0xe5775b0d],
493 [0x8d984cfd, 0xcbc81a8d, 0x71d5b37a, 0x74115bba],
494 [0x7ec2a9e8, 0x291fc62a, 0x5fc62722, 0xf2072b87],
495 [0xa150585b, 0x9d608fe7, 0xb8d42676, 0x070103f7],
496 [0x8aadd96f, 0xa02e0627, 0xa89e104f, 0xf47d1227],
497 [0xa4416bb1, 0xc9ca7a61, 0xad43de90, 0x3e9ec5b7]]));
498 }
499 #[test]
500 fn test_rv10_obmc() {
501 let mut dmx_reg = RegisteredDemuxers::new();
502 realmedia_register_all_demuxers(&mut dmx_reg);
503 let mut dec_reg = RegisteredDecoders::new();
504 realmedia_register_all_decoders(&mut dec_reg);
505
506 test_decoding("realmedia", "realvideo1",
507 "assets/RV/rv10_dnet_640x352_realvideo_encoder_4.0.rm",
508 Some(1000), &dmx_reg, &dec_reg, ExpectedTestResult::MD5Frames(vec![
509 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
510 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
511 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
512 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
513 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
514 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
515 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
516 [0x23599d2e, 0xf7212b24, 0x6b34b848, 0xbca84641],
517 [0x5cb179dc, 0x56ce9d07, 0x2439dd68, 0x80fec0bf],
518 [0x00de945d, 0xf44b71d3, 0x1dd93df9, 0x468bdcd5],
519 [0x7deb3aae, 0x8856c5da, 0x53011115, 0xed91377b],
520 [0x73afc311, 0xa61d36dc, 0x4e6ba0a3, 0x6dc64514],
521 [0xee35a8ce, 0x8edf5f32, 0x601d238f, 0xe5fa7ea7],
522 [0xe9aeaaa9, 0x876a221b, 0xe2d70923, 0x611849fd],
523 [0x0ff535cf, 0xf9e6ee1c, 0xed3a822c, 0x915056c0]]));
524 }
525}
526
527pub struct CodeReader { codes: &'static [u16], bits: &'static [u8] }
528
529impl CodeReader {
530 pub fn new(codes: &'static [u16], bits: &'static [u8]) -> Self {
531 CodeReader { codes, bits }
532 }
533}
534
535impl CodebookDescReader<u8> for CodeReader {
536 fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] }
537 fn code(&mut self, idx: usize) -> u32 { self.codes[idx] as u32 }
538 fn sym (&mut self, idx: usize) -> u8 { idx as u8 }
539 fn len(&mut self) -> usize { self.bits.len() }
540}
541
542const RV10_LUMA_DC_CODES: &[u16] = &[
543 0x001f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06,
544 0x0f07, 0x0f08, 0x0f09, 0x0f0a, 0x0f0b, 0x0f0c, 0x0f0d, 0x0f0e,
545 0x0f0f, 0x0f10, 0x0f11, 0x0f12, 0x0f13, 0x0f14, 0x0f15, 0x0f16,
546 0x0f17, 0x0f18, 0x0f19, 0x0f1a, 0x0f1b, 0x0f1c, 0x0f1d, 0x0f1e,
547 0x0f1f, 0x0f20, 0x0f21, 0x0f22, 0x0f23, 0x0f24, 0x0f25, 0x0f26,
548 0x0f27, 0x0f28, 0x0f29, 0x0f2a, 0x0f2b, 0x0f2c, 0x0f2d, 0x0f2e,
549 0x0f2f, 0x0f30, 0x0f31, 0x0f32, 0x0f33, 0x0f34, 0x0f35, 0x0f36,
550 0x0f37, 0x0f38, 0x0f39, 0x0f3a, 0x0f3b, 0x0f3c, 0x0f3d, 0x0f3e,
551 0x0f3f, 0x0380, 0x0381, 0x0382, 0x0383, 0x0384, 0x0385, 0x0386,
552 0x0387, 0x0388, 0x0389, 0x038a, 0x038b, 0x038c, 0x038d, 0x038e,
553 0x038f, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396,
554 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e,
555 0x039f, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6,
556 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce,
557 0x00cf, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056,
558 0x0057, 0x0020, 0x0021, 0x0022, 0x0023, 0x000c, 0x000d, 0x0004,
559 0x0000, 0x0005, 0x000e, 0x000f, 0x0024, 0x0025, 0x0026, 0x0027,
560 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
561 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
562 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
563 0x03a0, 0x03a1, 0x03a2, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
564 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
565 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
566 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
567 0x0f40, 0x0f41, 0x0f42, 0x0f43, 0x0f44, 0x0f45, 0x0f46, 0x0f47,
568 0x0f48, 0x0f49, 0x0f4a, 0x0f4b, 0x0f4c, 0x0f4d, 0x0f4e, 0x0f4f,
569 0x0f50, 0x0f51, 0x0f52, 0x0f53, 0x0f54, 0x0f55, 0x0f56, 0x0f57,
570 0x0f58, 0x0f59, 0x0f5a, 0x0f5b, 0x0f5c, 0x0f5d, 0x0f5e, 0x0f5f,
571 0x0f60, 0x0f61, 0x0f62, 0x0f63, 0x0f64, 0x0f65, 0x0f66, 0x0f67,
572 0x0f68, 0x0f69, 0x0f6a, 0x0f6b, 0x0f6c, 0x0f6d, 0x0f6e, 0x0f6f,
573 0x0f70, 0x0f71, 0x0f72, 0x0f73, 0x0f74, 0x0f75, 0x0f76, 0x0f77,
574 0x0f78, 0x0f79, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f7e, 0x0f7f,
575];
576
577const RV10_LUMA_DC_BITS: &[u8] = &[
578 5, 12, 12, 12, 12, 12, 12, 12,
579 12, 12, 12, 12, 12, 12, 12, 12,
580 12, 12, 12, 12, 12, 12, 12, 12,
581 12, 12, 12, 12, 12, 12, 12, 12,
582 12, 12, 12, 12, 12, 12, 12, 12,
583 12, 12, 12, 12, 12, 12, 12, 12,
584 12, 12, 12, 12, 12, 12, 12, 12,
585 12, 12, 12, 12, 12, 12, 12, 12,
586 12, 10, 10, 10, 10, 10, 10, 10,
587 10, 10, 10, 10, 10, 10, 10, 10,
588 10, 10, 10, 10, 10, 10, 10, 10,
589 10, 10, 10, 10, 10, 10, 10, 10,
590 10, 8, 8, 8, 8, 8, 8, 8,
591 8, 8, 8, 8, 8, 8, 8, 8,
592 8, 7, 7, 7, 7, 7, 7, 7,
593 7, 6, 6, 6, 6, 5, 5, 4,
594 2, 4, 5, 5, 6, 6, 6, 6,
595 7, 7, 7, 7, 7, 7, 7, 7,
596 8, 8, 8, 8, 8, 8, 8, 8,
597 8, 8, 8, 8, 8, 8, 8, 8,
598 10, 10, 10, 10, 10, 10, 10, 10,
599 10, 10, 10, 10, 10, 10, 10, 10,
600 10, 10, 10, 10, 10, 10, 10, 10,
601 10, 10, 10, 10, 10, 10, 10, 10,
602 12, 12, 12, 12, 12, 12, 12, 12,
603 12, 12, 12, 12, 12, 12, 12, 12,
604 12, 12, 12, 12, 12, 12, 12, 12,
605 12, 12, 12, 12, 12, 12, 12, 12,
606 12, 12, 12, 12, 12, 12, 12, 12,
607 12, 12, 12, 12, 12, 12, 12, 12,
608 12, 12, 12, 12, 12, 12, 12, 12,
609 12, 12, 12, 12, 12, 12, 12, 12,
610];
611
612const RV10_CHROMA_DC_CODES: &[u16] = &[
613 0x0000, 0x3f00, 0x3f01, 0x3f02, 0x3f03, 0x3f04, 0x3f05, 0x3f06,
614 0x3f07, 0x3f08, 0x3f09, 0x3f0a, 0x3f0b, 0x3f0c, 0x3f0d, 0x3f0e,
615 0x3f0f, 0x3f10, 0x3f11, 0x3f12, 0x3f13, 0x3f14, 0x3f15, 0x3f16,
616 0x3f17, 0x3f18, 0x3f19, 0x3f1a, 0x3f1b, 0x3f1c, 0x3f1d, 0x3f1e,
617 0x3f1f, 0x3f20, 0x3f21, 0x3f22, 0x3f23, 0x3f24, 0x3f25, 0x3f26,
618 0x3f27, 0x3f28, 0x3f29, 0x3f2a, 0x3f2b, 0x3f2c, 0x3f2d, 0x3f2e,
619 0x3f2f, 0x3f30, 0x3f31, 0x3f32, 0x3f33, 0x3f34, 0x3f35, 0x3f36,
620 0x3f37, 0x3f38, 0x3f39, 0x3f3a, 0x3f3b, 0x3f3c, 0x3f3d, 0x3f3e,
621 0x3f3f, 0x0f80, 0x0f81, 0x0f82, 0x0f83, 0x0f84, 0x0f85, 0x0f86,
622 0x0f87, 0x0f88, 0x0f89, 0x0f8a, 0x0f8b, 0x0f8c, 0x0f8d, 0x0f8e,
623 0x0f8f, 0x0f90, 0x0f91, 0x0f92, 0x0f93, 0x0f94, 0x0f95, 0x0f96,
624 0x0f97, 0x0f98, 0x0f99, 0x0f9a, 0x0f9b, 0x0f9c, 0x0f9d, 0x0f9e,
625 0x0f9f, 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6,
626 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce,
627 0x03cf, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6,
628 0x00e7, 0x0030, 0x0031, 0x0032, 0x0033, 0x0008, 0x0009, 0x0002,
629 0x0000, 0x0003, 0x000a, 0x000b, 0x0034, 0x0035, 0x0036, 0x0037,
630 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
631 0x03d0, 0x03d1, 0x03d2, 0x03d3, 0x03d4, 0x03d5, 0x03d6, 0x03d7,
632 0x03d8, 0x03d9, 0x03da, 0x03db, 0x03dc, 0x03dd, 0x03de, 0x03df,
633 0x0fa0, 0x0fa1, 0x0fa2, 0x0fa3, 0x0fa4, 0x0fa5, 0x0fa6, 0x0fa7,
634 0x0fa8, 0x0fa9, 0x0faa, 0x0fab, 0x0fac, 0x0fad, 0x0fae, 0x0faf,
635 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7,
636 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf,
637 0x3f40, 0x3f41, 0x3f42, 0x3f43, 0x3f44, 0x3f45, 0x3f46, 0x3f47,
638 0x3f48, 0x3f49, 0x3f4a, 0x3f4b, 0x3f4c, 0x3f4d, 0x3f4e, 0x3f4f,
639 0x3f50, 0x3f51, 0x3f52, 0x3f53, 0x3f54, 0x3f55, 0x3f56, 0x3f57,
640 0x3f58, 0x3f59, 0x3f5a, 0x3f5b, 0x3f5c, 0x3f5d, 0x3f5e, 0x3f5f,
641 0x3f60, 0x3f61, 0x3f62, 0x3f63, 0x3f64, 0x3f65, 0x3f66, 0x3f67,
642 0x3f68, 0x3f69, 0x3f6a, 0x3f6b, 0x3f6c, 0x3f6d, 0x3f6e, 0x3f6f,
643 0x3f70, 0x3f71, 0x3f72, 0x3f73, 0x3f74, 0x3f75, 0x3f76, 0x3f77,
644 0x3f78, 0x3f79, 0x3f7a, 0x3f7b, 0x3f7c, 0x3f7d, 0x3f7e, 0x3f7f,
645];
646
647const RV10_CHROMA_DC_BITS: &[u8] = &[
648 0, 14, 14, 14, 14, 14, 14, 14,
649 14, 14, 14, 14, 14, 14, 14, 14,
650 14, 14, 14, 14, 14, 14, 14, 14,
651 14, 14, 14, 14, 14, 14, 14, 14,
652 14, 14, 14, 14, 14, 14, 14, 14,
653 14, 14, 14, 14, 14, 14, 14, 14,
654 14, 14, 14, 14, 14, 14, 14, 14,
655 14, 14, 14, 14, 14, 14, 14, 14,
656 14, 12, 12, 12, 12, 12, 12, 12,
657 12, 12, 12, 12, 12, 12, 12, 12,
658 12, 12, 12, 12, 12, 12, 12, 12,
659 12, 12, 12, 12, 12, 12, 12, 12,
660 12, 10, 10, 10, 10, 10, 10, 10,
661 10, 10, 10, 10, 10, 10, 10, 10,
662 10, 8, 8, 8, 8, 8, 8, 8,
663 8, 6, 6, 6, 6, 4, 4, 3,
664 2, 3, 4, 4, 6, 6, 6, 6,
665 8, 8, 8, 8, 8, 8, 8, 8,
666 10, 10, 10, 10, 10, 10, 10, 10,
667 10, 10, 10, 10, 10, 10, 10, 10,
668 12, 12, 12, 12, 12, 12, 12, 12,
669 12, 12, 12, 12, 12, 12, 12, 12,
670 12, 12, 12, 12, 12, 12, 12, 12,
671 12, 12, 12, 12, 12, 12, 12, 12,
672 14, 14, 14, 14, 14, 14, 14, 14,
673 14, 14, 14, 14, 14, 14, 14, 14,
674 14, 14, 14, 14, 14, 14, 14, 14,
675 14, 14, 14, 14, 14, 14, 14, 14,
676 14, 14, 14, 14, 14, 14, 14, 14,
677 14, 14, 14, 14, 14, 14, 14, 14,
678 14, 14, 14, 14, 14, 14, 14, 14,
679 14, 14, 14, 14, 14, 14, 14, 14,
680];