DCMTK: DcmRLEEncoder Class Reference

DCMTK Version 3.6.9 OFFIS DICOM Toolkit

Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DcmRLEEncoder Class Reference

this class implements an RLE compressor conforming to the DICOM standard. More...

## Public Member Functions
| DcmRLEEncoder (int doPad)
| default constructor
| ~DcmRLEEncoder ()
| destructor
void | add (unsigned char ch)
| this method adds one byte to the byte stream to be compressed with the RLE compressor.
void | add (const unsigned char *buf, size_t bufcount)
| this method adds a block of bytes to the byte stream to be compressed with the RLE compressor.
void | flush ()
| this method finalizes the compressed RLE stream, i.e.
size_t | size () const
| returns the size of compressed RLE stream in bytes.
OFBool | fail () const
| returns true if the RLE compressor has run out of memory.
void | write (void *target) const
| copies the compressed RLE byte stream into a target array of at least size() bytes.
void | write (DcmEncoderOutputStream &os) const
| copies the compressed RLE byte stream into an output stream

## Private Member Functions
| DcmRLEEncoder (const DcmRLEEncoder &)
| private undefined copy constructor
DcmRLEEncoder & | operator= (const DcmRLEEncoder &)
| private undefined copy assignment operator
void | move (size_t numberOfBytes)
| this method moves the given number of bytes from buff_ to currentBlock_ and "flushes" currentBlock_ to blockList_ if necessary.

## Private Attributes
int | fail_
| this flag indicates a failure of the RLE codec.
int | pad_
| this flag indicates whether the RLE codec must pad encoded data to an even number of bytes (as required by DICOM).
unsigned char * | currentBlock_
| this member points to a block of size DcmRLEEncoder_BLOCKSIZE (unless fail_ is true).
size_t | offset_
| contains the number of bytes already written the the memory block pointed to by currentBlock_.
OFList< unsigned char * > | blockList_
| this member contains a list of memory blocks of size DcmRLEEncoder_BLOCKSIZE which already have been filled with encoded RLE data.
unsigned char * | RLE_buff_
| this member points to a buffer of 132 bytes that is used by the RLE encoding algorithm.
int | RLE_prev_
| value of the last byte fed to the RLE compressor.
int | RLE_pcount_
| repeat counter, for RLE compressor may temporarily become negative, guaranteed to be >= 0 between method calls.
unsigned int | RLE_bindex_
| index of next unused byte in RLE_buff_.

## Detailed Description

this class implements an RLE compressor conforming to the DICOM standard.

The class is loosely based on an implementation by Phil Norman.

## Constructor & Destructor Documentation

## ◆ DcmRLEEncoder()

DcmRLEEncoder::DcmRLEEncoder | ( | int | doPad | ) |
| inline

default constructor

Parameters

  doPad | if true, RLE codec will pad output data to even number of bytes

References blockList_, currentBlock_, fail_, offset_, pad_, RLE_bindex_, RLE_buff_, RLE_pcount_, and RLE_prev_.

Referenced by DcmRLEEncoder(), and operator=().

## Member Function Documentation

## ◆ add() [1/2]

void DcmRLEEncoder::add | ( | const unsigned char * | buf,
|  | size_t | bufcount )
| inline

this method adds a block of bytes to the byte stream to be compressed with the RLE compressor.

Parameters

  buf | buffer to be added
  bufcount | number of bytes in buffer

References add().

## ◆ add() [2/2]

void DcmRLEEncoder::add | ( | unsigned char | ch | ) |
| inline

this method adds one byte to the byte stream to be compressed with the RLE compressor.

Parameters

  ch | byte to be added

References fail_, move(), RLE_bindex_, RLE_buff_, RLE_pcount_, and RLE_prev_.

Referenced by add().

## ◆ fail()

OFBool DcmRLEEncoder::fail | ( |  | ) | const
| inline

returns true if the RLE compressor has run out of memory.

In this case, no output has been created.

References fail_.

## ◆ flush()

