for j in 0..8 {
for k in 0..8 {
let mut v = blk[0][k + j * 8];
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k] = v as u8;
}
for k in 0..8 {
let mut v = blk[1][k + j * 8];
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k + 8] = v as u8;
}
idxy += stridey;
for j in 0..8 {
for k in 0..8 {
let mut v = blk[2][k + j * 8];
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k] = v as u8;
}
for k in 0..8 {
let mut v = blk[3][k + j * 8];
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k + 8] = v as u8;
}
idxy += stridey;
for j in 0..8 {
for k in 0..8 {
let mut v = blk[4][k + j * 8];
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxu + k] = v as u8;
}
for k in 0..8 {
let mut v = blk[5][k + j * 8];
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxv + k] = v as u8;
}
idxu += strideu;
for j in 0..8 {
for k in 0..8 {
- let mut v = blk[0][k + j * 8] + (framebuf[idxy + k] as i16);
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ let mut v = blk[0][k + j * 8] + i16::from(framebuf[idxy + k]);
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k] = v as u8;
}
for k in 0..8 {
- let mut v = blk[1][k + j * 8] + (framebuf[idxy + k + 8] as i16);
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ let mut v = blk[1][k + j * 8] + i16::from(framebuf[idxy + k + 8]);
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k + 8] = v as u8;
}
idxy += stridey;
}
for j in 0..8 {
for k in 0..8 {
- let mut v = blk[2][k + j * 8] + (framebuf[idxy + k] as i16);
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ let mut v = blk[2][k + j * 8] + i16::from(framebuf[idxy + k]);
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k] = v as u8;
}
for k in 0..8 {
- let mut v = blk[3][k + j * 8] + (framebuf[idxy + k + 8] as i16);
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ let mut v = blk[3][k + j * 8] + i16::from(framebuf[idxy + k + 8]);
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k + 8] = v as u8;
}
idxy += stridey;
for j in 0..8 {
for k in 0..8 {
- let mut v = blk[4][k + j * 8] + (framebuf[idxu + k] as i16);
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ let mut v = blk[4][k + j * 8] + i16::from(framebuf[idxu + k]);
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxu + k] = v as u8;
}
for k in 0..8 {
- let mut v = blk[5][k + j * 8] + (framebuf[idxv + k] as i16);
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ let mut v = blk[5][k + j * 8] + i16::from(framebuf[idxv + k]);
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxv + k] = v as u8;
}
idxu += strideu;
if (sx - pre < 0) || ((sx >> 1) - pre < 0) || (sx + (bw as isize) + post > (w as isize)) ||
(sy - pre < 0) || ((sy >> 1) - pre < 0) || (sy + (bh as isize) + post > (h as isize)) {
let ebuf_stride: usize = 32;
- let mut ebuf: Vec<u8> = Vec::with_capacity(ebuf_stride * (bh + ((pre + post) as usize)));
- ebuf.resize((((pre + post) as usize) + bh) * ebuf_stride, 0);
+ let mut ebuf: Vec<u8> = vec![0; ebuf_stride * (bh + ((pre + post) as usize))];
for comp in 0..3 {
let dstride = dst.get_stride(comp);
const ROW_SHIFT: u8 = 8;
const COL_SHIFT: u8 = 14;
+#[allow(clippy::erasing_op)]
fn idct_row(row: &mut [i16]) {
- let in0 = ((row[0] as i32) << 11) + (1 << (ROW_SHIFT - 1));
- let in1 = (row[4] as i32) << 11;
- let in2 = row[6] as i32;
- let in3 = row[2] as i32;
- let in4 = row[1] as i32;
- let in5 = row[7] as i32;
- let in6 = row[5] as i32;
- let in7 = row[3] as i32;
+ let in0 = ((i32::from(row[0])) << 11) + (1 << (ROW_SHIFT - 1));
+ let in1 = (i32::from(row[4])) << 11;
+ let in2 = i32::from(row[6]);
+ let in3 = i32::from(row[2]);
+ let in4 = i32::from(row[1]);
+ let in5 = i32::from(row[7]);
+ let in6 = i32::from(row[5]);
+ let in7 = i32::from(row[3]);
let tmp = W7 * (in4 + in5);
let a4 = tmp + (W1 - W7) * in4;
row[4] = ((b5 - b6) >> ROW_SHIFT) as i16;
}
+#[allow(clippy::erasing_op)]
fn idct_col(blk: &mut [i16; 64], off: usize) {
- let in0 = ((blk[off + 0*8] as i32) << 8) + (1 << (COL_SHIFT - 1));
- let in1 = (blk[off + 4*8] as i32) << 8;
- let in2 = blk[off + 6*8] as i32;
- let in3 = blk[off + 2*8] as i32;
- let in4 = blk[off + 1*8] as i32;
- let in5 = blk[off + 7*8] as i32;
- let in6 = blk[off + 5*8] as i32;
- let in7 = blk[off + 3*8] as i32;
+ let in0 = ((i32::from(blk[off + 0*8])) << 8) + (1 << (COL_SHIFT - 1));
+ let in1 = (i32::from(blk[off + 4*8])) << 8;
+ let in2 = i32::from(blk[off + 6*8]);
+ let in3 = i32::from(blk[off + 2*8]);
+ let in4 = i32::from(blk[off + 1*8]);
+ let in5 = i32::from(blk[off + 7*8]);
+ let in6 = i32::from(blk[off + 5*8]);
+ let in7 = i32::from(blk[off + 3*8]);
let tmp = W7 * (in4 + in5);
let a4 = (tmp + (W1 - W7) * in4) >> 3;
}
}
+#[allow(clippy::erasing_op)]
fn deblock_hor(buf: &mut NAVideoBuffer<u8>, comp: usize, q: u8, off: usize) {
let stride = buf.get_stride(comp);
let dptr = buf.get_data_mut().unwrap();
pub struct H263ShortCodeReader { tab: &'static [(u8, u8)] }
impl H263ShortCodeReader {
- pub fn new(tab: &'static [(u8, u8)]) -> Self { H263ShortCodeReader { tab: tab } }
+ pub fn new(tab: &'static [(u8, u8)]) -> Self { H263ShortCodeReader { tab } }
}
impl CodebookDescReader<u8> for H263ShortCodeReader {
pub struct H263RLCodeReader { tab: &'static [H263RLCodeDesc] }
impl H263RLCodeReader {
- pub fn new(tab: &'static [H263RLCodeDesc]) -> Self { H263RLCodeReader { tab: tab } }
+ pub fn new(tab: &'static [H263RLCodeDesc]) -> Self { H263RLCodeReader { tab } }
}
impl CodebookDescReader<H263RLSym> for H263RLCodeReader {
last_ts: 0, next_ts: 0, tsdiff: 0,
has_b: false, b_data: Vec::new(),
pred_coeffs: Vec::new(),
- is_gob: is_gob, slice_reset: slice_reset,
- may_have_b_frames: may_have_b_frames,
+ is_gob, slice_reset,
+ may_have_b_frames,
mv_data: Vec::new(),
}
}
let fmt = formats::YUV420_FORMAT;
let vinfo = NAVideoInfo::new(self.w, self.h, false, fmt);
- let bufret = alloc_video_buffer(vinfo, 4);
- if let Err(_) = bufret { return Err(DecoderError::InvalidData); }
- let bufinfo = bufret.unwrap();
+ let bufinfo = alloc_video_buffer(vinfo, 4)?;
let mut buf = bufinfo.get_vbuf().unwrap();
let mut slice = if self.is_gob {
let fmt = formats::YUV420_FORMAT;
let vinfo = NAVideoInfo::new(self.w, self.h, false, fmt);
- let bufret = alloc_video_buffer(vinfo, 4);
- if let Err(_) = bufret { return Err(DecoderError::InvalidData); }
- let bufinfo = bufret.unwrap();
+ let bufinfo = alloc_video_buffer(vinfo, 4)?;
let mut b_buf = bufinfo.get_vbuf().unwrap();
if let (Some(ref bck_buf), Some(ref fwd_buf)) = (self.ipbs.get_nextref(), self.ipbs.get_lastref()) {
use super::{DecoderResult, MV, ZERO_MV};
use crate::frame::NAVideoBuffer;
+#[allow(clippy::many_single_char_names)]
pub mod code;
pub mod data;
pub mod decoder;
impl PBInfo {
pub fn new(trb: u8, dbquant: u8, improved: bool) -> Self {
- PBInfo{ trb: trb, dbquant: dbquant, improved: improved }
+ PBInfo{ trb, dbquant, improved }
}
pub fn get_trb(&self) -> u8 { self.trb }
pub fn get_dbquant(&self) -> u8 { self.dbquant }
impl PicInfo {
pub fn new(w: usize, h: usize, mode: Type, mvmode: MVMode, umv: bool, apm: bool, quant: u8, ts: u16, pb: Option<PBInfo>, plusinfo: Option<PlusInfo>) -> Self {
PicInfo {
- w: w, h: h, mode: mode, mvmode: mvmode,
- umv: umv, apm: apm, quant: quant,
- pb: pb, ts: ts, plusinfo: plusinfo
+ w, h, mode, mvmode,
+ umv, apm, quant,
+ pb, ts, plusinfo
}
}
pub fn get_width(&self) -> usize { self.w }
impl PlusInfo {
pub fn new(aic: bool, deblock: bool, aiv_mode: bool, mq_mode: bool) -> Self {
- PlusInfo { aic: aic, deblock: deblock, aiv_mode: aiv_mode, mq_mode: mq_mode }
+ PlusInfo { aic, deblock, aiv_mode, mq_mode }
}
}
impl SliceInfo {
pub fn new(mb_x: usize, mb_y: usize, mb_end: usize, quant: u8) -> Self {
- SliceInfo{ mb_x: mb_x, mb_y: mb_y, mb_end: mb_end, quant: quant }
+ SliceInfo{ mb_x, mb_y, mb_end, quant }
}
pub fn new_gob(mb_x: usize, mb_y: usize, quant: u8) -> Self {
- SliceInfo{ mb_x: mb_x, mb_y: mb_y, mb_end: SLICE_NO_END, quant: quant }
+ SliceInfo{ mb_x, mb_y, mb_end: SLICE_NO_END, quant }
}
pub fn get_default_slice(pinfo: &PicInfo) -> Self {
SliceInfo{ mb_x: 0, mb_y: 0, mb_end: SLICE_NO_END, quant: pinfo.get_quant() }
impl SliceState {
pub fn new(is_iframe: bool) -> Self {
SliceState {
- is_iframe: is_iframe, mb_x: 0, mb_y: 0, first_line: true, first_mb: true,
+ is_iframe, mb_x: 0, mb_y: 0, first_line: true, first_mb: true,
slice_mb_x: 0, slice_mb_y: 0, quant: 0
}
}
BlockInfo {
intra: mode == Type::I,
skip: (cbp == 0) && (mode != Type::I),
- mode: mode,
- cbp: cbp,
- q: q,
+ mode,
+ cbp,
+ q,
mv: [MV::new(0, 0), MV::new(0, 0), MV::new(0, 0), MV::new(0, 0)],
num_mv: 0,
bpart: false,
impl BBlockInfo {
pub fn new(present: bool, cbp: u8, num_mv: usize, fwd: bool) -> Self {
BBlockInfo {
- present: present,
- cbp: cbp,
- num_mv: num_mv,
- fwd: fwd,
+ present,
+ cbp,
+ num_mv,
+ fwd,
}
}
pub fn get_num_mv(&self) -> usize { self.num_mv }
let bscale = (trb as i32) - (trd as i32);
let x = if bvec.x != 0 { fwdvec.x - pvec.x } else if trd != 0 { (bscale * (pvec.x as i32) / (trd as i32)) as i16 } else { 0 };
let y = if bvec.y != 0 { fwdvec.y - pvec.y } else if trd != 0 { (bscale * (pvec.y as i32) / (trd as i32)) as i16 } else { 0 };
- MV { x: x, y: y }
+ MV { x, y }
}
}
pub y: i16,
}
+#[allow(clippy::many_single_char_names)]
+#[allow(clippy::collapsible_if)]
impl MV {
- pub fn new(x: i16, y: i16) -> Self { MV{ x: x, y: y } }
+ pub fn new(x: i16, y: i16) -> Self { MV{ x, y } }
pub fn pred(a: MV, b: MV, c: MV) -> Self {
let x;
if a.x < b.x {
y = b.y;
}
}
- MV { x: x, y: y }
+ MV { x, y }
}
}
}
}
+impl Default for NADecoderSupport {
+ fn default() -> Self { Self::new() }
+}
+
pub trait NADecoder {
fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()>;
#[cfg(feature="h263")]
pub mod h263;
+#[derive(Default)]
pub struct RegisteredDecoders {
decs: Vec<DecoderInfo>,
}
let mut buf: Vec<u8> = Vec::with_capacity(size);
if buf.capacity() < size { return Err(DemuxerError::MemoryError); }
buf.resize(size, 0);
- let res = self.read_buf(buf.as_mut_slice());
- if let Err(_) = res { return Err(DemuxerError::IOError); }
+ self.read_buf(buf.as_mut_slice())?;
let pkt = NAPacket::new(str, ts, kf, buf);
Ok(pkt)
}
fn fill_packet(&mut self, pkt: &mut NAPacket) -> DemuxerResult<()> {
let mut refbuf = pkt.get_buffer();
let buf = refbuf.as_mut().unwrap();
- let res = self.read_buf(buf.as_mut_slice());
- if let Err(_) = res { return Err(DemuxerError::IOError); }
+ self.read_buf(buf.as_mut_slice())?;
Ok(())
}
}
+#[derive(Default)]
pub struct StreamManager {
streams: Vec<NAStreamRef>,
ignored: Vec<bool>,
}
pub struct StreamIter<'a> {
- streams: &'a Vec<NAStreamRef>,
+ streams: &'a [NAStreamRef],
pos: usize,
}
impl<'a> StreamIter<'a> {
- pub fn new(streams: &'a Vec<NAStreamRef>) -> Self {
- StreamIter { streams: streams, pos: 0 }
+ pub fn new(streams: &'a [NAStreamRef]) -> Self {
+ StreamIter { streams, pos: 0 }
}
}
impl<'a> Demuxer<'a> {
fn new(dmx: Box<dyn DemuxCore<'a> + 'a>, str: StreamManager) -> Self {
Demuxer {
- dmx: dmx,
+ dmx,
streams: str,
}
}
Ok(Demuxer::new(dmx, str))
}
+#[derive(Default)]
pub struct RegisteredDemuxers {
dmxs: Vec<&'static DemuxerCreator>,
}
}
impl DetectionScore {
- pub fn less(&self, other: DetectionScore) -> bool {
- (*self as i32) < (other as i32)
+ pub fn less(self, other: DetectionScore) -> bool {
+ (self as i32) < (other as i32)
}
}
impl Arg {
fn val(&self) -> u64 {
match *self {
- Arg::Byte(b) => { b as u64 }
- Arg::U16BE(v) => { v as u64 }
- Arg::U16LE(v) => { v as u64 }
- Arg::U24BE(v) => { v as u64 }
- Arg::U24LE(v) => { v as u64 }
- Arg::U32BE(v) => { v as u64 }
- Arg::U32LE(v) => { v as u64 }
+ Arg::Byte(b) => { u64::from(b) }
+ Arg::U16BE(v) => { u64::from(v) }
+ Arg::U16LE(v) => { u64::from(v) }
+ Arg::U24BE(v) => { u64::from(v) }
+ Arg::U24LE(v) => { u64::from(v) }
+ Arg::U32BE(v) => { u64::from(v) }
+ Arg::U32LE(v) => { u64::from(v) }
Arg::U64BE(v) => { v }
Arg::U64LE(v) => { v }
}
match *self {
Arg::Byte(_) => {
let res = src.peek_byte();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U16BE(_) => {
let res = src.peek_u16be();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U16LE(_) => {
let res = src.peek_u16le();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U24BE(_) => {
let res = src.peek_u24be();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U24LE(_) => {
let res = src.peek_u24le();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U32BE(_) => {
let res = src.peek_u32be();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U32LE(_) => {
let res = src.peek_u32le();
- if let Err(_) = res { return None; }
- Some(res.unwrap() as u64)
+ if res.is_err() { return None; }
+ Some(u64::from(res.unwrap()))
}
Arg::U64BE(_) => {
let res = src.peek_u64be();
- if let Err(_) = res { return None; }
+ if res.is_err() { return None; }
Some(res.unwrap())
}
Arg::U64LE(_) => {
let res = src.peek_u64le();
- if let Err(_) = res { return None; }
+ if res.is_err() { return None; }
Some(res.unwrap())
}
}
}
fn eq(&self, src: &mut ByteReader) -> bool {
let val = self.read_val(src);
- if let None = val { false }
+ if val.is_none() { false }
else { val.unwrap() == self.val() }
}
fn ge(&self, src: &mut ByteReader) -> bool {
let val = self.read_val(src);
- if let None = val { false }
+ if val.is_none() { false }
else { val.unwrap() >= self.val() }
}
fn gt(&self, src: &mut ByteReader) -> bool {
let val = self.read_val(src);
- if let None = val { false }
+ if val.is_none() { false }
else { val.unwrap() > self.val() }
}
fn le(&self, src: &mut ByteReader) -> bool {
let val = self.read_val(src);
- if let None = val { false }
+ if val.is_none() { false }
else { val.unwrap() <= self.val() }
}
fn lt(&self, src: &mut ByteReader) -> bool {
let val = self.read_val(src);
- if let None = val { false }
+ if val.is_none() { false }
else { val.unwrap() < self.val() }
}
}
CC::Gt(ref arg) => { arg.gt(src) },
CC::Ge(ref arg) => { arg.ge(src) },
CC::Str(str) => {
- let mut val: Vec<u8> = Vec::with_capacity(str.len());
- val.resize(str.len(), 0);
+ let mut val: Vec<u8> = vec![0; str.len()];
let res = src.peek_buf(val.as_mut_slice());
- if let Err(_) = res { return false; }
+ if res.is_err() { return false; }
val == str
}
}
let lname = name.to_lowercase();
for detector in DETECTORS {
let mut score = DetectionScore::No;
- if name.len() > 0 {
+ if !name.is_empty() {
for ext in detector.extensions.split(',') {
if lname.ends_with(ext) {
score = DetectionScore::ExtensionMatches;
}
}
}
- let mut passed = detector.conditions.len() > 0;
+ let mut passed = !detector.conditions.is_empty();
for ck in detector.conditions {
- let ret = src.seek(SeekFrom::Start(ck.offs as u64));
- if let Err(_) = ret {
+ let ret = src.seek(SeekFrom::Start(u64::from(ck.offs)));
+ if ret.is_err() {
passed = false;
break;
}
s >> (32 - bits)
}
-fn gen_swaps_for_perm(swaps: &mut Vec<usize>, perms: &Vec<usize>) {
+fn gen_swaps_for_perm(swaps: &mut Vec<usize>, perms: &[usize]) {
let mut idx_arr: Vec<usize> = Vec::with_capacity(perms.len());
for i in 0..perms.len() { idx_arr.push(i); }
let mut run_size = 0;
}
}
-fn swap_buf(buf: &mut [f32], swaps: &Vec<usize>) {
+fn swap_buf(buf: &mut [f32], swaps: &[usize]) {
for (idx, nidx) in swaps.iter().enumerate() {
if idx != *nidx {
- let t = buf[*nidx];
- buf[*nidx] = buf[idx];
- buf[idx] = t;
+ buf.swap(*nidx, idx);
}
}
}
for i in 0..hsize {
let idx0 = i * step;
let idx1 = (size - 1 - i) * step;
- let t = buf[idx1];
- buf[idx1] = buf[idx0];
- buf[idx0] = t;
+ buf.swap(idx0, idx1);
}
}
dct_III_inplace(buf, hsize, step, tab, perm_tab);
dct_IV_inplace(&mut buf[step*hsize..], hsize, step, tab, perm_tab);
for i in 0..(size >> 2) {
- let t = buf[(size - 1 - i) * step];
- buf[(size - 1 - i) * step] = buf[(hsize + i) * step];
- buf[(hsize + i) * step] = t;
+ buf.swap((size - 1 - i) * step, (hsize + i) * step);
}
for i in 0..hsize {
let i0 = buf[i * step] / consts::SQRT_2;
for i in 0..hsize {
let idx0 = i * step;
let idx1 = (size - 1 - i) * step;
- let t = buf[idx1];
- buf[idx1] = buf[idx0];
- buf[idx0] = t;
+ buf.swap(idx0, idx1);
}
dct_III_inplace(buf, size, step, tab, perm_tab);
for i in 0..hsize { buf[i * 2 * step + step] = -buf[i * 2 * step + step]; }
dct_II_inplace(buf, hsize, step * 2, tab, perm_tab);
dct_II_inplace(&mut buf[step..], hsize, step * 2, tab, perm_tab);
for i in 0..(size >> 2) {
- let t = buf[(size - 1 - i * 2) * step];
- buf[(size - 1 - i * 2) * step] = buf[(i * 2 + 1) * step];
- buf[(i * 2 + 1) * step] = t;
+ buf.swap((size - 1 - i * 2) * step, (i * 2 + 1) * step);
}
for i in (3..size).step_by(4) {
buf[i] = -buf[i];
for idx in 0..self.swaps.len() {
let nidx = self.swaps[idx];
if idx != nidx {
- let t = data[nidx];
- data[nidx] = data[idx];
- data[idx] = t;
+ data.swap(nidx, idx);
}
}
self.do_fft_core(data);
for idx in 0..self.swaps.len() {
let nidx = self.swaps[idx];
if idx != nidx {
- let t = data[nidx];
- data[nidx] = data[idx];
- data[idx] = t;
+ data.swap(nidx, idx);
}
}
self.do_ifft_core(data);
#[cfg(feature="dct")]
+#[allow(clippy::erasing_op)]
pub mod dct;
#[cfg(feature="fft")]
+#[allow(clippy::erasing_op)]
pub mod fft;
#[cfg(feature="mdct")]
pub mod mdct;
let is_pl = (flags & SONITON_FLAG_PLANAR) != 0;
let is_fl = (flags & SONITON_FLAG_FLOAT) != 0;
let is_sg = (flags & SONITON_FLAG_SIGNED) != 0;
- NASoniton { bits: bits, be: is_be, packed: is_pk, planar: is_pl, float: is_fl, signed: is_sg }
+ NASoniton { bits, be: is_be, packed: is_pk, planar: is_pl, float: is_fl, signed: is_sg }
}
- pub fn get_bits(&self) -> u8 { self.bits }
- pub fn is_be(&self) -> bool { self.be }
- pub fn is_packed(&self) -> bool { self.packed }
- pub fn is_planar(&self) -> bool { self.planar }
- pub fn is_float(&self) -> bool { self.float }
- pub fn is_signed(&self) -> bool { self.signed }
+ pub fn get_bits(self) -> u8 { self.bits }
+ pub fn is_be(self) -> bool { self.be }
+ pub fn is_packed(self) -> bool { self.packed }
+ pub fn is_planar(self) -> bool { self.planar }
+ pub fn is_float(self) -> bool { self.float }
+ pub fn is_signed(self) -> bool { self.signed }
- pub fn get_audio_size(&self, length: u64) -> usize {
+ pub fn get_audio_size(self, length: u64) -> usize {
if self.packed {
- ((length * (self.bits as u64) + 7) >> 3) as usize
+ ((length * u64::from(self.bits) + 7) >> 3) as usize
} else {
- (length * (((self.bits + 7) >> 3) as u64)) as usize
+ (length * u64::from((self.bits + 7) >> 3)) as usize
}
}
}
}
impl NAChannelType {
- pub fn is_center(&self) -> bool {
- match *self {
+ pub fn is_center(self) -> bool {
+ match self {
NAChannelType::C => true, NAChannelType::Ch => true,
NAChannelType::Cl => true, NAChannelType::Ov => true,
NAChannelType::LFE => true, NAChannelType::LFE2 => true,
_ => false,
}
}
- pub fn is_left(&self) -> bool {
- match *self {
+ pub fn is_left(self) -> bool {
+ match self {
NAChannelType::L => true, NAChannelType::Ls => true,
NAChannelType::Lss => true, NAChannelType::Lc => true,
NAChannelType::Lh => true, NAChannelType::Lw => true,
_ => false,
}
}
- pub fn is_right(&self) -> bool {
- match *self {
+ pub fn is_right(self) -> bool {
+ match self {
NAChannelType::R => true, NAChannelType::Rs => true,
NAChannelType::Rss => true, NAChannelType::Rc => true,
NAChannelType::Rh => true, NAChannelType::Rw => true,
}
}
-#[derive(Clone)]
+#[derive(Clone,Default)]
pub struct NAChannelMap {
ids: Vec<NAChannelType>,
}
self.ids.push(ch);
}
pub fn add_channels(&mut self, chs: &[NAChannelType]) {
- for i in 0..chs.len() {
- self.ids.push(chs[i]);
+ for e in chs.iter() {
+ self.ids.push(*e);
}
}
pub fn num_channels(&self) -> usize {
}
pub fn from_ms_mapping(chmap: u32) -> Self {
let mut cm = NAChannelMap::new();
- for i in 0..MS_CHANNEL_MAP.len() {
+ for (i, ch) in MS_CHANNEL_MAP.iter().enumerate() {
if ((chmap >> i) & 1) != 0 {
- cm.add_channel(MS_CHANNEL_MAP[i]);
+ cm.add_channel(*ch);
}
}
cm
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut map = String::new();
for el in self.ids.iter() {
- if map.len() > 0 { map.push(','); }
+ if !map.is_empty() { map.push(','); }
map.push_str(&*el.to_string());
}
write!(f, "{}", map)
}
impl ColorModel {
- pub fn get_default_components(&self) -> usize {
- match *self {
+ pub fn get_default_components(self) -> usize {
+ match self {
ColorModel::CMYK => 4,
_ => 3,
}
}
- pub fn is_rgb(&self) -> bool {
- match *self {
+ pub fn is_rgb(self) -> bool {
+ match self {
ColorModel::RGB(_) => true,
_ => false,
}
}
- pub fn is_yuv(&self) -> bool {
- match *self {
+ pub fn is_yuv(self) -> bool {
+ match self {
ColorModel::YUV(_) => true,
_ => false,
}
}
- pub fn get_short_name(&self) -> &'static str {
- match *self {
+ pub fn get_short_name(self) -> &'static str {
+ match self {
ColorModel::RGB(_) => "rgb",
ColorModel::YUV(_) => "yuv",
ColorModel::CMYK => "cmyk",
pub fn new(h_ss: u8, v_ss: u8, packed: bool, depth: u8, shift: u8, comp_offs: u8, next_elem: u8) -> Self {
Self { h_ss, v_ss, packed, depth, shift, comp_offs, next_elem }
}
- pub fn get_subsampling(&self) -> (u8, u8) { (self.h_ss, self.v_ss) }
- pub fn is_packed(&self) -> bool { self.packed }
- pub fn get_depth(&self) -> u8 { self.depth }
- pub fn get_shift(&self) -> u8 { self.shift }
- pub fn get_offset(&self) -> u8 { self.comp_offs }
- pub fn get_step(&self) -> u8 { self.next_elem }
+ pub fn get_subsampling(self) -> (u8, u8) { (self.h_ss, self.v_ss) }
+ pub fn is_packed(self) -> bool { self.packed }
+ pub fn get_depth(self) -> u8 { self.depth }
+ pub fn get_shift(self) -> u8 { self.shift }
+ pub fn get_offset(self) -> u8 { self.comp_offs }
+ pub fn get_step(self) -> u8 { self.next_elem }
- pub fn get_width(&self, width: usize) -> usize {
+ pub fn get_width(self, width: usize) -> usize {
(width + ((1 << self.h_ss) - 1)) >> self.h_ss
}
- pub fn get_height(&self, height: usize) -> usize {
+ pub fn get_height(self, height: usize) -> usize {
(height + ((1 << self.v_ss) - 1)) >> self.v_ss
}
- pub fn get_linesize(&self, width: usize) -> usize {
+ pub fn get_linesize(self, width: usize) -> usize {
let d = self.depth as usize;
if self.packed {
(self.get_width(width) * d + d - 1) >> 3
self.get_width(width)
}
}
- pub fn get_data_size(&self, width: usize, height: usize) -> usize {
+ pub fn get_data_size(self, width: usize, height: usize) -> usize {
let nh = (height + ((1 << self.v_ss) - 1)) >> self.v_ss;
self.get_linesize(width) * nh
}
if let Some(c) = comp3 { chromatons[2] = Some(c); ncomp += 1; }
if let Some(c) = comp4 { chromatons[3] = Some(c); ncomp += 1; }
if let Some(c) = comp5 { chromatons[4] = Some(c); ncomp += 1; }
- NAPixelFormaton { model: model,
+ NAPixelFormaton { model,
components: ncomp,
comp_info: chromatons,
- elem_size: elem_size,
- be: be, alpha: alpha, palette: palette }
+ elem_size,
+ be, alpha, palette }
}
pub fn get_model(&self) -> ColorModel { self.model }
if idx < self.comp_info.len() { return self.comp_info[idx]; }
None
}
- pub fn is_be(&self) -> bool { self.be }
- pub fn has_alpha(&self) -> bool { self.alpha }
- pub fn is_paletted(&self) -> bool { self.palette }
- pub fn get_elem_size(&self) -> u8 { self.elem_size }
+ pub fn is_be(self) -> bool { self.be }
+ pub fn has_alpha(self) -> bool { self.alpha }
+ pub fn is_paletted(self) -> bool { self.palette }
+ pub fn get_elem_size(self) -> u8 { self.elem_size }
pub fn is_unpacked(&self) -> bool {
if self.palette { return false; }
for chr in self.comp_info.iter() {
impl fmt::Display for NACodecTypeInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let ret = match *self {
- NACodecTypeInfo::None => format!(""),
+ NACodecTypeInfo::None => "".to_string(),
NACodecTypeInfo::Audio(fmt) => format!("{}", fmt),
NACodecTypeInfo::Video(fmt) => format!("{}", fmt),
};
offs.clone_from(&self.offs);
let mut strides: Vec<usize> = Vec::with_capacity(self.strides.len());
strides.clone_from(&self.strides);
- NAVideoBuffer { info: self.info, data: NABufferRef::new(data), offs: offs, strides: strides }
+ NAVideoBuffer { info: self.info, data: NABufferRef::new(data), offs, strides }
}
pub fn get_stride(&self, idx: usize) -> usize {
if idx >= self.strides.len() { return 0; }
data.clone_from(self.data.as_ref());
let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len());
offs.clone_from(&self.offs);
- NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs: offs, chmap: self.get_chmap(), len: self.len }
+ NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs, chmap: self.get_chmap(), len: self.len }
}
pub fn get_length(&self) -> usize { self.len }
}
impl NAAudioBuffer<u8> {
pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef<Vec<u8>>, chmap: NAChannelMap) -> Self {
let len = data.len();
- NAAudioBuffer { info: info, data: data, chmap: chmap, offs: Vec::new(), len: len }
+ NAAudioBuffer { info, data, chmap, offs: Vec::new(), len }
}
}
let mut all_bytealigned = true;
for i in 0..fmt.get_num_comp() {
let ochr = fmt.get_chromaton(i);
- if let None = ochr { continue; }
+ if ochr.is_none() { continue; }
let chr = ochr.unwrap();
if !chr.is_packed() {
all_packed = false;
offs.push(0);
offs.push(stride * height);
strides.push(stride);
- let mut data: Vec<u8> = Vec::with_capacity(new_size.unwrap());
- data.resize(new_size.unwrap(), 0);
- let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let data: Vec<u8> = vec![0; new_size.unwrap()];
+ let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::Video(buf.into_ref()))
} else if !all_packed {
for i in 0..fmt.get_num_comp() {
let ochr = fmt.get_chromaton(i);
- if let None = ochr { continue; }
+ if ochr.is_none() { continue; }
let chr = ochr.unwrap();
if !vinfo.is_flipped() {
offs.push(new_size as usize);
strides.push(stride);
}
if max_depth <= 8 {
- let mut data: Vec<u8> = Vec::with_capacity(new_size);
- data.resize(new_size, 0);
- let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let data: Vec<u8> = vec![0; new_size];
+ let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::Video(buf.into_ref()))
} else if max_depth <= 16 {
- let mut data: Vec<u16> = Vec::with_capacity(new_size);
- data.resize(new_size, 0);
- let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let data: Vec<u16> = vec![0; new_size];
+ let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::Video16(buf.into_ref()))
} else {
- let mut data: Vec<u32> = Vec::with_capacity(new_size);
- data.resize(new_size, 0);
- let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let data: Vec<u32> = vec![0; new_size];
+ let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::Video32(buf.into_ref()))
}
} else if all_bytealigned || unfit_elem_size {
let new_sz = line_sz.unwrap().checked_mul(height);
if new_sz == None { return Err(AllocatorError::TooLargeDimensions); }
new_size = new_sz.unwrap();
- let mut data: Vec<u8> = Vec::with_capacity(new_size);
- data.resize(new_size, 0);
+ let data: Vec<u8> = vec![0; new_size];
strides.push(line_sz.unwrap());
- let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u8> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::VideoPacked(buf.into_ref()))
} else {
let elem_sz = fmt.get_elem_size();
new_size = new_sz.unwrap();
match elem_sz {
2 => {
- let mut data: Vec<u16> = Vec::with_capacity(new_size);
- data.resize(new_size, 0);
+ let data: Vec<u16> = vec![0; new_size];
strides.push(width);
- let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u16> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::Video16(buf.into_ref()))
},
4 => {
- let mut data: Vec<u32> = Vec::with_capacity(new_size);
- data.resize(new_size, 0);
+ let data: Vec<u32> = vec![0; new_size];
strides.push(width);
- let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs: offs, strides: strides };
+ let buf: NAVideoBuffer<u32> = NAVideoBuffer { data: NABufferRef::new(data), info: vinfo, offs, strides };
Ok(NABufferType::Video32(buf.into_ref()))
},
_ => unreachable!(),
}
}
+#[allow(clippy::collapsible_if)]
pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelMap) -> Result<NABufferType, AllocatorError> {
let mut offs: Vec<usize> = Vec::new();
if ainfo.format.is_planar() || (ainfo.channels == 1 && (ainfo.format.get_bits() % 8) == 0) {
}
if ainfo.format.is_float() {
if ainfo.format.get_bits() == 32 {
- let mut data: Vec<f32> = Vec::with_capacity(length);
- data.resize(length, 0.0);
- let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let data: Vec<f32> = vec![0.0; length];
+ let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
Ok(NABufferType::AudioF32(buf))
} else {
Err(AllocatorError::TooLargeDimensions)
}
} else {
if ainfo.format.get_bits() == 8 && !ainfo.format.is_signed() {
- let mut data: Vec<u8> = Vec::with_capacity(length);
- data.resize(length, 0);
- let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let data: Vec<u8> = vec![0; length];
+ let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
Ok(NABufferType::AudioU8(buf))
} else if ainfo.format.get_bits() == 16 && ainfo.format.is_signed() {
- let mut data: Vec<i16> = Vec::with_capacity(length);
- data.resize(length, 0);
- let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let data: Vec<i16> = vec![0; length];
+ let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
Ok(NABufferType::AudioI16(buf))
} else {
Err(AllocatorError::TooLargeDimensions)
let len = nsamples.checked_mul(ainfo.channels as usize);
if len == None { return Err(AllocatorError::TooLargeDimensions); }
let length = ainfo.format.get_audio_size(len.unwrap() as u64);
- let mut data: Vec<u8> = Vec::with_capacity(length);
- data.resize(length, 0);
- let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs: offs, chmap: chmap, len: nsamples };
+ let data: Vec<u8> = vec![0; length];
+ let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
Ok(NABufferType::AudioPacked(buf))
}
}
pub fn alloc_data_buffer(size: usize) -> Result<NABufferType, AllocatorError> {
- let mut data: Vec<u8> = Vec::with_capacity(size);
- data.resize(size, 0);
+ let data: Vec<u8> = vec![0; size];
let buf: NABufferRef<Vec<u8>> = NABufferRef::new(data);
Ok(NABufferType::Data(buf))
}
None
}
pub fn get_copy(&mut self, rbuf: &NAVideoBufferRef<T>) -> Option<NAVideoBufferRef<T>> {
- let res = self.get_free();
- if res.is_none() {
- return None;
- }
- let mut dbuf = res.unwrap();
+ let mut dbuf = self.get_free()?;
dbuf.data.copy_from_slice(&rbuf.data);
Some(dbuf)
}
pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> {
let nbufs = self.max_len + self.add_len - self.pool.len();
for _ in 0..nbufs {
- let vbuf = alloc_video_buffer(vinfo.clone(), align)?;
+ let vbuf = alloc_video_buffer(vinfo, align)?;
if let NABufferType::Video(buf) = vbuf {
self.pool.push(buf);
} else if let NABufferType::VideoPacked(buf) = vbuf {
pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> {
let nbufs = self.max_len + self.add_len - self.pool.len();
for _ in 0..nbufs {
- let vbuf = alloc_video_buffer(vinfo.clone(), align)?;
+ let vbuf = alloc_video_buffer(vinfo, align)?;
if let NABufferType::Video16(buf) = vbuf {
self.pool.push(buf);
} else {
pub fn prealloc_video(&mut self, vinfo: NAVideoInfo, align: u8) -> Result<(), AllocatorError> {
let nbufs = self.max_len + self.add_len - self.pool.len();
for _ in 0..nbufs {
- let vbuf = alloc_video_buffer(vinfo.clone(), align)?;
+ let vbuf = alloc_video_buffer(vinfo, align)?;
if let NABufferType::Video32(buf) = vbuf {
self.pool.push(buf);
} else {
None => None,
Some(vec) => Some(Arc::new(vec)),
};
- NACodecInfo { name: name, properties: p, extradata: extradata }
+ NACodecInfo { name, properties: p, extradata }
}
pub fn new_ref(name: &'static str, p: NACodecTypeInfo, edata: Option<Arc<Vec<u8>>>) -> Self {
- NACodecInfo { name: name, properties: p, extradata: edata }
+ NACodecInfo { name, properties: p, extradata: edata }
}
pub fn into_ref(self) -> NACodecInfoRef { Arc::new(self) }
pub fn get_properties(&self) -> NACodecTypeInfo { self.properties }
impl fmt::Display for NACodecInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let edata = match self.extradata.clone() {
- None => format!("no extradata"),
+ None => "no extradata".to_string(),
Some(v) => format!("{} byte(s) of extradata", v.len()),
};
write!(f, "{}: {} {}", self.name, self.properties, edata)
impl NATimeInfo {
pub fn new(pts: Option<u64>, dts: Option<u64>, duration: Option<u64>, tb_num: u32, tb_den: u32) -> Self {
- NATimeInfo { pts: pts, dts: dts, duration: duration, tb_num: tb_num, tb_den: tb_den }
+ NATimeInfo { pts, dts, duration, tb_num, tb_den }
}
pub fn get_pts(&self) -> Option<u64> { self.pts }
pub fn get_dts(&self) -> Option<u64> { self.dts }
fn get_plane_size(info: &NAVideoInfo, idx: usize) -> (usize, usize) {
let chromaton = info.get_format().get_chromaton(idx);
- if let None = chromaton { return (0, 0); }
+ if chromaton.is_none() { return (0, 0); }
let (hs, vs) = chromaton.unwrap().get_subsampling();
let w = (info.get_width() + ((1 << hs) - 1)) >> hs;
let h = (info.get_height() + ((1 << vs) - 1)) >> vs;
info: NACodecInfoRef,
options: HashMap<String, NAValue>,
buffer: NABufferType) -> Self {
- NAFrame { ts: ts, buffer: buffer, info: info, ftype: ftype, key: keyframe, options: options }
+ NAFrame { ts, buffer, info, ftype, key: keyframe, options }
}
pub fn get_info(&self) -> NACodecInfoRef { self.info.clone() }
pub fn get_frame_type(&self) -> FrameType { self.ftype }
impl fmt::Display for NAFrame {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut foo = format!("frame type {}", self.ftype);
- if let Some(pts) = self.ts.pts { foo = format!("{} pts {}", foo, pts); }
- if let Some(dts) = self.ts.dts { foo = format!("{} dts {}", foo, dts); }
- if let Some(dur) = self.ts.duration { foo = format!("{} duration {}", foo, dur); }
- if self.key { foo = format!("{} kf", foo); }
- write!(f, "[{}]", foo)
+ let mut ostr = format!("frame type {}", self.ftype);
+ if let Some(pts) = self.ts.pts { ostr = format!("{} pts {}", ostr, pts); }
+ if let Some(dts) = self.ts.dts { ostr = format!("{} dts {}", ostr, dts); }
+ if let Some(dur) = self.ts.duration { ostr = format!("{} duration {}", ostr, dur); }
+ if self.key { ostr = format!("{} kf", ostr); }
+ write!(f, "[{}]", ostr)
}
}
impl NAStream {
pub fn new(mt: StreamType, id: u32, info: NACodecInfo, tb_num: u32, tb_den: u32) -> Self {
let (n, d) = reduce_timebase(tb_num, tb_den);
- NAStream { media_type: mt, id: id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d }
+ NAStream { media_type: mt, id, num: 0, info: info.into_ref(), tb_num: n, tb_den: d }
}
pub fn get_id(&self) -> u32 { self.id }
pub fn get_num(&self) -> usize { self.num }
pub fn new(str: NAStreamRef, ts: NATimeInfo, kf: bool, vec: Vec<u8>) -> Self {
// let mut vec: Vec<u8> = Vec::new();
// vec.resize(size, 0);
- NAPacket { stream: str, ts: ts, keyframe: kf, buffer: NABufferRef::new(vec) }
+ NAPacket { stream: str, ts, keyframe: kf, buffer: NABufferRef::new(vec) }
}
pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() }
pub fn get_time_information(&self) -> NATimeInfo { self.ts }
impl fmt::Display for NAPacket {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len());
- if let Some(pts) = self.ts.pts { foo = format!("{} pts {}", foo, pts); }
- if let Some(dts) = self.ts.dts { foo = format!("{} dts {}", foo, dts); }
- if let Some(dur) = self.ts.duration { foo = format!("{} duration {}", foo, dur); }
- if self.keyframe { foo = format!("{} kf", foo); }
- foo = foo + "]";
- write!(f, "{}", foo)
+ let mut ostr = format!("[pkt for {} size {}", self.stream, self.buffer.len());
+ if let Some(pts) = self.ts.pts { ostr = format!("{} pts {}", ostr, pts); }
+ if let Some(dts) = self.ts.dts { ostr = format!("{} dts {}", ostr, dts); }
+ if let Some(dur) = self.ts.duration { ostr = format!("{} duration {}", ostr, dur); }
+ if self.keyframe { ostr = format!("{} kf", ostr); }
+ ostr += "]";
+ write!(f, "{}", ostr)
}
}
mode: BitReaderMode,
}
+#[allow(clippy::identity_op)]
impl<'a> BitReader<'a> {
pub fn new(src: &'a [u8], size: usize, mode: BitReaderMode) -> Self {
if src.len() < size { panic!("size is less than needed"); }
- BitReader{ cache: 0, pos: 0, bits: 0, end: size, src: src, mode: mode }
+ BitReader{ cache: 0, pos: 0, bits: 0, end: size, src, mode }
}
pub fn tell(&self) -> usize {
}
fn fill32be(&mut self, src: &[u8]) {
- let nw = (((src[0] as u32) << 24) |
- ((src[1] as u32) << 16) |
- ((src[2] as u32) << 8) |
- ((src[3] as u32) << 0)) as u64;
- self.cache |= nw << (32 - self.bits);
+ let nw = (u32::from(src[0]) << 24) |
+ (u32::from(src[1]) << 16) |
+ (u32::from(src[2]) << 8) |
+ (u32::from(src[3]) << 0);
+ self.cache |= u64::from(nw) << (32 - self.bits);
}
fn fill32le16(&mut self, src: &[u8]) {
- let nw = (((src[1] as u32) << 24) |
- ((src[0] as u32) << 16) |
- ((src[3] as u32) << 8) |
- ((src[2] as u32) << 0)) as u64;
- self.cache |= nw << (32 - self.bits);
+ let nw = (u32::from(src[1]) << 24) |
+ (u32::from(src[0]) << 16) |
+ (u32::from(src[3]) << 8) |
+ (u32::from(src[2]) << 0);
+ self.cache |= u64::from(nw) << (32 - self.bits);
}
fn fill32le32(&mut self, src: &[u8], lsb: bool) {
- let nw = (((src[3] as u32) << 24) |
- ((src[2] as u32) << 16) |
- ((src[1] as u32) << 8) |
- ((src[0] as u32) << 0)) as u64;
+ let nw = (u32::from(src[3]) << 24) |
+ (u32::from(src[2]) << 16) |
+ (u32::from(src[1]) << 8) |
+ (u32::from(src[0]) << 0);
if lsb {
- self.cache |= nw << self.bits;
+ self.cache |= u64::from(nw) << self.bits;
} else {
- self.cache |= nw << (32 - self.bits);
+ self.cache |= u64::from(nw) << (32 - self.bits);
}
}
} else {
let mut buf: [u8; 4] = [0, 0, 0, 0];
let mut newbits: u8 = 0;
- for i in 0..3 {
+ for out in buf.iter_mut().take(3) {
if self.pos < self.end {
- buf[i] = self.src[self.pos];
- self.pos = self.pos + 1;
+ *out = self.src[self.pos];
+ self.pos += 1;
newbits += 8;
}
}
fn read_cache(&mut self, nbits: u8) -> u32 {
let res = match self.mode {
BitReaderMode::LE => ((1u64 << nbits) - 1) & self.cache,
- _ => (self.cache as u64) >> (64 - nbits),
+ _ => self.cache >> (64 - nbits),
};
res as u32
}
#[inline(always)]
pub fn skip(&mut self, nbits: u32) -> BitReaderResult<()> {
- if self.bits as u32 >= nbits {
+ if u32::from(self.bits) >= nbits {
self.skip_cache(nbits as u8);
return Ok(());
}
- let mut skip_bits = nbits - (self.bits as u32);
+ let mut skip_bits = nbits - u32::from(self.bits);
self.reset_cache();
self.pos += ((skip_bits / 32) * 4) as usize;
- skip_bits = skip_bits & 0x1F;
+ skip_bits &= 0x1F;
self.refill()?;
if skip_bits > 0 {
self.skip_cache(skip_bits as u8);
let mut ret = 0;
let mut val = inval;
for _ in 0..8 {
- ret = (ret << 4) | (REV_TAB[(val & 0xF) as usize] as u32);
- val = val >> 4;
+ ret = (ret << 4) | u32::from(REV_TAB[(val & 0xF) as usize]);
+ val >>= 4;
}
ret >> (32 - len)
}
use std::io::SeekFrom;
use std::fs::File;
use std::io::prelude::*;
+use std::ptr;
#[derive(Debug)]
pub enum ByteIOError {
fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()>;
fn tell(&mut self) -> u64;
fn seek(&mut self, pos: SeekFrom) -> ByteIOResult<u64>;
- fn is_eof(&mut self) -> bool;
+ fn is_eof(&self) -> bool;
fn is_seekable(&mut self) -> bool;
fn size(&mut self) -> i64;
}
macro_rules! read_int {
($s: ident, $inttype: ty, $size: expr, $which: ident) => ({
- let mut buf = [0; $size];
- $s.read_buf(&mut buf)?;
unsafe {
- Ok((*(buf.as_ptr() as *const $inttype)).$which())
+ let mut buf: $inttype = 0;
+ $s.read_buf(&mut *(&mut buf as *mut $inttype as *mut [u8; $size]))?;
+ Ok(buf.$which())
}
})
}
macro_rules! peek_int {
($s: ident, $inttype: ty, $size: expr, $which: ident) => ({
- let mut buf = [0; $size];
- $s.peek_buf(&mut buf)?;
unsafe {
- Ok((*(buf.as_ptr() as *const $inttype)).$which())
+ let mut buf: $inttype = 0;
+ $s.peek_buf(&mut *(&mut buf as *mut $inttype as *mut [u8; $size]))?;
+ Ok(buf.$which())
}
})
}
pub fn $s(src: &[u8]) -> ByteIOResult<$inttype> {
if src.len() < $size { return Err(ByteIOError::ReadError); }
unsafe {
- Ok((*(src.as_ptr() as *const $inttype)).$which())
+ let mut buf: $inttype = 0;
+ ptr::copy_nonoverlapping(src.as_ptr(), &mut buf as *mut $inttype as *mut u8, 1);
+ Ok(buf.$which())
}
}
}
pub fn read_u24be(src: &[u8]) -> ByteIOResult<u32> {
if src.len() < 3 { return Err(ByteIOError::ReadError); }
- Ok(((src[0] as u32) << 16) | ((src[1] as u32) << 8) | (src[2] as u32))
+ Ok((u32::from(src[0]) << 16) | (u32::from(src[1]) << 8) | u32::from(src[2]))
}
pub fn read_u24le(src: &[u8]) -> ByteIOResult<u32> {
if src.len() < 3 { return Err(ByteIOError::ReadError); }
- Ok(((src[2] as u32) << 16) | ((src[1] as u32) << 8) | (src[0] as u32))
+ Ok((u32::from(src[2]) << 16) | (u32::from(src[1]) << 8) | u32::from(src[0]))
}
impl<'a> ByteReader<'a> {
- pub fn new(io: &'a mut ByteIO) -> Self { ByteReader { io: io } }
+ pub fn new(io: &'a mut ByteIO) -> Self { ByteReader { io } }
pub fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
self.io.read_buf(buf)
pub fn read_u24be(&mut self) -> ByteIOResult<u32> {
let p16 = self.read_u16be()?;
let p8 = self.read_byte()?;
- Ok(((p16 as u32) << 8) | (p8 as u32))
+ Ok((u32::from(p16) << 8) | u32::from(p8))
}
pub fn peek_u24be(&mut self) -> ByteIOResult<u32> {
let mut src: [u8; 3] = [0; 3];
self.peek_buf(&mut src)?;
- Ok(((src[0] as u32) << 16) | ((src[1] as u32) << 8) | (src[2] as u32))
+ Ok((u32::from(src[0]) << 16) | (u32::from(src[1]) << 8) | u32::from(src[2]))
}
pub fn read_u32be(&mut self) -> ByteIOResult<u32> {
pub fn read_u24le(&mut self) -> ByteIOResult<u32> {
let p8 = self.read_byte()?;
let p16 = self.read_u16le()?;
- Ok(((p16 as u32) << 8) | (p8 as u32))
+ Ok((u32::from(p16) << 8) | u32::from(p8))
}
pub fn peek_u24le(&mut self) -> ByteIOResult<u32> {
let mut src: [u8; 3] = [0; 3];
self.peek_buf(&mut src)?;
- Ok((src[0] as u32) | ((src[1] as u32) << 8) | ((src[2] as u32) << 16))
+ Ok(u32::from(src[0]) | (u32::from(src[1]) << 8) | (u32::from(src[2]) << 16))
}
pub fn read_u32le(&mut self) -> ByteIOResult<u32> {
}
while ssize > 0 {
self.io.read_byte()?;
- ssize = ssize - 1;
+ ssize -= 1;
}
}
Ok(())
self.io.seek(pos)
}
- pub fn is_eof(&mut self) -> bool {
+ pub fn is_eof(&self) -> bool {
self.io.is_eof()
}
pub fn left(&mut self) -> i64 {
let size = self.io.size();
if size == -1 { return -1; }
- return size - (self.io.tell() as i64)
+ size - (self.io.tell() as i64)
}
}
impl<'a> MemoryReader<'a> {
pub fn new_read(buf: &'a [u8]) -> Self {
- MemoryReader { buf: buf, size: buf.len(), pos: 0 }
+ MemoryReader { buf, size: buf.len(), pos: 0 }
}
fn real_seek(&mut self, pos: i64) -> ByteIOResult<u64> {
if pos < 0 || (pos as usize) > self.size {
- return Err(ByteIOError::WrongRange)
+ return Err(ByteIOError::WrongRange);
}
self.pos = pos as usize;
Ok(pos as u64)
fn read_byte(&mut self) -> ByteIOResult<u8> {
if self.is_eof() { return Err(ByteIOError::EOF); }
let res = self.buf[self.pos];
- self.pos = self.pos + 1;
+ self.pos += 1;
Ok(res)
}
fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
let copy_size = if self.size - self.pos < buf.len() { self.size } else { buf.len() };
if copy_size == 0 { return Err(ByteIOError::EOF); }
- for i in 0..copy_size {
- buf[i] = self.buf[self.pos + i];
- }
+ let dst = &mut buf[0..copy_size];
+ dst.copy_from_slice(&self.buf[self.pos..][..copy_size]);
Ok(copy_size)
}
}
}
- fn is_eof(&mut self) -> bool {
+ fn is_eof(&self) -> bool {
self.pos >= self.size
}
impl<'a> FileReader<'a> {
pub fn new_read(file: &'a mut File) -> Self {
- FileReader { file: file, eof : false }
+ FileReader { file, eof : false }
}
}
impl<'a> ByteIO for FileReader<'a> {
fn read_byte(&mut self) -> ByteIOResult<u8> {
let mut byte : [u8; 1] = [0];
- let err = self.file.read(&mut byte);
- if let Err(_) = err { return Err(ByteIOError::ReadError); }
- let sz = err.unwrap();
+ let ret = self.file.read(&mut byte);
+ if ret.is_err() { return Err(ByteIOError::ReadError); }
+ let sz = ret.unwrap();
if sz == 0 { self.eof = true; return Err(ByteIOError::EOF); }
Ok (byte[0])
}
}
fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
- let res = self.file.read(buf);
- if let Err(_) = res { return Err(ByteIOError::ReadError); }
- let sz = res.unwrap();
+ let ret = self.file.read(buf);
+ if ret.is_err() { return Err(ByteIOError::ReadError); }
+ let sz = ret.unwrap();
if sz < buf.len() { self.eof = true; return Err(ByteIOError::EOF); }
Ok(sz)
}
fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
- let res = self.file.read(buf);
- if let Err(_) = res { return Err(ByteIOError::ReadError); }
- let sz = res.unwrap();
+ let ret = self.file.read(buf);
+ if ret.is_err() { return Err(ByteIOError::ReadError); }
+ let sz = ret.unwrap();
if sz < buf.len() { self.eof = true; }
Ok(sz)
}
}
}
- fn is_eof(&mut self) -> bool {
+ fn is_eof(&self) -> bool {
self.eof
}
}
impl<'a> ByteWriter<'a> {
- pub fn new(io: &'a mut ByteIO) -> Self { ByteWriter { io: io } }
+ pub fn new(io: &'a mut ByteIO) -> Self { ByteWriter { io } }
pub fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
self.io.write_buf(buf)
}
pub fn write_u64be(&mut self, val: u64) -> ByteIOResult<()> {
- self.write_u32be(((val >> 32) & 0xFFFFFFFF) as u32)?;
- self.write_u32be((val & 0xFFFFFFFF) as u32)
+ self.write_u32be((val >> 32) as u32)?;
+ self.write_u32be(val as u32)
}
pub fn write_u64le(&mut self, val: u64) -> ByteIOResult<()> {
- self.write_u32le((val & 0xFFFFFFFF) as u32)?;
- self.write_u32le(((val >> 32) & 0xFFFFFFFF) as u32)
+ self.write_u32le(val as u32)?;
+ self.write_u32le((val >> 32) as u32)
}
pub fn tell(&mut self) -> u64 {
pub fn new_write(buf: &'a mut [u8]) -> Self {
let len = buf.len();
- MemoryWriter { buf: buf, size: len, pos: 0 }
+ MemoryWriter { buf, size: len, pos: 0 }
}
fn real_seek(&mut self, pos: i64) -> ByteIOResult<u64> {
}
}
- fn is_eof(&mut self) -> bool {
+ fn is_eof(&self) -> bool {
self.pos >= self.size
}
impl FileWriter {
pub fn new_write(file: File) -> Self {
- FileWriter { file: file }
+ FileWriter { file }
}
}
}
}
- fn is_eof(&mut self) -> bool {
+ fn is_eof(&self) -> bool {
false
}
let fill_len = lut_bits - bits;
let fill_size = 1 << fill_len;
let fill_code = code << (lut_bits - bits);
- let lut_value = (symidx << 8) | (bits as u32);
+ let lut_value = (symidx << 8) | u32::from(bits);
for j in 0..fill_size {
let idx = (fill_code + j) as usize;
table[idx + off] = lut_value;
}
} else {
let idx = (code as usize) + off;
- table[idx] = (symidx << 8) | 0x80 | (bits as u32);
+ table[idx] = (symidx << 8) | 0x80 | u32::from(bits);
}
}
let step = lut_bits - fill_len;
for j in 0..fill_size {
let idx = (fill_code + (j << step)) as usize;
- table[idx + off] = (symidx << 8) | (bits as u32);
+ table[idx + off] = (symidx << 8) | u32::from(bits);
}
} else {
let idx = (code as usize) + off;
- table[idx] = (symidx << 8) | 0x80 | (bits as u32);
+ table[idx] = (symidx << 8) | 0x80 | u32::from(bits);
}
}
type EscapeCodes = HashMap<u32, CodeBucket>;
fn add_esc_code(cc: &mut EscapeCodes, key: u32, code: u32, bits: u8, idx: usize) {
- if !cc.contains_key(&key) { cc.insert(key, CodeBucket::new()); }
+ cc.entry(key).or_insert_with(CodeBucket::new);
let b = cc.get_mut(&key);
if let Some(bucket) = b {
- bucket.add_code(Code {code: code, bits: bits, idx: idx });
+ bucket.add_code(Code {code, bits, idx });
} else { panic!("no bucket when expected!"); }
}
sec_bucket.offset = new_off as usize;
}
- for (_, sec_bucket) in &escape_list {
+ for sec_bucket in escape_list.values() {
build_esc_lut(table, mode, sec_bucket)?;
}
for i in 0..cb.len() {
let bits = cb.bits(i);
if bits > 0 {
- nnz = nnz + 1;
+ nnz += 1;
if cb.code(i) >= (1 << bits) {
return Err(CodebookError::InvalidCodebook);
}
let cval = extract_esc_part(code, bits, MAX_LUT_BITS, mode);
add_esc_code(&mut escape_list, ckey, cval, bits - MAX_LUT_BITS, symidx);
}
- if bits > 0 { symidx = symidx + 1; }
+ if bits > 0 { symidx += 1; }
}
if maxbits == 0 { return Err(CodebookError::InvalidCodebook); }
}
}
}
- symidx = symidx + 1;
+ symidx += 1;
}
- for (_, bucket) in &escape_list {
+ for bucket in escape_list.values() {
build_esc_lut(&mut table, mode, &bucket)?;
}
}
}
- Ok(Codebook { table: table, syms: syms, lut_bits: maxbits })
+ Ok(Codebook { table, syms, lut_bits: maxbits })
}
}
if (bits as isize) > self.left() {
return Err(CodebookError::InvalidCode);
}
- let skip_bits = if esc { lut_bits as u32 } else { bits };
- if let Err(_) = self.skip(skip_bits as u32) {}
+ let skip_bits = if esc { u32::from(lut_bits) } else { bits };
+ self.skip(skip_bits as u32).unwrap();
lut_bits = bits as u8;
}
Ok(cb.syms[idx])
impl<S> FullCodebookDescReader<S> {
pub fn new(data: Vec<FullCodebookDesc<S>>) -> Self {
- FullCodebookDescReader { data: data }
+ FullCodebookDescReader { data }
}
}
impl ShortCodebookDescReader {
pub fn new(data: Vec<ShortCodebookDesc<>>) -> Self {
- ShortCodebookDescReader { data: data }
+ ShortCodebookDescReader { data }
}
}
let mut res: u32 = 0;
loop {
if br.read(1)? == terminator { return Ok(res); }
- res = res + 1;
+ res += 1;
}
}
let mut res: u32 = 0;
loop {
if br.read(1)? == terminator { return Ok(res); }
- res = res + 1;
+ res += 1;
if res == len { return Ok(res); }
}
}
if m == 0 { return Err(BitReaderError::InvalidValue); }
let nbits = (8 - m.leading_zeros()) as u8;
if (m & (m - 1)) == 0 { return read_rice(br, nbits); }
- let cutoff = ((1 << nbits) - m) as u32;
+ let cutoff = u32::from((1 << nbits) - m);
let pfx = read_unary(br, 0)?;
let tail = br.read(nbits - 1)?;
if tail < cutoff {
- let res = pfx * (m as u32) + tail;
+ let res = pfx * u32::from(m) + tail;
Ok (res)
} else {
let add = br.read(1)?;
- let res = pfx * (m as u32) + (tail - cutoff) * 2 + add + cutoff;
+ let res = pfx * u32::from(m) + (tail - cutoff) * 2 + add + cutoff;
Ok (res)
}
}
#[cfg(feature="decoders")]
+#[allow(clippy::unreadable_literal)]
pub mod codecs;
#[cfg(feature="demuxers")]
pub mod io;
pub mod refs;
pub mod register;
+#[allow(clippy::unreadable_literal)]
pub mod detect;
pub mod scale;
#[cfg(feature="dsp")]
+#[allow(clippy::unreadable_literal)]
pub mod dsp;
pub mod test;
use std::ops::{Deref, DerefMut};
+use std::convert::AsRef;
use std::sync::atomic::*;
struct NABufferData<T> {
impl<T> NABufferData<T> {
fn new(data: T) -> Self {
Self {
- data: data,
+ data,
refs: AtomicUsize::new(1),
}
}
fn inc_refs(obj: &mut Self) {
obj.refs.fetch_add(1, Ordering::SeqCst);
}
- fn dec_refs(obj: &mut Self) {
- if obj.refs.fetch_sub(1, Ordering::SeqCst) == 0 {
- std::mem::forget(obj);
- }
+ fn dec_refs(obj: &mut Self) -> bool {
+ obj.refs.fetch_sub(1, Ordering::SeqCst) == 0
}
fn get_num_refs(obj: &Self) -> usize {
obj.refs.load(Ordering::Relaxed)
NABufferData::get_num_refs(self.ptr.as_mut().unwrap())
}
}
- pub fn as_ref(&self) -> &T {
+ pub fn as_mut(&mut self) -> Option<&mut T> {
unsafe {
- NABufferData::get_read_ptr(self.ptr.as_mut().unwrap())
+ NABufferData::get_write_ptr(self.ptr.as_mut().unwrap())
}
}
- pub fn as_mut(&mut self) -> Option<&mut T> {
+}
+
+impl<T> AsRef<T> for NABufferRef<T> {
+ fn as_ref(&self) -> &T {
unsafe {
- NABufferData::get_write_ptr(self.ptr.as_mut().unwrap())
+ NABufferData::get_read_ptr(self.ptr.as_mut().unwrap())
}
}
}
impl<T> Drop for NABufferRef<T> {
fn drop(&mut self) {
unsafe {
- NABufferData::dec_refs(self.ptr.as_mut().unwrap());
+ if NABufferData::dec_refs(self.ptr.as_mut().unwrap()) {
+ std::ptr::drop_in_place(self.ptr);
+ }
}
}
}
}
}
-const CODEC_CAP_INTRAONLY:u32 = 0x000001;
-const CODEC_CAP_LOSSLESS:u32 = 0x000002;
-const CODEC_CAP_REORDER:u32 = 0x000004;
-const CODEC_CAP_HYBRID:u32 = 0x000008;
-const CODEC_CAP_SCALABLE:u32 = 0x000010;
+const CODEC_CAP_INTRAONLY:u32 = 0x0001;
+const CODEC_CAP_LOSSLESS:u32 = 0x0002;
+const CODEC_CAP_REORDER:u32 = 0x0004;
+const CODEC_CAP_HYBRID:u32 = 0x0008;
+const CODEC_CAP_SCALABLE:u32 = 0x0010;
#[derive(Clone)]
pub struct CodecDescription {
impl fmt::Display for CodecDescription {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut out = format!("{}", self.fname);
+ let mut out = self.fname.to_string();
if self.caps != 0 {
let mut capfmt = "".to_string();
if (self.caps & CODEC_CAP_INTRAONLY) != 0 {
];
pub fn find_codec_from_avi_fourcc(fcc: &[u8;4]) -> Option<&'static str> {
- for i in 0..AVI_VIDEO_CODEC_REGISTER.len() {
- let (fourcc, name) = AVI_VIDEO_CODEC_REGISTER[i];
- if fourcc == fcc { return Some(name); }
+ for (fourcc, name) in AVI_VIDEO_CODEC_REGISTER.iter() {
+ if *fourcc == fcc { return Some(name); }
}
None
}
pub fn find_codec_from_wav_twocc(tcc: u16) -> Option<&'static str> {
- for i in 0..WAV_CODEC_REGISTER.len() {
- let (twocc, name) = WAV_CODEC_REGISTER[i];
- if twocc == tcc { return Some(name); }
+ for (twocc, name) in WAV_CODEC_REGISTER.iter() {
+ if *twocc == tcc { return Some(name); }
}
None
}
fn new() -> Self { Self::default() }
}
+#[allow(clippy::many_single_char_names)]
impl Kernel for RgbToYuv {
fn init(&mut self, in_fmt: &ScaleInfo, dest_fmt: &ScaleInfo) -> ScaleResult<NABufferType> {
let mut df = dest_fmt.fmt;
let dst = dbuf.get_data_mut().unwrap();
for _y in 0..h {
for x in 0..w {
- let r = src[roff + x] as f32;
- let g = src[goff + x] as f32;
- let b = src[boff + x] as f32;
+ let r = f32::from(src[roff + x]);
+ let g = f32::from(src[goff + x]);
+ let b = f32::from(src[boff + x]);
let (y, u, v) = matrix_mul(&self.matrix, r, g, b);
dst[yoff + x] = (y as i16).max(0).min(255) as u8;
fn new() -> Self { Self::default() }
}
+#[allow(clippy::many_single_char_names)]
impl Kernel for YuvToRgb {
fn init(&mut self, in_fmt: &ScaleInfo, dest_fmt: &ScaleInfo) -> ScaleResult<NABufferType> {
let mut df = dest_fmt.fmt;
let dst = dbuf.get_data_mut().unwrap();
for y in 0..h {
for x in 0..w {
- let y = src[yoff + x] as f32;
- let u = ((src[uoff + (x >> sv0)] as i16) - 128) as f32;
- let v = ((src[voff + (x >> sv1)] as i16) - 128) as f32;
+ let y = f32::from(src[yoff + x]);
+ let u = f32::from(i16::from(src[uoff + (x >> sv0)]) - 128);
+ let v = f32::from(i16::from(src[voff + (x >> sv1)]) - 128);
let (r, g, b) = matrix_mul(&self.matrix, y, u, v);
dst[roff + x] = (r as i16).max(0).min(255) as u8;
let outname = ofmt.fmt.get_model().get_short_name();
println!("convert {} -> {}", ifmt, ofmt);
- let mut needs_scale = !just_convert;
- if (ofmt.fmt.get_max_subsampling() > 0) &&
+ let needs_scale = if (ofmt.fmt.get_max_subsampling() > 0) &&
(ofmt.fmt.get_max_subsampling() != ifmt.fmt.get_max_subsampling()) {
- needs_scale = true;
- }
+ true
+ } else {
+ !just_convert
+ };
let needs_unpack = needs_scale || !ifmt.fmt.is_unpacked();
let needs_pack = !ofmt.fmt.is_unpacked();
- let mut needs_convert = false;
- if inname != outname {
- needs_convert = true;
- }
+ let needs_convert = inname != outname;
let scale_before_cvt = is_better_fmt(&ifmt, &ofmt) && needs_convert
&& (ofmt.fmt.get_max_subsampling() == 0);
//todo stages for model and gamma conversion
if needs_unpack {
println!("[adding unpack]");
- let new_stage;
- if !cur_fmt.fmt.is_paletted() {
- new_stage = Stage::new("unpack", &cur_fmt, &ofmt)?;
- } else {
- new_stage = Stage::new("depal", &cur_fmt, &ofmt)?;
- }
+ let new_stage = if !cur_fmt.fmt.is_paletted() {
+ Stage::new("unpack", &cur_fmt, &ofmt)?
+ } else {
+ Stage::new("depal", &cur_fmt, &ofmt)?
+ };
cur_fmt = new_stage.fmt_out;
add_stage!(stages, new_stage);
}
let ddata = dbuf.get_data_mut().unwrap();
for (src, dst) in sdata.chunks(istride).zip(ddata.chunks_mut(dstride)).take(h) {
for x in 0..w {
- dst[x * step + self.ooff[comp]] = convert_depth(src[x] as u32, self.depths[comp], self.osize[comp]) as u8;
+ dst[x * step + self.ooff[comp]] = convert_depth(u32::from(src[x]), self.depths[comp], self.osize[comp]) as u8;
}
}
}
for x in 0..w {
let mut elem: u32 = 0;
for comp in 0..self.ncomps {
- let c = src[ioff[comp] + x] as u32;
+ let c = u32::from(src[ioff[comp] + x]);
elem |= convert_depth(c, self.depths[comp], self.osize[comp]) << self.shifts[comp];
}
dst[x] = elem as u16;
let dst = dbuf.get_data_mut().unwrap();
for src in sdata.chunks(istride).take(h) {
for x in 0..w {
- let elem = src[x] as u32;
+ let elem = u32::from(src[x]);
for i in 0..self.ncomps {
dst[offs[i] + x] = convert_depth((elem >> self.shifts[i]) & self.masks[i], self.depths[i], self.osize[i]) as u8;
}
for x in 0..w {
let palidx = src[x] as usize;
for i in 0..self.ncomps {
- let elem = pal[palidx * self.palstep + self.coffs[i]] as u32;
+ let elem = u32::from(pal[palidx * self.palstep + self.coffs[i]]);
dst[offs[i] + x] = convert_depth(elem, self.depths[i], 8) as u8;
}
}
idx2 += ls;
}
if w2 <= w/2 {
- let mut pad: Vec<u8> = Vec::with_capacity((w - w2 * 2) / 2);
- pad.resize((w - w2 * 2) / 2, 0xFF);
+ let pad: Vec<u8> = vec![0xFF; (w - w2 * 2) / 2];
let mut base1 = buf.get_offset(1);
let stride1 = buf.get_stride(1);
let mut base2 = buf.get_offset(2);
base2 += stride2;
}
} else {
- let mut pad: Vec<u8> = Vec::with_capacity(w - w2);
- pad.resize(w - w2, 0xFF);
+ let pad: Vec<u8> = vec![0xFF; w - w2];
let mut base1 = buf.get_offset(1);
let stride1 = buf.get_stride(1);
for _ in 0..h2 {
buf.get_info().get_format().get_chromaton(2).unwrap().get_offset() as usize
];
let mut idx = 0;
- let mut line: Vec<u8> = Vec::with_capacity(w * 3);
- line.resize(w * 3, 0);
+ let mut line: Vec<u8> = vec![0; w * 3];
for _ in 0..h {
let src = &dta[idx..(idx+w)];
for x in 0..w {
ofile.write_all(hdr.as_bytes()).unwrap();
let dta = buf.get_data();
let stride = buf.get_stride(0);
- let mut line: Vec<u8> = Vec::with_capacity(w * 3);
- line.resize(w * 3, 0);
for src in dta.chunks(stride) {
ofile.write_all(&src[0..w*3]).unwrap();
}
panic!("error");
}
let pkt = pktres.unwrap();
- if limit.is_some() && pkt.get_pts().is_some() {
- if pkt.get_pts().unwrap() > limit.unwrap() { break; }
+ if let (Some(lim), Some(ppts)) = (limit, pkt.get_pts()) {
+ if ppts > lim { break; }
}
let streamno = pkt.get_stream().get_id() as usize;
if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] {
let frm = dec.decode(dsupp, &pkt).unwrap();
if pkt.get_stream().get_info().is_video() && video_pfx.is_some() && frm.get_frame_type() != FrameType::Skip {
let pfx = video_pfx.unwrap();
- let pts = if let Some(fpts) = frm.get_pts() { fpts } else { pkt.get_pts().unwrap() };
+ let pts = if let Some(fpts) = frm.get_pts() { fpts } else { pkt.get_pts().unwrap() };
let vinfo = frm.get_buffer().get_video_info().unwrap();
if vinfo.get_format().is_paletted() {
write_palppm(pfx, streamno, pts, frm);
panic!("error");
}
let pkt = pktres.unwrap();
- if limit.is_some() && pkt.get_pts().is_some() {
- if pkt.get_pts().unwrap() > limit.unwrap() { break; }
+ if limit.is_some() && pkt.get_pts().is_some() && pkt.get_pts().unwrap() > limit.unwrap() {
+ break;
}
let streamno = pkt.get_stream().get_id() as usize;
if let Some((ref mut dsupp, ref mut dec)) = decs[streamno] {
impl<'a> WavWriter<'a> {
pub fn new(io: &'a mut ByteWriter<'a>) -> Self {
- WavWriter { io: io, data_pos: 0 }
+ WavWriter { io, data_pos: 0 }
}
pub fn write_header(&mut self, ainfo: NAAudioInfo) -> ByteIOResult<()> {
let bits = ainfo.get_format().get_bits() as usize;
self.io.write_buf(b"fmt ")?;
self.io.write_u32le(16)?;
self.io.write_u16le(0x0001)?; // PCM
- self.io.write_u16le(ainfo.get_channels() as u16)?;
- self.io.write_u32le(ainfo.get_sample_rate() as u32)?;
+ self.io.write_u16le(u16::from(ainfo.get_channels()))?;
+ self.io.write_u32le(ainfo.get_sample_rate())?;
if bits < 16 {
- self.io.write_u32le((ainfo.get_channels() as u32) * (ainfo.get_sample_rate() as u32))?;
- self.io.write_u16le(ainfo.get_channels() as u16)?; // block align
+ self.io.write_u32le(u32::from(ainfo.get_channels()) * ainfo.get_sample_rate())?;
+ self.io.write_u16le(u16::from(ainfo.get_channels()))?; // block align
self.io.write_u16le(8)?;
} else {
- self.io.write_u32le(2 * (ainfo.get_channels() as u32) * (ainfo.get_sample_rate() as u32))?;
- self.io.write_u16le((2 * ainfo.get_channels()) as u16)?; // block align
+ self.io.write_u32le(2 * u32::from(ainfo.get_channels()) * ainfo.get_sample_rate())?;
+ self.io.write_u16le(u16::from(2 * ainfo.get_channels()))?; // block align
self.io.write_u16le(16)?;
}