32 #include "dcmtk/config/osconfig.h"
33 #include "dcmtk/ofstd/offile.h"
34 #include "dcmtk/ofstd/oflist.h"
35 #include "dcmtk/dcmdata/libi2d/i2dimgs.h"
44 enum E_JPGMARKER { E_JPGMARKER_SOF0 = 0xC0, E_JPGMARKER_SOF1 = 0xC1, E_JPGMARKER_SOF2 = 0xC2,
45 E_JPGMARKER_SOF3 = 0xC3, E_JPGMARKER_SOF5 = 0xC5,
46 E_JPGMARKER_SOF6 = 0xC6, E_JPGMARKER_SOF7 = 0xC7, E_JPGMARKER_JPG = 0xC8,
47 E_JPGMARKER_SOF9 = 0xC9, E_JPGMARKER_SOF10 = 0xCA, E_JPGMARKER_SOF11 = 0xCB,
48 E_JPGMARKER_SOF13 = 0xCD, E_JPGMARKER_SOF14 = 0xCE, E_JPGMARKER_SOF15 = 0xCF,
49 E_JPGMARKER_DHT = 0xC4, E_JPGMARKER_DAC = 0xCC, E_JPGMARKER_RST0 = 0xD0,
50 E_JPGMARKER_RST1 = 0xD1, E_JPGMARKER_RST2 = 0xD2, E_JPGMARKER_RST3 = 0xD3,
51 E_JPGMARKER_RST4 = 0xD4, E_JPGMARKER_RST5 = 0xD5, E_JPGMARKER_RST6 = 0xD6,
52 E_JPGMARKER_RST7 = 0xD7, E_JPGMARKER_SOI = 0xD8, E_JPGMARKER_EOI = 0xD9,
53 E_JPGMARKER_SOS = 0xDA, E_JPGMARKER_DQT = 0xDB, E_JPGMARKER_DNL = 0xDC,
54 E_JPGMARKER_DRI = 0xDD, E_JPGMARKER_DHP = 0xDE, E_JPGMARKER_EXP = 0xDF,
55 E_JPGMARKER_APP0 = 0xE0, E_JPGMARKER_APP1 = 0xE1, E_JPGMARKER_APP2 = 0xE2,
56 E_JPGMARKER_APP3 = 0xE3, E_JPGMARKER_APP4 = 0xE4, E_JPGMARKER_APP5 = 0xE5,
57 E_JPGMARKER_APP6 = 0xE6, E_JPGMARKER_APP7 = 0xE7, E_JPGMARKER_APP8 = 0xE8,
58 E_JPGMARKER_APP9 = 0xE9, E_JPGMARKER_APP10 = 0xEA, E_JPGMARKER_APP11 = 0xEB,
59 E_JPGMARKER_APP12 = 0xEC, E_JPGMARKER_APP13 = 0xED, E_JPGMARKER_APP14 = 0xEE,
60 E_JPGMARKER_APP15 = 0xEF, E_JPGMARKER_JPGN0 = 0xF0, E_JPGMARKER_JPGN1 = 0xF1,
61 E_JPGMARKER_JPGN2 = 0xF2, E_JPGMARKER_JPGN3 = 0xF3, E_JPGMARKER_JPGN4 = 0xF4,
62 E_JPGMARKER_JPGN5 = 0xF5, E_JPGMARKER_JPGN6 = 0xF6, E_JPGMARKER_JPGN7 = 0xF7,
63 E_JPGMARKER_JPGN8 = 0xF8, E_JPGMARKER_JPGN9 = 0xF9, E_JPGMARKER_JPGN10 = 0xFA,
64 E_JPGMARKER_JPGN11 = 0xFB, E_JPGMARKER_JPGN12 = 0xFC, E_JPGMARKER_JPGN13 = 0xFD,
65 E_JPGMARKER_COM = 0xFE, E_JPGMARKER_TEM = 0x01, E_JPGMARKER_RES0 = 0x02,
66 E_JPGMARKER_RESN = 0xBF };
121 Uint16& samplesPerPixel,
132 E_TransferSyntax& ts);
143 OFCondition getLossyComprInfo(OFBool& srcEncodingLossy,
144 OFString& srcLossyComprMethod)
const;
222 Uint16& samplesPerPixel,
223 Uint16& bitsPerSample);
235 Uint16& pixelAspectH,
236 Uint16& pixelAspectV,
252 static E_TransferSyntax
associatedTS(
const E_JPGMARKER& jpegEncoding);
258 static OFBool
isRSTMarker(
const E_JPGMARKER& jpegEncoding);
264 static OFBool
isSOFMarker(
const E_JPGMARKER& jpegEncoding);
302 E_JPGMARKER& result);
350 #endif // #ifndef I2DJPGS_H
static OFString jpegMarkerToString(const E_JPGMARKER &marker)
Returns a string representation of a JPEG marker code.
this class provides a simple C++ encapsulation layer for stdio FILE pointers.
OFCondition nextMarker(const OFBool &lastWasSOSMarker, E_JPGMARKER &result)
Tries to find the next JPEG marker in underlying file stream.
OFBool m_keepAPPn
If true, APPn markers (except JFIF!) are also copied to the output file.
static E_TransferSyntax associatedTS(const E_JPGMARKER &jpegEncoding)
Returns if possible the DICOM transfer syntax matching the coding of the JPEG data.
void setKeepAPPn(const OFBool enabled)
If enabled, APPn markers (except JFIF!) are also copied to the output file.
OFCondition extractRawJPEGStream(char *&pixelData, Uint32 &pixLength)
Extract raw JPEG stream (i.e.
OFCondition createJPEGFileMap()
Function that scans a JPEG file and creates a "file map" which includes all JPEG markes and their byt...
offile_off_t bytePos
The byte position of the marker.
OFCondition firstMarker(E_JPGMARKER &result)
Tries to read the SOI marker.
OFBool m_disableExtSeqTs
If true, JPEGs with extended sequential coding are not supported.
OFCondition openFile(const OFString &filename)
Opens the JPEG file specified by the given filename.
OFCondition isJPEGEncodingSupported(const E_JPGMARKER &jpegEncoding) const
Check, whether a given JPEG image marker (SOFn) is supported by this plugin.
OFString inputFormat() const
Returns format of input image.
void debugDumpJPEGFileMap() const
Dump the internal JPEG file map to a given stream.
static OFBool isSOFMarker(const E_JPGMARKER &jpegEncoding)
Returns true if marker is one of the SOF0 to SOF15 markers.
OFBool m_insistOnJFIF
If true, conversion will only work if JFIF header can be found.
OFBool m_disableProgrTs
If true, JPEGs with progressive coding are not supported.
OFFile jpegFile
The JPEG file, if opened.
OFBool m_lossyCompressed
After reading pixel data, this denotes whether the source data is already lossy compressed.
void clearMap()
Deletes internal JPEG file map and frees memory.
void setInsistOnJFIF(const OFBool enabled)
If enabled, conversion will only take place if JFIF data could be found and evaluated.
I2DJpegSource()
Constructor, initializes member variables.
void closeFile()
Closes JPEG file.
Struct that represents a marker in a JPEG file, i.e.
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 image information about thi...
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.
~I2DJpegSource()
Destructor, frees some memory.
OFList< JPEGFileMapEntry * > m_jpegFileMap
JPEG file map. This map includes all JPEG markers and their byte positions in the JPEG file...
OFCondition copyJPEGStream(char *&pixelData, Uint32 &pixLength)
Copies JPEG stream (with APPn markers, excluding JFIF) from JPEG file.
void setExtSeqSupport(const OFBool enabled)
Enable/Disable support for Extended Sequential JPEG Coding.
a simple string class that implements a subset of std::string.
int read1Byte(Uint8 &result)
Read 1 byte from the byte stream.
OFCondition skipVariable()
Skips one marker while scanning through the JPEG file stream.
static OFBool isRSTMarker(const E_JPGMARKER &jpegEncoding)
Returns true if marker is one of the RST0 to RST7 markers.
E_JPGMARKER marker
The marker byte itself.
void setProgrSupport(const OFBool enabled)
Enable/Disable support for Progressive JPEG Coding.
int read2Bytes(Uint16 &result)
Read 2 bytes from the byte stream.
General purpose class for condition codes.
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.