Mercurial > hg > orthanc
annotate Core/DicomParsing/Internals/DicomImageDecoder.cpp @ 2513:97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Mar 2018 18:02:07 +0200 |
parents | 345725b9350c |
children | 52217dc47a4e |
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 |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2430
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
845 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
34 #include "../../PrecompiledHeaders.h" |
845 | 35 #include "DicomImageDecoder.h" |
36 | |
846 | 37 |
38 /*========================================================================= | |
39 | |
40 This file is based on portions of the following project | |
41 (cf. function "DecodePsmctRle1()"): | |
42 | |
43 Program: GDCM (Grassroots DICOM). A DICOM library | |
44 Module: http://gdcm.sourceforge.net/Copyright.html | |
45 | |
863 | 46 Copyright (c) 2006-2011 Mathieu Malaterre |
47 Copyright (c) 1993-2005 CREATIS | |
48 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image) | |
49 All rights reserved. | |
846 | 50 |
863 | 51 Redistribution and use in source and binary forms, with or without |
52 modification, are permitted provided that the following conditions are met: | |
846 | 53 |
863 | 54 * Redistributions of source code must retain the above copyright notice, |
55 this list of conditions and the following disclaimer. | |
846 | 56 |
863 | 57 * Redistributions in binary form must reproduce the above copyright notice, |
58 this list of conditions and the following disclaimer in the documentation | |
59 and/or other materials provided with the distribution. | |
846 | 60 |
863 | 61 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any |
62 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to | |
63 endorse or promote products derived from this software without specific | |
64 prior written permission. | |
846 | 65 |
863 | 66 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' |
67 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
68 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
69 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR | |
70 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
71 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
72 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
73 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
74 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
75 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
846 | 76 |
863 | 77 =========================================================================*/ |
846 | 78 |
79 | |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
80 #include "../../Logging.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
81 #include "../../OrthancException.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
82 #include "../../Images/Image.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
83 #include "../../Images/ImageProcessing.h" |
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2381
diff
changeset
|
84 #include "../../DicomFormat/DicomIntegerPixelAccessor.h" |
845 | 85 #include "../ToDcmtkBridge.h" |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
86 #include "../FromDcmtkBridge.h" |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
87 #include "../ParsedDicomFile.h" |
845 | 88 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
89 #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
|
90 # include "../../Images/PngWriter.h" |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
91 #endif |
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
92 |
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
93 #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
|
94 # include "../../Images/JpegWriter.h" |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
95 #endif |
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
96 |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
97 #include <boost/lexical_cast.hpp> |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
98 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
99 #include <dcmtk/dcmdata/dcdeftag.h> |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
100 #include <dcmtk/dcmdata/dcfilefo.h> |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
101 #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
|
102 #include <dcmtk/dcmdata/dcrlecp.h> |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
103 #include <dcmtk/dcmdata/dcrlerp.h> |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
104 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
105 #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
|
106 # include <dcmtk/dcmjpeg/djrplol.h> |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
107 # include <dcmtk/dcmjpls/djcodecd.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
108 # include <dcmtk/dcmjpls/djcparam.h> |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
109 # include <dcmtk/dcmjpls/djrparam.h> |
845 | 110 #endif |
111 | |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
112 #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
|
113 # include <dcmtk/dcmjpeg/djcodecd.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
114 # include <dcmtk/dcmjpeg/djcparam.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
115 # include <dcmtk/dcmjpeg/djdecbas.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
116 # include <dcmtk/dcmjpeg/djdecext.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
117 # include <dcmtk/dcmjpeg/djdeclol.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
118 # include <dcmtk/dcmjpeg/djdecpro.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
119 # include <dcmtk/dcmjpeg/djdecsps.h> |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
120 # include <dcmtk/dcmjpeg/djdecsv1.h> |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
121 # 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
|
122 #endif |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
123 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
124 #if DCMTK_VERSION_NUMBER <= 360 |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
125 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
126 # 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
|
127 # 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
|
128 # 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
|
129 # define EXS_JPEGProcess14 EXS_JPEGProcess14TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
130 # define EXS_JPEGProcess14SV1 EXS_JPEGProcess14SV1TransferSyntax |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
131 #endif |
845 | 132 |
133 namespace Orthanc | |
134 { | |
846 | 135 static const DicomTag DICOM_TAG_CONTENT(0x07a1, 0x100a); |
136 static const DicomTag DICOM_TAG_COMPRESSION_TYPE(0x07a1, 0x1011); | |
137 | |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
138 |
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
|
139 bool DicomImageDecoder::IsPsmctRle1(DcmDataset& dataset) |
846 | 140 { |
141 DcmElement* e; | |
142 char* c; | |
143 | |
144 // Check whether the DICOM instance contains an image encoded with | |
145 // the PMSCT_RLE1 scheme. | |
146 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_COMPRESSION_TYPE), e).good() || | |
147 e == NULL || | |
148 !e->isaString() || | |
149 !e->getString(c).good() || | |
150 c == NULL || | |
151 strcmp("PMSCT_RLE1", c)) | |
152 { | |
153 return false; | |
154 } | |
155 else | |
156 { | |
157 return true; | |
158 } | |
159 } | |
160 | |
161 | |
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
|
162 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
|
163 DcmDataset& dataset) |
846 | 164 { |
165 // Check whether the DICOM instance contains an image encoded with | |
166 // the PMSCT_RLE1 scheme. | |
167 if (!IsPsmctRle1(dataset)) | |
168 { | |
169 return false; | |
170 } | |
171 | |
172 // OK, this is a custom RLE encoding from Philips. Get the pixel | |
173 // data from the appropriate private DICOM tag. | |
174 Uint8* pixData = NULL; | |
175 DcmElement* e; | |
176 if (!dataset.findAndGetElement(ToDcmtkBridge::Convert(DICOM_TAG_CONTENT), e).good() || | |
177 e == NULL || | |
178 e->getUint8Array(pixData) != EC_Normal) | |
179 { | |
180 return false; | |
181 } | |
182 | |
183 // The "unsigned" below IS VERY IMPORTANT | |
184 const uint8_t* inbuffer = reinterpret_cast<const uint8_t*>(pixData); | |
185 const size_t length = e->getLength(); | |
186 | |
187 /** | |
188 * The code below is an adaptation of a sample code for GDCM by | |
189 * Mathieu Malaterre (under a BSD license). | |
190 * http://gdcm.sourceforge.net/html/rle2img_8cxx-example.html | |
191 **/ | |
192 | |
193 // RLE pass | |
194 std::vector<uint8_t> temp; | |
195 temp.reserve(length); | |
196 for (size_t i = 0; i < length; i++) | |
197 { | |
198 if (inbuffer[i] == 0xa5) | |
199 { | |
200 temp.push_back(inbuffer[i+2]); | |
201 for (uint8_t repeat = inbuffer[i + 1]; repeat != 0; repeat--) | |
202 { | |
203 temp.push_back(inbuffer[i+2]); | |
204 } | |
205 i += 2; | |
206 } | |
207 else | |
208 { | |
209 temp.push_back(inbuffer[i]); | |
210 } | |
211 } | |
212 | |
213 // Delta encoding pass | |
214 uint16_t delta = 0; | |
215 output.clear(); | |
216 output.reserve(temp.size()); | |
217 for (size_t i = 0; i < temp.size(); i++) | |
218 { | |
219 uint16_t value; | |
220 | |
221 if (temp[i] == 0x5a) | |
222 { | |
223 uint16_t v1 = temp[i + 1]; | |
224 uint16_t v2 = temp[i + 2]; | |
225 value = (v2 << 8) + v1; | |
226 i += 2; | |
227 } | |
228 else | |
229 { | |
230 value = delta + (int8_t) temp[i]; | |
231 } | |
232 | |
233 output.push_back(value & 0xff); | |
234 output.push_back(value >> 8); | |
235 delta = value; | |
236 } | |
237 | |
238 if (output.size() % 2) | |
239 { | |
240 output.resize(output.size() - 1); | |
241 } | |
242 | |
243 return true; | |
244 } | |
245 | |
246 | |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
247 class DicomImageDecoder::ImageSource |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
248 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
249 private: |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
250 std::string psmct_; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
251 std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
252 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
253 public: |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
254 void Setup(DcmDataset& dataset, |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
255 unsigned int frame) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
256 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
257 psmct_.clear(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
258 slowAccessor_.reset(NULL); |
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 // 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
|
261 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
262 DicomMap m; |
2381
b8969010b534
uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2380
diff
changeset
|
263 FromDcmtkBridge::ExtractDicomSummary(m, dataset); |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
264 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
265 /** |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
266 * 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
|
267 **/ |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
268 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
269 DcmElement* e; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
270 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
|
271 e != NULL) |
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 Uint8* pixData = NULL; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
274 if (e->getUint8Array(pixData) == EC_Normal) |
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 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, e->getLength())); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
277 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
278 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
279 else if (DecodePsmctRle1(psmct_, dataset)) |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
280 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
281 LOG(INFO) << "The PMSCT_RLE1 decoding has succeeded"; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
282 Uint8* pixData = NULL; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
283 if (psmct_.size() > 0) |
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 pixData = reinterpret_cast<Uint8*>(&psmct_[0]); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
286 } |
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 slowAccessor_.reset(new DicomIntegerPixelAccessor(m, pixData, psmct_.size())); |
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 if (slowAccessor_.get() == NULL) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
294 } |
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 slowAccessor_->SetCurrentFrame(frame); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
297 } |
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 unsigned int GetWidth() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
300 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
301 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
302 return slowAccessor_->GetInformation().GetWidth(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
303 } |
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 unsigned int GetHeight() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
306 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
307 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
308 return slowAccessor_->GetInformation().GetHeight(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
309 } |
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 unsigned int GetChannelCount() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
312 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
313 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
314 return slowAccessor_->GetInformation().GetChannelCount(); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
315 } |
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 const DicomIntegerPixelAccessor& GetAccessor() const |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
318 { |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
319 assert(slowAccessor_.get() != NULL); |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
320 return *slowAccessor_; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
321 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
322 |
1190 | 323 unsigned int GetSize() const |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
324 { |
1190 | 325 assert(slowAccessor_.get() != NULL); |
326 return slowAccessor_->GetSize(); | |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
327 } |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
328 }; |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
329 |
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
876
diff
changeset
|
330 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
331 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
|
332 bool ignorePhotometricInterpretation) |
845 | 333 { |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
334 DicomMap m; |
2381
b8969010b534
uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2380
diff
changeset
|
335 FromDcmtkBridge::ExtractDicomSummary(m, dataset); |
845 | 336 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
337 DicomImageInformation info(m); |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
338 PixelFormat format; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
339 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
340 if (!info.ExtractPixelFormat(format, ignorePhotometricInterpretation)) |
845 | 341 { |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
342 LOG(WARNING) << "Unsupported DICOM image: " << info.GetBitsStored() |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
343 << "bpp, " << info.GetChannelCount() << " channels, " |
860 | 344 << (info.IsSigned() ? "signed" : "unsigned") |
1206
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1190
diff
changeset
|
345 << (info.IsPlanar() ? ", planar, " : ", non-planar, ") |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1190
diff
changeset
|
346 << EnumerationToString(info.GetPhotometricInterpretation()) |
f5b0207967bc
Fix issue 19 (YBR_FULL are decoded incorrectly)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1190
diff
changeset
|
347 << " photometric interpretation"; |
845 | 348 throw OrthancException(ErrorCode_NotImplemented); |
349 } | |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
863
diff
changeset
|
350 |
2107 | 351 return new Image(format, info.GetWidth(), info.GetHeight(), false); |
845 | 352 } |
353 | |
354 | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
355 template <typename PixelType> |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
356 static void CopyPixels(ImageAccessor& target, |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
357 const DicomIntegerPixelAccessor& source) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
358 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
359 const PixelType minValue = std::numeric_limits<PixelType>::min(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
360 const PixelType maxValue = std::numeric_limits<PixelType>::max(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
361 |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
852
diff
changeset
|
362 for (unsigned int y = 0; y < source.GetInformation().GetHeight(); y++) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
363 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
364 PixelType* pixel = reinterpret_cast<PixelType*>(target.GetRow(y)); |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
852
diff
changeset
|
365 for (unsigned int x = 0; x < source.GetInformation().GetWidth(); x++) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
366 { |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
852
diff
changeset
|
367 for (unsigned int c = 0; c < source.GetInformation().GetChannelCount(); c++, pixel++) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
368 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
369 int32_t v = source.GetValue(x, y, c); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
370 if (v < static_cast<int32_t>(minValue)) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
371 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
372 *pixel = 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 else if (v > static_cast<int32_t>(maxValue)) |
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 *pixel = 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 else |
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 *pixel = static_cast<PixelType>(v); |
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 } |
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 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
388 static ImageAccessor* DecodeLookupTable(std::auto_ptr<ImageAccessor>& target, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
389 const DicomImageInformation& info, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
390 DcmDataset& dataset, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
391 const uint8_t* pixelData, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
392 unsigned long pixelLength) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
393 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
394 LOG(INFO) << "Decoding a lookup table"; |
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 OFString r, g, b; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
397 PixelFormat format; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
398 const uint16_t* lutRed = NULL; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
399 const uint16_t* lutGreen = NULL; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
400 const uint16_t* lutBlue = NULL; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
401 unsigned long rc = 0; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
402 unsigned long gc = 0; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
403 unsigned long bc = 0; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
404 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
405 if (pixelData == NULL && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
406 !dataset.findAndGetUint8Array(DCM_PixelData, pixelData, &pixelLength).good()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
407 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
408 throw OrthancException(ErrorCode_NotImplemented); |
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 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
411 if (info.IsPlanar() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
412 info.GetNumberOfFrames() != 1 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
413 !info.ExtractPixelFormat(format, false) || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
414 !dataset.findAndGetOFStringArray(DCM_BluePaletteColorLookupTableDescriptor, b).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
415 !dataset.findAndGetOFStringArray(DCM_GreenPaletteColorLookupTableDescriptor, g).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
416 !dataset.findAndGetOFStringArray(DCM_RedPaletteColorLookupTableDescriptor, r).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
417 !dataset.findAndGetUint16Array(DCM_BluePaletteColorLookupTableData, lutBlue, &bc).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
418 !dataset.findAndGetUint16Array(DCM_GreenPaletteColorLookupTableData, lutGreen, &gc).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
419 !dataset.findAndGetUint16Array(DCM_RedPaletteColorLookupTableData, lutRed, &rc).good() || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
420 r != g || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
421 r != b || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
422 g != b || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
423 lutRed == NULL || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
424 lutGreen == NULL || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
425 lutBlue == NULL || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
426 pixelData == NULL) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
427 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
428 throw OrthancException(ErrorCode_NotImplemented); |
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 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
431 switch (format) |
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 case PixelFormat_RGB24: |
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 if (r != "256\\0\\16" || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
436 rc != 256 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
437 gc != 256 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
438 bc != 256 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
439 pixelLength != target->GetWidth() * target->GetHeight()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
440 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
441 throw OrthancException(ErrorCode_NotImplemented); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
442 } |
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 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
445 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
446 for (unsigned int y = 0; y < target->GetHeight(); y++) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
447 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
448 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
|
449 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
450 for (unsigned int x = 0; x < target->GetWidth(); x++) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
451 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
452 p[0] = lutRed[*source] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
453 p[1] = lutGreen[*source] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
454 p[2] = lutBlue[*source] >> 8; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
455 source++; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
456 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
457 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
458 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
459 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
460 return target.release(); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
461 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
462 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
463 case PixelFormat_RGB48: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
464 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
465 if (r != "0\\0\\16" || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
466 rc != 65536 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
467 gc != 65536 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
468 bc != 65536 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
469 pixelLength != 2 * target->GetWidth() * target->GetHeight()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
470 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
471 throw OrthancException(ErrorCode_NotImplemented); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
472 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
473 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
474 const uint16_t* source = reinterpret_cast<const uint16_t*>(pixelData); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
475 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
476 for (unsigned int y = 0; y < target->GetHeight(); y++) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
477 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
478 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
|
479 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
480 for (unsigned int x = 0; x < target->GetWidth(); x++) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
481 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
482 p[0] = lutRed[*source]; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
483 p[1] = lutGreen[*source]; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
484 p[2] = lutBlue[*source]; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
485 source++; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
486 p += 3; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
487 } |
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 return target.release(); |
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 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
493 default: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
494 break; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
495 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
496 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
497 throw OrthancException(ErrorCode_InternalError); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
498 } |
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 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
501 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
|
502 unsigned int frame) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
503 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
504 /** |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
505 * Create the target image. |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
506 **/ |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
507 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
508 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, false)); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
509 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
510 ImageSource source; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
511 source.Setup(dataset, frame); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
512 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
513 if (source.GetWidth() != target->GetWidth() || |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
514 source.GetHeight() != target->GetHeight()) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
515 { |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
516 throw OrthancException(ErrorCode_InternalError); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
517 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
518 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
519 |
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 * Deal with lookup tables |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
522 **/ |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
523 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
524 const DicomImageInformation& info = source.GetAccessor().GetInformation(); |
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 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette) |
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 return DecodeLookupTable(target, info, dataset, NULL, 0); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
529 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
530 |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
531 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
532 /** |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
533 * 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
|
534 * direct access to copy its values. |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
535 **/ |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
536 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
537 bool fastVersionSuccess = false; |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
538 PixelFormat sourceFormat; |
863 | 539 if (!info.IsPlanar() && |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
540 info.ExtractPixelFormat(sourceFormat, false)) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
541 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
542 try |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
543 { |
1190 | 544 size_t frameSize = info.GetHeight() * info.GetWidth() * GetBytesPerPixel(sourceFormat); |
545 if ((frame + 1) * frameSize <= source.GetSize()) | |
546 { | |
547 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
|
548 |
1190 | 549 ImageAccessor sourceImage; |
550 sourceImage.AssignReadOnly(sourceFormat, | |
551 info.GetWidth(), | |
552 info.GetHeight(), | |
553 info.GetWidth() * GetBytesPerPixel(sourceFormat), | |
554 buffer + frame * frameSize); | |
555 | |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
556 ImageProcessing::Convert(*target, sourceImage); |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
557 ImageProcessing::ShiftRight(*target, info.GetShift()); |
1190 | 558 fastVersionSuccess = true; |
559 } | |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
560 } |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
561 catch (OrthancException&) |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
562 { |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
563 // Unsupported conversion, use the slow version |
854
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 |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
567 /** |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
568 * Slow version : loop over the DICOM buffer, storing its value |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
569 * into the target image. |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
570 **/ |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
571 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
572 if (!fastVersionSuccess) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
573 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
574 switch (target->GetFormat()) |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
575 { |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
576 case PixelFormat_RGB24: |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
577 case PixelFormat_RGBA32: |
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
578 case PixelFormat_Grayscale8: |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
579 CopyPixels<uint8_t>(*target, source.GetAccessor()); |
863 | 580 break; |
860 | 581 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
582 case PixelFormat_Grayscale16: |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
583 CopyPixels<uint16_t>(*target, source.GetAccessor()); |
863 | 584 break; |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
585 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
586 case PixelFormat_SignedGrayscale16: |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
587 CopyPixels<int16_t>(*target, source.GetAccessor()); |
863 | 588 break; |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
589 |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
590 default: |
863 | 591 throw OrthancException(ErrorCode_InternalError); |
854
ff530685e46a
fast version of image copy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
592 } |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
593 } |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
594 |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
595 return target.release(); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
596 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
597 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
598 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
599 ImageAccessor* DicomImageDecoder::ApplyCodec |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
600 (const DcmCodec& codec, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
601 const DcmCodecParameter& parameters, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
602 const DcmRepresentationParameter& representationParameter, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
603 DcmDataset& dataset, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
604 unsigned int frame) |
1903 | 605 { |
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
|
606 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
|
607 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
|
608 { |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
609 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
|
610 } |
6c73df12ca51
New URI: "/instances/.../frames/.../raw" to access the raw frames (bypass image decoding)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1905
diff
changeset
|
611 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
612 DicomMap m; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
613 FromDcmtkBridge::ExtractDicomSummary(m, dataset); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
614 DicomImageInformation info(m); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
615 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
616 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, true)); |
845 | 617 |
618 Uint32 startFragment = 0; // Default | |
619 OFString decompressedColorModel; // Out | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
620 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
621 OFCondition c; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
622 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
623 if (info.GetPhotometricInterpretation() == PhotometricInterpretation_Palette && |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
624 info.GetChannelCount() == 1) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
625 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
626 std::string uncompressed; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
627 uncompressed.resize(info.GetWidth() * info.GetHeight() * info.GetBytesPerValue()); |
845 | 628 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
629 if (uncompressed.size() == 0 || |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
630 !codec.decodeFrame(&representationParameter, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
631 pixelSequence, ¶meters, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
632 &dataset, frame, startFragment, &uncompressed[0], |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
633 uncompressed.size(), decompressedColorModel).good()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
634 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
635 LOG(ERROR) << "Cannot decode a palette image"; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
636 throw OrthancException(ErrorCode_BadFileFormat); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
637 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
638 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
639 return DecodeLookupTable(target, info, dataset, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
640 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
|
641 uncompressed.size()); |
845 | 642 } |
1903 | 643 else |
644 { | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
645 if (!codec.decodeFrame(&representationParameter, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
646 pixelSequence, ¶meters, |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
647 &dataset, frame, startFragment, target->GetBuffer(), |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
648 target->GetSize(), decompressedColorModel).good()) |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
649 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
650 LOG(ERROR) << "Cannot decode a non-palette image"; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
651 throw OrthancException(ErrorCode_BadFileFormat); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
652 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
653 |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
654 return target.release(); |
1903 | 655 } |
845 | 656 } |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
657 |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
658 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
659 ImageAccessor* DicomImageDecoder::Decode(ParsedDicomFile& dicom, |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
660 unsigned int frame) |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
661 { |
1904 | 662 DcmDataset& dataset = *dicom.GetDcmtkObject().getDataset(); |
663 E_TransferSyntax syntax = dataset.getOriginalXfer(); | |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
664 |
1903 | 665 /** |
666 * Deal with uncompressed, raw images. | |
667 * http://support.dcmtk.org/docs/dcxfer_8h-source.html | |
668 **/ | |
1904 | 669 if (syntax == EXS_Unknown || |
670 syntax == EXS_LittleEndianImplicit || | |
671 syntax == EXS_BigEndianImplicit || | |
672 syntax == EXS_LittleEndianExplicit || | |
673 syntax == EXS_BigEndianExplicit) | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
674 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
675 return DecodeUncompressedImage(dataset, frame); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
676 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
677 |
1904 | 678 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
679 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 |
1904 | 680 /** |
681 * Deal with JPEG-LS images. | |
682 **/ | |
683 | |
684 if (syntax == EXS_JPEGLSLossless || | |
685 syntax == EXS_JPEGLSLossy) | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
686 { |
2430
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
687 // 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
|
688 // http://support.dcmtk.org/docs/classDJLSRepresentationParameter.html |
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
689 DJLSRepresentationParameter representationParameter(2, OFTrue); |
a6fab385b89e
fix for dcmtk 3.6.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2423
diff
changeset
|
690 |
1904 | 691 DJLSCodecParameter parameters; |
692 std::auto_ptr<DJLSDecoderBase> decoder; | |
1903 | 693 |
1904 | 694 switch (syntax) |
695 { | |
696 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
|
697 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image"; |
1904 | 698 decoder.reset(new DJLSLosslessDecoder); |
699 break; | |
700 | |
701 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
|
702 LOG(INFO) << "Decoding a JPEG-LS near-lossless DICOM image"; |
1904 | 703 decoder.reset(new DJLSNearLosslessDecoder); |
704 break; | |
1903 | 705 |
1904 | 706 default: |
707 throw OrthancException(ErrorCode_InternalError); | |
708 } | |
709 | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
710 return ApplyCodec(*decoder, parameters, representationParameter, dataset, frame); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
711 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
712 #endif |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
713 |
852 | 714 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
715 #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
|
716 /** |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
717 * 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
|
718 **/ |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
719 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
720 if (syntax == EXS_JPEGProcess1 || // DJDecoderBaseline |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
721 syntax == EXS_JPEGProcess2_4 || // DJDecoderExtended |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
722 syntax == EXS_JPEGProcess6_8 || // DJDecoderSpectralSelection (retired) |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
723 syntax == EXS_JPEGProcess10_12 || // DJDecoderProgressive (retired) |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
724 syntax == EXS_JPEGProcess14 || // DJDecoderLossless |
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
725 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
|
726 { |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
727 // 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
|
728 DJCodecParameter parameters( |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
729 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
|
730 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
|
731 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
|
732 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
|
733 DJ_RPLossy representationParameter; |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
734 std::auto_ptr<DJCodecDecoder> decoder; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
735 |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
736 switch (syntax) |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
737 { |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
738 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
|
739 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
|
740 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
|
741 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
742 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
743 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
|
744 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
|
745 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
|
746 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
747 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
752 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
753 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
|
754 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
|
755 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
|
756 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
757 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
758 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
|
759 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
|
760 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
|
761 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
762 |
1944
1a5e070a21c3
fix compilation against DCMTK 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1929
diff
changeset
|
763 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
|
764 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
|
765 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
|
766 break; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
767 |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
768 default: |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
769 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
|
770 } |
1904 | 771 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
772 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
|
773 } |
852 | 774 #endif |
775 | |
1904 | 776 |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
777 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
|
778 { |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
779 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
|
780 DcmRLECodecParameter parameters; |
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
781 DcmRLECodecDecoder decoder; |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
782 DcmRLERepresentationParameter representationParameter; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
783 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
|
784 } |
1904 | 785 |
786 | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
787 /** |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
788 * 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
|
789 * 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
|
790 * 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
|
791 * 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
|
792 * second example of the following page: |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
793 * 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
|
794 **/ |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
795 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
796 { |
1905
8b1baa2315b8
Huge speedup if decoding the family of JPEG transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1904
diff
changeset
|
797 LOG(INFO) << "Decoding a compressed image by converting its transfer syntax to Little Endian"; |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
798 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
799 std::auto_ptr<DcmDataset> converted(dynamic_cast<DcmDataset*>(dataset.clone())); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
800 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
801 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
802 if (converted->canWriteXfer(EXS_LittleEndianExplicit)) |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
803 { |
1903 | 804 return DecodeUncompressedImage(*converted, frame); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
805 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
806 } |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
807 |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
808 LOG(ERROR) << "Cannot decode a DICOM image with the built-in decoder"; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
809 throw OrthancException(ErrorCode_BadFileFormat); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
846
diff
changeset
|
810 } |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
811 |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
812 |
1015
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
813 static bool IsColorImage(PixelFormat format) |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
814 { |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
815 return (format == PixelFormat_RGB24 || |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
816 format == PixelFormat_RGBA32); |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
817 } |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
818 |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
819 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
820 bool DicomImageDecoder::TruncateDecodedImage(std::auto_ptr<ImageAccessor>& image, |
1824
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
821 PixelFormat format, |
b530c3dfe2a6
refactoring image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
822 bool allowColorConversion) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
823 { |
1015
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
824 // If specified, prevent the conversion between color and |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
825 // grayscale images |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
826 bool isSourceColor = IsColorImage(image->GetFormat()); |
1015
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
827 bool isTargetColor = IsColorImage(format); |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
828 |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
829 if (!allowColorConversion) |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
830 { |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
831 if (isSourceColor ^ isTargetColor) |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
832 { |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
833 return false; |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
834 } |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
835 } |
f009f7c75069
fix integration tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
836 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
837 if (image->GetFormat() != format) |
863 | 838 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
839 // A conversion is required |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
840 std::auto_ptr<ImageAccessor> target |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
841 (new Image(format, image->GetWidth(), image->GetHeight(), false)); |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
842 ImageProcessing::Convert(*target, *image); |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
843 image = target; |
863 | 844 } |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
845 |
863 | 846 return true; |
847 } | |
848 | |
849 | |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
850 bool DicomImageDecoder::PreviewDecodedImage(std::auto_ptr<ImageAccessor>& image) |
863 | 851 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
852 switch (image->GetFormat()) |
861 | 853 { |
863 | 854 case PixelFormat_RGB24: |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
855 { |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
856 // Directly return color images without modification (RGB) |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
857 return true; |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
858 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
859 |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
860 case PixelFormat_RGB48: |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
861 { |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
862 std::auto_ptr<ImageAccessor> target |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
863 (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
|
864 ImageProcessing::Convert(*target, *image); |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
865 image = target; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
866 return true; |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
867 } |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
868 |
863 | 869 case PixelFormat_Grayscale8: |
870 case PixelFormat_Grayscale16: | |
871 case PixelFormat_SignedGrayscale16: | |
872 { | |
873 // 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
|
874 int64_t a, b; |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
875 ImageProcessing::GetMinMaxIntegerValue(a, b, *image); |
863 | 876 |
877 if (a == b) | |
878 { | |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
879 ImageProcessing::Set(*image, 0); |
863 | 880 } |
881 else | |
882 { | |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
883 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
|
884 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
|
885 true /* TODO - Consider using "false" to speed up */); |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
886 } |
863 | 887 |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
888 // If the source image is not grayscale 8bpp, convert it |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
889 if (image->GetFormat() != PixelFormat_Grayscale8) |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
890 { |
2423
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
891 std::auto_ptr<ImageAccessor> target |
5a7c5c541a1d
Built-in decoding of palette images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2415
diff
changeset
|
892 (new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false)); |
1826
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
893 ImageProcessing::Convert(*target, *image); |
ac5b0b4e2434
refactoring of DicomImageDecoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1824
diff
changeset
|
894 image = target; |
863 | 895 } |
896 | |
897 return true; | |
898 } | |
899 | |
859
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
900 default: |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
901 throw OrthancException(ErrorCode_NotImplemented); |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
902 } |
610a9a1ed855
ImageProcessing::Convert
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
858
diff
changeset
|
903 } |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
904 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
905 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
906 void DicomImageDecoder::ApplyExtractionMode(std::auto_ptr<ImageAccessor>& image, |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
907 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
908 bool invert) |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
909 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
910 if (image.get() == NULL) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
911 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
912 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
913 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
914 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
915 bool ok = false; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
916 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
917 switch (mode) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
918 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
919 case ImageExtractionMode_UInt8: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
920 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
|
921 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
922 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
923 case ImageExtractionMode_UInt16: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
924 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
|
925 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
926 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
927 case ImageExtractionMode_Int16: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
928 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
|
929 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
930 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
931 case ImageExtractionMode_Preview: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
932 ok = PreviewDecodedImage(image); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
933 break; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
934 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
935 default: |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
936 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
937 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
938 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
939 if (ok) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
940 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
941 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
|
942 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
943 if (invert) |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
944 { |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
945 Orthanc::ImageProcessing::Invert(*image); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
946 } |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
947 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
948 else |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
949 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
950 throw OrthancException(ErrorCode_NotImplemented); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
951 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
952 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
953 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
954 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
955 #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
|
956 void DicomImageDecoder::ExtractPngImage(std::string& result, |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
957 std::auto_ptr<ImageAccessor>& image, |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
958 ImageExtractionMode mode, |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
959 bool invert) |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
960 { |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
961 ApplyExtractionMode(image, mode, invert); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
962 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
963 PngWriter writer; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
964 writer.WriteToMemory(result, *image); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
965 } |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
966 #endif |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
967 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
968 |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
969 #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
|
970 void DicomImageDecoder::ExtractJpegImage(std::string& result, |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
971 std::auto_ptr<ImageAccessor>& image, |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
972 ImageExtractionMode mode, |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
973 bool invert, |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
974 uint8_t quality) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
975 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
976 if (mode != ImageExtractionMode_UInt8 && |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
977 mode != ImageExtractionMode_Preview) |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
978 { |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
979 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
980 } |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
981 |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
982 ApplyExtractionMode(image, mode, invert); |
1902
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
983 |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
984 JpegWriter writer; |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
985 writer.SetQuality(quality); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
986 writer.WriteToMemory(result, *image); |
8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
987 } |
2380
96b3ec054b69
reorganization in macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
988 #endif |
845 | 989 } |