void DcmRLEEncoder::flush | ( |  | ) |
| inline

this method finalizes the compressed RLE stream, i.e.

flushes all pending literal or repeat runs. This method can be called at any time; however, it must be called before size() or write() can be used. Intermediate calls should be avoided since they possibly decrease the compression ratio.

References fail_, move(), RLE_bindex_, RLE_buff_, RLE_pcount_, and RLE_prev_.

## ◆ move()

void DcmRLEEncoder::move | ( | size_t | numberOfBytes | ) |
| inlineprivate

this method moves the given number of bytes from buff_ to currentBlock_ and "flushes" currentBlock_ to blockList_ if necessary.

Parameters

  numberOfBytes | number of bytes to copy

References blockList_, currentBlock_, fail_, offset_, and RLE_buff_.

Referenced by add(), and flush().

## ◆ size()

size_t DcmRLEEncoder::size | ( |  | ) | const
| inline

returns the size of compressed RLE stream in bytes.

The size is guaranteed to be an even number of bytes (padded with a trailing zero byte as required by DICOM if necessary). This method may only be called after flush() has been executed to finalize the compressed stream.

Returns
  size of compressed stream, in bytes

References blockList_, offset_, and pad_.

## ◆ write() [1/2]

void DcmRLEEncoder::write | ( | DcmEncoderOutputStream & | os | ) | const
| inline

copies the compressed RLE byte stream into an output stream

Parameters

  os | output stream

References blockList_, currentBlock_, fail_, offset_, pad_, and DcmEncoderOutputStream::write().

## ◆ write() [2/2]

void DcmRLEEncoder::write | ( | void * | target | ) | const
| inline

copies the compressed RLE byte stream into a target array of at least size() bytes.

Parameters

  target | pointer to array of at least size() bytes, must not be NULL.

References blockList_, currentBlock_, fail_, offset_, and pad_.

## Member Data Documentation

## ◆ blockList_

OFList<unsigned char *> DcmRLEEncoder::blockList_
| private

this member contains a list of memory blocks of size DcmRLEEncoder_BLOCKSIZE which already have been filled with encoded RLE data.

The current block (pointed to by currentBlock_) is not contained in this list.

Referenced by DcmRLEEncoder(), ~DcmRLEEncoder(), move(), size(), write(), and write().

## ◆ currentBlock_

unsigned char* DcmRLEEncoder::currentBlock_
| private

this member points to a block of size DcmRLEEncoder_BLOCKSIZE (unless fail_ is true).

This is the current block of data to which the RLE stream is written

Referenced by DcmRLEEncoder(), ~DcmRLEEncoder(), move(), write(), and write().

## ◆ fail_

int DcmRLEEncoder::fail_
| private

this flag indicates a failure of the RLE codec.

Once a failure is flagged, the codec will consume all input and not produce any more output. A failure status can only be caused by an out-of-memory condition.

Referenced by DcmRLEEncoder(), add(), fail(), flush(), move(), write(), and write().

## ◆ offset_

size_t DcmRLEEncoder::offset_
| private

contains the number of bytes already written the the memory block pointed to by currentBlock_.

Value is always less than DcmRLEEncoder_BLOCKSIZE.

Referenced by DcmRLEEncoder(), move(), size(), write(), and write().

## ◆ pad_

int DcmRLEEncoder::pad_
| private

this flag indicates whether the RLE codec must pad encoded data to an even number of bytes (as required by DICOM).

True if padding is required, false otherwise

Referenced by DcmRLEEncoder(), size(), write(), and write().

## ◆ RLE_prev_

int DcmRLEEncoder::RLE_prev_
| private

value of the last byte fed to the RLE compressor.

This byte is not yet stored in the RLE_buff_ buffer. Type is int because this allows an "impossible" -1 as default value

Referenced by DcmRLEEncoder(), add(), and flush().

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

- dcmdata/include/dcmtk/dcmdata/dcrleenc.h

Generated on Wed Apr 30 2025 for DCMTK Version 3.6.9 by Doxygen 1.13.2