Mercurial > hg > orthanc
comparison OrthancServer/Internals/DicomImageDecoder.cpp @ 1902:8b0ee8d5e6d0
Refactoring leading to speedups with custom image decoders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 05 Jan 2016 13:26:51 +0100 |
parents | b1291df2f780 |
children | 554ec8422ec5 |
comparison
equal
deleted
inserted
replaced
1901:50234539a0dd | 1902:8b0ee8d5e6d0 |
---|---|
82 | 82 |
83 #include "../../Core/Logging.h" | 83 #include "../../Core/Logging.h" |
84 #include "../../Core/OrthancException.h" | 84 #include "../../Core/OrthancException.h" |
85 #include "../../Core/Images/Image.h" | 85 #include "../../Core/Images/Image.h" |
86 #include "../../Core/Images/ImageProcessing.h" | 86 #include "../../Core/Images/ImageProcessing.h" |
87 #include "../../Core/Images/PngWriter.h" | |
88 #include "../../Core/Images/JpegWriter.h" | |
87 #include "../../Core/DicomFormat/DicomIntegerPixelAccessor.h" | 89 #include "../../Core/DicomFormat/DicomIntegerPixelAccessor.h" |
88 #include "../ToDcmtkBridge.h" | 90 #include "../ToDcmtkBridge.h" |
89 #include "../FromDcmtkBridge.h" | 91 #include "../FromDcmtkBridge.h" |
90 #include "../ParsedDicomFile.h" | 92 #include "../ParsedDicomFile.h" |
91 | 93 |
569 { | 571 { |
570 return DecodeUncompressedImageInternal(*converted, frame); | 572 return DecodeUncompressedImageInternal(*converted, frame); |
571 } | 573 } |
572 } | 574 } |
573 | 575 |
574 return NULL; | 576 LOG(ERROR) << "Cannot decode a DICOM image with the built-in decoder"; |
577 throw OrthancException(ErrorCode_BadFileFormat); | |
575 } | 578 } |
576 | 579 |
577 | 580 |
578 static bool IsColorImage(PixelFormat format) | 581 static bool IsColorImage(PixelFormat format) |
579 { | 582 { |
651 | 654 |
652 default: | 655 default: |
653 throw OrthancException(ErrorCode_NotImplemented); | 656 throw OrthancException(ErrorCode_NotImplemented); |
654 } | 657 } |
655 } | 658 } |
659 | |
660 | |
661 void DicomImageDecoder::ApplyExtractionMode(std::auto_ptr<ImageAccessor>& image, | |
662 ImageExtractionMode mode) | |
663 { | |
664 if (image.get() == NULL) | |
665 { | |
666 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
667 } | |
668 | |
669 bool ok = false; | |
670 | |
671 switch (mode) | |
672 { | |
673 case ImageExtractionMode_UInt8: | |
674 ok = TruncateDecodedImage(image, PixelFormat_Grayscale8, false); | |
675 break; | |
676 | |
677 case ImageExtractionMode_UInt16: | |
678 ok = TruncateDecodedImage(image, PixelFormat_Grayscale16, false); | |
679 break; | |
680 | |
681 case ImageExtractionMode_Int16: | |
682 ok = TruncateDecodedImage(image, PixelFormat_SignedGrayscale16, false); | |
683 break; | |
684 | |
685 case ImageExtractionMode_Preview: | |
686 ok = PreviewDecodedImage(image); | |
687 break; | |
688 | |
689 default: | |
690 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
691 } | |
692 | |
693 if (ok) | |
694 { | |
695 assert(image.get() != NULL); | |
696 } | |
697 else | |
698 { | |
699 throw OrthancException(ErrorCode_NotImplemented); | |
700 } | |
701 } | |
702 | |
703 | |
704 void DicomImageDecoder::ExtractPngImage(std::string& result, | |
705 std::auto_ptr<ImageAccessor>& image, | |
706 ImageExtractionMode mode) | |
707 { | |
708 ApplyExtractionMode(image, mode); | |
709 | |
710 PngWriter writer; | |
711 writer.WriteToMemory(result, *image); | |
712 } | |
713 | |
714 | |
715 void DicomImageDecoder::ExtractJpegImage(std::string& result, | |
716 std::auto_ptr<ImageAccessor>& image, | |
717 ImageExtractionMode mode, | |
718 uint8_t quality) | |
719 { | |
720 if (mode != ImageExtractionMode_UInt8 && | |
721 mode != ImageExtractionMode_Preview) | |
722 { | |
723 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
724 } | |
725 | |
726 ApplyExtractionMode(image, mode); | |
727 | |
728 JpegWriter writer; | |
729 writer.SetQuality(quality); | |
730 writer.WriteToMemory(result, *image); | |
731 } | |
656 } | 732 } |