Loading...
Searching...
No Matches
I2DJpegSource Class Reference

This is a I2DImgSource implementation that can parse JPEG files and convert them into DICOM images. More...

Inheritance diagram for I2DJpegSource:

## Public Member Functions

| I2DJpegSource ()
| Constructor, initializes member variables.
OFString | inputFormat () const
| Returns format of input image.
OFCondition | readPixelData (Uint16 &rows, Uint16 &cols, Uint16 &samplesPerPixel, OFString &photoMetrInt, Uint16 &bitsAlloc, Uint16 &bitsStored, Uint16 &highBit, Uint16 &pixelRepr, Uint16 &planConf, Uint16 &pixAspectH, Uint16 &pixAspectV, char *&pixData, Uint32 &length, E_TransferSyntax &ts)
| Extracts the raw JPEG pixel data stream from a JPEG file and returns some further information about this pixel data.
OFCondition | getLossyComprInfo (OFBool &srcEncodingLossy, OFString &srcLossyComprMethod) const
| After reading of pixel data, this function can be used for getting information about lossy compression parameters.
void | setExtSeqSupport (const OFBool enabled)
| Enable/Disable support for Extended Sequential JPEG Coding.
void | setProgrSupport (const OFBool enabled)
| Enable/Disable support for Progressive JPEG Coding.
void | setInsistOnJFIF (const OFBool enabled)
| If enabled, conversion will only take place if JFIF data could be found and evaluated.
void | setKeepAPPn (const OFBool enabled)
| If enabled, APPn markers (except JFIF!) are also copied to the output file.
void | setKeepCOM (const OFBool enabled)
| If enabled, COM marker is also copied to the output file.
| ~I2DJpegSource ()
| Destructor, frees some memory.
Public Member Functions inherited from I2DImgSource
| I2DImgSource ()
| Constructor.
void | setImageFile (const OFString &filename)
| Sets the input image file to read.
OFString | getImageFile ()
| Returns the input image file that currently associated with plugin.
virtual | ~I2DImgSource ()
| Virtual Destructor.

## Static Public Member Functions

static OFString | jpegMarkerToString (const E_JPGMARKER &marker, const OFBool isJPEGLS)
| Returns a string representation of a JPEG marker code.

## Protected Member Functions

