Mercurial > hg > orthanc
comparison OrthancServer/FromDcmtkBridge.cpp @ 874:87791ebc1f50
download matlab images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Jun 2014 12:23:02 +0200 |
parents | 2c545bb20dd3 |
children | e57e08ed510f 766a57997121 |
comparison
equal
deleted
inserted
replaced
873:fc34356283e1 | 874:87791ebc1f50 |
---|---|
426 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); | 426 FromDcmtkBridge::ToJson(target, *dicom.getDataset(), maxStringLength); |
427 } | 427 } |
428 } | 428 } |
429 | 429 |
430 | 430 |
431 void FromDcmtkBridge::ExtractPngImage(std::string& result, | |
432 DcmDataset& dataset, | |
433 unsigned int frame, | |
434 ImageExtractionMode mode) | |
435 { | |
436 ImageBuffer tmp; | |
437 bool ok = false; | |
438 | |
439 switch (mode) | |
440 { | |
441 case ImageExtractionMode_UInt8: | |
442 ok = DicomImageDecoder::DecodeAndTruncate(tmp, dataset, frame, PixelFormat_Grayscale8); | |
443 break; | |
444 | |
445 case ImageExtractionMode_UInt16: | |
446 ok = DicomImageDecoder::DecodeAndTruncate(tmp, dataset, frame, PixelFormat_Grayscale16); | |
447 break; | |
448 | |
449 case ImageExtractionMode_Int16: | |
450 ok = DicomImageDecoder::DecodeAndTruncate(tmp, dataset, frame, PixelFormat_SignedGrayscale16); | |
451 break; | |
452 | |
453 case ImageExtractionMode_Preview: | |
454 ok = DicomImageDecoder::DecodePreview(tmp, dataset, frame); | |
455 break; | |
456 | |
457 default: | |
458 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
459 } | |
460 | |
461 if (!ok) | |
462 { | |
463 throw OrthancException(ErrorCode_BadFileFormat); | |
464 } | |
465 | |
466 ImageAccessor accessor(tmp.GetAccessor()); | |
467 PngWriter writer; | |
468 writer.WriteToMemory(result, accessor); | |
469 } | |
470 | |
471 | |
472 void FromDcmtkBridge::ExtractPngImage(std::string& result, | |
473 const std::string& dicomContent, | |
474 unsigned int frame, | |
475 ImageExtractionMode mode) | |
476 { | |
477 DcmInputBufferStream is; | |
478 if (dicomContent.size() > 0) | |
479 { | |
480 is.setBuffer(&dicomContent[0], dicomContent.size()); | |
481 } | |
482 is.setEos(); | |
483 | |
484 DcmFileFormat dicom; | |
485 if (dicom.read(is).good()) | |
486 { | |
487 ExtractPngImage(result, *dicom.getDataset(), frame, mode); | |
488 } | |
489 else | |
490 { | |
491 throw OrthancException(ErrorCode_BadFileFormat); | |
492 } | |
493 } | |
494 | |
495 | |
496 | 431 |
497 std::string FromDcmtkBridge::GetName(const DicomTag& t) | 432 std::string FromDcmtkBridge::GetName(const DicomTag& t) |
498 { | 433 { |
499 // Some patches for important tags because of different DICOM | 434 // Some patches for important tags because of different DICOM |
500 // dictionaries between DCMTK versions | 435 // dictionaries between DCMTK versions |