Mercurial > hg > orthanc
annotate OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp @ 5485:48b8dae6dc77
upgrade to year 2024
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jan 2024 15:10:42 +0100 |
parents | 57c0fba5e5c7 |
children | f7adfb22e20e |
rev | line source |
---|---|
845 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1206
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5283
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5283
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
845 | 7 * |
8 * 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:
4044
diff
changeset
|
9 * 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:
4044
diff
changeset
|
10 * 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:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
845 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * 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:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
845 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * 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:
4044
diff
changeset
|
19 * 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:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
845 | 21 **/ |
22 | |
23 | |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
24 #include "../../PrecompiledHeaders.h" |
845 | 25 #include "DicomImageDecoder.h" |
26 | |
3744
accf1b60b108
accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
27 #include "../ParsedDicomFile.h" |
accf1b60b108
accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
28 |
846 | 29 |
30 /*========================================================================= | |
31 | |
32 This file is based on portions of the following project | |
33 (cf. function "DecodePsmctRle1()"): | |
34 | |
35 Program: GDCM (Grassroots DICOM). A DICOM library | |
36 Module: http://gdcm.sourceforge.net/Copyright.html | |
37 | |
863 | 38 Copyright (c) 2006-2011 Mathieu Malaterre |
39 Copyright (c) 1993-2005 CREATIS | |
40 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image) | |
41 All rights reserved. | |
846 | 42 |
863 | 43 Redistribution and use in source and binary forms, with or without |
44 modification, are permitted provided that the following conditions are met: | |
846 | 45 |
863 | 46 * Redistributions of source code must retain the above copyright notice, |
47 this list of conditions and the following disclaimer. | |
846 | 48 |
863 | 49 * Redistributions in binary form must reproduce the above copyright notice, |
50 this list of conditions and the following disclaimer in the documentation | |
51 and/or other materials provided with the distribution. | |
846 | 52 |
863 | 53 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any |
54 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to | |
55 endorse or promote products derived from this software without specific | |
56 prior written permission. | |
846 | 57 |
863 | 58 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' |
59 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
60 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
61 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR | |
62 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
63 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
64 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
65 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
66 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
67 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
846 | 68 |
863 | 69 =========================================================================*/ |
846 | 70 |
71 | |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
72 #include "../../Logging.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
73 #include "../../OrthancException.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
74 #include "../../Images/Image.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
75 #include "../../Images/ImageProcessing.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
76 #include "../../DicomFormat/DicomIntegerPixelAccessor.h" |
845 | 77 #include "../ToDcmtkBridge.h" |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
78 #include "../FromDcmtkBridge.h" |
845 | 79 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
80 #if ORTHANC_ENABLE_PNG == 1 |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
81 # include "../../Images/PngWriter.h" |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
82 #endif |
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
83 |
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
84 #if ORTHANC_ENABLE_JPEG == 1 |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
85 # include "../../Images/JpegWriter.h" |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
86 #endif |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
87 #include "../../Images/PamWriter.h" |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
88 |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
89 #include <boost/lexical_cast.hpp> |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
90 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
91 #include <dcmtk/dcmdata/dcdeftag.h> |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
92 #include <dcmtk/dcmdata/dcrleccd.h> |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
93 #include <dcmtk/dcmdata/dcrlecp.h> |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
94 #include <dcmtk/dcmdata/dcrlerp.h> |
4529
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
95 #include <dcmtk/dcmdata/dcswap.h> |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
96 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
97 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
98 # include <dcmtk/dcmjpeg/djrplol.h> |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
99 # include <dcmtk/dcmjpls/djcodecd.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
100 # include <dcmtk/dcmjpls/djcparam.h> |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
101 # include <dcmtk/dcmjpls/djrparam.h> |
845 | 102 #endif |
103 | |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
104 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
105 # include <dcmtk/dcmjpeg/djcodecd.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
106 # include <dcmtk/dcmjpeg/djcparam.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
107 # include <dcmtk/dcmjpeg/djdecbas.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
108 # include <dcmtk/dcmjpeg/djdecext.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
109 # include <dcmtk/dcmjpeg/djdeclol.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
110 # include <dcmtk/dcmjpeg/djdecpro.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
111 # include <dcmtk/dcmjpeg/djdecsps.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
112 # include <dcmtk/dcmjpeg/djdecsv1.h> |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
113 # include <dcmtk/dcmjpeg/djrploss.h> |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
114 #endif |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
115 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
116 #if DCMTK_VERSION_NUMBER <= 360 |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
117 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
118 # define EXS_JPEGProcess2_4 EXS_JPEGProcess2_4TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
119 # define EXS_JPEGProcess6_8 EXS_JPEGProcess6_8TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
120 # define EXS_JPEGProcess10_12 EXS_JPEGProcess10_12TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
121 # define EXS_JPEGProcess14 EXS_JPEGProcess14TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
122 # define EXS_JPEGProcess14SV1 EXS_JPEGProcess14SV1TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
123 #endif |
845 | 124 |
125 namespace Orthanc | |
126 { | |
4529
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
127 static const Endianness ENDIANNESS = Toolbox::DetectEndianness(); |
846 | 128 static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a); |
129 static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011); | |
130 | |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
131 |
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
|
132 bool DicomImageDecoder::IsPsmctRle1(DcmDataset& dataset) |
846 | 133 { |
134 DcmElement* e; | |
135 char* c; | |
136 | |
137 // Check whether the DICOM instance contains an image encoded with | |
138 // the PMSCT_RLE1 scheme. | |
139 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_COMPRESSION_TYPE), e).good() || | |
4184
dbd74fa2f446
Enable the access to raw frames in Philips ELSCINT1 proprietary compression
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4138
diff
changeset
|
140 !dataset.tagExistsWithValue(ToDcmtkBridge::Convert(DICOM_TAG_CONTENT)) || // New in Orthanc 1.7.4 |
846 | 141 e == NULL || |
142 !e->isaString() || | |
143 !e->getString(c).good() || | |
144 c == NULL || | |
145 strcmp("PMSCT_RLE1", c)) | |
146 { | |
147 return false; | |
148 } | |
149 else | |
150 { | |
151 return true; | |
152 } | |
153 } | |
154 | |
155 | |
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
|
156 bool DicomImageDecoder::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
|
157 DcmDataset& dataset) |
846 | 158 { |
159 // Check whether the DICOM instance contains an image encoded with | |
160 // the PMSCT_RLE1 scheme. | |
161 if (!IsPsmctRle1(dataset)) | |
162 { | |
163 return false; | |
164 } | |
165 | |
166 // OK, this is a custom RLE encoding from Philips. Get the pixel | |
167 // data from the appropriate private DICOM tag. | |
168 Uint8* pixData = NULL; | |
169 DcmElement* e; | |
170 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_CONTENT), e).good() || | |
171 e == NULL || | |
172 e->getUint8Array(pixData) != EC_Normal) | |
173 { | |
174 return false; | |
175 } | |
176 | |
177 // The "unsigned" below IS VERY IMPORTANT | |
178 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData); | |
179 const size_t length = e->getLength(); | |
180 | |
181 /** | |
182 * The code below is an adaptation of a sample code for GDCM by | |
183 * Mathieu Malaterre (under a BSD license). | |
184 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html | |
185 **/ | |
186 | |
187 // RLE pass | |
188 std::vector<uint8_t> temp; | |
189 temp.reserve(length); | |
190 for (size_t i = 0; i < length; i++) | |
191 { | |
192 if (inbuffer[i] == 0xa5) | |
193 { | |
194 temp.push_back(inbuffer[i+2]); | |
195 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--) | |
196 { | |
197 temp.push_back(inbuffer[i+2]); | |
198 } | |
199 i += 2; | |
200 } | |
201 else | |
202 { | |
203 temp.push_back(inbuffer[i]); | |
204 } | |
205 } | |
206 | |
207 // Delta encoding pass | |
208 uint16_t delta = 0; | |
209 output.clear(); | |
210 output.reserve(temp.size()); | |
211 for (size_t i = 0; i < temp.size(); i++) | |
212 { | |
213 uint16_t value; | |
214 | |
215 if (temp[i] == 0x5a) | |
216 { | |
217 uint16_t v1 = temp[i + 1]; | |
218 uint16_t v2 = temp[i + 2]; | |
219 value = (v2 << 8) + v1; | |
220 i += 2; | |
221 } | |
222 else | |
223 { | |
224 value = delta + (int8_t) temp[i]; | |
225 } | |
226 | |
227 output.push_back(value & 0xff); | |
228 output.push_back(value >> 8); | |
229 delta = value; | |
230 } | |
231 | |
232 if (output.size() % 2) | |
233 { | |
234 output.resize(output.size() - 1); | |
235 } | |
236 | |
237 return true; | |
238 } | |
239 | |
240 | |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
241 class DicomImageDecoder::ImageSource |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
242 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
243 private: |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
244 std::string psmct_; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
245 std::unique_ptr<DicomIntegerPixelAccessor> slowAccessor_; |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
246 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
247 public: |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
248 void Setup(DcmDataset& dataset, |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
249 unsigned int frame) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
250 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
251 psmct_.clear(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
252 slowAccessor_.reset(NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
253 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
254 // See also: http://support.dcmtk.org/wiki/dcmtk/howto/accessing-compressed-data |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
255 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
256 DicomMap m; |
4137
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
257 std::set<DicomTag> ignoreTagLength; |
4312
6d49e3b6ff77
fix abi of DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
258 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::GetUsefulTagLength(), ignoreTagLength); |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
259 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
260 /** |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
261 * Create an accessor to the raw values of the DICOM image. |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
262 **/ |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
263 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
264 DcmElement* e; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
265 if (dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_PIXEL_DATA), e).good() && |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
266 e != NULL) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
267 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
268 Uint8* pixData = NULL; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
269 if (e->getUint8Array(pixData) == EC_Normal) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
270 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
271 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength())); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
272 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
273 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
274 else if (DecodePsmctRle1(psmct_, dataset)) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
275 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
276 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded"; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
277 Uint8* pixData = NULL; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
278 if (psmct_.size() > 0) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
279 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
280 pixData = reinterpret_cast<Uint8*>(&psmct_[0]); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
281 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
282 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
283 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, psmct_.size())); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
284 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
285 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
286 if (slowAccessor_.get() == NULL) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
287 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
288 throw OrthancException(ErrorCode_BadFileFormat); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
289 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
290 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
291 slowAccessor_->SetCurrentFrame(frame); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
292 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
293 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
294 unsigned int GetWidth() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
295 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
296 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
297 return slowAccessor_->GetInformation().GetWidth(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
298 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
299 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
300 unsigned int GetHeight() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
301 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
302 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
303 return slowAccessor_->GetInformation().GetHeight(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
304 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
305 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
306 unsigned int GetChannelCount() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
307 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
308 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
309 return slowAccessor_->GetInformation().GetChannelCount(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
310 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
311 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
312 const DicomIntegerPixelAccessor& GetAccessor() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
313 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
314 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
315 return *slowAccessor_; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
316 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
317 |
1190 | 318 unsigned int GetSize() const |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
319 { |
1190 | 320 assert(slowAccessor_.get() != NULL); |
321 return slowAccessor_->GetSize(); | |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
322 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
323 }; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
324 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
325 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
326 ImageAccessor* DicomImageDecoder::CreateImage(DcmDataset& dataset, |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
327 bool ignorePhotometricInterpretation) |
845 | 328 { |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
329 DicomMap m; |
4137
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
330 std::set<DicomTag> ignoreTagLength; |
4312
6d49e3b6ff77
fix abi of DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
331 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::GetUsefulTagLength(), ignoreTagLength); |
845 | 332 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
333 DicomImageInformation info(m); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
334 PixelFormat format; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
335 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
336 if (!info.ExtractPixelFormat(format, ignorePhotometricInterpretation)) |
845 | 337 { |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
338 LOG(WARNING) << "Unsupported DICOM image: " << info.GetBitsStored() |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
339 << "bpp, " << info.GetChannelCount() << " channels, " |
860 | 340 << (info.IsSigned() ? "signed" : "unsigned") |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1190
diff
changeset
|
341 << (info.IsPlanar() ? ", planar, " : ", non-planar, ") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1190
diff
changeset
|
342 << EnumerationToString(info.GetPhotometricInterpretation()) |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1190
diff
changeset
|
343 << " photometric interpretation"; |
845 | 344 throw OrthancException(ErrorCode_NotImplemented); |
345 } | |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
346 |
2107 | 347 return new Image(format, info.GetWidth(), info.GetHeight(), false); |
845 | 348 } |
349 | |
350 | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
351 template <typename PixelType> |
4201 | 352 static void CopyPixels(ImageAccessor& target, |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
353 const DicomIntegerPixelAccessor& source) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
354 { |
3525
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
355 // WARNING - "::min()" should be replaced by "::lowest()" if |
8c66c9c2257b
fix ImageProcessing::ShiftScale() on float images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
356 // dealing with float or double (which is not the case so far) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
357 const PixelType minValue = std::numeric_limits<PixelType>::min(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
358 const PixelType maxValue = std::numeric_limits<PixelType>::max(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
359 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
360 const unsigned int height = source.GetInformation().GetHeight(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
361 const unsigned int width = source.GetInformation().GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
362 const unsigned int channels = source.GetInformation().GetChannelCount(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
363 |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
364 for (unsigned int y = 0; y < height; y++) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
365 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
366 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y)); |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
367 for (unsigned int x = 0; x < width; x++) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
368 { |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
369 for (unsigned int c = 0; c < channels; c++, pixel++) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
370 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
371 int32_t v = source.GetValue(x, y, c); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
372 if (v < static_cast<int32_t>(minValue)) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
373 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
374 *pixel = minValue; |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
375 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
376 else if (v > static_cast<int32_t>(maxValue)) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
377 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
378 *pixel = maxValue; |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
379 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
380 else |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
381 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
382 *pixel = static_cast<PixelType>(v); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
383 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
384 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
385 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
386 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
387 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
388 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
389 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
390 static ImageAccessor* DecodeLookupTable(std::unique_ptr<ImageAccessor>& target, |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
391 const DicomImageInformation& info, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
392 DcmDataset& dataset, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
393 const uint8_t* pixelData, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
394 unsigned long pixelLength) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
395 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
396 LOG(INFO) << "Decoding a lookup table"; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
397 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
398 OFString r, g, b; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
399 PixelFormat format; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
400 const uint16_t* lutRed = NULL; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
401 const uint16_t* lutGreen = NULL; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
402 const uint16_t* lutBlue = NULL; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
403 unsigned long rc = 0; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
404 unsigned long gc = 0; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
405 unsigned long bc = 0; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
406 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
407 if (pixelData == NULL && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
408 !dataset.findAndGetUint8Array(DCM_PixelData, pixelData, &pixelLength).good()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
409 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
410 throw OrthancException(ErrorCode_NotImplemented); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
411 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
412 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
413 if (info.IsPlanar() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
414 info.GetNumberOfFrames() != 1 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
415 !info.ExtractPixelFormat(format, false) || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
416 !dataset.findAndGetOFStringArray(DCM_BluePaletteColorLookupTableDescriptor, b).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
417 !dataset.findAndGetOFStringArray(DCM_GreenPaletteColorLookupTableDescriptor, g).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
418 !dataset.findAndGetOFStringArray(DCM_RedPaletteColorLookupTableDescriptor, r).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
419 !dataset.findAndGetUint16Array(DCM_BluePaletteColorLookupTableData, lutBlue, &bc).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
420 !dataset.findAndGetUint16Array(DCM_GreenPaletteColorLookupTableData, lutGreen, &gc).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
421 !dataset.findAndGetUint16Array(DCM_RedPaletteColorLookupTableData, lutRed, &rc).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
422 r != g || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
423 r != b || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
424 g != b || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
425 lutRed == NULL || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
426 lutGreen == NULL || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
427 lutBlue == NULL || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
428 pixelData == NULL) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
429 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
430 throw OrthancException(ErrorCode_NotImplemented); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
431 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
432 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
433 switch (format) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
434 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
435 case PixelFormat_RGB24: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
436 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
437 if (r != "256\\0\\16" || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
438 rc != 256 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
439 gc != 256 || |
4975
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
440 bc != 256) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
441 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
442 throw OrthancException(ErrorCode_NotImplemented); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
443 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
444 |
4975
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
445 if (pixelLength != target->GetWidth() * target->GetHeight()) |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
446 { |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
447 DcmElement *elem; |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
448 Uint16 bitsAllocated = 0; |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
449 |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
450 if (!dataset.findAndGetUint16(DCM_BitsAllocated, bitsAllocated).good()) |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
451 { |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
452 throw OrthancException(ErrorCode_NotImplemented); |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
453 } |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
454 |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
455 if (!dataset.findAndGetElement(DCM_PixelData, elem).good()) |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
456 { |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
457 throw OrthancException(ErrorCode_NotImplemented); |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
458 } |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
459 |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
460 // In implicit VR files, pixelLength is expressed in words (OW) although pixels can actually be 8 bits |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
461 // -> pixelLength is wrong by a factor of two and the image can still be decoded! |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
462 // seen in some Philips ClearVue 650 images (using 8 bits LUT) |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
463 if (!(elem->getVR() == EVR_OW && bitsAllocated == 8 && (2*pixelLength == target->GetWidth() * target->GetHeight()))) |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
464 { |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
465 throw OrthancException(ErrorCode_NotImplemented); |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
466 } |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
467 } |
5e7404f23fa8
Improved decoding of US Images with Implicit VR
Alain Mazy <am@osimis.io>
parents:
4902
diff
changeset
|
468 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
469 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData); |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
470 const unsigned int width = target->GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
471 const unsigned int height = target->GetHeight(); |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
472 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
473 for (unsigned int y = 0; y < height; y++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
474 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
475 uint8_t* p = reinterpret_cast<uint8_t*>(target->GetRow(y)); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
476 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
477 for (unsigned int x = 0; x < width; x++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
478 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
479 p[0] = lutRed[*source] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
480 p[1] = lutGreen[*source] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
481 p[2] = lutBlue[*source] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
482 source++; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
483 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
484 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
485 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
486 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
487 return target.release(); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
488 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
489 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
490 case PixelFormat_RGB48: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
491 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
492 if (r != "0\\0\\16" || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
493 rc != 65536 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
494 gc != 65536 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
495 bc != 65536 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
496 pixelLength != 2 * target->GetWidth() * target->GetHeight()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
497 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
498 throw OrthancException(ErrorCode_NotImplemented); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
499 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
500 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
501 const uint16_t* source = reinterpret_cast<const uint16_t*>(pixelData); |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
502 const unsigned int width = target->GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
503 const unsigned int height = target->GetHeight(); |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
504 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
505 for (unsigned int y = 0; y < height; y++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
506 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
507 uint16_t* p = reinterpret_cast<uint16_t*>(target->GetRow(y)); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
508 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
509 for (unsigned int x = 0; x < width; x++) |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
510 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
511 p[0] = lutRed[*source]; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
512 p[1] = lutGreen[*source]; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
513 p[2] = lutBlue[*source]; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
514 source++; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
515 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
516 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
517 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
518 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
519 return target.release(); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
520 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
521 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
522 default: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
523 break; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
524 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
525 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
526 throw OrthancException(ErrorCode_InternalError); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
527 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
528 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
529 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
530 ImageAccessor* DicomImageDecoder::DecodeUncompressedImage(DcmDataset& dataset, |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
531 unsigned int frame) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
532 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
533 /** |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
534 * Create the target image. |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
535 **/ |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
536 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
537 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, false)); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
538 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
539 ImageSource source; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
540 source.Setup(dataset, frame); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
541 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
542 if (source.GetWidth() != target->GetWidth() || |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
543 source.GetHeight() != target->GetHeight()) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
544 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
545 throw OrthancException(ErrorCode_InternalError); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
546 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
547 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
548 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
549 /** |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
550 * Deal with lookup tables |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
551 **/ |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
552 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
553 const DicomImageInformation& info = source.GetAccessor().GetInformation(); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
554 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
555 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
556 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
557 return DecodeLookupTable(target, info, dataset, NULL, 0); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
558 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
559 |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
560 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
561 /** |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
562 * If the format of the DICOM buffer is natively supported, use a |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
563 * direct access to copy its values. |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
564 **/ |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
565 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
566 bool fastVersionSuccess = false; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
567 PixelFormat sourceFormat; |
863 | 568 if (!info.IsPlanar() && |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
569 info.GetBitsStored() != 1 && // Black-and-white image, notably DICOM SEG (new in Orthanc 1.10.0) |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
570 info.ExtractPixelFormat(sourceFormat, false)) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
571 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
572 try |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
573 { |
1190 | 574 size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat); |
575 if ((frame + 1) * frameSize <= source.GetSize()) | |
576 { | |
577 const uint8_t* buffer = reinterpret_cast<const uint8_t*>(source.GetAccessor().GetPixelData()); | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
578 |
1190 | 579 ImageAccessor sourceImage; |
580 sourceImage.AssignReadOnly(sourceFormat, | |
581 info.GetWidth(), | |
582 info.GetHeight(), | |
583 info.GetWidth() * GetBytesPerPixel(sourceFormat), | |
584 buffer + frame * frameSize); | |
585 | |
4529
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
586 switch (ENDIANNESS) |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
587 { |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
588 case Endianness_Little: |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
589 ImageProcessing::Convert(*target, sourceImage); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
590 break; |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
591 |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
592 case Endianness_Big: |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
593 { |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
594 // We cannot do byte swapping directly on the constant DcmDataset |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
595 std::unique_ptr<ImageAccessor> copy(Image::Clone(sourceImage)); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
596 ImageProcessing::SwapEndianness(*copy); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
597 ImageProcessing::Convert(*target, *copy); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
598 break; |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
599 } |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
600 |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
601 default: |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
602 throw OrthancException(ErrorCode_InternalError); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
603 } |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
604 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
605 ImageProcessing::ShiftRight(*target, info.GetShift()); |
1190 | 606 fastVersionSuccess = true; |
607 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
608 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
609 catch (OrthancException&) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
610 { |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
611 // Unsupported conversion, use the slow version |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
612 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
613 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
614 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
615 /** |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
616 * Slow version : loop over the DICOM buffer, storing its value |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
617 * into the target image. |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
618 **/ |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
619 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
620 if (!fastVersionSuccess) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
621 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
622 switch (target->GetFormat()) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
623 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
624 case PixelFormat_RGB24: |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
625 case PixelFormat_RGBA32: |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
626 case PixelFormat_Grayscale8: |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
627 CopyPixels<uint8_t>(*target, source.GetAccessor()); |
863 | 628 break; |
860 | 629 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
630 case PixelFormat_Grayscale16: |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
631 CopyPixels<uint16_t>(*target, source.GetAccessor()); |
863 | 632 break; |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
633 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
634 case PixelFormat_SignedGrayscale16: |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
635 CopyPixels<int16_t>(*target, source.GetAccessor()); |
863 | 636 break; |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
637 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
638 default: |
863 | 639 throw OrthancException(ErrorCode_InternalError); |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
640 } |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
641 } |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
642 |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
643 return target.release(); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
644 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
645 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
646 |
5129
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
647 static ImageAccessor* DecodePlanarConfiguration(const ImageAccessor& source) |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
648 { |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
649 /** |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
650 * This function will interleave the RGB channels, if the source |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
651 * DICOM image has the "Planar Configuration" (0028,0006) tag that |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
652 * equals 1. This process was not applied to images using the RLE |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
653 * codec, which led to the following issue: |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
654 * https://groups.google.com/g/orthanc-users/c/CSVWfRasSR0/m/y1XDRXVnAgAJ |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
655 **/ |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
656 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
657 const unsigned int height = source.GetHeight(); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
658 const unsigned int width = source.GetWidth(); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
659 const size_t size = static_cast<size_t>(height) * static_cast<size_t>(width); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
660 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
661 if (source.GetFormat() != PixelFormat_RGB24 || |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
662 3 * width != source.GetPitch()) |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
663 { |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
664 throw OrthancException(ErrorCode_NotImplemented); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
665 } |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
666 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
667 std::unique_ptr<ImageAccessor> target(new Image(PixelFormat_RGB24, width, height, false)); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
668 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
669 const uint8_t* red = reinterpret_cast<const uint8_t*>(source.GetConstBuffer()); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
670 const uint8_t* green = red + size; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
671 const uint8_t* blue = red + 2 * size; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
672 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
673 for (unsigned int y = 0; y < height; y++) |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
674 { |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
675 uint8_t* interleaved = reinterpret_cast<uint8_t*>(target->GetRow(y)); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
676 for (unsigned int x = 0; x < width; x++) |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
677 { |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
678 interleaved[0] = *red; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
679 interleaved[1] = *green; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
680 interleaved[2] = *blue; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
681 interleaved += 3; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
682 red++; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
683 green++; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
684 blue++; |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
685 } |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
686 } |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
687 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
688 return target.release(); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
689 } |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
690 |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
691 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
692 ImageAccessor* DicomImageDecoder::ApplyCodec |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
693 (const DcmCodec& codec, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
694 const DcmCodecParameter& parameters, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
695 const DcmRepresentationParameter& representationParameter, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
696 DcmDataset& dataset, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
697 unsigned int frame) |
1903 | 698 { |
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
|
699 DcmPixelSequence* pixelSequence = FromDcmtkBridge::GetPixelSequence(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
|
700 if (pixelSequence == NULL) |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
701 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
702 throw OrthancException(ErrorCode_BadFileFormat); |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
703 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
704 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
705 DicomMap m; |
4137
6774605d4341
keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4136
diff
changeset
|
706 std::set<DicomTag> ignoreTagLength; |
4312
6d49e3b6ff77
fix abi of DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
707 FromDcmtkBridge::ExtractDicomSummary(m, dataset, DicomImageInformation::GetUsefulTagLength(), ignoreTagLength); |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
708 DicomImageInformation info(m); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
709 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
710 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, true)); |
845 | 711 |
712 Uint32 startFragment = 0; // Default | |
713 OFString decompressedColorModel; // Out | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
714 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
715 OFCondition c; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
716 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
717 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
718 info.GetChannelCount() == 1) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
719 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
720 std::string uncompressed; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
721 uncompressed.resize(info.GetWidth() * info.GetHeight() * info.GetBytesPerValue()); |
845 | 722 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
723 if (uncompressed.size() == 0 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
724 !codec.decodeFrame(&representationParameter, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
725 pixelSequence, ¶meters, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
726 &dataset, frame, startFragment, &uncompressed[0], |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
727 uncompressed.size(), decompressedColorModel).good()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
728 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2699
diff
changeset
|
729 throw OrthancException(ErrorCode_BadFileFormat, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2699
diff
changeset
|
730 "Cannot decode a palette image"); |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
731 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
732 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
733 return DecodeLookupTable(target, info, dataset, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
734 reinterpret_cast<const uint8_t*>(uncompressed.c_str()), |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
735 uncompressed.size()); |
845 | 736 } |
1903 | 737 else |
738 { | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
739 if (!codec.decodeFrame(&representationParameter, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
740 pixelSequence, ¶meters, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
741 &dataset, frame, startFragment, target->GetBuffer(), |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
742 target->GetSize(), decompressedColorModel).good()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
743 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2699
diff
changeset
|
744 throw OrthancException(ErrorCode_BadFileFormat, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2699
diff
changeset
|
745 "Cannot decode a non-palette image"); |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
746 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
747 |
5283
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
748 std::string colorModel = Orthanc::Toolbox::StripSpaces(decompressedColorModel.c_str()); |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
749 |
5129
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
750 if (target->GetFormat() == PixelFormat_RGB24 && |
5283
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
751 (colorModel == "RGB" || colorModel == "YBR_FULL") && |
5129
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
752 info.IsPlanar()) |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
753 { |
5283
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
754 std::unique_ptr<ImageAccessor> output(DecodePlanarConfiguration(*target)); |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
755 |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
756 if (colorModel == "YBR_FULL") |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
757 { |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
758 ImageProcessing::ConvertJpegYCbCrToRgb(*output); |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
759 } |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
760 |
57c0fba5e5c7
fix decoding of YBR_FULL RLE images with PlanarConfiguration=1
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
761 return output.release(); |
5129
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
762 } |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
763 else |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
764 { |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
765 return target.release(); |
16138d6d568d
fix decoding of RLE images for which the "Planar Configuration" tag (0028,0006) equals 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4975
diff
changeset
|
766 } |
1903 | 767 } |
845 | 768 } |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
769 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
770 |
4529
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
771 static void UndoBigEndianSwapping(ImageAccessor& decoded) |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
772 { |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
773 if (ENDIANNESS == Endianness_Big && |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
774 decoded.GetFormat() == PixelFormat_Grayscale8) |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
775 { |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
776 /** |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
777 * Undo the call to "swapIfNecessary()" that is done in |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
778 * "dcmjpeg/libsrc/djcodecd.cc" and "dcmjpls/libsrc/djcodecd.cc" |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
779 * if "jpeg->bytesPerSample() == 1", presumably because DCMTK |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
780 * plans for DICOM-to-DICOM conversion |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
781 **/ |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
782 if (decoded.GetPitch() % 2 == 0) |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
783 { |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
784 swapBytes(decoded.GetBuffer(), decoded.GetPitch() * decoded.GetHeight(), sizeof(uint16_t)); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
785 } |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
786 else |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
787 { |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
788 throw OrthancException(ErrorCode_InternalError, "Cannot swap the bytes of an image that has an odd width"); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
789 } |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
790 } |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
791 } |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
792 |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
793 |
3744
accf1b60b108
accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
794 ImageAccessor* DicomImageDecoder::Decode(DcmDataset& dataset, |
accf1b60b108
accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
795 unsigned int frame) |
accf1b60b108
accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
796 { |
3883
795c9ca5eb91
DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3744
diff
changeset
|
797 E_TransferSyntax syntax = dataset.getCurrentXfer(); |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
798 |
1903 | 799 /** |
800 * Deal with uncompressed, raw images. | |
801 * http://support.dcmtk.org/docs/dcxfer_8h-source.html | |
802 **/ | |
1904 | 803 if (syntax == EXS_Unknown || |
804 syntax == EXS_LittleEndianImplicit || | |
805 syntax == EXS_BigEndianImplicit || | |
806 syntax == EXS_LittleEndianExplicit || | |
807 syntax == EXS_BigEndianExplicit) | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
808 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
809 return DecodeUncompressedImage(dataset, frame); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
810 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
811 |
1904 | 812 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
813 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
1904 | 814 /** |
815 * Deal with JPEG-LS images. | |
816 **/ | |
817 | |
818 if (syntax == EXS_JPEGLSLossless || | |
819 syntax == EXS_JPEGLSLossy) | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
820 { |
2430
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
821 // The (2, OFTrue) are the default parameters as found in DCMTK 3.6.2 |
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
822 // http://support.dcmtk.org/docs/classDJLSRepresentationParameter.html |
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
823 DJLSRepresentationParameter representationParameter(2, OFTrue); |
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
824 |
1904 | 825 DJLSCodecParameter parameters; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
826 std::unique_ptr<DJLSDecoderBase> decoder; |
1903 | 827 |
1904 | 828 switch (syntax) |
829 { | |
830 case EXS_JPEGLSLossless: | |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
831 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image"; |
1904 | 832 decoder.reset(new DJLSLosslessDecoder); |
833 break; | |
834 | |
835 case EXS_JPEGLSLossy: | |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
836 LOG(INFO) << "Decoding a JPEG-LS near-lossless DICOM image"; |
1904 | 837 decoder.reset(new DJLSNearLosslessDecoder); |
838 break; | |
1903 | 839 |
1904 | 840 default: |
841 throw OrthancException(ErrorCode_InternalError); | |
842 } | |
843 | |
4529
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
844 std::unique_ptr<ImageAccessor> result(ApplyCodec(*decoder, parameters, representationParameter, dataset, frame)); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
845 UndoBigEndianSwapping(*result); // New in Orthanc 1.9.1 to decode on big-endian architectures |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
846 return result.release(); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
847 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
848 #endif |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
849 |
852 | 850 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
851 #if ORTHANC_ENABLE_DCMTK_JPEG == 1 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
852 /** |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
853 * Deal with JPEG images. |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
854 **/ |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
855 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
856 if (syntax == EXS_JPEGProcess1 || // DJDecoderBaseline |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
857 syntax == EXS_JPEGProcess2_4 || // DJDecoderExtended |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
858 syntax == EXS_JPEGProcess6_8 || // DJDecoderSpectralSelection (retired) |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
859 syntax == EXS_JPEGProcess10_12 || // DJDecoderProgressive (retired) |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
860 syntax == EXS_JPEGProcess14 || // DJDecoderLossless |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
861 syntax == EXS_JPEGProcess14SV1) // DJDecoderP14SV1 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
862 { |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
863 // http://support.dcmtk.org/docs-snapshot/djutils_8h.html#a2a9695e5b6b0f5c45a64c7f072c1eb9d |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
864 DJCodecParameter parameters( |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
865 ECC_lossyYCbCr, // Mode for color conversion for compression, Unused for decompression |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
866 EDC_photometricInterpretation, // Perform color space conversion from YCbCr to RGB if DICOM photometric interpretation indicates YCbCr |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
867 EUC_default, // Mode for UID creation, unused for decompression |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
868 EPC_default); // Automatically determine whether color-by-plane is required from the SOP Class UID and decompressed photometric interpretation |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
869 DJ_RPLossy representationParameter; |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
870 std::unique_ptr<DJCodecDecoder> decoder; |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
871 |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
872 switch (syntax) |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
873 { |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
874 case EXS_JPEGProcess1: |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
875 LOG(INFO) << "Decoding a JPEG baseline (process 1) DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
876 decoder.reset(new DJDecoderBaseline); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
877 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
878 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
879 case EXS_JPEGProcess2_4 : |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
880 LOG(INFO) << "Decoding a JPEG baseline (processes 2 and 4) DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
881 decoder.reset(new DJDecoderExtended); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
882 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
883 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
884 case EXS_JPEGProcess6_8: // Retired |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
885 LOG(INFO) << "Decoding a JPEG spectral section, nonhierarchical (processes 6 and 8) DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
886 decoder.reset(new DJDecoderSpectralSelection); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
887 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
888 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
889 case EXS_JPEGProcess10_12: // Retired |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
890 LOG(INFO) << "Decoding a JPEG full progression, nonhierarchical (processes 10 and 12) DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
891 decoder.reset(new DJDecoderProgressive); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
892 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
893 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
894 case EXS_JPEGProcess14: |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
895 LOG(INFO) << "Decoding a JPEG lossless, nonhierarchical (process 14) DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
896 decoder.reset(new DJDecoderLossless); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
897 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
898 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
899 case EXS_JPEGProcess14SV1: |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
900 LOG(INFO) << "Decoding a JPEG lossless, nonhierarchical, first-order prediction (process 14 selection value 1) DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
901 decoder.reset(new DJDecoderP14SV1); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
902 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
903 |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
904 default: |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
905 throw OrthancException(ErrorCode_InternalError); |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
906 } |
4529
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
907 |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
908 std::unique_ptr<ImageAccessor> result(ApplyCodec(*decoder, parameters, representationParameter, dataset, frame)); |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
909 UndoBigEndianSwapping(*result); // New in Orthanc 1.9.1 to decode on big-endian architectures |
5774fe497ff2
fix decoding of images on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
910 return result.release(); |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
911 } |
852 | 912 #endif |
913 | |
1904 | 914 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
915 if (syntax == EXS_RLELossless) |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
916 { |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
917 LOG(INFO) << "Decoding a RLE lossless DICOM image"; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
918 DcmRLECodecParameter parameters; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
919 DcmRLECodecDecoder decoder; |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
920 DcmRLERepresentationParameter representationParameter; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
921 return ApplyCodec(decoder, parameters, representationParameter, dataset, frame); |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
922 } |
1904 | 923 |
924 | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
925 /** |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
926 * This DICOM image format is not natively supported by |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
927 * Orthanc. As a last resort, try and decode it through DCMTK by |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
928 * converting its transfer syntax to Little Endian. This will |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
929 * result in higher memory consumption. This is actually the |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
930 * second example of the following page: |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
931 * http://support.dcmtk.org/docs/mod_dcmjpeg.html#Examples |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
932 **/ |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
933 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
934 { |
3932
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
935 LOG(INFO) << "Trying to decode a compressed image by transcoding it to Little Endian Explicit"; |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
936 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
937 std::unique_ptr<DcmDataset> converted(dynamic_cast<DcmDataset*>(dataset.clone())); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
938 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
939 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
940 if (converted->canWriteXfer(EXS_LittleEndianExplicit)) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
941 { |
1903 | 942 return DecodeUncompressedImage(*converted, frame); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
943 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
944 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
945 |
3932
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
946 DicomTransferSyntax s; |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
947 if (FromDcmtkBridge::LookupOrthancTransferSyntax(s, dataset.getCurrentXfer())) |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
948 { |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
949 throw OrthancException(ErrorCode_NotImplemented, |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
950 "The built-in DCMTK decoder cannot decode some DICOM instance " |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
951 "whose transfer syntax is: " + std::string(GetTransferSyntaxUid(s))); |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
952 } |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
953 else |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
954 { |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
955 throw OrthancException(ErrorCode_NotImplemented, |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
956 "The built-in DCMTK decoder cannot decode some DICOM instance"); |
bf46e10de8ae
clarifying debug message
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3883
diff
changeset
|
957 } |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
958 } |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
959 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
960 |
1015
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
961 static bool IsColorImage(PixelFormat format) |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
962 { |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
963 return (format == PixelFormat_RGB24 || |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
964 format == PixelFormat_RGBA32); |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
965 } |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
966 |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
967 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
968 bool DicomImageDecoder::TruncateDecodedImage(std::unique_ptr<ImageAccessor>& image, |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
969 PixelFormat format, |
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
970 bool allowColorConversion) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
971 { |
1015
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
972 // If specified, prevent the conversion between color and |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
973 // grayscale images |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
974 bool isSourceColor = IsColorImage(image->GetFormat()); |
1015
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
975 bool isTargetColor = IsColorImage(format); |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
976 |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
977 if (!allowColorConversion) |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
978 { |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
979 if (isSourceColor ^ isTargetColor) |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
980 { |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
981 return false; |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
982 } |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
983 } |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
984 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
985 if (image->GetFormat() != format) |
863 | 986 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
987 // A conversion is required |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
988 std::unique_ptr<ImageAccessor> target |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
989 (new Image(format, image->GetWidth(), image->GetHeight(), false)); |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
990 ImageProcessing::Convert(*target, *image); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
991 |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
992 #if __cplusplus < 201103L |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
993 image.reset(target.release()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
994 #else |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
995 image = std::move(target); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
996 #endif |
863 | 997 } |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
998 |
863 | 999 return true; |
1000 } | |
1001 | |
1002 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1003 bool DicomImageDecoder::PreviewDecodedImage(std::unique_ptr<ImageAccessor>& image) |
863 | 1004 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1005 switch (image->GetFormat()) |
861 | 1006 { |
863 | 1007 case PixelFormat_RGB24: |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1008 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1009 // Directly return color images without modification (RGB) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1010 return true; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1011 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1012 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1013 case PixelFormat_RGB48: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1014 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1015 std::unique_ptr<ImageAccessor> target |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1016 (new Image(PixelFormat_RGB24, image->GetWidth(), image->GetHeight(), false)); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1017 ImageProcessing::Convert(*target, *image); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1018 |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1019 #if __cplusplus < 201103L |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1020 image.reset(target.release()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1021 #else |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1022 image = std::move(target); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1023 #endif |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1024 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1025 return true; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1026 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1027 |
863 | 1028 case PixelFormat_Grayscale8: |
1029 case PixelFormat_Grayscale16: | |
1030 case PixelFormat_SignedGrayscale16: | |
1031 { | |
1032 // Grayscale image: Stretch its dynamics to the [0,255] range | |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1033 int64_t a, b; |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
1034 ImageProcessing::GetMinMaxIntegerValue(a, b, *image); |
863 | 1035 |
1036 if (a == b) | |
1037 { | |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1038 ImageProcessing::Set(*image, 0); |
863 | 1039 } |
1040 else | |
1041 { | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1042 ImageProcessing::ShiftScale(*image, static_cast<float>(-a), |
2488
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1043 255.0f / static_cast<float>(b - a), |
345725b9350c
back to rounding to fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1044 true /* TODO - Consider using "false" to speed up */); |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1045 } |
863 | 1046 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1047 // If the source image is not grayscale 8bpp, convert it |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1048 if (image->GetFormat() != PixelFormat_Grayscale8) |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1049 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1050 std::unique_ptr<ImageAccessor> target |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
1051 (new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false)); |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
1052 ImageProcessing::Convert(*target, *image); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1053 |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1054 #if __cplusplus < 201103L |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1055 image.reset(target.release()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1056 #else |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1057 image = std::move(target); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1058 #endif |
863 | 1059 } |
1060 | |
1061 return true; | |
1062 } | |
1063 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1064 default: |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1065 throw OrthancException(ErrorCode_NotImplemented); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1066 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
1067 } |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1068 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1069 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1070 void DicomImageDecoder::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
|
1071 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1072 bool invert) |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1073 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1074 if (image.get() == NULL) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1075 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1076 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1077 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1078 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1079 bool ok = false; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1080 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1081 switch (mode) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1082 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1083 case ImageExtractionMode_UInt8: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1084 ok = TruncateDecodedImage(image, PixelFormat_Grayscale8, false); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1085 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1086 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1087 case ImageExtractionMode_UInt16: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1088 ok = TruncateDecodedImage(image, PixelFormat_Grayscale16, false); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1089 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1090 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1091 case ImageExtractionMode_Int16: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1092 ok = TruncateDecodedImage(image, PixelFormat_SignedGrayscale16, false); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1093 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1094 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1095 case ImageExtractionMode_Preview: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1096 ok = PreviewDecodedImage(image); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1097 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1098 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1099 default: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1100 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1101 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1102 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1103 if (ok) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1104 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1105 assert(image.get() != NULL); |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1106 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1107 if (invert) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1108 { |
4297 | 1109 ImageProcessing::Invert(*image); |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1110 } |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1111 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1112 else |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1113 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1114 throw OrthancException(ErrorCode_NotImplemented); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1115 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1116 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1117 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1118 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1119 void DicomImageDecoder::ExtractPamImage(std::string& result, |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1120 std::unique_ptr<ImageAccessor>& image, |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1121 ImageExtractionMode mode, |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1122 bool invert) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1123 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1124 ApplyExtractionMode(image, mode, invert); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1125 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1126 PamWriter writer; |
4311
cb9aef006229
turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
1127 IImageWriter::WriteToMemory(writer, result, *image); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1128 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2488
diff
changeset
|
1129 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1130 #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
|
1131 void DicomImageDecoder::ExtractPngImage(std::string& result, |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1132 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
|
1133 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1134 bool invert) |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1135 { |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1136 ApplyExtractionMode(image, mode, invert); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1137 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1138 PngWriter writer; |
4311
cb9aef006229
turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
1139 IImageWriter::WriteToMemory(writer, result, *image); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1140 } |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1141 #endif |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1142 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1143 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1144 #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
|
1145 void DicomImageDecoder::ExtractJpegImage(std::string& result, |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
1146 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
|
1147 ImageExtractionMode mode, |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1148 bool invert, |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1149 uint8_t quality) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1150 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1151 if (mode != ImageExtractionMode_UInt8 && |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1152 mode != ImageExtractionMode_Preview) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1153 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1154 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1155 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1156 |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
1157 ApplyExtractionMode(image, mode, invert); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1158 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1159 JpegWriter writer; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1160 writer.SetQuality(quality); |
4311
cb9aef006229
turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
1161 IImageWriter::WriteToMemory(writer, result, *image); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
1162 } |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
1163 #endif |
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
|
1164 |
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
|
1165 |
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
|
1166 #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
|
1167 ImageAccessor *DicomImageDecoder::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
|
1168 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
|
1169 { |
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
|
1170 return Decode(*dataset.GetDcmtkObject().getDataset(), 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
|
1171 } |
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
|
1172 #endif |
845 | 1173 } |