vtk-dicom  0.8.17
vtkDICOMImageCodec.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2024 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  JPEG2KLossless, // 1.2.4.90 JPEG 2000 lossless
43  JPEG2K, // 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  JPEGXLLossless, // 1.2.4.110 JPEG XL Lossless
54  JPEGXLRecomp, // 1.2.4.111 JPEG XL JPEG Recompression
55  JPEGXL, // 1.2.4.112 JPEG XL
56  NumberOfCodecs
57  };
58 
59  enum ErrorCode
60  {
61  NoError,
62  MissingCodec,
63  BadPixelFormat,
64  MissingData,
65  UnknownError
66  };
67 
69  struct ImageFormat
70  {
71  unsigned short Rows;
72  unsigned short Columns;
73  unsigned short BitsAllocated;
74  unsigned short BitsStored;
75  unsigned short PixelRepresentation;
76  unsigned short SamplesPerPixel;
77  unsigned short PlanarConfiguration;
78  bool AllowLossyCompression;
79 
80  ImageFormat() : Rows(0), Columns(0), BitsAllocated(0), BitsStored(0),
81  PixelRepresentation(0), SamplesPerPixel(0),
82  PlanarConfiguration(0), AllowLossyCompression(false) {}
83 
85  };
86 
88  vtkDICOMImageCodec() : Key(0) {}
90 
92 
95  vtkDICOMImageCodec(int k) : Key(static_cast<unsigned char>(k)) {}
96 
98 
102  explicit vtkDICOMImageCodec(const std::string& syntax);
104 
106 
110  std::string GetTransferSyntaxUID() const;
111 
113  unsigned char GetKey() const { return this->Key; }
115 
117 
123  int Decode(const ImageFormat& image,
124  const unsigned char *source, size_t sourceSize,
125  unsigned char *dest, size_t destSize) const;
126 
128 
132  int Encode(const ImageFormat& image,
133  const unsigned char *source, size_t sourceSize,
134  unsigned char **dest, size_t *destSize) const;
136 
138  bool operator==(vtkDICOMImageCodec b) const { return (this->Key == b.Key); }
139  bool operator!=(vtkDICOMImageCodec b) const { return (this->Key != b.Key); }
140  bool operator<=(vtkDICOMImageCodec a) const { return (this->Key <= a.Key); }
141  bool operator>=(vtkDICOMImageCodec a) const { return (this->Key >= a.Key); }
142  bool operator<(vtkDICOMImageCodec a) const { return (this->Key < a.Key); }
143  bool operator>(vtkDICOMImageCodec a) const { return (this->Key > a.Key); }
145 
146 private:
147  unsigned char Key;
148  static const char *UIDs[24];
149 
150  static int DecodeRLE(
151  const ImageFormat& image,
152  const unsigned char *source, size_t sourceSize,
153  unsigned char *dest, size_t destSize);
154 
155  static int EncodeRLE(
156  const ImageFormat& image,
157  const unsigned char *source, size_t sourceSize,
158  unsigned char **dest, size_t *destSize);
159 
161  static unsigned int UnpackUnsignedInt(const void *source) {
162  const unsigned char *cp = static_cast<const unsigned char *>(source);
163  return cp[0] + (cp[1] << 8) + (cp[2] << 16) + (cp[3] << 24); }
164 };
165 
166 VTKDICOM_EXPORT ostream& operator<<(ostream& o, const vtkDICOMImageCodec& a);
167 
168 #endif /* vtkDICOMImageCodec_h */
169 // 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:113
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:95
A container class for DICOM metadata.
Definition: vtkDICOMMetaData.h:44
A struct to store basic image information for a codec.
Definition: vtkDICOMImageCodec.h:70