PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::encoding::compression::rle_codec Class Referencefinal

DICOM RLE Lossless codec implementation. More...

#include <rle_codec.h>

Inheritance diagram for kcenon::pacs::encoding::compression::rle_codec:
Inheritance graph
Collaboration diagram for kcenon::pacs::encoding::compression::rle_codec:
Collaboration graph

Classes

class  impl
 PIMPL implementation for rle_codec. More...
 

Public Member Functions

 rle_codec ()
 Constructs an RLE codec instance.
 
 ~rle_codec () override
 
 rle_codec (const rle_codec &)=delete
 
rle_codecoperator= (const rle_codec &)=delete
 
 rle_codec (rle_codec &&) noexcept
 
rle_codecoperator= (rle_codec &&) noexcept
 
Codec Information
std::string_view transfer_syntax_uid () const noexcept override
 Returns the Transfer Syntax UID supported by this codec.
 
std::string_view name () const noexcept override
 Returns a human-readable name for the codec.
 
bool is_lossy () const noexcept override
 Checks if this codec produces lossy compression.
 
bool can_encode (const image_params &params) const noexcept override
 Checks if this codec supports the given image parameters.
 
bool can_decode (const image_params &params) const noexcept override
 Checks if this codec can decode data with given parameters.
 
Compression Operations
codec_result encode (std::span< const uint8_t > pixel_data, const image_params &params, const compression_options &options={}) const override
 Compresses pixel data to RLE format.
 
codec_result decode (std::span< const uint8_t > compressed_data, const image_params &params) const override
 Decompresses RLE data.
 
- Public Member Functions inherited from kcenon::pacs::encoding::compression::compression_codec
virtual ~compression_codec ()=default
 

Static Public Attributes

static constexpr std::string_view kTransferSyntaxUID = "1.2.840.10008.1.2.5"
 DICOM Transfer Syntax UID for RLE Lossless.
 
static constexpr int kMaxSegments = 15
 Maximum number of RLE segments allowed by DICOM specification.
 
static constexpr size_t kRLEHeaderSize = 64
 RLE header size (64 bytes: 16 x 4-byte offsets)
 

Private Attributes

std::unique_ptr< implimpl_
 

Additional Inherited Members

- Protected Member Functions inherited from kcenon::pacs::encoding::compression::compression_codec
 compression_codec ()=default
 
 compression_codec (const compression_codec &)=default
 
compression_codecoperator= (const compression_codec &)=default
 
 compression_codec (compression_codec &&)=default
 
compression_codecoperator= (compression_codec &&)=default
 

Detailed Description

DICOM RLE Lossless codec implementation.

Implements DICOM Transfer Syntax 1.2.840.10008.1.2.5. Uses pure C++ implementation without external library dependencies.

DICOM RLE uses a segment-based approach where each sample is encoded separately, allowing for efficient lossless compression of medical images.

Supported Features:

  • 8-bit grayscale and color images
  • 16-bit grayscale images (stored as two 8-bit segments)
  • RGB color images (3 samples per pixel)
  • Multi-frame images (via external frame-by-frame processing)

Limitations:

  • Maximum 15 segments (DICOM RLE specification)
  • Maximum image size: 65535 x 65535 pixels
  • No support for signed pixel representation in encoding

Thread Safety:

  • This class is NOT thread-safe
  • Create separate instances per thread for concurrent operations

Integration:

  • Uses thread_system for parallel batch encoding (via thread_pool_adapter)
  • Logs operations via logger_system (via logger_adapter)
  • Reports metrics to monitoring_system (via monitoring_adapter)
See also
DICOM PS3.5 Annex G - RLE Lossless Compression

Definition at line 49 of file rle_codec.h.

Constructor & Destructor Documentation

◆ rle_codec() [1/3]

kcenon::pacs::encoding::compression::rle_codec::rle_codec ( )

Constructs an RLE codec instance.

Definition at line 543 of file rle_codec.cpp.

543: impl_(std::make_unique<impl>()) {}

◆ ~rle_codec()

kcenon::pacs::encoding::compression::rle_codec::~rle_codec ( )
overridedefault

◆ rle_codec() [2/3]

kcenon::pacs::encoding::compression::rle_codec::rle_codec ( const rle_codec & )
delete

◆ rle_codec() [3/3]

kcenon::pacs::encoding::compression::rle_codec::rle_codec ( rle_codec && )
defaultnoexcept

Member Function Documentation

◆ can_decode()

bool kcenon::pacs::encoding::compression::rle_codec::can_decode ( const image_params & params) const
nodiscardoverridevirtualnoexcept

Checks if this codec can decode data with given parameters.

Parameters
paramsThe image parameters
Returns
true if decoding is supported

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 585 of file rle_codec.cpp.

585 {
586 // Can decode if parameters are valid for RLE
587 // Width/height can be 0 (unknown) for partial validation
588 if (params.bits_allocated != 0 &&
589 params.bits_allocated != 8 &&
590 params.bits_allocated != 16) {
591 return false;
592 }
593 if (params.samples_per_pixel != 0 &&
594 (params.samples_per_pixel < 1 || params.samples_per_pixel > 3)) {
595 return false;
596 }
597 return true;
598}

◆ can_encode()

bool kcenon::pacs::encoding::compression::rle_codec::can_encode ( const image_params & params) const
nodiscardoverridevirtualnoexcept

Checks if this codec supports the given image parameters.

Parameters
paramsThe image parameters to check
Returns
true if the codec can handle these parameters

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 563 of file rle_codec.cpp.

