annotate OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.h @ 5814:122fd5f97d39

fix
author Alain Mazy <am@orthanc.team>
date Wed, 25 Sep 2024 16:36:04 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1826
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1015
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
12 * the License, or (at your option) any later version.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * Lesser General Public License for more details.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
21 * <http://www.gnu.org/licenses/>.
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #pragma once
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
27 #include "../../Compatibility.h"
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
28 #include "../../Images/ImageAccessor.h"
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
30 #include <memory>
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
2137
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
32 #if !defined(ORTHANC_ENABLE_JPEG)
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
33 # error The macro ORTHANC_ENABLE_JPEG must be defined
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
34 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
35
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
36 #if !defined(ORTHANC_ENABLE_PNG)
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
37 # error The macro ORTHANC_ENABLE_PNG must be defined
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
38 #endif
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
39
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
40 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG)
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
41 # error The macro ORTHANC_ENABLE_DCMTK_JPEG must be defined
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
42 #endif
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
43
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
44 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS)
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
45 # error The macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined
2137
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
46 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
47
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1924
diff changeset
48
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
49 class DcmDataset;
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
50 class DcmCodec;
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
51 class DcmCodecParameter;
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
52 class DcmRepresentationParameter;
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
53
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 namespace Orthanc
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
56 class ParsedDicomFile;
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
57
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
58 class ORTHANC_PUBLIC DicomImageDecoder : public boost::noncopyable
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
60 private:
852
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 847
diff changeset
61 class ImageSource;
5944b8b80842 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 847
diff changeset
62
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
63 DicomImageDecoder() // This is a fully abstract class, no constructor
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
64 {
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
65 }
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
66
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
67 static ImageAccessor* CreateImage(DcmDataset& dataset,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
68 bool ignorePhotometricInterpretation);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
69
1826
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
70 static ImageAccessor* DecodeUncompressedImage(DcmDataset& dataset,
ac5b0b4e2434 refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1824
diff changeset
71 unsigned int frame);
847
03ea55da7429 fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 846
diff changeset
72
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
73 static ImageAccessor* ApplyCodec(const DcmCodec& codec,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
74 const DcmCodecParameter& parameters,
2423
5a7c5c541a1d Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
75 const DcmRepresentationParameter& representationParameter,
1905
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
76 DcmDataset& dataset,
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
77 unsigned int frame);
8b1baa2315b8 Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1903
diff changeset
78
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
79 static bool TruncateDecodedImage(std::unique_ptr<ImageAccessor>& image,
1824
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
80 PixelFormat format,
b530c3dfe2a6 refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
81 bool allowColorConversion);
859
610a9a1ed855 ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 852
diff changeset
82
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
83 static bool PreviewDecodedImage(std::unique_ptr<ImageAccessor>& image);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
84
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
85 static void ApplyExtractionMode(std::unique_ptr<ImageAccessor>& image,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
86 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
87 bool invert);
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
88
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
89 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
90 // Alias for binary compatibility with Orthanc Framework 1.7.2 => don't use it anymore
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
91 static ImageAccessor *Decode(ParsedDicomFile& dataset,
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
92 unsigned int frame);
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
93 #endif
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
94
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
95 public:
1924
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
96 static bool IsPsmctRle1(DcmDataset& dataset);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
97
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
98 static bool DecodePsmctRle1(std::string& output,
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
99 DcmDataset& dataset);
6c73df12ca51 New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1905
diff changeset
100
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
101 static ImageAccessor *Decode(DcmDataset& dataset,
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
102 unsigned int frame);
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
103
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
104 static void ExtractPamImage(std::string& result,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
105 std::unique_ptr<ImageAccessor>& image,
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
106 ImageExtractionMode mode,
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
107 bool invert);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
108
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
109 #if ORTHANC_ENABLE_PNG == 1
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
110 static void ExtractPngImage(std::string& result,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
111 std::unique_ptr<ImageAccessor>& image,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
112 ImageExtractionMode mode,
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
113 bool invert);
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
114 #endif
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
115
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
116 #if ORTHANC_ENABLE_JPEG == 1
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
117 static void ExtractJpegImage(std::string& result,
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
118 std::unique_ptr<ImageAccessor>& image,
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
119 ImageExtractionMode mode,
2281
e002430baa41 Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
120 bool invert,
1902
8b0ee8d5e6d0 Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
121 uint8_t quality);
2380
96b3ec054b69 reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2281
diff changeset
122 #endif
845
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 };
48016722c770 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }