OFFIS DCMTK  Version 3.6.0
i2djpgs.h
1 /*
2  *
3  * Copyright (C) 2001-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmdata
15  *
16  * Author: Michael Onken
17  *
18  * Purpose: Class to extract pixel data and meta information from JPEG file
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:15:46 $
22  * CVS/RCS Revision: $Revision: 1.8 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 #ifndef I2DJPGS_H
30 #define I2DJPGS_H
31 
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"
36 
44 enum E_JPGMARKER { E_JPGMARKER_SOF0 = 0xC0, E_JPGMARKER_SOF1 = 0xC1, E_JPGMARKER_SOF2 = 0xC2,
45  E_JPGMARKER_SOF3 = 0xC3, /*C4 and CC are not SOF markers,*/ 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 };
67 
74  offile_off_t bytePos;
76  E_JPGMARKER marker;
77 };
78 
79 
81 {
82 
83 public:
84 
88  I2DJpegSource();
89 
93  OFString inputFormat() const;
94 
119  OFCondition readPixelData( Uint16& rows,
120  Uint16& cols,
121  Uint16& samplesPerPixel,
122  OFString& photoMetrInt,
123  Uint16& bitsAlloc,
124  Uint16& bitsStored,
125  Uint16& highBit,
126  Uint16& pixelRepr,
127  Uint16& planConf,
128  Uint16& pixAspectH,
129  Uint16& pixAspectV,
130  char*& pixData,
131  Uint32& length,
132  E_TransferSyntax& ts);
133 
134  /* After reading of pixel data, this function can be used for getting
135  * information about lossy compression parameters.
136  * @param srcEncodingLossy - [out] Denotes, whether the encoding of the pixel
137  * data read was lossy (OFtrue) or lossless (OFFalse)
138  * @param srcLossyComprMethod - [out] Denotes the lossy compression method used
139  * in source if there is one (srcEncodingLossy = OFTrue).
140  * Should use defined terms of attribute Lossy Compression Method.
141  * @return EC_Normal if information is available, error otherwise
142  */
143  OFCondition getLossyComprInfo(OFBool& srcEncodingLossy,
144  OFString& srcLossyComprMethod) const;
145 
150  void setExtSeqSupport(const OFBool enabled);
151 
156  void setProgrSupport(const OFBool enabled);
157 
162  void setInsistOnJFIF(const OFBool enabled);
163 
172  void setKeepAPPn(const OFBool enabled);
173 
178  static OFString jpegMarkerToString(const E_JPGMARKER& marker);
179 
183  ~I2DJpegSource();
184 
185 protected:
186 
191  OFCondition openFile(const OFString& filename);
192 
196  void closeFile();
197 
203 
209  void debugDumpJPEGFileMap() const;
210 
220  Uint16& imageWidth,
221  Uint16& imageHeight,
222  Uint16& samplesPerPixel,
223  Uint16& bitsPerSample);
224 
234  Uint16& jfifVersion,
235  Uint16& pixelAspectH,
236  Uint16& pixelAspectV,
237  Uint16& unit);
238 
244  OFCondition isJPEGEncodingSupported(const E_JPGMARKER& jpegEncoding) const;
245 
246 
252  static E_TransferSyntax associatedTS(const E_JPGMARKER& jpegEncoding);
253 
258  static OFBool isRSTMarker(const E_JPGMARKER& jpegEncoding);
259 
264  static OFBool isSOFMarker(const E_JPGMARKER& jpegEncoding);
265 
266 
272  OFCondition extractRawJPEGStream(char*& pixelData,
273  Uint32& pixLength);
274 
280  OFCondition copyJPEGStream(char*& pixelData,
281  Uint32& pixLength);
282 
287 
292  OFCondition firstMarker(E_JPGMARKER& result);
293 
301  OFCondition nextMarker(const OFBool& lastWasSOSMarker,
302  E_JPGMARKER& result);
303 
308  inline int read2Bytes(Uint16& result);
309 
314  inline int read1Byte(Uint8& result);
315 
319  void clearMap();
320 
323 
326 
329 
332 
336 
342  OFBool m_keepAPPn;
343 
347 
348 };
349 
350 #endif // #ifndef I2DJPGS_H
351 
352 /*
353  * CVS/RCS Log:
354  * $Log: i2djpgs.h,v $
355  * Revision 1.8 2010-10-14 13:15:46 joergr
356  * Updated copyright header. Added reference to COPYRIGHT file.
357  *
358  * Revision 1.7 2009-11-04 09:58:08 uli
359  * Switched to logging mechanism provided by the "new" oflog module
360  *
361  * Revision 1.6 2009-09-30 08:05:25 uli
362  * Stop including dctk.h in libi2d's header files.
363  *
364  * Revision 1.5 2009-07-16 14:22:19 onken
365  * Changed comment (and thus semantic of parameter for output transfer syntax).
366  *
367  * Revision 1.4 2009-03-31 13:06:09 onken
368  * Changed implementation of lossy compression attribute detection and writing.
369  *
370  * Revision 1.2 2009-01-16 09:51:55 onken
371  * Completed doxygen documentation for libi2d.
372  *
373  * Revision 1.1 2008-01-16 15:09:17 onken
374  * Moved library "i2dlib" from /dcmdata/libsrc/i2dlib to /dcmdata/libi2d
375  *
376  * Revision 1.2 2008-01-11 14:17:53 onken
377  * Added various options to i2dlib. Changed logging to use a configurable
378  * logstream. Added output plugin for the new Multiframe Secondary Capture SOP
379  * Classes. Added mode for JPEG plugin to copy exsiting APPn markers (except
380  * JFIF). Changed img2dcm default behaviour to invent type1/type2 attributes (no
381  * need for templates any more). Added some bug fixes.
382  *
383  * Revision 1.1 2007/11/08 15:58:55 onken
384  * Initial checkin of img2dcm application and corresponding library i2dlib.
385  *
386  *
387  */
388 
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.
Definition: offile.h:115
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.
Definition: i2djpgs.h:342
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.
Definition: i2djpgs.h:74
OFCondition firstMarker(E_JPGMARKER &result)
Tries to read the SOI marker.
OFBool m_disableExtSeqTs
If true, JPEGs with extended sequential coding are not supported.
Definition: i2djpgs.h:331
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.
Definition: i2djpgs.h:335
OFBool m_disableProgrTs
If true, JPEGs with progressive coding are not supported.
Definition: i2djpgs.h:328
OFFile jpegFile
The JPEG file, if opened.
Definition: i2djpgs.h:325
OFBool m_lossyCompressed
After reading pixel data, this denotes whether the source data is already lossy compressed.
Definition: i2djpgs.h:346
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.
Definition: i2djpgs.h:72
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...
Definition: i2djpgs.h:322
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.
Definition: ofstring.h:86
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.
Definition: i2djpgs.h:76
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.
Definition: ofcond.h:305
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.


Generated on Thu Aug 27 2015 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.9.1