Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/codecs/hdr/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,31 +184,33 @@ impl Rgbe8Pixel {
}

impl<R: Read> HdrDecoder<R> {
/// Reads Radiance HDR image header from stream ```r```
/// if the header is valid, creates `HdrDecoder`
/// strict mode is enabled
/// Reads Radiance HDR image header from `reader` with strict mode enabled.
///
/// In strict mode, the header is required to be well-formed. This prevents
/// certain older slightly-malformed files from being read. See
/// [`HdrDecoder::with_strictness`] for details.
pub fn new(reader: R) -> ImageResult<Self> {
HdrDecoder::with_strictness(reader, true)
}

/// Allows reading old Radiance HDR images
#[deprecated(note = "Use `new_with_spec_compliance(reader, SpecCompliance::Lenient)` instead")]
pub fn new_nonstrict(reader: R) -> ImageResult<Self> {
Self::with_strictness(reader, false)
}

/// Create a new decoder with the given spec compliance mode.
pub(crate) fn new_with_spec_compliance(reader: R, spec: SpecCompliance) -> ImageResult<Self> {
Self::with_strictness(reader, spec == SpecCompliance::Strict)
}

/// Reads Radiance HDR image header from stream `reader`,
/// if the header is valid, creates `HdrDecoder`.
/// Reads Radiance HDR image header from `reader`.
///
/// In strict mode, the header is required to be well-formed. I.e. it must
/// contain a valid signature among other requirements. In non-strict mode,
/// certain malformed headers are accepted, allowing more files to be read
/// but potentially incorrectly.
///
/// Certain older files require non-strict mode to be read.
///
/// strict enables strict mode
/// # Warning
///
/// Warning! Reading wrong file in non-strict mode could consume up to a few
/// megabytes of memory before this errors, if the file is large enough.
/// In non-strict mode, certain invalid files may consume multiple megabytes of memory
/// before an error is returned.
pub fn with_strictness(mut reader: R, strict: bool) -> ImageResult<HdrDecoder<R>> {
let mut attributes = HdrMetadata::new();

Expand Down
Loading