563 {
564 // RLE supports 8-bit and 16-bit samples
565 if (params.bits_allocated != 8 && params.bits_allocated != 16) {
566 return false;
567 }
568 // 1-3 samples per pixel
569 if (params.samples_per_pixel < 1 || params.samples_per_pixel > 3) {
570 return false;
571 }
572 // Check segment count limit
573 int bytes_per_sample = (params.bits_allocated + 7) / 8;
574 int num_segments = params.samples_per_pixel * bytes_per_sample;
575 if (num_segments > kMaxSegments) {
576 return false;
577 }
578 // Valid dimensions
579 if (params.width == 0 || params.height == 0) {
580 return false;
581 }
582 return true;
583}
static constexpr int kMaxSegments
Maximum number of RLE segments allowed by DICOM specification.
Definition rle_codec.h:55

◆ decode()

codec_result kcenon::pacs::encoding::compression::rle_codec::decode ( std::span< const uint8_t > compressed_data,
const image_params & params ) const
nodiscardoverridevirtual

Decompresses RLE data.

Parameters
compressed_dataRLE compressed data (including header)
paramsImage parameters (width, height, samples_per_pixel)
Returns
Decompressed pixel data or error

Output format matches the original bit depth:

  • 8-bit: single byte per sample
  • 16-bit: two bytes per sample (little-endian)

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 607 of file rle_codec.cpp.

609 {
610 return impl_->decode(compressed_data, params);
611}
codec_result decode(std::span< const uint8_t > compressed_data, const image_params &params) const

References kcenon::pacs::encoding::compression::rle_codec::impl::decode(), and impl_.

Here is the call graph for this function:

◆ encode()

codec_result kcenon::pacs::encoding::compression::rle_codec::encode ( std::span< const uint8_t > pixel_data,
const image_params & params,
const compression_options & options = {} ) const
nodiscardoverridevirtual

Compresses pixel data to RLE format.

Parameters
pixel_dataUncompressed pixel data
paramsImage parameters
optionsCompression options (lossless flag is ignored, always lossless)
Returns
Compressed RLE data or error

The output is guaranteed to be exactly reconstructible (lossless). The output includes the 64-byte RLE header followed by segment data.

For 16-bit images, each pixel is split into high byte and low byte, creating twice the number of segments as 8-bit images.

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 600 of file rle_codec.cpp.

603 {
604 return impl_->encode(pixel_data, params, options);
605}
codec_result encode(std::span< const uint8_t > pixel_data, const image_params &params, const compression_options &options) const

References kcenon::pacs::encoding::compression::rle_codec::impl::encode(), and impl_.

Here is the call graph for this function:

◆ is_lossy()

bool kcenon::pacs::encoding::compression::rle_codec::is_lossy ( ) const
nodiscardoverridevirtualnoexcept

Checks if this codec produces lossy compression.

Returns
true if lossy, false if lossless

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 559 of file rle_codec.cpp.

559 {
560 return false;
561}

◆ name()

std::string_view kcenon::pacs::encoding::compression::rle_codec::name ( ) const
nodiscardoverridevirtualnoexcept

Returns a human-readable name for the codec.

Returns
The codec name (e.g., "JPEG Baseline")

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 555 of file rle_codec.cpp.

555 {
556 return "RLE Lossless";
557}

◆ operator=() [1/2]

rle_codec & kcenon::pacs::encoding::compression::rle_codec::operator= ( const rle_codec & )
delete

◆ operator=() [2/2]

rle_codec & kcenon::pacs::encoding::compression::rle_codec::operator= ( rle_codec && )
defaultnoexcept

◆ transfer_syntax_uid()

std::string_view kcenon::pacs::encoding::compression::rle_codec::transfer_syntax_uid ( ) const
nodiscardoverridevirtualnoexcept

Returns the Transfer Syntax UID supported by this codec.

Returns
The DICOM Transfer Syntax UID

Implements kcenon::pacs::encoding::compression::compression_codec.

Definition at line 551 of file rle_codec.cpp.

551 {
552 return kTransferSyntaxUID;
553}
static constexpr std::string_view kTransferSyntaxUID
DICOM Transfer Syntax UID for RLE Lossless.
Definition rle_codec.h:52

Member Data Documentation

◆ impl_

std::unique_ptr<impl> kcenon::pacs::encoding::compression::rle_codec::impl_
private

Definition at line 125 of file rle_codec.h.

Referenced by decode(), and encode().

◆ kMaxSegments

int kcenon::pacs::encoding::compression::rle_codec::kMaxSegments = 15
staticconstexpr

Maximum number of RLE segments allowed by DICOM specification.

Definition at line 55 of file rle_codec.h.

Referenced by kcenon::pacs::encoding::compression::rle_codec::impl::decode_frame(), and kcenon::pacs::encoding::compression::rle_codec::impl::valid_for_rle().

◆ kRLEHeaderSize

size_t kcenon::pacs::encoding::compression::rle_codec::kRLEHeaderSize = 64
staticconstexpr

RLE header size (64 bytes: 16 x 4-byte offsets)

Definition at line 58 of file rle_codec.h.

Referenced by kcenon::pacs::encoding::compression::rle_codec::impl::decode(), and kcenon::pacs::encoding::compression::rle_codec::impl::encode_frame().

◆ kTransferSyntaxUID

std::string_view kcenon::pacs::encoding::compression::rle_codec::kTransferSyntaxUID = "1.2.840.10008.1.2.5"
staticconstexpr

DICOM Transfer Syntax UID for RLE Lossless.

Definition at line 52 of file rle_codec.h.

Referenced by kcenon::pacs::encoding::compression::codec_factory::create().


The documentation for this class was generated from the following files: