comparison OrthancServer/Internals/DicomImageDecoder.cpp @ 1824:b530c3dfe2a6

refactoring image decoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2015 14:14:32 +0100
parents 96582230ddcb
children ac5b0b4e2434
comparison
equal deleted inserted replaced
1823:0ef4e6e66b56 1824:b530c3dfe2a6
85 #include "../../Core/Images/ImageProcessing.h" 85 #include "../../Core/Images/ImageProcessing.h"
86 #include "../../Core/Images/PngWriter.h" // TODO REMOVE THIS 86 #include "../../Core/Images/PngWriter.h" // TODO REMOVE THIS
87 #include "../../Core/DicomFormat/DicomIntegerPixelAccessor.h" 87 #include "../../Core/DicomFormat/DicomIntegerPixelAccessor.h"
88 #include "../ToDcmtkBridge.h" 88 #include "../ToDcmtkBridge.h"
89 #include "../FromDcmtkBridge.h" 89 #include "../FromDcmtkBridge.h"
90 #include "../ParsedDicomFile.h"
90 91
91 #include <boost/lexical_cast.hpp> 92 #include <boost/lexical_cast.hpp>
92 93
93 #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1 94 #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1
94 #include <dcmtk/dcmjpls/djcodecd.h> 95 #include <dcmtk/dcmjpls/djcodecd.h>
529 530
530 531
531 532
532 533
533 bool DicomImageDecoder::Decode(ImageBuffer& target, 534 bool DicomImageDecoder::Decode(ImageBuffer& target,
534 DcmDataset& dataset, 535 ParsedDicomFile& dicom,
535 unsigned int frame) 536 unsigned int frame)
536 { 537 {
538 DcmDataset& dataset = *dicom.GetDcmtkObject().getDataset();
539
537 if (IsUncompressedImage(dataset)) 540 if (IsUncompressedImage(dataset))
538 { 541 {
539 DecodeUncompressedImage(target, dataset, frame); 542 DecodeUncompressedImage(target, dataset, frame);
540 return true; 543 return true;
541 } 544 }
586 return (format == PixelFormat_RGB24 || 589 return (format == PixelFormat_RGB24 ||
587 format == PixelFormat_RGBA32); 590 format == PixelFormat_RGBA32);
588 } 591 }
589 592
590 593
591 bool DicomImageDecoder::DecodeAndTruncate(ImageBuffer& target, 594 bool DicomImageDecoder::TruncateDecodedImage(ImageBuffer& target,
592 DcmDataset& dataset, 595 ImageBuffer& source,
593 unsigned int frame, 596 PixelFormat format,
594 PixelFormat format, 597 bool allowColorConversion)
595 bool allowColorConversion) 598 {
596 {
597 // TODO Special case for uncompressed images
598
599 ImageBuffer source;
600 if (!Decode(source, dataset, frame))
601 {
602 return false;
603 }
604
605 // If specified, prevent the conversion between color and 599 // If specified, prevent the conversion between color and
606 // grayscale images 600 // grayscale images
607 bool isSourceColor = IsColorImage(source.GetFormat()); 601 bool isSourceColor = IsColorImage(source.GetFormat());
608 bool isTargetColor = IsColorImage(format); 602 bool isTargetColor = IsColorImage(format);
609 603
632 626
633 return true; 627 return true;
634 } 628 }
635 629
636 630
637 bool DicomImageDecoder::DecodePreview(ImageBuffer& target, 631 bool DicomImageDecoder::PreviewDecodedImage(ImageBuffer& target,
638 DcmDataset& dataset, 632 ImageBuffer& source)
639 unsigned int frame) 633 {
640 {
641 // TODO Special case for uncompressed images
642
643 ImageBuffer source;
644 if (!Decode(source, dataset, frame))
645 {
646 return false;
647 }
648
649 switch (source.GetFormat()) 634 switch (source.GetFormat())
650 { 635 {
651 case PixelFormat_RGB24: 636 case PixelFormat_RGB24:
652 { 637 {
653 // Directly return color images (RGB) 638 // Directly return color images (RGB)