aboutsummaryrefslogtreecommitdiffstats
path: root/src/formats.rs
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2017-05-21 20:17:34 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2017-05-21 20:17:34 +0200
commit15e41b31398703237f32813f89606a45562d5891 (patch)
tree010dd03a3b9eeba2e74efce34aafc7780ae2726a /src/formats.rs
parent663836ea11aabb7d587f2c38f9376a2acf9cf94a (diff)
downloadnihav-15e41b31398703237f32813f89606a45562d5891.tar.gz
more utility code
Diffstat (limited to 'src/formats.rs')
-rw-r--r--src/formats.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/formats.rs b/src/formats.rs
index 8e6bc68..03e6411 100644
--- a/src/formats.rs
+++ b/src/formats.rs
@@ -41,6 +41,14 @@ impl NASoniton {
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 {
+ if self.packed {
+ ((length * (self.bits as u64) + 7) >> 3) as usize
+ } else {
+ (length * (((self.bits + 7) >> 3) as u64)) as usize
+ }
+ }
}
impl fmt::Display for NASoniton {
@@ -124,6 +132,7 @@ impl fmt::Display for NAChannelType {
}
}
+#[derive(Clone)]
pub struct NAChannelMap {
ids: Vec<NAChannelType>,
}
@@ -308,10 +317,15 @@ impl NAPixelChromaton {
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 {
+ (width + ((1 << self.h_ss) - 1)) >> self.h_ss
+ }
+ 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 {
- let nw = (width + ((1 << self.h_ss) - 1)) >> self.h_ss;
let d = self.depth as usize;
- (nw * d + d - 1) >> 3
+ (self.get_width(width) * d + d - 1) >> 3
}
pub fn get_data_size(&self, width: usize, height: usize) -> usize {
let nh = (height + ((1 << self.v_ss) - 1)) >> self.v_ss;