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 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2