1 /*=========================================================================
2 
3   Program: GDCM (Grassroots DICOM). A DICOM library
4 
5   Copyright (c) 2006-2011 Mathieu Malaterre
6   All rights reserved.
7   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef GDCMIMAGECHANGETRANSFERSYNTAX_H
15 #define GDCMIMAGECHANGETRANSFERSYNTAX_H
16 
17 #include "gdcmImageToImageFilter.h"
18 #include "gdcmTransferSyntax.h"
19 
20 namespace gdcm
21 {
22 
23 class DataElement;
24 class ImageCodec;
25 /**
26  * \brief ImageChangeTransferSyntax class
27  * \details Class to change the transfer syntax of an input DICOM
28  *
29  * If only Force param is set but no input TransferSyntax is set, it is assumed
30  * that user only wants to inspect encapsulated stream (advanced dev. option).
31  *
32  * When using UserCodec it is very important that the TransferSyntax (as set in
33  * SetTransferSyntax) is actually understood by UserCodec (ie.
34  * UserCodec->CanCode( TransferSyntax ) ). Otherwise the behavior is to use a
35  * default codec.
36  *
37  * \sa JPEGCodec JPEGLSCodec JPEG2000Codec
38  */
39 class GDCM_EXPORT ImageChangeTransferSyntax : public ImageToImageFilter
40 {
41 public:
ImageChangeTransferSyntax()42   ImageChangeTransferSyntax():TS(TransferSyntax::TS_END),Force(false),CompressIconImage(false),UserCodec(nullptr) {}
43   ~ImageChangeTransferSyntax() = default;
44 
45   /// Set target Transfer Syntax
SetTransferSyntax(const TransferSyntax & ts)46   void SetTransferSyntax(const TransferSyntax &ts) { TS = ts; }
47   /// Get Transfer Syntax
GetTransferSyntax()48   const TransferSyntax &GetTransferSyntax() const { return TS; }
49 
50   /// Change
51   bool Change();
52 
53   /// Decide whether or not to also compress the Icon Image using the same
54   /// Transfer Syntax.  Default is to simply decompress icon image
SetCompressIconImage(bool b)55   void SetCompressIconImage(bool b) { CompressIconImage = b; }
56 
57   /// When target Transfer Syntax is identical to input target syntax, no
58   /// operation is actually done.
59   /// This is an issue when someone wants to re-compress using GDCM internal
60   /// implementation a JPEG (for example) image
SetForce(bool f)61   void SetForce( bool f ) { Force = f; }
62 
63   /// Allow user to specify exactly which codec to use. this is needed to
64   /// specify special qualities or compression option.
65   /// \warning if the codec 'ic' is not compatible with the TransferSyntax
66   /// requested, it will not be used. It is the user responsibility to check
67   /// that UserCodec->CanCode( TransferSyntax )
SetUserCodec(ImageCodec * ic)68   void SetUserCodec(ImageCodec *ic) { UserCodec = ic; }
69 
70 protected:
71   bool TryJPEGCodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output);
72   bool TryJPEG2000Codec(const DataElement &pixelde, Bitmap const &input, Bitmap &output);
73   bool TryJPEGLSCodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output);
74   bool TryRAWCodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output);
75   bool TryRLECodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output);
76 
77 private:
78   TransferSyntax TS;
79   bool Force;
80   bool CompressIconImage;
81 
82   ImageCodec *UserCodec;
83 };
84 
85 /**
86  * \example StandardizeFiles.cs
87  * This is a C++ example on how to use ImageChangeTransferSyntax
88  */
89 
90 } // end namespace gdcm
91 
92 #endif //GDCMIMAGECHANGETRANSFERSYNTAX_H
93