00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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, 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
00135
00136
00137
00138
00139
00140
00141
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
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388