|
2 | 2 | use std::convert::TryFrom; |
3 | 3 | use std::error::Error; |
4 | 4 |
|
5 | | -// use bitvec::prelude::*; |
6 | | - |
7 | 5 | use pyo3::prelude::*; |
8 | 6 | use pyo3::wrap_pyfunction; |
9 | 7 | use pyo3::types::{PyBytes, PyByteArray}; |
@@ -426,74 +424,6 @@ fn _decode_frame( |
426 | 424 | } |
427 | 425 |
|
428 | 426 |
|
429 | | -fn _decode_bit_packed_segment( |
430 | | - src: &[u8], segment_length: usize |
431 | | -) -> Result<Vec<u8>, Box<dyn Error>> { |
432 | | - /* |
433 | | -
|
434 | | - The returned data is guaranteed to be no more than segment_length in size. |
435 | | - */ |
436 | | - let eod = src.len() - 1; |
437 | | - let mut pos = 0; |
438 | | - let mut header_byte: usize; |
439 | | - let mut dst: Vec<u8> = Vec::new(); |
440 | | - let mut op_len: usize; |
441 | | - let mut idx: usize = 0; // number of bytes decoded |
442 | | - |
443 | | - let err_eod = Err( |
444 | | - String::from( |
445 | | - "The end of the data was reached before the segment was completely decoded" |
446 | | - ).into() |
447 | | - ); |
448 | | - |
449 | | - loop { |
450 | | - // `header_byte` is equivalent to N in the DICOM Standard |
451 | | - // usize is at least u8 |
452 | | - header_byte = usize::from(src[pos]); |
453 | | - pos += 1; |
454 | | - if header_byte > 128 { |
455 | | - // Extend by copying the next byte (-N + 1) times |
456 | | - // however since using uint8 instead of int8 this will be |
457 | | - // (256 - N + 1) times |
458 | | - op_len = 257 - header_byte; |
459 | | - |
460 | | - // Check we have enough encoded data |
461 | | - if pos > eod { return err_eod } |
462 | | - |
463 | | - // Check segment for excess padding |
464 | | - if (idx + op_len) > segment_length { |
465 | | - dst.extend(vec![src[pos]; segment_length - idx]); |
466 | | - |
467 | | - return Ok(dst) |
468 | | - } |
469 | | - |
470 | | - dst.extend(vec![src[pos]; op_len]); |
471 | | - idx += op_len; |
472 | | - pos += 1; |
473 | | - } else if header_byte < 128 { |
474 | | - // Extend by literally copying the next (N + 1) bytes |
475 | | - op_len = header_byte + 1; |
476 | | - |
477 | | - // Check we have enough encoded data |
478 | | - if (pos + header_byte) > eod { return err_eod } |
479 | | - |
480 | | - // Check segment for excess padding |
481 | | - if (idx + op_len) > segment_length { |
482 | | - dst.extend(&src[pos..pos + segment_length - idx]); |
483 | | - |
484 | | - return Ok(dst) |
485 | | - } |
486 | | - |
487 | | - dst.extend(&src[pos..pos + op_len]); |
488 | | - pos += header_byte + 1; |
489 | | - idx += op_len; |
490 | | - } // header_byte == 128 is noop |
491 | | - |
492 | | - if pos >= eod { return Ok(dst) } |
493 | | - } |
494 | | -} |
495 | | - |
496 | | - |
497 | 427 | fn _decode_segment_into_frame( |
498 | 428 | src: &[u8], dst: &mut Vec<u8>, bpp: usize, initial_offset: usize |
499 | 429 | ) -> Result<usize, Box<dyn Error>> { |
|
0 commit comments