From d7fded827d7216a3f887fb9c661c44eef5d1a152 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 21:54:31 +0000 Subject: [PATCH 1/9] Wrap the imf_version module --- openexr-rs/src/lib.rs | 2 + openexr-rs/src/version.rs | 309 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 311 insertions(+) create mode 100644 openexr-rs/src/version.rs diff --git a/openexr-rs/src/lib.rs b/openexr-rs/src/lib.rs index 654d0e7..463c78a 100644 --- a/openexr-rs/src/lib.rs +++ b/openexr-rs/src/lib.rs @@ -57,6 +57,8 @@ pub use flat_image_level::{ }; pub mod flat_image_channel; pub use flat_image_channel::{FlatChannelF16, FlatChannelF32, FlatChannelU32}; +pub mod version; +pub use version::{TILED_FLAG, LONG_NAMES_FLAG, NON_IMAGE_FLAG, MULTI_PART_FILE_FLAG, ALL_FLAGS, Version}; pub mod imath; diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs new file mode 100644 index 0000000..f84c895 --- /dev/null +++ b/openexr-rs/src/version.rs @@ -0,0 +1,309 @@ +use openexr_sys as sys; +use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign}; +use std::os::raw::{c_char, c_int}; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct Flag(c_int); + +impl BitAnd for Flag { + type Output = Self; + + fn bitand(self, rhs: Self) -> Self::Output { + Self(self.0.bitand(rhs.0)) + } +} + +impl BitAndAssign for Flag { + fn bitand_assign(&mut self, rhs: Self) { + self.0.bitand_assign(rhs.0) + } +} + +impl BitOr for Flag { + type Output = Self; + + fn bitor(self, rhs: Self) -> Self::Output { + Self(self.0.bitor(rhs.0)) + } +} + +impl BitOrAssign for Flag { + fn bitor_assign(&mut self, rhs: Self) { + self.0.bitor_assign(rhs.0) + } +} + +impl BitXor for Flag { + type Output = Self; + + fn bitxor(self, rhs: Self) -> Self::Output { + Self(self.0.bitxor(rhs.0)) + } +} + +impl BitXorAssign for Flag { + fn bitxor_assign(&mut self, rhs: Self) { + self.0.bitxor_assign(rhs.0) + } +} + +impl Flag { + /// The flag object is supported by the bound OpenEXR library. + pub fn supports_flags(&self) -> bool { + let mut result: bool = false; + + unsafe { + // NOTE: This will not raise an error, so error checking is skipped. + sys::Imf_supportsFlags(&mut result, self.0); + } + + result + } +} + +/// File is tiled +pub static TILED_FLAG: Flag = Flag(0x00000200); +/// File contains long attribute or channel names +pub static LONG_NAMES_FLAG: Flag = Flag(0x00000400); +/// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) +pub static NON_IMAGE_FLAG: Flag = Flag(0x00000800); +/// File has multiple parts +pub static MULTI_PART_FILE_FLAG: Flag = Flag(0x00001000); + +/// Bitwise OR of all known flags. +pub static ALL_FLAGS: Flag = + Flag(TILED_FLAG.0 | LONG_NAMES_FLAG.0 | NON_IMAGE_FLAG.0 | MULTI_PART_FILE_FLAG.0); + +/// The version represents a version number and the flags that are enabled for the file. For example, +pub struct Version { + inner: c_int, +} + +// NOTE: All of the functions below will not raise errors, so error checking is skipped. + +impl Version { + /// Create a version from a given version number and flag. + /// + /// # Panics + /// + /// The version number must be between 0 and 255, otherwise this will panic. + pub fn new(version: i32, flags: Flag) -> Self { + assert!(version <= 0x000000ff && version >= 0, "Version must be between 0 and 255"); + Self { + inner: version | flags.0, + } + } + + /// Create a version from the wrapped OpenEXR API. + pub fn from_c_int(version: c_int) -> Self { + Self { inner: version } + } + + /// File is tiled + pub fn is_tiled(&self) -> bool { + let mut result = false; + + unsafe { + sys::Imf_isTiled_1(&mut result, self.inner); + } + + result + } + + /// File has multiple parts + pub fn is_multi_part(&self) -> bool { + let mut result = false; + + unsafe { + sys::Imf_isMultiPart(&mut result, self.inner); + } + + result + } + + /// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) + pub fn is_non_image(&self) -> bool { + let mut result = false; + + unsafe { + sys::Imf_isNonImage(&mut result, self.inner); + } + + result + } + + // Return the version as a tiled version + pub fn make_tiled(&self) -> Self { + let mut result: c_int = 0; + + unsafe { + sys::Imf_makeTiled(&mut result, self.inner); + } + + Self { inner: result } + } + + // Return the version as a non-tiled version + pub fn make_non_tiled(&self) -> Self { + let mut result: c_int = 0; + + unsafe { + sys::Imf_makeNotTiled(&mut result, self.inner); + } + + Self { inner: result } + } + + // Get the version number portion of encoded version. + pub fn get_version(&self) -> i32 { + let mut result: c_int = 0; + + unsafe { + sys::Imf_getVersion(&mut result, self.inner); + } + + result + } + + // Get the flags portion of encoded version. + pub fn get_flags(&self) -> Flag { + let mut result: c_int = 0; + + unsafe { + sys::Imf_getFlags(&mut result, self.inner); + } + + Flag(result) + } +} + +// Return if the byte array represents the OpenEXR magic number. +pub fn is_imf_magic(bytes: &[c_char; 4]) -> bool { + let mut result: bool = false; + + unsafe { + sys::Imf_isImfMagic(&mut result, bytes.as_ptr()); + } + + result +} + +#[cfg(test)] +mod tests { + #[test] + fn test_version_new_success() { + super::Version::new(0, super::Flag(0)); + super::Version::new(1, super::Flag(0)); + super::Version::new(255, super::Flag(0)); + } + + #[test] + #[should_panic] + fn test_version_new_failure_version_less_than_0() { + super::Version::new(-1, super::Flag(0)); + } + + #[test] + #[should_panic] + fn test_version_new_failure_version_greater_than_255() { + super::Version::new(256, super::Flag(0)); + } + + #[test] + fn test_is_tiled_true() { + let version = super::Version::new(1, super::TILED_FLAG); + let result = version.is_tiled(); + assert_eq!(result, true); + } + + #[test] + fn test_is_tiled_false() { + let version = super::Version::new(1, super::Flag(0)); + let result = version.is_tiled(); + assert_eq!(result, false); + } + + #[test] + fn test_is_multi_part_true() { + let version = super::Version::new(1, super::MULTI_PART_FILE_FLAG); + let result = version.is_multi_part(); + assert_eq!(result, true); + } + + #[test] + fn test_is_multi_part_false() { + let version = super::Version::new(1, super::Flag(0)); + let result = version.is_multi_part(); + assert_eq!(result, false); + } + + #[test] + fn test_is_non_image_true() { + let version = super::Version::new(1, super::NON_IMAGE_FLAG); + let result = version.is_non_image(); + assert_eq!(result, true); + } + + #[test] + fn test_is_non_image_false() { + let version = super::Version::new(1, super::Flag(0)); + let result = version.is_non_image(); + assert_eq!(result, false); + } + + #[test] + fn test_make_tiled_success() { + let version = super::Version::new(1, super::Flag(0)).make_tiled(); + assert_eq!(version.is_tiled(), true); + } + + #[test] + fn test_make_non_tiled_success() { + let version = super::Version::new(1, super::TILED_FLAG).make_non_tiled(); + assert_eq!(version.is_tiled(), false); + } + + #[test] + fn test_get_version_success() { + #[allow(overflowing_literals)] + let version = super::Version::from_c_int(0xffffffff); + let result = version.get_version(); + + assert_eq!(result, 0x000000ff); + } + + #[test] + fn test_get_flags_success() { + #[allow(overflowing_literals)] + let version = super::Version::from_c_int(0xffffffff); + let result = version.get_flags(); + + #[allow(overflowing_literals)] + let expected = super::Flag(0xffffff00); + assert_eq!(result, expected); + } + + #[test] + fn test_supports_flags_true() { + let result = super::ALL_FLAGS.supports_flags(); + assert_eq!(result, true); + } + + #[test] + fn test_supports_flags_false() { + let result = super::Flag(0x10000000).supports_flags(); + assert_eq!(result, false); + } + + #[test] + fn test_is_imf_magic_true() { + let result = super::is_imf_magic(&[118, 47, 49, 1]); + assert_eq!(result, true); + } + + #[test] + fn test_is_imf_magic_false() { + let result = super::is_imf_magic(&[0, 0, 0, 0]); + assert_eq!(result, false); + } +} From 410302eabd361259d82f7ffee536a136f0b2eae5 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 21:59:57 +0000 Subject: [PATCH 2/9] Rename the Version getters to drop the `get_` --- openexr-rs/src/version.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index f84c895..c948525 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -155,7 +155,7 @@ impl Version { } // Get the version number portion of encoded version. - pub fn get_version(&self) -> i32 { + pub fn version(&self) -> i32 { let mut result: c_int = 0; unsafe { @@ -166,7 +166,7 @@ impl Version { } // Get the flags portion of encoded version. - pub fn get_flags(&self) -> Flag { + pub fn flags(&self) -> Flag { let mut result: c_int = 0; unsafe { @@ -267,7 +267,7 @@ mod tests { fn test_get_version_success() { #[allow(overflowing_literals)] let version = super::Version::from_c_int(0xffffffff); - let result = version.get_version(); + let result = version.version(); assert_eq!(result, 0x000000ff); } @@ -276,7 +276,7 @@ mod tests { fn test_get_flags_success() { #[allow(overflowing_literals)] let version = super::Version::from_c_int(0xffffffff); - let result = version.get_flags(); + let result = version.flags(); #[allow(overflowing_literals)] let expected = super::Flag(0xffffff00); From 7aca828f6d37f55d4195de9ba2caceec8c6808f2 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 15:05:26 -0700 Subject: [PATCH 3/9] Add missing debug derive --- openexr-rs/src/version.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index c948525..58e27e1 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -75,6 +75,7 @@ pub static ALL_FLAGS: Flag = Flag(TILED_FLAG.0 | LONG_NAMES_FLAG.0 | NON_IMAGE_FLAG.0 | MULTI_PART_FILE_FLAG.0); /// The version represents a version number and the flags that are enabled for the file. For example, +#[derive(Debug)] pub struct Version { inner: c_int, } From a6a4907511d2f9f30d19ecb7e5606f1196a8023c Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 15:06:01 -0700 Subject: [PATCH 4/9] Add missing copy/clone to version --- openexr-rs/src/version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index 58e27e1..c341555 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -75,7 +75,7 @@ pub static ALL_FLAGS: Flag = Flag(TILED_FLAG.0 | LONG_NAMES_FLAG.0 | NON_IMAGE_FLAG.0 | MULTI_PART_FILE_FLAG.0); /// The version represents a version number and the flags that are enabled for the file. For example, -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub struct Version { inner: c_int, } From e8de50c2cb32f7932587da0dc9304145172718d6 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 23:17:25 +0000 Subject: [PATCH 5/9] Replace int flags with bitflags --- openexr-rs/Cargo.toml | 1 + openexr-rs/src/lib.rs | 2 +- openexr-rs/src/version.rs | 118 +++++++++++++------------------------- 3 files changed, 41 insertions(+), 80 deletions(-) diff --git a/openexr-rs/Cargo.toml b/openexr-rs/Cargo.toml index 6ee3c1f..d940146 100644 --- a/openexr-rs/Cargo.toml +++ b/openexr-rs/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" openexr-sys = {path="../build/openexr-sys"} half = "1.7.1" thiserror = "1.0.24" +bitflags = "1.2.1" [dev-dependencies] png = "0.16.8" diff --git a/openexr-rs/src/lib.rs b/openexr-rs/src/lib.rs index 463c78a..7ace49c 100644 --- a/openexr-rs/src/lib.rs +++ b/openexr-rs/src/lib.rs @@ -58,7 +58,7 @@ pub use flat_image_level::{ pub mod flat_image_channel; pub use flat_image_channel::{FlatChannelF16, FlatChannelF32, FlatChannelU32}; pub mod version; -pub use version::{TILED_FLAG, LONG_NAMES_FLAG, NON_IMAGE_FLAG, MULTI_PART_FILE_FLAG, ALL_FLAGS, Version}; +pub use version::{VersionFlags, Version}; pub mod imath; diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index c341555..19d074d 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -1,79 +1,36 @@ use openexr_sys as sys; -use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign}; +// use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign}; use std::os::raw::{c_char, c_int}; -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct Flag(c_int); - -impl BitAnd for Flag { - type Output = Self; - - fn bitand(self, rhs: Self) -> Self::Output { - Self(self.0.bitand(rhs.0)) - } -} - -impl BitAndAssign for Flag { - fn bitand_assign(&mut self, rhs: Self) { - self.0.bitand_assign(rhs.0) +bitflags::bitflags! { + pub struct VersionFlags: i32 { + /// File is tiled + const TILED_FLAG = 0x00000200; + /// File contains long attribute or channel names + const LONG_NAMES_FLAG = 0x00000400; + /// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) + const NON_IMAGE_FLAG = 0x00000800; + /// File has multiple parts + const MULTI_PART_FILE_FLAG = 0x00001000; + /// Bitwise OR of all known flags. + const ALL_FLAGS = Self::TILED_FLAG.bits | Self::LONG_NAMES_FLAG.bits | Self::NON_IMAGE_FLAG.bits | Self::MULTI_PART_FILE_FLAG.bits; } } -impl BitOr for Flag { - type Output = Self; - - fn bitor(self, rhs: Self) -> Self::Output { - Self(self.0.bitor(rhs.0)) - } -} - -impl BitOrAssign for Flag { - fn bitor_assign(&mut self, rhs: Self) { - self.0.bitor_assign(rhs.0) - } -} - -impl BitXor for Flag { - type Output = Self; - - fn bitxor(self, rhs: Self) -> Self::Output { - Self(self.0.bitxor(rhs.0)) - } -} - -impl BitXorAssign for Flag { - fn bitxor_assign(&mut self, rhs: Self) { - self.0.bitxor_assign(rhs.0) - } -} - -impl Flag { +impl VersionFlags { /// The flag object is supported by the bound OpenEXR library. pub fn supports_flags(&self) -> bool { let mut result: bool = false; unsafe { // NOTE: This will not raise an error, so error checking is skipped. - sys::Imf_supportsFlags(&mut result, self.0); + sys::Imf_supportsFlags(&mut result, self.bits); } result } } -/// File is tiled -pub static TILED_FLAG: Flag = Flag(0x00000200); -/// File contains long attribute or channel names -pub static LONG_NAMES_FLAG: Flag = Flag(0x00000400); -/// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) -pub static NON_IMAGE_FLAG: Flag = Flag(0x00000800); -/// File has multiple parts -pub static MULTI_PART_FILE_FLAG: Flag = Flag(0x00001000); - -/// Bitwise OR of all known flags. -pub static ALL_FLAGS: Flag = - Flag(TILED_FLAG.0 | LONG_NAMES_FLAG.0 | NON_IMAGE_FLAG.0 | MULTI_PART_FILE_FLAG.0); - /// The version represents a version number and the flags that are enabled for the file. For example, #[derive(Debug, Copy, Clone)] pub struct Version { @@ -88,10 +45,13 @@ impl Version { /// # Panics /// /// The version number must be between 0 and 255, otherwise this will panic. - pub fn new(version: i32, flags: Flag) -> Self { - assert!(version <= 0x000000ff && version >= 0, "Version must be between 0 and 255"); + pub fn new(version: i32, flags: VersionFlags) -> Self { + assert!( + version <= 0x000000ff && version >= 0, + "Version must be between 0 and 255" + ); Self { - inner: version | flags.0, + inner: version | flags.bits, } } @@ -167,14 +127,14 @@ impl Version { } // Get the flags portion of encoded version. - pub fn flags(&self) -> Flag { + pub fn flags(&self) -> VersionFlags { let mut result: c_int = 0; unsafe { sys::Imf_getFlags(&mut result, self.inner); } - Flag(result) + VersionFlags { bits: result } } } @@ -193,74 +153,74 @@ pub fn is_imf_magic(bytes: &[c_char; 4]) -> bool { mod tests { #[test] fn test_version_new_success() { - super::Version::new(0, super::Flag(0)); - super::Version::new(1, super::Flag(0)); - super::Version::new(255, super::Flag(0)); + super::Version::new(0, super::VersionFlags { bits: 0 }); + super::Version::new(1, super::VersionFlags { bits: 0 }); + super::Version::new(255, super::VersionFlags { bits: 0 }); } #[test] #[should_panic] fn test_version_new_failure_version_less_than_0() { - super::Version::new(-1, super::Flag(0)); + super::Version::new(-1, super::VersionFlags { bits: 0 }); } #[test] #[should_panic] fn test_version_new_failure_version_greater_than_255() { - super::Version::new(256, super::Flag(0)); + super::Version::new(256, super::VersionFlags { bits: 0 }); } #[test] fn test_is_tiled_true() { - let version = super::Version::new(1, super::TILED_FLAG); + let version = super::Version::new(1, super::VersionFlags::TILED_FLAG); let result = version.is_tiled(); assert_eq!(result, true); } #[test] fn test_is_tiled_false() { - let version = super::Version::new(1, super::Flag(0)); + let version = super::Version::new(1, super::VersionFlags { bits: 0 }); let result = version.is_tiled(); assert_eq!(result, false); } #[test] fn test_is_multi_part_true() { - let version = super::Version::new(1, super::MULTI_PART_FILE_FLAG); + let version = super::Version::new(1, super::VersionFlags::MULTI_PART_FILE_FLAG); let result = version.is_multi_part(); assert_eq!(result, true); } #[test] fn test_is_multi_part_false() { - let version = super::Version::new(1, super::Flag(0)); + let version = super::Version::new(1, super::VersionFlags { bits: 0 }); let result = version.is_multi_part(); assert_eq!(result, false); } #[test] fn test_is_non_image_true() { - let version = super::Version::new(1, super::NON_IMAGE_FLAG); + let version = super::Version::new(1, super::VersionFlags::NON_IMAGE_FLAG); let result = version.is_non_image(); assert_eq!(result, true); } #[test] fn test_is_non_image_false() { - let version = super::Version::new(1, super::Flag(0)); + let version = super::Version::new(1, super::VersionFlags { bits: 0 }); let result = version.is_non_image(); assert_eq!(result, false); } #[test] fn test_make_tiled_success() { - let version = super::Version::new(1, super::Flag(0)).make_tiled(); + let version = super::Version::new(1, super::VersionFlags { bits: 0 }).make_tiled(); assert_eq!(version.is_tiled(), true); } #[test] fn test_make_non_tiled_success() { - let version = super::Version::new(1, super::TILED_FLAG).make_non_tiled(); + let version = super::Version::new(1, super::VersionFlags::TILED_FLAG).make_non_tiled(); assert_eq!(version.is_tiled(), false); } @@ -280,19 +240,19 @@ mod tests { let result = version.flags(); #[allow(overflowing_literals)] - let expected = super::Flag(0xffffff00); + let expected = super::VersionFlags { bits: 0xffffff00 }; assert_eq!(result, expected); } #[test] fn test_supports_flags_true() { - let result = super::ALL_FLAGS.supports_flags(); + let result = super::VersionFlags::ALL_FLAGS.supports_flags(); assert_eq!(result, true); } #[test] fn test_supports_flags_false() { - let result = super::Flag(0x10000000).supports_flags(); + let result = super::VersionFlags { bits: 0x10000000 }.supports_flags(); assert_eq!(result, false); } From 736e39ee7a8254309d0bbd3c5c31666c97bdbf85 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 23:18:31 +0000 Subject: [PATCH 6/9] Fix docstring syntax --- openexr-rs/src/version.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index 19d074d..259ef79 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -93,7 +93,7 @@ impl Version { result } - // Return the version as a tiled version + /// Return the version as a tiled version pub fn make_tiled(&self) -> Self { let mut result: c_int = 0; @@ -104,7 +104,7 @@ impl Version { Self { inner: result } } - // Return the version as a non-tiled version + /// Return the version as a non-tiled version pub fn make_non_tiled(&self) -> Self { let mut result: c_int = 0; @@ -115,7 +115,7 @@ impl Version { Self { inner: result } } - // Get the version number portion of encoded version. + /// Get the version number portion of encoded version. pub fn version(&self) -> i32 { let mut result: c_int = 0; @@ -126,7 +126,7 @@ impl Version { result } - // Get the flags portion of encoded version. + /// Get the flags portion of encoded version. pub fn flags(&self) -> VersionFlags { let mut result: c_int = 0; From c635f8d294b18247c1de82150e04c7929e7bedc0 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sat, 15 May 2021 23:20:28 +0000 Subject: [PATCH 7/9] fix docstrings --- openexr-rs/src/version.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index 259ef79..9685621 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -3,6 +3,8 @@ use openexr_sys as sys; use std::os::raw::{c_char, c_int}; bitflags::bitflags! { + /// The version flags represents the options that are supported in the library and the EXR file. + /// pub struct VersionFlags: i32 { /// File is tiled const TILED_FLAG = 0x00000200; @@ -31,7 +33,8 @@ impl VersionFlags { } } -/// The version represents a version number and the flags that are enabled for the file. For example, +/// The version represents a version number and the flags that are enabled for the file. +/// #[derive(Debug, Copy, Clone)] pub struct Version { inner: c_int, From 07b204666e2550a89328571e35baa32dbe2d0831 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sun, 16 May 2021 00:02:01 +0000 Subject: [PATCH 8/9] Remove _FLAG from flags --- openexr-rs/src/version.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index 9685621..1158869 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -7,15 +7,15 @@ bitflags::bitflags! { /// pub struct VersionFlags: i32 { /// File is tiled - const TILED_FLAG = 0x00000200; + const TILED = 0x00000200; /// File contains long attribute or channel names - const LONG_NAMES_FLAG = 0x00000400; + const LONG_NAMES = 0x00000400; /// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) - const NON_IMAGE_FLAG = 0x00000800; + const NON_IMAGE = 0x00000800; /// File has multiple parts - const MULTI_PART_FILE_FLAG = 0x00001000; + const MULTI_PART_FILE = 0x00001000; /// Bitwise OR of all known flags. - const ALL_FLAGS = Self::TILED_FLAG.bits | Self::LONG_NAMES_FLAG.bits | Self::NON_IMAGE_FLAG.bits | Self::MULTI_PART_FILE_FLAG.bits; + const ALL = Self::TILED.bits | Self::LONG_NAMES.bits | Self::NON_IMAGE.bits | Self::MULTI_PART_FILE.bits; } } @@ -175,7 +175,7 @@ mod tests { #[test] fn test_is_tiled_true() { - let version = super::Version::new(1, super::VersionFlags::TILED_FLAG); + let version = super::Version::new(1, super::VersionFlags::TILED); let result = version.is_tiled(); assert_eq!(result, true); } @@ -189,7 +189,7 @@ mod tests { #[test] fn test_is_multi_part_true() { - let version = super::Version::new(1, super::VersionFlags::MULTI_PART_FILE_FLAG); + let version = super::Version::new(1, super::VersionFlags::MULTI_PART_FILE); let result = version.is_multi_part(); assert_eq!(result, true); } @@ -203,7 +203,7 @@ mod tests { #[test] fn test_is_non_image_true() { - let version = super::Version::new(1, super::VersionFlags::NON_IMAGE_FLAG); + let version = super::Version::new(1, super::VersionFlags::NON_IMAGE); let result = version.is_non_image(); assert_eq!(result, true); } @@ -223,7 +223,7 @@ mod tests { #[test] fn test_make_non_tiled_success() { - let version = super::Version::new(1, super::VersionFlags::TILED_FLAG).make_non_tiled(); + let version = super::Version::new(1, super::VersionFlags::TILED).make_non_tiled(); assert_eq!(version.is_tiled(), false); } @@ -249,7 +249,7 @@ mod tests { #[test] fn test_supports_flags_true() { - let result = super::VersionFlags::ALL_FLAGS.supports_flags(); + let result = super::VersionFlags::ALL.supports_flags(); assert_eq!(result, true); } From f4d531d1d4d070fe6eb7b3db583402d511ab5ecb Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Sun, 16 May 2021 00:39:50 +0000 Subject: [PATCH 9/9] Docstring updates and removing unused imports --- openexr-rs/src/version.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/openexr-rs/src/version.rs b/openexr-rs/src/version.rs index 1158869..b78c6d3 100644 --- a/openexr-rs/src/version.rs +++ b/openexr-rs/src/version.rs @@ -1,5 +1,4 @@ use openexr_sys as sys; -// use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign}; use std::os::raw::{c_char, c_int}; bitflags::bitflags! { @@ -7,20 +6,26 @@ bitflags::bitflags! { /// pub struct VersionFlags: i32 { /// File is tiled + /// const TILED = 0x00000200; /// File contains long attribute or channel names + /// const LONG_NAMES = 0x00000400; /// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) + /// const NON_IMAGE = 0x00000800; /// File has multiple parts + /// const MULTI_PART_FILE = 0x00001000; - /// Bitwise OR of all known flags. + /// Bitwise OR of all known flags + /// const ALL = Self::TILED.bits | Self::LONG_NAMES.bits | Self::NON_IMAGE.bits | Self::MULTI_PART_FILE.bits; } } impl VersionFlags { /// The flag object is supported by the bound OpenEXR library. + /// pub fn supports_flags(&self) -> bool { let mut result: bool = false; @@ -48,6 +53,7 @@ impl Version { /// # Panics /// /// The version number must be between 0 and 255, otherwise this will panic. + /// pub fn new(version: i32, flags: VersionFlags) -> Self { assert!( version <= 0x000000ff && version >= 0, @@ -59,11 +65,13 @@ impl Version { } /// Create a version from the wrapped OpenEXR API. + /// pub fn from_c_int(version: c_int) -> Self { Self { inner: version } } /// File is tiled + /// pub fn is_tiled(&self) -> bool { let mut result = false; @@ -75,6 +83,7 @@ impl Version { } /// File has multiple parts + /// pub fn is_multi_part(&self) -> bool { let mut result = false; @@ -86,6 +95,7 @@ impl Version { } /// File has at least one part which is not a regular scanline image or regular tiled image (that is, it is a deep format) + /// pub fn is_non_image(&self) -> bool { let mut result = false; @@ -97,6 +107,7 @@ impl Version { } /// Return the version as a tiled version + /// pub fn make_tiled(&self) -> Self { let mut result: c_int = 0; @@ -108,6 +119,7 @@ impl Version { } /// Return the version as a non-tiled version + /// pub fn make_non_tiled(&self) -> Self { let mut result: c_int = 0; @@ -119,6 +131,7 @@ impl Version { } /// Get the version number portion of encoded version. + /// pub fn version(&self) -> i32 { let mut result: c_int = 0; @@ -130,6 +143,7 @@ impl Version { } /// Get the flags portion of encoded version. + /// pub fn flags(&self) -> VersionFlags { let mut result: c_int = 0; @@ -141,7 +155,8 @@ impl Version { } } -// Return if the byte array represents the OpenEXR magic number. +/// Return if the byte array represents the OpenEXR magic number. +/// pub fn is_imf_magic(bytes: &[c_char; 4]) -> bool { let mut result: bool = false;