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