OFCondition | openFile (const OFString &filename)
| Opens the JPEG file specified by the given filename.
void | closeFile ()
| Closes JPEG file.
OFCondition | createJPEGFileMap ()
| Function that scans a JPEG file and creates a "file map" which includes all JPEG markers and their byte positions in the file.
void | debugDumpJPEGFileMap () const
| Dump the internal JPEG file map to a given stream.
OFCondition | getSOFImageParameters (const JPEGFileMapEntry &entry, Uint16 &imageWidth, Uint16 &imageHeight, Uint16 &samplesPerPixel, Uint16 &bitsPerSample, OFString &colorModel)
| Get image parameters as found at given SOF marker of the JPEG image.
OFCondition | getSOSImageParameters (const JPEGFileMapEntry &entry, Uint8 &nearLossless)
| Get image parameters as found at given SOF marker of the JPEG image.
OFCondition | getAPP8ImageParameters (const JPEGFileMapEntry &entry, Uint8 &xform)
| Get color transform as found at given APP8 marker of the JPEG image.
OFCondition | getJFIFImageParameters (const JPEGFileMapEntry &entry, Uint16 &jfifVersion, Uint16 &pixelAspectH, Uint16 &pixelAspectV, Uint16 &unit)
| Get JPEG parameters as found at given JFIF marker of the JPEG image.
OFCondition | isJPEGEncodingSupported (const E_JPGMARKER &jpegEncoding) const
| Check, whether a given JPEG image marker (SOFn) is supported by this plugin.
OFCondition | extractRawJPEGStream (char *&pixelData, Uint32 &pixLength)
| Extract raw JPEG stream (i.e.
OFCondition | skipVariable ()
| Skips one marker while scanning through the JPEG file stream.
OFCondition | firstMarker (E_JPGMARKER &result)
| Tries to read the SOI marker.
OFCondition | nextMarker (const OFBool &lastWasSOSMarker, E_JPGMARKER &result)
| Tries to find the next JPEG marker in underlying file stream.
int | read2Bytes (Uint16 &result)
| Read 2 bytes from the byte stream.
int | read1Byte (Uint8 &result)
| Read 1 byte from the byte stream.
void | clearMap ()
| Deletes internal JPEG file map and frees memory.

## Static Protected Member Functions

static E_TransferSyntax | associatedTS (const E_JPGMARKER &jpegEncoding, OFBool const useJPEGLS, Uint8 const nearLossless)
| Returns if possible the DICOM transfer syntax matching the coding of the JPEG data.
static OFBool | isRSTMarker (const E_JPGMARKER &jpegEncoding)
| Returns true if marker is one of the RST0 to RST7 markers.
static OFBool | isSOFMarker (const E_JPGMARKER &jpegEncoding, const OFBool isJPEGLS)
| Returns true if marker is one of the SOF0 to SOF15 markers.

## Protected Attributes

OFList< JPEGFileMapEntry * > | m_jpegFileMap
| JPEG file map.
OFFile | jpegFile
| The JPEG file, if opened.
OFBool | m_disableProgrTs
| If true, JPEGs with progressive coding are not supported.
OFBool | m_disableExtSeqTs
| If true, JPEGs with extended sequential coding are not supported.
OFBool | m_insistOnJFIF
| If true, conversion will only work if JFIF header can be found.
OFBool | m_keepAPPn
| If true, APPn markers (except JFIF!) are also copied to the output file.
OFBool | m_keepCOM
| If true, COM segment is also copied to the output file.
OFBool | m_lossyCompressed
| After reading pixel data, this denotes whether the source data is already lossy compressed.
OFBool | m_isJPEGLS
| After reading pixel data, this denotes whether the source data is JPEG-LS (ITU 87) or original JPEG (ITU 81).
Protected Attributes inherited from I2DImgSource
OFString | m_imageFile
| The input file.

## Detailed Description

This is a I2DImgSource implementation that can parse JPEG files and convert them into DICOM images.

This includes files using the original JPEG encoding (ITU-T Recommendation T.81) and JPEG-LS encoding (ITU-T Recommendation T.87).

## Member Function Documentation

## associatedTS()

E_TransferSyntax I2DJpegSource::associatedTS | ( | const E_JPGMARKER & | jpegEncoding,
|  | OFBool const | useJPEGLS,
|  | Uint8 const | nearLossless )

static protected

Returns if possible the DICOM transfer syntax matching the coding of the JPEG data.

Parameters

  jpegEncoding | - [in] Image marker that should be tested
  useJPEGLS | - [in] Denotes whether we are handling JPEG-LS data
  nearLossless | - [in] Denotes whether we are handling JPEG-LS data in near-lossless mode

Returns
  EC_Normal, marker is supported, error otherwise

## createJPEGFileMap()

OFCondition I2DJpegSource::createJPEGFileMap | ( |  | ) |

protected

Function that scans a JPEG file and creates a "file map" which includes all JPEG markers and their byte positions in the file.

Returns
  EC_Normal, if successful, error otherwise

## debugDumpJPEGFileMap()

void I2DJpegSource::debugDumpJPEGFileMap | ( |  | ) | const

protected

Dump the internal JPEG file map to a given stream.

The file map lists JPEG markers and their position in the bitstream found in the JPEG file

## extractRawJPEGStream()

OFCondition I2DJpegSource::extractRawJPEGStream | ( | char *& | pixelData,
|  | Uint32 & | pixLength )

protected

Extract raw JPEG stream (i.e.

without APPn markers) from JPEG file.

Parameters

  pixelData | - [out] The resulting JPEG stream
  pixLength | - [out] The length of the resulting stream

Returns
  EC_Normal, if successful, error otherwise

## firstMarker()

OFCondition I2DJpegSource::firstMarker | ( | E_JPGMARKER & | result | ) |

protected

Tries to read the SOI marker.

Parameters

  result | - [out] The code of the SOI marker if successful (0xD8)

Returns
  EC_Normal, if successful, error otherwise

## getAPP8ImageParameters()

OFCondition I2DJpegSource::getAPP8ImageParameters | ( | const JPEGFileMapEntry & | entry,
|  | Uint8 & | xform )

protected

Get color transform as found at given APP8 marker of the JPEG image.

Used for JPEG-LS codec.

Parameters

  entry | - [in] Related APP8 marker (E_JPGMARKER_APP8)
  xform | - [out] Returns the color transform

Returns
  EC_Normal, if successful, error otherwise

## getJFIFImageParameters()

OFCondition I2DJpegSource::getJFIFImageParameters | ( | const JPEGFileMapEntry & | entry,
|  | Uint16 & | jfifVersion,
|  | Uint16 & | pixelAspectH,
|  | Uint16 & | pixelAspectV,
|  | Uint16 & | unit )

protected

Get JPEG parameters as found at given JFIF marker of the JPEG image.

Parameters

  entry | - [in] This specifies the marker and the byte position of the JFIF marker
  jfifVersion | - [out] The JFIF version of the JFIF data
  pixelAspectH | - [out] The horizontal pixel aspect ratio
  pixelAspectV | - [out] The vertical pixel aspect ratio
  unit | - [out] The contents of the pixel aspect ratio unit field

Returns
  EC_Normal, if successful, error otherwise

## getLossyComprInfo()

OFCondition I2DJpegSource::getLossyComprInfo | ( | OFBool & | srcEncodingLossy,
|  | OFString & | srcLossyComprMethod ) const

virtual

After reading of pixel data, this function can be used for getting information about lossy compression parameters.

Parameters

  srcEncodingLossy | - [out] Denotes, whether the encoding of the pixel data read was lossy (OFTrue) or lossless (OFFalse)
  srcLossyComprMethod | - [out] Denotes the lossy compression method used in source if there is one (srcEncodingLossy = OFTrue). Should use defined terms of attribute Lossy Compression Method.

Returns
  EC_Normal if information is available, error otherwise

Implements I2DImgSource.

## getSOFImageParameters()

OFCondition I2DJpegSource::getSOFImageParameters | ( | const JPEGFileMapEntry & | entry,
|  | Uint16 & | imageWidth,
|  | Uint16 & | imageHeight,
|  | Uint16 & | samplesPerPixel,
|  | Uint16 & | bitsPerSample,
|  | OFString & | colorModel )

protected

Get image parameters as found at given SOF marker of the JPEG image.

Parameters

  entry | - [in] This specifies the marker and the byte position of the SOF marker
  imageWidth | - [out] The width of the image
  imageHeight | - [out] The height of the image
  samplesPerPixel | - [out] Number of components per pixel
  bitsPerSample | - [out] Number of bits per pixel component
  colorModel | - [out] color model of the JPEG bitstream

Returns
  EC_Normal, if successful, error otherwise

## getSOSImageParameters()

OFCondition I2DJpegSource::getSOSImageParameters | ( | const JPEGFileMapEntry & | entry,
|  | Uint8 & | nearLossless )

protected

Get image parameters as found at given SOF marker of the JPEG image.

Used for JPEG-LS codec.

Parameters

  entry | - [in] Related SOS marker (E_JPGMARKER_SOS)
  nearLossless | - [out] Returns whether image is encoded in lossless (0) or near-lossless (>0) mode

Returns
  EC_Normal, if successful, error otherwise

## inputFormat()

OFString I2DJpegSource::inputFormat | ( |  | ) | const

virtual

Returns format of input image.

For this class "JPEG" is returned.

Returns
  Returns format of input image, i.e. "JPEG".

Implements I2DImgSource.

## isJPEGEncodingSupported()

OFCondition I2DJpegSource::isJPEGEncodingSupported | ( | const E_JPGMARKER & | jpegEncoding | ) | const

protected

Check, whether a given JPEG image marker (SOFn) is supported by this plugin.

Parameters

  jpegEncoding | - [in] Image marker that should be tested

Returns
  EC_Normal, marker is supported, error otherwise

## isRSTMarker()

OFBool I2DJpegSource::isRSTMarker | ( | const E_JPGMARKER & | jpegEncoding | ) |

static protected

Returns true if marker is one of the RST0 to RST7 markers.

Parameters

  jpegEncoding | - [in] Image marker that should be tested

Returns
  OFTrue, if marker is RST0 to RST7, OFFalse otherwise

## isSOFMarker()

OFBool I2DJpegSource::isSOFMarker | ( | const E_JPGMARKER & | jpegEncoding,
|  | const OFBool | isJPEGLS )

static protected

Returns true if marker is one of the SOF0 to SOF15 markers.

Parameters

  jpegEncoding | - [in] Image marker that should be tested
  isJPEGLS | - [in] Denotes whether we are handling JPEG-LS data

Returns
  OFTrue, if marker is SOF0 to SOF15, OFFalse otherwise

## jpegMarkerToString()

OFString I2DJpegSource::jpegMarkerToString | ( | const E_JPGMARKER & | marker,
|  | const OFBool | isJPEGLS )

static

Returns a string representation of a JPEG marker code.

Parameters

  marker | - [in] The marker to be converted
  isJPEGLS | - [in] Denotes whether we are handling JPEG-LS data

Returns
  A string representation of the marker

## nextMarker()

OFCondition I2DJpegSource::nextMarker | ( | const OFBool & | lastWasSOSMarker,
|  | E_JPGMARKER & | result )

protected

Tries to find the next JPEG marker in underlying file stream.

Parameters

  lastWasSOSMarker | - [in] Denotes, whether the last marker read before was the SOS (start of scan) marker. This is needed to ignore non-marker 0xFF occurrences in the compressed data.
  result | - [out] The result marker

Returns
  EC_Normal, if successful, error otherwise

## openFile()

OFCondition I2DJpegSource::openFile | ( | const OFString & | filename | ) |

protected

Opens the JPEG file specified by the given filename.

Parameters

  filename | - [in] The file to be opened

Returns
  EC_Normal, if successful, error otherwise

## read1Byte()

int I2DJpegSource::read1Byte | ( | Uint8 & | result | ) |

inline protected

Read 1 byte from the byte stream.

Parameters

  result | - [out] The result

Returns
  0, if successful, EOF if rest of stream does not contain enough bytes

## read2Bytes()

int I2DJpegSource::read2Bytes | ( | Uint16 & | result | ) |

inline protected

Read 2 bytes from the byte stream.

Parameters

  result | - [out] The result

Returns
  0, if successful, EOF if rest of stream does not contain enough bytes

## readPixelData()

OFCondition I2DJpegSource::readPixelData | ( | Uint16 & | rows,
|  | Uint16 & | cols,
|  | Uint16 & | samplesPerPixel,
|  | OFString & | photoMetrInt,
|  | Uint16 & | bitsAlloc,
|  | Uint16 & | bitsStored,
|  | Uint16 & | highBit,
|  | Uint16 & | pixelRepr,
|  | Uint16 & | planConf,
|  | Uint16 & | pixAspectH,
|  | Uint16 & | pixAspectV,
|  | char *& | pixData,
|  | Uint32 & | length,
|  | E_TransferSyntax & | ts )

virtual

Extracts the raw JPEG pixel data stream from a JPEG file and returns some further information about this pixel data.

Raw means here that all APP markers (e.g. JFIF information) are removed from the JPEG stream. The pixel data returned is a JPEG stream in JPEG interchange format. This function allocates memory for the pixel data returned to the user. The caller of this function is responsible for deleting the memory buffer.

Parameters

  rows | - [out] Rows of image
  cols | - [out] Columns of image
  samplesPerPixel | - [out] Number of components per pixel
  photoMetrInt | - [out] The DICOM color model used for the compressed data
  bitsAlloc | - [out] Bits Allocated for one sample
  bitsStored | - [out] Bits Stored, Number of bits actually stored within Bits Allocated
  highBit | - [out] High Bit, Highest stored in bit within Bits Allocated
  pixelRepr | - [out] Pixel Representation (0=unsigned, 1=signed)
  planConf | - [out] Planar Configuration
  pixAspectH | - [out] Horizontal value of pixel aspect ratio
  pixAspectV | - [out] Vertical value of pixel aspect ratio
  pixData | - [out] Pointer to the pixel data in JPEG Interchange Format (but without APPx markers).
  length | - [out] Length of pixel data
  ts | - [out] The transfer syntax imposed by the imported pixel pixel data. This is necessary for the JPEG importer that needs to report which TS must be used for the imported JPEG data (ie. baseline, progressive, ...).

Returns
  EC_Normal, if successful, error otherwise

Implements I2DImgSource.

## setExtSeqSupport()

void I2DJpegSource::setExtSeqSupport | ( | const OFBool | enabled | ) |

Enable/Disable support for Extended Sequential JPEG Coding.

Parameters

  enabled | - [in] OFTrue: support Extended Sequential, OFFalse: do not support

## setInsistOnJFIF()

void I2DJpegSource::setInsistOnJFIF | ( | const OFBool | enabled | ) |

If enabled, conversion will only take place if JFIF data could be found and evaluated.

Many digital cameras do not provide a JFIF header, so this is disabled by default.

Parameters

  enabled | - [in] Set whether we want to insist on JFIF header (OFTrue) or not (OFFalse)

## setKeepAPPn()

void I2DJpegSource::setKeepAPPn | ( | const OFBool | enabled | ) |

If enabled, APPn markers (except JFIF!) are also copied to the output file.

Default: false

Parameters

  enabled | - [in] OFTrue: copy APPn, OFFalse: cut off APPn info

## setKeepCOM()

void I2DJpegSource::setKeepCOM | ( | const OFBool | enabled | ) |

If enabled, COM marker is also copied to the output file.

Default: true

Parameters

  enabled | - [in] OFTrue: copy COM, OFFalse: cut off COM segment

## setProgrSupport()

void I2DJpegSource::setProgrSupport | ( | const OFBool | enabled | ) |

Enable/Disable support for Progressive JPEG Coding.

Parameters

  enabled | - [in] OFTrue: support Extended Sequential, OFFalse: do not support

## skipVariable()

OFCondition I2DJpegSource::skipVariable | ( |  | ) |

protected

Skips one marker while scanning through the JPEG file stream.

Returns
  EC_Normal, if successful, error otherwise

## Member Data Documentation

## m_insistOnJFIF

OFBool I2DJpegSource::m_insistOnJFIF

protected

If true, conversion will only work if JFIF header can be found.

Default: false

## m_jpegFileMap

OFList<JPEGFileMapEntry*> I2DJpegSource::m_jpegFileMap

protected

JPEG file map.

This map includes all JPEG markers and their byte positions in the JPEG file.

## m_keepAPPn

OFBool I2DJpegSource::m_keepAPPn

protected

If true, APPn markers (except JFIF!) are also copied to the output file.

This can cause a huge speedup because instead of parsing the whole JPEG file (for finding any APPn markers) the parsing stops after finding the SOFn marker (which is relevant for extracting width/height and so on. Default: false

## m_keepCOM

OFBool I2DJpegSource::m_keepCOM

protected

If true, COM segment is also copied to the output file.

Default: true

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

- dcmdata/include/dcmtk/dcmdata/libi2d/i2djpgs.h

Generated on for DCMTK Version 3.7.0 by Doxygen 1.15.0