1 /*
2  *
3  *  Copyright (C) 1997-2014, 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:  dcmjpeg
15  *
16  *  Author:  Norbert Olges, Marco Eichelberg
17  *
18  *  Purpose: decompression routines of the IJG JPEG library configured for 16 bits/sample.
19  *
20  */
21 
22 #ifndef DJDIJG16_H
23 #define DJDIJG16_H
24 
25 #include "dcmtk/config/osconfig.h"
26 #include "dcmtk/dcmjpeg/djdecabs.h" /* for class DJDecoder */
27 
28 extern "C"
29 {
30   struct jpeg_decompress_struct;
31 }
32 
33 class DJCodecParameter;
34 
35 /** this class encapsulates the decompression routines of the
36  *  IJG JPEG library configured for 16 bits/sample.
37  */
38 class DCMTK_DCMJPEG_EXPORT DJDecompressIJG16Bit : public DJDecoder
39 {
40 public:
41 
42   /** constructor
43    *  @param cp codec parameters
44    *  @param isYBR flag indicating if DICOM photometric interpretation is YCbCr
45    */
46   DJDecompressIJG16Bit(const DJCodecParameter& cp, OFBool isYBR);
47 
48   /// destructor
49   virtual ~DJDecompressIJG16Bit();
50 
51   /** initializes internal object structures.
52    *  Must be called before a new frame is decompressed.
53    *  @return EC_Normal if successful, an error code otherwise
54    */
55   virtual OFCondition init();
56 
57   /** suspended decompression routine. Decompresses a JPEG frame
58    *  until finished or out of data. Can be called with new data
59    *  until a frame is complete.
60    *  @param compressedFrameBuffer pointer to compressed input data, must not be NULL
61    *  @param compressedFrameBufferSize size of buffer, in bytes
62    *  @param uncompressedFrameBuffer pointer to uncompressed output data, must not be NULL.
63    *     This buffer must not change between multiple decode() calls for a single frame.
64    *  @param uncompressedFrameBufferSize size of buffer, in bytes (!)
65    *     Buffer must be large enough to contain a complete frame.
66    *  @param isSigned OFTrue, if uncompressed pixel data is signed, OFFalse otherwise
67    *  @return EC_Normal if successful, EC_Suspend if more data is needed, an error code otherwise.
68    */
69   virtual OFCondition decode(
70     Uint8 *compressedFrameBuffer,
71     Uint32 compressedFrameBufferSize,
72     Uint8 *uncompressedFrameBuffer,
73     Uint32 uncompressedFrameBufferSize,
74     OFBool isSigned);
75 
76   /** returns the number of bytes per sample that will be written when decoding.
77    */
bytesPerSample()78   virtual Uint16 bytesPerSample() const
79   {
80     return OFstatic_cast(Uint16, sizeof(Uint16));
81   }
82 
83   /** after successful compression,
84    *  returns the color model of the decompressed image
85    */
getDecompressedColorModel()86   virtual EP_Interpretation getDecompressedColorModel() const
87   {
88     return decompressedColorModel;
89   }
90 
91   /** callback function used to report warning messages and the like.
92    *  Should not be called by user code directly.
93    *  @param msg_level -1 for warnings, 0 and above for trace messages
94    */
95   virtual void emitMessage(int msg_level) const;
96 
97 private:
98 
99   /// private undefined copy constructor
100   DJDecompressIJG16Bit(const DJDecompressIJG16Bit&);
101 
102   /// private undefined copy assignment operator
103   DJDecompressIJG16Bit& operator=(const DJDecompressIJG16Bit&);
104 
105   /// cleans up cinfo structure, called from destructor and error handlers
106   void cleanup();
107 
108   /// codec parameters
109   const DJCodecParameter *cparam;
110 
111   /// decompression structure
112   jpeg_decompress_struct *cinfo;
113 
114   /// position of last suspend
115   int suspension;
116 
117   /// temporary storage for row buffer during suspension
118   void *jsampBuffer;
119 
120   /// Flag indicating if DICOM photometric interpretation is YCbCr
121   OFBool dicomPhotometricInterpretationIsYCbCr;
122 
123   /// color model after decompression
124   EP_Interpretation decompressedColorModel;
125 
126 };
127 
128 #endif
129