00001 /* 00002 * 00003 * Copyright (C) 2001-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmdata 00015 * 00016 * Author: Michael Onken 00017 * 00018 * Purpose: Class to extract pixel data and meta information from JPEG file 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:15:46 $ 00022 * CVS/RCS Revision: $Revision: 1.8 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 #ifndef I2DJPGS_H 00030 #define I2DJPGS_H 00031 00032 #include "dcmtk/config/osconfig.h" 00033 #include "dcmtk/ofstd/offile.h" 00034 #include "dcmtk/ofstd/oflist.h" 00035 #include "dcmtk/dcmdata/libi2d/i2dimgs.h" 00036 00044 enum E_JPGMARKER { E_JPGMARKER_SOF0 = 0xC0, E_JPGMARKER_SOF1 = 0xC1, E_JPGMARKER_SOF2 = 0xC2, 00045 E_JPGMARKER_SOF3 = 0xC3, /*C4 and CC are not SOF markers,*/ E_JPGMARKER_SOF5 = 0xC5, 00046 E_JPGMARKER_SOF6 = 0xC6, E_JPGMARKER_SOF7 = 0xC7, E_JPGMARKER_JPG = 0xC8, 00047 E_JPGMARKER_SOF9 = 0xC9, E_JPGMARKER_SOF10 = 0xCA, E_JPGMARKER_SOF11 = 0xCB, 00048 E_JPGMARKER_SOF13 = 0xCD, E_JPGMARKER_SOF14 = 0xCE, E_JPGMARKER_SOF15 = 0xCF, 00049 E_JPGMARKER_DHT = 0xC4, E_JPGMARKER_DAC = 0xCC, E_JPGMARKER_RST0 = 0xD0, 00050 E_JPGMARKER_RST1 = 0xD1, E_JPGMARKER_RST2 = 0xD2, E_JPGMARKER_RST3 = 0xD3, 00051 E_JPGMARKER_RST4 = 0xD4, E_JPGMARKER_RST5 = 0xD5, E_JPGMARKER_RST6 = 0xD6, 00052 E_JPGMARKER_RST7 = 0xD7, E_JPGMARKER_SOI = 0xD8, E_JPGMARKER_EOI = 0xD9, 00053 E_JPGMARKER_SOS = 0xDA, E_JPGMARKER_DQT = 0xDB, E_JPGMARKER_DNL = 0xDC, 00054 E_JPGMARKER_DRI = 0xDD, E_JPGMARKER_DHP = 0xDE, E_JPGMARKER_EXP = 0xDF, 00055 E_JPGMARKER_APP0 = 0xE0, E_JPGMARKER_APP1 = 0xE1, E_JPGMARKER_APP2 = 0xE2, 00056 E_JPGMARKER_APP3 = 0xE3, E_JPGMARKER_APP4 = 0xE4, E_JPGMARKER_APP5 = 0xE5, 00057 E_JPGMARKER_APP6 = 0xE6, E_JPGMARKER_APP7 = 0xE7, E_JPGMARKER_APP8 = 0xE8, 00058 E_JPGMARKER_APP9 = 0xE9, E_JPGMARKER_APP10 = 0xEA, E_JPGMARKER_APP11 = 0xEB, 00059 E_JPGMARKER_APP12 = 0xEC, E_JPGMARKER_APP13 = 0xED, E_JPGMARKER_APP14 = 0xEE, 00060 E_JPGMARKER_APP15 = 0xEF, E_JPGMARKER_JPGN0 = 0xF0, E_JPGMARKER_JPGN1 = 0xF1, 00061 E_JPGMARKER_JPGN2 = 0xF2, E_JPGMARKER_JPGN3 = 0xF3, E_JPGMARKER_JPGN4 = 0xF4, 00062 E_JPGMARKER_JPGN5 = 0xF5, E_JPGMARKER_JPGN6 = 0xF6, E_JPGMARKER_JPGN7 = 0xF7, 00063 E_JPGMARKER_JPGN8 = 0xF8, E_JPGMARKER_JPGN9 = 0xF9, E_JPGMARKER_JPGN10 = 0xFA, 00064 E_JPGMARKER_JPGN11 = 0xFB, E_JPGMARKER_JPGN12 = 0xFC, E_JPGMARKER_JPGN13 = 0xFD, 00065 E_JPGMARKER_COM = 0xFE, E_JPGMARKER_TEM = 0x01, E_JPGMARKER_RES0 = 0x02, 00066 E_JPGMARKER_RESN = 0xBF }; 00067 00072 struct JPEGFileMapEntry { 00074 offile_off_t bytePos; 00076 E_JPGMARKER marker; 00077 }; 00078 00079 00080 class I2DJpegSource : public I2DImgSource 00081 { 00082 00083 public: 00084 00088 I2DJpegSource(); 00089 00093 OFString inputFormat() const; 00094 00119 OFCondition readPixelData( Uint16& rows, 00120 Uint16& cols, 00121 Uint16& samplesPerPixel, 00122 OFString& photoMetrInt, 00123 Uint16& bitsAlloc, 00124 Uint16& bitsStored, 00125 Uint16& highBit, 00126 Uint16& pixelRepr, 00127 Uint16& planConf, 00128 Uint16& pixAspectH, 00129 Uint16& pixAspectV, 00130 char*& pixData, 00131 Uint32& length, 00132 E_TransferSyntax& ts); 00133 00134 /* After reading of pixel data, this function can be used for getting 00135 * information about lossy compression parameters. 00136 * @param srcEncodingLossy - [out] Denotes, whether the encoding of the pixel 00137 * data read was lossy (OFtrue) or lossless (OFFalse) 00138 * @param srcLossyComprMethod - [out] Denotes the lossy compression method used 00139 * in source if there is one (srcEncodingLossy = OFTrue). 00140 * Should use defined terms of attribute Lossy Compression Method. 00141 * @return EC_Normal if information is available, error otherwise 00142 */ 00143 OFCondition getLossyComprInfo(OFBool& srcEncodingLossy, 00144 OFString& srcLossyComprMethod) const; 00145 00150 void setExtSeqSupport(const OFBool enabled); 00151 00156 void setProgrSupport(const OFBool enabled); 00157 00162 void setInsistOnJFIF(const OFBool enabled); 00163 00172 void setKeepAPPn(const OFBool enabled); 00173 00178 static OFString jpegMarkerToString(const E_JPGMARKER& marker); 00179 00183 ~I2DJpegSource(); 00184 00185 protected: 00186 00191 OFCondition openFile(const OFString& filename); 00192 00196 void closeFile(); 00197 00202 OFCondition createJPEGFileMap(); 00203 00209 void debugDumpJPEGFileMap() const; 00210 00219 OFCondition getSOFImageParameters( const JPEGFileMapEntry& entry, 00220 Uint16& imageWidth, 00221 Uint16& imageHeight, 00222 Uint16& samplesPerPixel, 00223 Uint16& bitsPerSample); 00224 00233 OFCondition getJFIFImageParameters( const JPEGFileMapEntry& entry, 00234 Uint16& jfifVersion, 00235 Uint16& pixelAspectH, 00236 Uint16& pixelAspectV, 00237 Uint16& unit); 00238 00244 OFCondition isJPEGEncodingSupported(const E_JPGMARKER& jpegEncoding) const; 00245 00246 00252 static E_TransferSyntax associatedTS(const E_JPGMARKER& jpegEncoding); 00253 00258 static OFBool isRSTMarker(const E_JPGMARKER& jpegEncoding); 00259 00264 static OFBool isSOFMarker(const E_JPGMARKER& jpegEncoding); 00265 00266 00272 OFCondition extractRawJPEGStream(char*& pixelData, 00273 Uint32& pixLength); 00274 00280 OFCondition copyJPEGStream(char*& pixelData, 00281 Uint32& pixLength); 00282 00286 OFCondition skipVariable(); 00287 00292 OFCondition firstMarker(E_JPGMARKER& result); 00293 00301 OFCondition nextMarker(const OFBool& lastWasSOSMarker, 00302 E_JPGMARKER& result); 00303 00308 inline int read2Bytes(Uint16& result); 00309 00314 inline int read1Byte(Uint8& result); 00315 00319 void clearMap(); 00320 00322 OFList<JPEGFileMapEntry*> m_jpegFileMap; 00323 00325 OFFile jpegFile; 00326 00328 OFBool m_disableProgrTs; 00329 00331 OFBool m_disableExtSeqTs; 00332 00335 OFBool m_insistOnJFIF; 00336 00342 OFBool m_keepAPPn; 00343 00346 OFBool m_lossyCompressed; 00347 00348 }; 00349 00350 #endif // #ifndef I2DJPGS_H 00351 00352 /* 00353 * CVS/RCS Log: 00354 * $Log: i2djpgs.h,v $ 00355 * Revision 1.8 2010-10-14 13:15:46 joergr 00356 * Updated copyright header. Added reference to COPYRIGHT file. 00357 * 00358 * Revision 1.7 2009-11-04 09:58:08 uli 00359 * Switched to logging mechanism provided by the "new" oflog module 00360 * 00361 * Revision 1.6 2009-09-30 08:05:25 uli 00362 * Stop including dctk.h in libi2d's header files. 00363 * 00364 * Revision 1.5 2009-07-16 14:22:19 onken 00365 * Changed comment (and thus semantic of parameter for output transfer syntax). 00366 * 00367 * Revision 1.4 2009-03-31 13:06:09 onken 00368 * Changed implementation of lossy compression attribute detection and writing. 00369 * 00370 * Revision 1.2 2009-01-16 09:51:55 onken 00371 * Completed doxygen documentation for libi2d. 00372 * 00373 * Revision 1.1 2008-01-16 15:09:17 onken 00374 * Moved library "i2dlib" from /dcmdata/libsrc/i2dlib to /dcmdata/libi2d 00375 * 00376 * Revision 1.2 2008-01-11 14:17:53 onken 00377 * Added various options to i2dlib. Changed logging to use a configurable 00378 * logstream. Added output plugin for the new Multiframe Secondary Capture SOP 00379 * Classes. Added mode for JPEG plugin to copy exsiting APPn markers (except 00380 * JFIF). Changed img2dcm default behaviour to invent type1/type2 attributes (no 00381 * need for templates any more). Added some bug fixes. 00382 * 00383 * Revision 1.1 2007/11/08 15:58:55 onken 00384 * Initial checkin of img2dcm application and corresponding library i2dlib. 00385 * 00386 * 00387 */ 00388