vtk-dicom  0.8.14
vtkDICOMImageCodec.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2022 David Gobbi
6  All rights reserved.
7  See Copyright.txt or http://dgobbi.github.io/bsd3.txt 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 vtkDICOMImageCodec_h
15 #define vtkDICOMImageCodec_h
16 
17 #include "vtkSystemIncludes.h"
18 #include "vtkDICOMModule.h" // For export macro
19 
20 #include <string>
21 
22 class vtkDICOMMetaData;
23 
25 
28 class VTKDICOM_EXPORT vtkDICOMImageCodec
29 {
30 public:
31  enum EnumType
32  {
33  LittleEndian, // 1.2.1 Little endian
34  BigEndian, // 1.2.2 Big endian
35  RLE, // 1.2.5 RLE packbits
36  JPEGBaseline, // 1.2.4.50 JPEG baseline (1)
37  JPEGExtended, // 1.2.4.51 JPEG extended (1,2,4)
38  JPEGLossless, // 1.2.4.57 JPEG lossless (14)
39  JPEGPrediction, // 1.2.4.70 JPEG lossless prediction (14)
40  JPEGLS, // 1.2.4.80 JPEG-LS
41  JPEGLSConstrained, // 1.2.4.81 JPEG-LS constrained error
42  JPEG2K, // 1.2.4.90 JPEG 2000 lossless
43  JPEG2KLossless, // 1.2.4.91 JPEG 2000 lossless/lossy
44  MPEG2ML, // 1.2.4.100 MPEG2 ML
45  MPEG2HL, // 1.2.4.101 MPEG2 HL
46  MPEG4HPL41, // 1.2.4.102 MPEG4 AVC/H.264 High Profile / Level 4.1
47  MPEG4HPL41BD, // 1.2.4.103 MPEG4 AVC/H.264 BD-compatible
48  MPEG4HPL42V2D, // 1.2.4.104 MPEG4 AVC/H.264 High Profile / 4.2 2D
49  MPEG4HPL42V3D, // 1.2.4.105 MPEG4 AVC/H.264 High Profile / 4.2 3D
50  MPEG4HPL42Stereo, // 1.2.4.106 MPEG4 AVC/H.264 Stereo High Profile / 4.2
51  HEVCMPL51, // 1.2.4.107 HEVC/H.265 Main Profile / 5.1
52  HEVCM10PL51, // 1.2.4.108 HEVC/H.265 Main 10 Profile / 5.1
53  NumberOfCodecs
54  };
55 
56  enum ErrorCode
57  {
58  NoError,
59  MissingCodec,
60  BadPixelFormat,
61  MissingData,
62  UnknownError
63  };
64 
66  struct ImageFormat
67  {
68  unsigned short Rows;
69  unsigned short Columns;
70  unsigned short BitsAllocated;
71  unsigned short BitsStored;
72  unsigned short PixelRepresentation;
73  unsigned short SamplesPerPixel;
74  unsigned short PlanarConfiguration;
75  bool AllowLossyCompression;
76 
77  ImageFormat() : Rows(0), Columns(0), BitsAllocated(0), BitsStored(0),
78  PixelRepresentation(0), SamplesPerPixel(0),
79  PlanarConfiguration(0), AllowLossyCompression(false) {}
80 
82  };
83 
85  vtkDICOMImageCodec() : Key(0) {}
87 
89 
92  vtkDICOMImageCodec(int k) : Key(static_cast<unsigned char>(k)) {}
93 
95 
99  explicit vtkDICOMImageCodec(const std::string& syntax);
101 
103 
107  std::string GetTransferSyntaxUID() const;
108 
110  unsigned char GetKey() const { return this->Key; }
112 
114 
120  int Decode(const ImageFormat& image,
121  const unsigned char *source, size_t sourceSize,
122  unsigned char *dest, size_t destSize) const;
123 
125 
129  int Encode(const ImageFormat& image,
130  const unsigned char *source, size_t sourceSize,
131  unsigned char **dest, size_t *destSize) const;
133 
135  bool operator==(vtkDICOMImageCodec b) const { return (this->Key == b.Key); }
136  bool operator!=(vtkDICOMImageCodec b) const { return (this->Key != b.Key); }
137  bool operator<=(vtkDICOMImageCodec a) const { return (this->Key <= a.Key); }
138  bool operator>=(vtkDICOMImageCodec a) const { return (this->Key >= a.Key); }
139  bool operator<(vtkDICOMImageCodec a) const { return (this->Key < a.Key); }
140  bool operator>(vtkDICOMImageCodec a) const { return (this->Key > a.Key); }
142 
143 private:
144  unsigned char Key;
145  static const char *UIDs[21];
146 
147  static int DecodeRLE(
148  const ImageFormat& image,
149  const unsigned char *source, size_t sourceSize,
150  unsigned char *dest, size_t destSize);
151 
152  static int EncodeRLE(
153  const ImageFormat& image,
154  const unsigned char *source, size_t sourceSize,
155  unsigned char **dest, size_t *destSize);
156 
158  static unsigned int UnpackUnsignedInt(const void *source) {
159  const unsigned char *cp = static_cast<const unsigned char *>(source);
160  return cp[0] + (cp[1] << 8) + (cp[2] << 16) + (cp[3] << 24); }
161 };
162 
163 VTKDICOM_EXPORT ostream& operator<<(ostream& o, const vtkDICOMImageCodec& a);
164 
165 #endif /* vtkDICOMImageCodec_h */
166 // VTK-HeaderTest-Exclude: vtkDICOMImageCodec.h
Codecs for encapsulated images.
Definition: vtkDICOMImageCodec.h:29
std::string GetTransferSyntaxUID() const
Get the transfer syntax for this codec.
int Encode(const ImageFormat &image, const unsigned char *source, size_t sourceSize, unsigned char **dest, size_t *destSize) const
Encode a compressed image, and return an allocated destination buffer.
unsigned char GetKey() const
Get the numerical identifier for this codec.
Definition: vtkDICOMImageCodec.h:110
vtkDICOMImageCodec(const std::string &syntax)
Get a codec for the specified transfer syntax UID.
int Decode(const ImageFormat &image, const unsigned char *source, size_t sourceSize, unsigned char *dest, size_t destSize) const
Decode a compressed image into the given destination buffer.
vtkDICOMImageCodec(int k)
Construct a codec object from the given code.
Definition: vtkDICOMImageCodec.h:92
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
A struct to store basic image information for a codec.
Definition: vtkDICOMImageCodec.h:67