Skip to content

Commit

Permalink
[pixeldata] Revert addition of NoPixelData error variant
Browse files Browse the repository at this point in the history
- InnerError was mistakenly made public
  • Loading branch information
Enet4 committed Oct 6, 2023
1 parent c45955d commit 34be166
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 11 additions & 1 deletion pixeldata/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use dicom_core::{DataDictionary, Tag};
use dicom_dictionary_std::tags;
use dicom_object::{FileDicomObject, InMemDicomObject};
use dicom_object::{mem::InMemElement, FileDicomObject, InMemDicomObject};
use snafu::{ensure, Backtrace, OptionExt, ResultExt, Snafu};
use std::fmt;

Expand Down Expand Up @@ -142,6 +142,16 @@ pub fn high_bit<D: DataDictionary + Clone>(
retrieve_required_u16(obj, tags::HIGH_BIT, AttributeName::HighBit)
}

/// Get the PixelData element from the DICOM object
pub fn pixel_data<D: DataDictionary + Clone>(
obj: &FileDicomObject<InMemDicomObject<D>>,
) -> Result<&InMemElement<D>> {
let name = AttributeName::PixelData;
obj.element_opt(tags::PIXEL_DATA)
.context(RetrieveSnafu { name })?
.context(MissingRequiredSnafu { name })
}

/// Get the RescaleIntercept from the DICOM object or returns 0
pub fn rescale_intercept<D: DataDictionary + Clone>(
obj: &FileDicomObject<InMemDicomObject<D>>,
Expand Down
3 changes: 1 addition & 2 deletions pixeldata/src/gdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ where
{
fn decode_pixel_data(&self) -> Result<DecodedPixelData> {
use super::attribute::*;
use dicom_dictionary_std::tags;

let pixel_data = self.get(tags::PIXEL_DATA).context(NoPixelDataSnafu)?;
let pixel_data = pixel_data(self).context(GetAttributeSnafu)?;

let cols = cols(self).context(GetAttributeSnafu)?;
let rows = rows(self).context(GetAttributeSnafu)?;
Expand Down
13 changes: 2 additions & 11 deletions pixeldata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ pub struct Error(InnerError);
/// Inner error type
#[derive(Debug, Snafu)]
pub enum InnerError {
#[snafu(display("Object has no Pixel Data"))]
NoPixelData {
backtrace: Backtrace,
},

#[snafu(display("Failed to get required DICOM attribute"))]
GetAttribute {
#[snafu(backtrace)]
Expand Down Expand Up @@ -1769,9 +1764,7 @@ where
D: DataDictionary + Clone,
{
fn decode_pixel_data(&self) -> Result<DecodedPixelData> {
use dicom_dictionary_std::tags;

let pixel_data = self.get(tags::PIXEL_DATA).context(NoPixelDataSnafu)?;
let pixel_data = attribute::pixel_data(self).context(GetAttributeSnafu)?;

let ImagingProperties {
cols,
Expand Down Expand Up @@ -1871,9 +1864,7 @@ where
}

fn decode_pixel_data_frame(&self, frame: u32) -> Result<DecodedPixelData<'_>> {
use dicom_dictionary_std::tags;

let pixel_data = self.get(tags::PIXEL_DATA).context(NoPixelDataSnafu)?;
let pixel_data = attribute::pixel_data(self).context(GetAttributeSnafu)?;

let ImagingProperties {
cols,
Expand Down

0 comments on commit 34be166

Please sign in to comment.