DCMTK  Version 3.6.1 20170228
OFFIS DICOM Toolkit
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
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. More...
 
OFString inputFormat () const
 Returns format of input image. More...
 
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. More...
 
OFCondition getLossyComprInfo (OFBool &srcEncodingLossy, OFString &srcLossyComprMethod) const
 After reading of pixel data, this function can be used for getting information about lossy compression parameters. More...
 
void setExtSeqSupport (const OFBool enabled)
 Enable/Disable support for Extended Sequential JPEG Coding. More...
 
void setProgrSupport (const OFBool enabled)
 Enable/Disable support for Progressive JPEG Coding. More...
 
void setInsistOnJFIF (const OFBool enabled)
 If enabled, conversion will only take place if JFIF data could be found and evaluated. More...
 
void setKeepAPPn (const OFBool enabled)
 If enabled, APPn markers (except JFIF!) are also copied to the output file. More...
 
 ~I2DJpegSource ()
 Destructor, frees some memory. More...
 
- Public Member Functions inherited from I2DImgSource
 I2DImgSource ()
 Constructor.
 
void setImageFile (const OFString &filename)
 Sets the input image file to read. More...
 
OFString getImageFile ()
 Returns the input image file that currently associated with plugin. More...
 
virtual ~I2DImgSource ()
 Virtual Destructor.
 

Static Public Member Functions

static OFString jpegMarkerToString (const E_JPGMARKER &marker)
 Returns a string representation of a JPEG marker code. More...
 

Protected Member Functions

OFCondition openFile (const OFString &filename)
 Opens the JPEG file specified by the given filename. More...
 
void closeFile ()
 Closes JPEG file. More...
 
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. More...
 
void debugDumpJPEGFileMap () const
 Dump the internal JPEG file map to a given stream. More...
 
OFCondition getSOFImageParameters (const JPEGFileMapEntry &entry, Uint16 &imageWidth, Uint16 &imageHeight, Uint16 &samplesPerPixel, Uint16 &bitsPerSample)
 Get image parameters as found at given SOF marker of the JPEG image. More...
 
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. More...
 
OFCondition isJPEGEncodingSupported (const E_JPGMARKER &jpegEncoding) const
 Check, whether a given JPEG image marker (SOFn) is supported by this plugin. More...
 
OFCondition extractRawJPEGStream (char *&pixelData, Uint32 &pixLength)
 Extract raw JPEG stream (i.e. More...
 
OFCondition copyJPEGStream (char *&pixelData, Uint32 &pixLength)
 Copies JPEG stream (with APPn markers, excluding JFIF) from JPEG file. More...
 
OFCondition skipVariable ()
 Skips one marker while scanning through the JPEG file stream. More...
 
OFCondition firstMarker (E_JPGMARKER &result)
 Tries to read the SOI marker. More...
 
OFCondition nextMarker (const OFBool &lastWasSOSMarker, E_JPGMARKER &result)
 Tries to find the next JPEG marker in underlying file stream. More...
 
int read2Bytes (Uint16 &result)
 Read 2 bytes from the byte stream. More...
 
int read1Byte (Uint8 &result)
 Read 1 byte from the byte stream. More...
 
void clearMap ()
 Deletes internal JPEG file map and frees memory. More...
 

Static Protected Member Functions

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

Protected Attributes

OFList< JPEGFileMapEntry * > m_jpegFileMap
 JPEG file map. More...
 
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. More...
 
OFBool m_keepAPPn
 If true, APPn markers (except JFIF!) are also copied to the output file. More...
 
OFBool m_lossyCompressed
 After reading pixel data, this denotes whether the source data is already lossy compressed.
 
- 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.

Constructor & Destructor Documentation

I2DJpegSource::I2DJpegSource ( )

Constructor, initializes member variables.

Returns
none
I2DJpegSource::~I2DJpegSource ( )

Destructor, frees some memory.

Returns
none

Member Function Documentation

static E_TransferSyntax I2DJpegSource::associatedTS ( const E_JPGMARKER &  jpegEncoding)
staticprotected

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

Parameters
jpegEncoding- [in] Image marker that should be tested
Returns
EC_Normal, marker is supported, error otherwise
void I2DJpegSource::clearMap ( )
protected

Deletes internal JPEG file map and frees memory.

Returns
none
void I2DJpegSource::closeFile ( )
protected

Closes JPEG file.

Returns
A string representation of the marker
OFCondition I2DJpegSource::copyJPEGStream ( char *&  pixelData,
Uint32 &  pixLength 
)
protected

Copies JPEG stream (with APPn markers, excluding JFIF) 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
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
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

Returns
none
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
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
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
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.

OFCondition I2DJpegSource::getSOFImageParameters ( const JPEGFileMapEntry entry,
Uint16 &  imageWidth,
Uint16 &  imageHeight,
Uint16 &  samplesPerPixel,
Uint16 &  bitsPerSample 
)
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
Returns
EC_Normal, if successful, error otherwise
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.

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
static OFBool I2DJpegSource::isRSTMarker ( const E_JPGMARKER &  jpegEncoding)
staticprotected

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
static OFBool I2DJpegSource::isSOFMarker ( const E_JPGMARKER &  jpegEncoding)
staticprotected

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

Parameters
jpegEncoding- [in] Image marker that should be tested
Returns
OFTrue, if marker is SOF0 to SOF15, OFFalse otherwise
static OFString I2DJpegSource::jpegMarkerToString ( const E_JPGMARKER &  marker)
static

Returns a string representation of a JPEG marker code.

Parameters
marker- [in] The marker to be converted
Returns
A string representation of the marker
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
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
int I2DJpegSource::read1Byte ( Uint8 &  result)
inlineprotected

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
int I2DJpegSource::read2Bytes ( Uint16 &  result)
inlineprotected

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
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.

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
Returns
none
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.

void I2DJpegSource::setKeepAPPn ( const OFBool  enabled)

If enabled, 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

Parameters
enabled- [in] OFTrue: copy APPn, OFFalse: cut off APPn info
Returns
none
void I2DJpegSource::setProgrSupport ( const OFBool  enabled)

Enable/Disable support for Progressive JPEG Coding.

Parameters
enabled- [in] OFTrue: support Extended Sequential, OFFalse: do not support
Returns
none
OFCondition I2DJpegSource::skipVariable ( )
protected

Skips one marker while scanning through the JPEG file stream.

Returns
EC_Normal, if successful, error otherwise

Member Data Documentation

OFBool I2DJpegSource::m_insistOnJFIF
protected

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

Default: false

OFList<JPEGFileMapEntry*> I2DJpegSource::m_jpegFileMap
protected

JPEG file map.

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

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


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


Generated on Tue Feb 28 2017 for DCMTK Version 3.6.1 20170228 by Doxygen 1.8.8