Mercurial > hg > orthanc
annotate OrthancServer/ParsedDicomFile.cpp @ 989:8566ba2d4b3a plugins
integration mainline->plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Jul 2014 16:54:34 +0200 |
parents | 509e146c3cb3 |
children | af014624dac1 |
rev | line source |
---|---|
790 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 | |
34 /*========================================================================= | |
35 | |
36 This file is based on portions of the following project: | |
37 | |
38 Program: GDCM (Grassroots DICOM). A DICOM library | |
39 Module: http://gdcm.sourceforge.net/Copyright.html | |
40 | |
41 Copyright (c) 2006-2011 Mathieu Malaterre | |
42 Copyright (c) 1993-2005 CREATIS | |
43 (CREATIS = Centre de Recherche et d'Applications en Traitement de l'Image) | |
44 All rights reserved. | |
45 | |
46 Redistribution and use in source and binary forms, with or without | |
47 modification, are permitted provided that the following conditions are met: | |
48 | |
49 * Redistributions of source code must retain the above copyright notice, | |
50 this list of conditions and the following disclaimer. | |
51 | |
52 * Redistributions in binary form must reproduce the above copyright notice, | |
53 this list of conditions and the following disclaimer in the documentation | |
54 and/or other materials provided with the distribution. | |
55 | |
56 * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any | |
57 contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to | |
58 endorse or promote products derived from this software without specific | |
59 prior written permission. | |
60 | |
61 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' | |
62 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
63 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
64 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR | |
65 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
66 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
67 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
68 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
69 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
70 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
71 | |
72 =========================================================================*/ | |
73 | |
74 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
75 #include "PrecompiledHeadersServer.h" |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
817
diff
changeset
|
76 |
790 | 77 #ifndef NOMINMAX |
78 #define NOMINMAX | |
79 #endif | |
80 | |
81 #include "ParsedDicomFile.h" | |
82 | |
83 #include "FromDcmtkBridge.h" | |
84 #include "ToDcmtkBridge.h" | |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
85 #include "Internals/DicomImageDecoder.h" |
790 | 86 #include "../Core/Toolbox.h" |
87 #include "../Core/OrthancException.h" | |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
88 #include "../Core/ImageFormats/ImageBuffer.h" |
799 | 89 #include "../Core/ImageFormats/PngWriter.h" |
790 | 90 #include "../Core/Uuid.h" |
91 #include "../Core/DicomFormat/DicomString.h" | |
92 #include "../Core/DicomFormat/DicomNullValue.h" | |
93 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h" | |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
94 #include "../Core/ImageFormats/PngReader.h" |
790 | 95 |
96 #include <list> | |
97 #include <limits> | |
98 | |
99 #include <boost/lexical_cast.hpp> | |
100 | |
101 #include <dcmtk/dcmdata/dcchrstr.h> | |
102 #include <dcmtk/dcmdata/dcdicent.h> | |
103 #include <dcmtk/dcmdata/dcdict.h> | |
104 #include <dcmtk/dcmdata/dcfilefo.h> | |
105 #include <dcmtk/dcmdata/dcistrmb.h> | |
106 #include <dcmtk/dcmdata/dcuid.h> | |
107 #include <dcmtk/dcmdata/dcmetinf.h> | |
108 | |
109 #include <dcmtk/dcmdata/dcvrae.h> | |
110 #include <dcmtk/dcmdata/dcvras.h> | |
111 #include <dcmtk/dcmdata/dcvrcs.h> | |
112 #include <dcmtk/dcmdata/dcvrda.h> | |
113 #include <dcmtk/dcmdata/dcvrds.h> | |
114 #include <dcmtk/dcmdata/dcvrdt.h> | |
115 #include <dcmtk/dcmdata/dcvrfd.h> | |
116 #include <dcmtk/dcmdata/dcvrfl.h> | |
117 #include <dcmtk/dcmdata/dcvris.h> | |
118 #include <dcmtk/dcmdata/dcvrlo.h> | |
119 #include <dcmtk/dcmdata/dcvrlt.h> | |
120 #include <dcmtk/dcmdata/dcvrpn.h> | |
121 #include <dcmtk/dcmdata/dcvrsh.h> | |
122 #include <dcmtk/dcmdata/dcvrsl.h> | |
123 #include <dcmtk/dcmdata/dcvrss.h> | |
124 #include <dcmtk/dcmdata/dcvrst.h> | |
125 #include <dcmtk/dcmdata/dcvrtm.h> | |
126 #include <dcmtk/dcmdata/dcvrui.h> | |
127 #include <dcmtk/dcmdata/dcvrul.h> | |
128 #include <dcmtk/dcmdata/dcvrus.h> | |
129 #include <dcmtk/dcmdata/dcvrut.h> | |
130 #include <dcmtk/dcmdata/dcpixel.h> | |
131 #include <dcmtk/dcmdata/dcpixseq.h> | |
132 #include <dcmtk/dcmdata/dcpxitem.h> | |
133 | |
134 | |
135 #include <boost/math/special_functions/round.hpp> | |
136 #include <glog/logging.h> | |
137 #include <dcmtk/dcmdata/dcostrmb.h> | |
138 | |
139 | |
140 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream"; | |
141 | |
142 | |
143 | |
144 namespace Orthanc | |
145 { | |
794 | 146 struct ParsedDicomFile::PImpl |
147 { | |
148 std::auto_ptr<DcmFileFormat> file_; | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
149 Encoding encoding_; |
794 | 150 }; |
151 | |
152 | |
153 // This method can only be called from the constructors! | |
790 | 154 void ParsedDicomFile::Setup(const char* buffer, size_t size) |
155 { | |
156 DcmInputBufferStream is; | |
157 if (size > 0) | |
158 { | |
159 is.setBuffer(buffer, size); | |
160 } | |
161 is.setEos(); | |
162 | |
794 | 163 pimpl_->file_.reset(new DcmFileFormat); |
164 pimpl_->file_->transferInit(); | |
165 if (!pimpl_->file_->read(is).good()) | |
790 | 166 { |
794 | 167 delete pimpl_; // Avoid a memory leak due to exception |
168 // throwing, as we are in the constructor | |
169 | |
790 | 170 throw OrthancException(ErrorCode_BadFileFormat); |
171 } | |
794 | 172 pimpl_->file_->loadAllDataIntoMemory(); |
173 pimpl_->file_->transferEnd(); | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
174 |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
175 pimpl_->encoding_ = FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset()); |
790 | 176 } |
177 | |
178 | |
179 static void SendPathValueForDictionary(RestApiOutput& output, | |
180 DcmItem& dicom) | |
181 { | |
182 Json::Value v = Json::arrayValue; | |
183 | |
184 for (unsigned long i = 0; i < dicom.card(); i++) | |
185 { | |
186 DcmElement* element = dicom.getElement(i); | |
187 if (element) | |
188 { | |
189 char buf[16]; | |
190 sprintf(buf, "%04x-%04x", element->getTag().getGTag(), element->getTag().getETag()); | |
191 v.append(buf); | |
192 } | |
193 } | |
194 | |
195 output.AnswerJson(v); | |
196 } | |
197 | |
198 static inline uint16_t GetCharValue(char c) | |
199 { | |
200 if (c >= '0' && c <= '9') | |
201 return c - '0'; | |
202 else if (c >= 'a' && c <= 'f') | |
203 return c - 'a' + 10; | |
204 else if (c >= 'A' && c <= 'F') | |
205 return c - 'A' + 10; | |
206 else | |
207 return 0; | |
208 } | |
209 | |
210 static inline uint16_t GetTagValue(const char* c) | |
211 { | |
212 return ((GetCharValue(c[0]) << 12) + | |
213 (GetCharValue(c[1]) << 8) + | |
214 (GetCharValue(c[2]) << 4) + | |
215 GetCharValue(c[3])); | |
216 } | |
217 | |
218 static void ParseTagAndGroup(DcmTagKey& key, | |
219 const std::string& tag) | |
220 { | |
221 DicomTag t = FromDcmtkBridge::ParseTag(tag); | |
222 key = DcmTagKey(t.GetGroup(), t.GetElement()); | |
223 } | |
224 | |
225 | |
226 static void SendSequence(RestApiOutput& output, | |
227 DcmSequenceOfItems& sequence) | |
228 { | |
229 // This element is a sequence | |
230 Json::Value v = Json::arrayValue; | |
231 | |
232 for (unsigned long i = 0; i < sequence.card(); i++) | |
233 { | |
234 v.append(boost::lexical_cast<std::string>(i)); | |
235 } | |
236 | |
237 output.AnswerJson(v); | |
238 } | |
239 | |
240 | |
241 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData, | |
242 E_TransferSyntax transferSyntax) | |
243 { | |
244 DcmPixelSequence* pixelSequence = NULL; | |
245 if (pixelData.getEncapsulatedRepresentation | |
246 (transferSyntax, NULL, pixelSequence).good() && pixelSequence) | |
247 { | |
248 return pixelSequence->card(); | |
249 } | |
250 else | |
251 { | |
252 return 1; | |
253 } | |
254 } | |
255 | |
256 | |
257 static void AnswerDicomField(RestApiOutput& output, | |
258 DcmElement& element, | |
259 E_TransferSyntax transferSyntax) | |
260 { | |
261 // This element is nor a sequence, neither a pixel-data | |
262 std::string buffer; | |
263 buffer.resize(65536); | |
264 Uint32 length = element.getLength(transferSyntax); | |
265 Uint32 offset = 0; | |
266 | |
267 output.GetLowLevelOutput().SendOkHeader(CONTENT_TYPE_OCTET_STREAM, true, length, NULL); | |
268 | |
269 while (offset < length) | |
270 { | |
271 Uint32 nbytes; | |
272 if (length - offset < buffer.size()) | |
273 { | |
274 nbytes = length - offset; | |
275 } | |
276 else | |
277 { | |
278 nbytes = buffer.size(); | |
279 } | |
280 | |
281 OFCondition cond = element.getPartialValue(&buffer[0], offset, nbytes); | |
282 | |
283 if (cond.good()) | |
284 { | |
908
e078ea944089
refactoring HttpOutput
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
285 output.GetLowLevelOutput().SendBodyData(&buffer[0], nbytes); |
790 | 286 offset += nbytes; |
287 } | |
288 else | |
289 { | |
290 LOG(ERROR) << "Error while sending a DICOM field: " << cond.text(); | |
291 return; | |
292 } | |
293 } | |
294 | |
295 output.MarkLowLevelOutputDone(); | |
296 } | |
297 | |
298 | |
299 static bool AnswerPixelData(RestApiOutput& output, | |
300 DcmItem& dicom, | |
301 E_TransferSyntax transferSyntax, | |
302 const std::string* blockUri) | |
303 { | |
304 DcmTag k(DICOM_TAG_PIXEL_DATA.GetGroup(), | |
305 DICOM_TAG_PIXEL_DATA.GetElement()); | |
306 | |
307 DcmElement *element = NULL; | |
308 if (!dicom.findAndGetElement(k, element).good() || | |
309 element == NULL) | |
310 { | |
311 return false; | |
312 } | |
313 | |
314 try | |
315 { | |
316 DcmPixelData& pixelData = dynamic_cast<DcmPixelData&>(*element); | |
317 if (blockUri == NULL) | |
318 { | |
319 // The user asks how many blocks are presents in this pixel data | |
320 unsigned int blocks = GetPixelDataBlockCount(pixelData, transferSyntax); | |
321 | |
322 Json::Value result(Json::arrayValue); | |
323 for (unsigned int i = 0; i < blocks; i++) | |
324 { | |
325 result.append(boost::lexical_cast<std::string>(i)); | |
326 } | |
327 | |
328 output.AnswerJson(result); | |
329 return true; | |
330 } | |
331 | |
332 | |
333 unsigned int block = boost::lexical_cast<unsigned int>(*blockUri); | |
334 | |
335 if (block < GetPixelDataBlockCount(pixelData, transferSyntax)) | |
336 { | |
337 DcmPixelSequence* pixelSequence = NULL; | |
338 if (pixelData.getEncapsulatedRepresentation | |
339 (transferSyntax, NULL, pixelSequence).good() && pixelSequence) | |
340 { | |
341 // This is the case for JPEG transfer syntaxes | |
342 if (block < pixelSequence->card()) | |
343 { | |
344 DcmPixelItem* pixelItem = NULL; | |
345 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem) | |
346 { | |
347 if (pixelItem->getLength() == 0) | |
348 { | |
349 output.AnswerBuffer(NULL, 0, CONTENT_TYPE_OCTET_STREAM); | |
350 return true; | |
351 } | |
352 | |
353 Uint8* buffer = NULL; | |
354 if (pixelItem->getUint8Array(buffer).good() && buffer) | |
355 { | |
356 output.AnswerBuffer(buffer, pixelItem->getLength(), CONTENT_TYPE_OCTET_STREAM); | |
357 return true; | |
358 } | |
359 } | |
360 } | |
361 } | |
362 else | |
363 { | |
364 // This is the case for raw, uncompressed image buffers | |
365 assert(*blockUri == "0"); | |
366 AnswerDicomField(output, *element, transferSyntax); | |
367 } | |
368 } | |
369 } | |
370 catch (boost::bad_lexical_cast&) | |
371 { | |
372 // The URI entered by the user is not a number | |
373 } | |
374 catch (std::bad_cast&) | |
375 { | |
376 // This should never happen | |
377 } | |
378 | |
379 return false; | |
380 } | |
381 | |
382 | |
383 | |
384 static void SendPathValueForLeaf(RestApiOutput& output, | |
385 const std::string& tag, | |
386 DcmItem& dicom, | |
387 E_TransferSyntax transferSyntax) | |
388 { | |
389 DcmTagKey k; | |
390 ParseTagAndGroup(k, tag); | |
391 | |
392 DcmSequenceOfItems* sequence = NULL; | |
393 if (dicom.findAndGetSequence(k, sequence).good() && | |
394 sequence != NULL && | |
395 sequence->getVR() == EVR_SQ) | |
396 { | |
397 SendSequence(output, *sequence); | |
398 return; | |
399 } | |
400 | |
401 DcmElement* element = NULL; | |
402 if (dicom.findAndGetElement(k, element).good() && | |
403 element != NULL && | |
404 //element->getVR() != EVR_UNKNOWN && // This would forbid private tags | |
405 element->getVR() != EVR_SQ) | |
406 { | |
407 AnswerDicomField(output, *element, transferSyntax); | |
408 } | |
409 } | |
410 | |
411 void ParsedDicomFile::SendPathValue(RestApiOutput& output, | |
412 const UriComponents& uri) | |
413 { | |
794 | 414 DcmItem* dicom = pimpl_->file_->getDataset(); |
415 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer(); | |
790 | 416 |
417 // Special case: Accessing the pixel data | |
418 if (uri.size() == 1 || | |
419 uri.size() == 2) | |
420 { | |
421 DcmTagKey tag; | |
422 ParseTagAndGroup(tag, uri[0]); | |
423 | |
424 if (tag.getGroup() == DICOM_TAG_PIXEL_DATA.GetGroup() && | |
425 tag.getElement() == DICOM_TAG_PIXEL_DATA.GetElement()) | |
426 { | |
427 AnswerPixelData(output, *dicom, transferSyntax, uri.size() == 1 ? NULL : &uri[1]); | |
428 return; | |
429 } | |
430 } | |
431 | |
432 // Go down in the tag hierarchy according to the URI | |
433 for (size_t pos = 0; pos < uri.size() / 2; pos++) | |
434 { | |
435 size_t index; | |
436 try | |
437 { | |
438 index = boost::lexical_cast<size_t>(uri[2 * pos + 1]); | |
439 } | |
440 catch (boost::bad_lexical_cast&) | |
441 { | |
442 return; | |
443 } | |
444 | |
445 DcmTagKey k; | |
446 DcmItem *child = NULL; | |
447 ParseTagAndGroup(k, uri[2 * pos]); | |
448 if (!dicom->findAndGetSequenceItem(k, child, index).good() || | |
449 child == NULL) | |
450 { | |
451 return; | |
452 } | |
453 | |
454 dicom = child; | |
455 } | |
456 | |
457 // We have reached the end of the URI | |
458 if (uri.size() % 2 == 0) | |
459 { | |
460 SendPathValueForDictionary(output, *dicom); | |
461 } | |
462 else | |
463 { | |
464 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax); | |
465 } | |
466 } | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 static DcmElement* CreateElementForTag(const DicomTag& tag) | |
473 { | |
474 DcmTag key(tag.GetGroup(), tag.GetElement()); | |
475 | |
476 switch (key.getEVR()) | |
477 { | |
478 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
479 | |
480 /** | |
481 * TODO. | |
482 **/ | |
483 | |
484 case EVR_OB: // other byte | |
485 case EVR_OF: // other float | |
486 case EVR_OW: // other word | |
487 case EVR_AT: // attribute tag | |
488 throw OrthancException(ErrorCode_NotImplemented); | |
489 | |
490 case EVR_UN: // unknown value representation | |
491 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
492 | |
493 | |
494 /** | |
495 * String types. | |
496 * http://support.dcmtk.org/docs/classDcmByteString.html | |
497 **/ | |
498 | |
499 case EVR_AS: // age string | |
500 return new DcmAgeString(key); | |
501 | |
502 case EVR_AE: // application entity title | |
503 return new DcmApplicationEntity(key); | |
504 | |
505 case EVR_CS: // code string | |
506 return new DcmCodeString(key); | |
507 | |
508 case EVR_DA: // date string | |
509 return new DcmDate(key); | |
510 | |
511 case EVR_DT: // date time string | |
512 return new DcmDateTime(key); | |
513 | |
514 case EVR_DS: // decimal string | |
515 return new DcmDecimalString(key); | |
516 | |
517 case EVR_IS: // integer string | |
518 return new DcmIntegerString(key); | |
519 | |
520 case EVR_TM: // time string | |
521 return new DcmTime(key); | |
522 | |
523 case EVR_UI: // unique identifier | |
524 return new DcmUniqueIdentifier(key); | |
525 | |
526 case EVR_ST: // short text | |
527 return new DcmShortText(key); | |
528 | |
529 case EVR_LO: // long string | |
530 return new DcmLongString(key); | |
531 | |
532 case EVR_LT: // long text | |
533 return new DcmLongText(key); | |
534 | |
535 case EVR_UT: // unlimited text | |
536 return new DcmUnlimitedText(key); | |
537 | |
538 case EVR_SH: // short string | |
539 return new DcmShortString(key); | |
540 | |
541 case EVR_PN: // person name | |
542 return new DcmPersonName(key); | |
543 | |
544 | |
545 /** | |
546 * Numerical types | |
547 **/ | |
548 | |
549 case EVR_SL: // signed long | |
550 return new DcmSignedLong(key); | |
551 | |
552 case EVR_SS: // signed short | |
553 return new DcmSignedShort(key); | |
554 | |
555 case EVR_UL: // unsigned long | |
556 return new DcmUnsignedLong(key); | |
557 | |
558 case EVR_US: // unsigned short | |
559 return new DcmUnsignedShort(key); | |
560 | |
561 case EVR_FL: // float single-precision | |
562 return new DcmFloatingPointSingle(key); | |
563 | |
564 case EVR_FD: // float double-precision | |
565 return new DcmFloatingPointDouble(key); | |
566 | |
567 | |
568 /** | |
569 * Sequence types, should never occur at this point. | |
570 **/ | |
571 | |
572 case EVR_SQ: // sequence of items | |
573 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
574 | |
575 | |
576 /** | |
577 * Internal to DCMTK. | |
578 **/ | |
579 | |
580 case EVR_ox: // OB or OW depending on context | |
581 case EVR_xs: // SS or US depending on context | |
582 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) | |
583 case EVR_na: // na="not applicable", for data which has no VR | |
584 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor | |
585 case EVR_item: // used internally for items | |
586 case EVR_metainfo: // used internally for meta info datasets | |
587 case EVR_dataset: // used internally for datasets | |
588 case EVR_fileFormat: // used internally for DICOM files | |
589 case EVR_dicomDir: // used internally for DICOMDIR objects | |
590 case EVR_dirRecord: // used internally for DICOMDIR records | |
591 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image | |
592 case EVR_pixelItem: // used internally for pixel items in a compressed image | |
593 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | |
594 case EVR_PixelData: // used internally for uncompressed pixeld data | |
595 case EVR_OverlayData: // used internally for overlay data | |
596 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR | |
597 default: | |
598 break; | |
599 } | |
600 | |
601 throw OrthancException(ErrorCode_InternalError); | |
602 } | |
603 | |
604 | |
605 | |
606 static void FillElementWithString(DcmElement& element, | |
607 const DicomTag& tag, | |
608 const std::string& value) | |
609 { | |
610 DcmTag key(tag.GetGroup(), tag.GetElement()); | |
611 bool ok = false; | |
612 | |
613 try | |
614 { | |
615 switch (key.getEVR()) | |
616 { | |
617 // http://support.dcmtk.org/docs/dcvr_8h-source.html | |
618 | |
619 /** | |
620 * TODO. | |
621 **/ | |
622 | |
623 case EVR_OB: // other byte | |
624 case EVR_OF: // other float | |
625 case EVR_OW: // other word | |
626 case EVR_AT: // attribute tag | |
627 throw OrthancException(ErrorCode_NotImplemented); | |
628 | |
629 case EVR_UN: // unknown value representation | |
630 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
631 | |
632 | |
633 /** | |
634 * String types. | |
635 **/ | |
636 | |
637 case EVR_DS: // decimal string | |
638 case EVR_IS: // integer string | |
639 case EVR_AS: // age string | |
640 case EVR_DA: // date string | |
641 case EVR_DT: // date time string | |
642 case EVR_TM: // time string | |
643 case EVR_AE: // application entity title | |
644 case EVR_CS: // code string | |
645 case EVR_SH: // short string | |
646 case EVR_LO: // long string | |
647 case EVR_ST: // short text | |
648 case EVR_LT: // long text | |
649 case EVR_UT: // unlimited text | |
650 case EVR_PN: // person name | |
651 case EVR_UI: // unique identifier | |
652 { | |
653 ok = element.putString(value.c_str()).good(); | |
654 break; | |
655 } | |
656 | |
657 | |
658 /** | |
659 * Numerical types | |
660 **/ | |
661 | |
662 case EVR_SL: // signed long | |
663 { | |
664 ok = element.putSint32(boost::lexical_cast<Sint32>(value)).good(); | |
665 break; | |
666 } | |
667 | |
668 case EVR_SS: // signed short | |
669 { | |
670 ok = element.putSint16(boost::lexical_cast<Sint16>(value)).good(); | |
671 break; | |
672 } | |
673 | |
674 case EVR_UL: // unsigned long | |
675 { | |
676 ok = element.putUint32(boost::lexical_cast<Uint32>(value)).good(); | |
677 break; | |
678 } | |
679 | |
680 case EVR_US: // unsigned short | |
681 { | |
682 ok = element.putUint16(boost::lexical_cast<Uint16>(value)).good(); | |
683 break; | |
684 } | |
685 | |
686 case EVR_FL: // float single-precision | |
687 { | |
688 ok = element.putFloat32(boost::lexical_cast<float>(value)).good(); | |
689 break; | |
690 } | |
691 | |
692 case EVR_FD: // float double-precision | |
693 { | |
694 ok = element.putFloat64(boost::lexical_cast<double>(value)).good(); | |
695 break; | |
696 } | |
697 | |
698 | |
699 /** | |
700 * Sequence types, should never occur at this point. | |
701 **/ | |
702 | |
703 case EVR_SQ: // sequence of items | |
704 { | |
705 ok = false; | |
706 break; | |
707 } | |
708 | |
709 | |
710 /** | |
711 * Internal to DCMTK. | |
712 **/ | |
713 | |
714 case EVR_ox: // OB or OW depending on context | |
715 case EVR_xs: // SS or US depending on context | |
716 case EVR_lt: // US, SS or OW depending on context, used for LUT Data (thus the name) | |
717 case EVR_na: // na="not applicable", for data which has no VR | |
718 case EVR_up: // up="unsigned pointer", used internally for DICOMDIR suppor | |
719 case EVR_item: // used internally for items | |
720 case EVR_metainfo: // used internally for meta info datasets | |
721 case EVR_dataset: // used internally for datasets | |
722 case EVR_fileFormat: // used internally for DICOM files | |
723 case EVR_dicomDir: // used internally for DICOMDIR objects | |
724 case EVR_dirRecord: // used internally for DICOMDIR records | |
725 case EVR_pixelSQ: // used internally for pixel sequences in a compressed image | |
726 case EVR_pixelItem: // used internally for pixel items in a compressed image | |
727 case EVR_UNKNOWN: // used internally for elements with unknown VR (encoded with 4-byte length field in explicit VR) | |
728 case EVR_PixelData: // used internally for uncompressed pixeld data | |
729 case EVR_OverlayData: // used internally for overlay data | |
730 case EVR_UNKNOWN2B: // used internally for elements with unknown VR with 2-byte length field in explicit VR | |
731 default: | |
732 break; | |
733 } | |
734 } | |
735 catch (boost::bad_lexical_cast&) | |
736 { | |
737 ok = false; | |
738 } | |
739 | |
740 if (!ok) | |
741 { | |
742 throw OrthancException(ErrorCode_InternalError); | |
743 } | |
744 } | |
745 | |
746 | |
747 void ParsedDicomFile::Remove(const DicomTag& tag) | |
748 { | |
749 DcmTagKey key(tag.GetGroup(), tag.GetElement()); | |
794 | 750 DcmElement* element = pimpl_->file_->getDataset()->remove(key); |
790 | 751 if (element != NULL) |
752 { | |
753 delete element; | |
754 } | |
755 } | |
756 | |
757 | |
758 | |
759 void ParsedDicomFile::RemovePrivateTags() | |
760 { | |
761 typedef std::list<DcmElement*> Tags; | |
762 | |
763 Tags privateTags; | |
764 | |
794 | 765 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
790 | 766 for (unsigned long i = 0; i < dataset.card(); i++) |
767 { | |
768 DcmElement* element = dataset.getElement(i); | |
769 DcmTag tag(element->getTag()); | |
770 if (!strcmp("PrivateCreator", tag.getTagName()) || // TODO - This may change with future versions of DCMTK | |
771 tag.getPrivateCreator() != NULL) | |
772 { | |
773 privateTags.push_back(element); | |
774 } | |
775 } | |
776 | |
777 for (Tags::iterator it = privateTags.begin(); | |
778 it != privateTags.end(); ++it) | |
779 { | |
780 DcmElement* tmp = dataset.remove(*it); | |
781 if (tmp != NULL) | |
782 { | |
783 delete tmp; | |
784 } | |
785 } | |
786 } | |
787 | |
788 | |
789 | |
790 void ParsedDicomFile::Insert(const DicomTag& tag, | |
791 const std::string& value) | |
792 { | |
793 std::auto_ptr<DcmElement> element(CreateElementForTag(tag)); | |
794 FillElementWithString(*element, tag, value); | |
795 | |
794 | 796 if (!pimpl_->file_->getDataset()->insert(element.release(), false, false).good()) |
790 | 797 { |
798 // This field already exists | |
799 throw OrthancException(ErrorCode_InternalError); | |
800 } | |
801 } | |
802 | |
803 | |
804 void ParsedDicomFile::Replace(const DicomTag& tag, | |
805 const std::string& value, | |
806 DicomReplaceMode mode) | |
807 { | |
808 DcmTagKey key(tag.GetGroup(), tag.GetElement()); | |
809 DcmElement* element = NULL; | |
810 | |
794 | 811 if (!pimpl_->file_->getDataset()->findAndGetElement(key, element).good() || |
790 | 812 element == NULL) |
813 { | |
814 // This field does not exist, act wrt. the specified "mode" | |
815 switch (mode) | |
816 { | |
817 case DicomReplaceMode_InsertIfAbsent: | |
818 Insert(tag, value); | |
819 break; | |
820 | |
821 case DicomReplaceMode_ThrowIfAbsent: | |
822 throw OrthancException(ErrorCode_InexistentItem); | |
823 | |
824 case DicomReplaceMode_IgnoreIfAbsent: | |
825 return; | |
826 } | |
827 } | |
828 else | |
829 { | |
830 FillElementWithString(*element, tag, value); | |
831 } | |
832 | |
833 | |
834 /** | |
835 * dcmodify will automatically correct 'Media Storage SOP Class | |
836 * UID' and 'Media Storage SOP Instance UID' in the metaheader, if | |
837 * you make changes to the related tags in the dataset ('SOP Class | |
838 * UID' and 'SOP Instance UID') via insert or modify mode | |
839 * options. You can disable this behaviour by using the -nmu | |
840 * option. | |
841 **/ | |
842 | |
843 if (tag == DICOM_TAG_SOP_CLASS_UID) | |
844 { | |
845 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID, value, DicomReplaceMode_InsertIfAbsent); | |
846 } | |
847 | |
848 if (tag == DICOM_TAG_SOP_INSTANCE_UID) | |
849 { | |
850 Replace(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID, value, DicomReplaceMode_InsertIfAbsent); | |
851 } | |
852 } | |
853 | |
854 | |
855 void ParsedDicomFile::Answer(RestApiOutput& output) | |
856 { | |
857 std::string serialized; | |
794 | 858 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, pimpl_->file_->getDataset())) |
790 | 859 { |
860 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM); | |
861 } | |
862 } | |
863 | |
864 | |
865 | |
866 bool ParsedDicomFile::GetTagValue(std::string& value, | |
867 const DicomTag& tag) | |
868 { | |
869 DcmTagKey k(tag.GetGroup(), tag.GetElement()); | |
794 | 870 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
790 | 871 DcmElement* element = NULL; |
872 if (!dataset.findAndGetElement(k, element).good() || | |
873 element == NULL) | |
874 { | |
875 return false; | |
876 } | |
877 | |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
878 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); |
790 | 879 |
880 if (v.get() == NULL) | |
881 { | |
882 value = ""; | |
883 } | |
884 else | |
885 { | |
886 value = v->AsString(); | |
887 } | |
888 | |
889 return true; | |
890 } | |
891 | |
892 | |
893 DicomInstanceHasher ParsedDicomFile::GetHasher() | |
894 { | |
895 std::string patientId, studyUid, seriesUid, instanceUid; | |
896 | |
897 if (!GetTagValue(patientId, DICOM_TAG_PATIENT_ID) || | |
898 !GetTagValue(studyUid, DICOM_TAG_STUDY_INSTANCE_UID) || | |
899 !GetTagValue(seriesUid, DICOM_TAG_SERIES_INSTANCE_UID) || | |
900 !GetTagValue(instanceUid, DICOM_TAG_SOP_INSTANCE_UID)) | |
901 { | |
902 throw OrthancException(ErrorCode_BadFileFormat); | |
903 } | |
904 | |
905 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid); | |
906 } | |
907 | |
908 | |
909 template <typename T> | |
910 static void ExtractPngImageTruncate(std::string& result, | |
911 DicomIntegerPixelAccessor& accessor, | |
912 PixelFormat format) | |
913 { | |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
914 assert(accessor.GetInformation().GetChannelCount() == 1); |
790 | 915 |
916 PngWriter w; | |
917 | |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
918 std::vector<T> image(accessor.GetInformation().GetWidth() * accessor.GetInformation().GetHeight(), 0); |
790 | 919 T* pixel = &image[0]; |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
920 for (unsigned int y = 0; y < accessor.GetInformation().GetHeight(); y++) |
790 | 921 { |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
922 for (unsigned int x = 0; x < accessor.GetInformation().GetWidth(); x++, pixel++) |
790 | 923 { |
924 int32_t v = accessor.GetValue(x, y); | |
925 if (v < static_cast<int32_t>(std::numeric_limits<T>::min())) | |
926 *pixel = std::numeric_limits<T>::min(); | |
927 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max())) | |
928 *pixel = std::numeric_limits<T>::max(); | |
929 else | |
930 *pixel = static_cast<T>(v); | |
931 } | |
932 } | |
933 | |
853
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
934 w.WriteToMemory(result, accessor.GetInformation().GetWidth(), accessor.GetInformation().GetHeight(), |
839be3022203
DicomImageInformation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
935 accessor.GetInformation().GetWidth() * sizeof(T), format, &image[0]); |
790 | 936 } |
937 | |
938 | |
939 void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer) | |
940 { | |
794 | 941 FromDcmtkBridge::SaveToMemoryBuffer(buffer, pimpl_->file_->getDataset()); |
790 | 942 } |
943 | |
944 | |
945 void ParsedDicomFile::SaveToFile(const std::string& path) | |
946 { | |
947 // TODO Avoid using a temporary memory buffer, write directly on disk | |
948 std::string content; | |
949 SaveToMemoryBuffer(content); | |
950 Toolbox::WriteFile(content, path); | |
951 } | |
952 | |
953 | |
794 | 954 ParsedDicomFile::ParsedDicomFile() : pimpl_(new PImpl) |
790 | 955 { |
794 | 956 pimpl_->file_.reset(new DcmFileFormat); |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
957 pimpl_->encoding_ = Encoding_Ascii; |
790 | 958 Replace(DICOM_TAG_PATIENT_ID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Patient)); |
959 Replace(DICOM_TAG_STUDY_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Study)); | |
960 Replace(DICOM_TAG_SERIES_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Series)); | |
961 Replace(DICOM_TAG_SOP_INSTANCE_UID, FromDcmtkBridge::GenerateUniqueIdentifier(ResourceType_Instance)); | |
962 } | |
963 | |
791 | 964 |
794 | 965 ParsedDicomFile::ParsedDicomFile(const char* content, size_t size) : pimpl_(new PImpl) |
791 | 966 { |
967 Setup(content, size); | |
968 } | |
969 | |
794 | 970 ParsedDicomFile::ParsedDicomFile(const std::string& content) : pimpl_(new PImpl) |
791 | 971 { |
972 if (content.size() == 0) | |
973 { | |
974 Setup(NULL, 0); | |
975 } | |
976 else | |
977 { | |
978 Setup(&content[0], content.size()); | |
979 } | |
980 } | |
792 | 981 |
982 | |
794 | 983 ParsedDicomFile::ParsedDicomFile(ParsedDicomFile& other) : |
984 pimpl_(new PImpl) | |
792 | 985 { |
794 | 986 pimpl_->file_.reset(dynamic_cast<DcmFileFormat*>(other.pimpl_->file_->clone())); |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
987 |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
988 pimpl_->encoding_ = other.pimpl_->encoding_; |
792 | 989 } |
990 | |
991 | |
992 ParsedDicomFile::~ParsedDicomFile() | |
993 { | |
794 | 994 delete pimpl_; |
792 | 995 } |
996 | |
793 | 997 |
998 void* ParsedDicomFile::GetDcmtkObject() | |
999 { | |
794 | 1000 return pimpl_->file_.get(); |
793 | 1001 } |
1002 | |
1003 | |
1004 ParsedDicomFile* ParsedDicomFile::Clone() | |
1005 { | |
794 | 1006 return new ParsedDicomFile(*this); |
793 | 1007 } |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1008 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1009 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1010 void ParsedDicomFile::EmbedImage(const std::string& dataUriScheme) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1011 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1012 std::string mime, content; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1013 Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1014 |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
1015 std::string decoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
1016 Toolbox::DecodeBase64(decoded, content); |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1017 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1018 if (mime == "image/png") |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1019 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1020 PngReader reader; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1021 reader.ReadFromMemory(decoded); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1022 EmbedImage(reader); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1023 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1024 else |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1025 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1026 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1027 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1028 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1029 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1030 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1031 void ParsedDicomFile::EmbedImage(const ImageAccessor& accessor) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1032 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1033 if (accessor.GetFormat() != PixelFormat_Grayscale8 && |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1034 accessor.GetFormat() != PixelFormat_Grayscale16 && |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1035 accessor.GetFormat() != PixelFormat_RGB24 && |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1036 accessor.GetFormat() != PixelFormat_RGBA32) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1037 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1038 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1039 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1040 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1041 if (accessor.GetFormat() == PixelFormat_RGBA32) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1042 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1043 LOG(WARNING) << "Getting rid of the alpha channel when embedding a RGBA image inside DICOM"; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1044 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1045 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1046 // http://dicomiseasy.blogspot.be/2012/08/chapter-12-pixel-data.html |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1047 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1048 Remove(DICOM_TAG_PIXEL_DATA); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1049 Replace(DICOM_TAG_COLUMNS, boost::lexical_cast<std::string>(accessor.GetWidth())); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1050 Replace(DICOM_TAG_ROWS, boost::lexical_cast<std::string>(accessor.GetHeight())); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1051 Replace(DICOM_TAG_SAMPLES_PER_PIXEL, "1"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1052 Replace(DICOM_TAG_NUMBER_OF_FRAMES, "1"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1053 Replace(DICOM_TAG_PIXEL_REPRESENTATION, "0"); // Unsigned pixels |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1054 Replace(DICOM_TAG_PLANAR_CONFIGURATION, "0"); // Color channels are interleaved |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1055 Replace(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "MONOCHROME2"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1056 Replace(DICOM_TAG_BITS_ALLOCATED, "8"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1057 Replace(DICOM_TAG_BITS_STORED, "8"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1058 Replace(DICOM_TAG_HIGH_BIT, "7"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1059 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1060 unsigned int bytesPerPixel = 1; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1061 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1062 switch (accessor.GetFormat()) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1063 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1064 case PixelFormat_RGB24: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1065 case PixelFormat_RGBA32: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1066 Replace(DICOM_TAG_PHOTOMETRIC_INTERPRETATION, "RGB"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1067 Replace(DICOM_TAG_SAMPLES_PER_PIXEL, "3"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1068 bytesPerPixel = 3; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1069 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1070 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1071 case PixelFormat_Grayscale8: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1072 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1073 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1074 case PixelFormat_Grayscale16: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1075 Replace(DICOM_TAG_BITS_ALLOCATED, "16"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1076 Replace(DICOM_TAG_BITS_STORED, "16"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1077 Replace(DICOM_TAG_HIGH_BIT, "15"); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1078 bytesPerPixel = 2; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1079 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1080 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1081 default: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1082 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1083 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1084 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1085 DcmTag key(DICOM_TAG_PIXEL_DATA.GetGroup(), |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1086 DICOM_TAG_PIXEL_DATA.GetElement()); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1087 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1088 std::auto_ptr<DcmPixelData> pixels(new DcmPixelData(key)); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1089 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1090 unsigned int pitch = accessor.GetWidth() * bytesPerPixel; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1091 Uint8* target = NULL; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1092 pixels->createUint8Array(accessor.GetHeight() * pitch, target); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1093 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1094 for (unsigned int y = 0; y < accessor.GetHeight(); y++) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1095 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1096 switch (accessor.GetFormat()) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1097 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1098 case PixelFormat_RGB24: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1099 case PixelFormat_Grayscale8: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1100 case PixelFormat_Grayscale16: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1101 case PixelFormat_SignedGrayscale16: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1102 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1103 memcpy(target, reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)), pitch); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1104 target += pitch; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1105 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1106 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1107 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1108 case PixelFormat_RGBA32: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1109 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1110 // The alpha channel is not supported by the DICOM standard |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1111 const Uint8* source = reinterpret_cast<const Uint8*>(accessor.GetConstRow(y)); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1112 for (unsigned int x = 0; x < accessor.GetWidth(); x++, target += 3, source += 4) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1113 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1114 target[0] = source[0]; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1115 target[1] = source[1]; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1116 target[2] = source[2]; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1117 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1118 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1119 break; |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1120 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1121 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1122 default: |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1123 throw OrthancException(ErrorCode_NotImplemented); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1124 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1125 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1126 |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1127 if (!pimpl_->file_->getDataset()->insert(pixels.release(), false, false).good()) |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1128 { |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1129 throw OrthancException(ErrorCode_InternalError); |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1130 } |
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
1131 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1132 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1133 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1134 void ParsedDicomFile::ExtractImage(ImageBuffer& result, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1135 unsigned int frame) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1136 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1137 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1138 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1139 if (!DicomImageDecoder::Decode(result, dataset, frame)) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1140 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1141 throw OrthancException(ErrorCode_BadFileFormat); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1142 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1143 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1144 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1145 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1146 void ParsedDicomFile::ExtractImage(ImageBuffer& result, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1147 unsigned int frame, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1148 ImageExtractionMode mode) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1149 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1150 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1151 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1152 bool ok = false; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1153 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1154 switch (mode) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1155 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1156 case ImageExtractionMode_UInt8: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1157 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale8); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1158 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1159 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1160 case ImageExtractionMode_UInt16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1161 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale16); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1162 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1163 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1164 case ImageExtractionMode_Int16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1165 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_SignedGrayscale16); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1166 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1167 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1168 case ImageExtractionMode_Preview: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1169 ok = DicomImageDecoder::DecodePreview(result, dataset, frame); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1170 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1171 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1172 default: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1173 throw OrthancException(ErrorCode_ParameterOutOfRange); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1174 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1175 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1176 if (!ok) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1177 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1178 throw OrthancException(ErrorCode_BadFileFormat); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1179 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1180 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1181 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1182 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1183 void ParsedDicomFile::ExtractPngImage(std::string& result, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1184 unsigned int frame, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1185 ImageExtractionMode mode) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1186 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1187 ImageBuffer buffer; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1188 ExtractImage(buffer, frame, mode); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1189 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1190 ImageAccessor accessor(buffer.GetConstAccessor()); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1191 PngWriter writer; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1192 writer.WriteToMemory(result, accessor); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1193 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
853
diff
changeset
|
1194 |
956
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1195 |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1196 Encoding ParsedDicomFile::GetEncoding() const |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1197 { |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1198 return pimpl_->encoding_; |
2fd5a163776d
primitives for proper encoding handling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
874
diff
changeset
|
1199 } |
790 | 1200 } |