comparison Core/DicomParsing/Internals/DicomImageDecoder.cpp @ 3712:2a170a8f1faf

replacing std::auto_ptr by std::unique_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Mar 2020 15:32:45 +0100
parents 94f4a18a79cc
children accf1b60b108
comparison
equal deleted inserted replaced
3709:1f4910999fe7 3712:2a170a8f1faf
247 247
248 class DicomImageDecoder::ImageSource 248 class DicomImageDecoder::ImageSource
249 { 249 {
250 private: 250 private:
251 std::string psmct_; 251 std::string psmct_;
252 std::auto_ptr<DicomIntegerPixelAccessor> slowAccessor_; 252 std::unique_ptr<DicomIntegerPixelAccessor> slowAccessor_;
253 253
254 public: 254 public:
255 void Setup(DcmDataset& dataset, 255 void Setup(DcmDataset& dataset,
256 unsigned int frame) 256 unsigned int frame)
257 { 257 {
386 } 386 }
387 } 387 }
388 } 388 }
389 389
390 390
391 static ImageAccessor* DecodeLookupTable(std::auto_ptr<ImageAccessor>& target, 391 static ImageAccessor* DecodeLookupTable(std::unique_ptr<ImageAccessor>& target,
392 const DicomImageInformation& info, 392 const DicomImageInformation& info,
393 DcmDataset& dataset, 393 DcmDataset& dataset,
394 const uint8_t* pixelData, 394 const uint8_t* pixelData,
395 unsigned long pixelLength) 395 unsigned long pixelLength)
396 { 396 {
506 { 506 {
507 /** 507 /**
508 * Create the target image. 508 * Create the target image.
509 **/ 509 **/
510 510
511 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, false)); 511 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, false));
512 512
513 ImageSource source; 513 ImageSource source;
514 source.Setup(dataset, frame); 514 source.Setup(dataset, frame);
515 515
516 if (source.GetWidth() != target->GetWidth() || 516 if (source.GetWidth() != target->GetWidth() ||
614 614
615 DicomMap m; 615 DicomMap m;
616 FromDcmtkBridge::ExtractDicomSummary(m, dataset); 616 FromDcmtkBridge::ExtractDicomSummary(m, dataset);
617 DicomImageInformation info(m); 617 DicomImageInformation info(m);
618 618
619 std::auto_ptr<ImageAccessor> target(CreateImage(dataset, true)); 619 std::unique_ptr<ImageAccessor> target(CreateImage(dataset, true));
620 620
621 Uint32 startFragment = 0; // Default 621 Uint32 startFragment = 0; // Default
622 OFString decompressedColorModel; // Out 622 OFString decompressedColorModel; // Out
623 623
624 OFCondition c; 624 OFCondition c;
690 // The (2, OFTrue) are the default parameters as found in DCMTK 3.6.2 690 // The (2, OFTrue) are the default parameters as found in DCMTK 3.6.2
691 // http://support.dcmtk.org/docs/classDJLSRepresentationParameter.html 691 // http://support.dcmtk.org/docs/classDJLSRepresentationParameter.html
692 DJLSRepresentationParameter representationParameter(2, OFTrue); 692 DJLSRepresentationParameter representationParameter(2, OFTrue);
693 693
694 DJLSCodecParameter parameters; 694 DJLSCodecParameter parameters;
695 std::auto_ptr<DJLSDecoderBase> decoder; 695 std::unique_ptr<DJLSDecoderBase> decoder;
696 696
697 switch (syntax) 697 switch (syntax)
698 { 698 {
699 case EXS_JPEGLSLossless: 699 case EXS_JPEGLSLossless:
700 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image"; 700 LOG(INFO) << "Decoding a JPEG-LS lossless DICOM image";
732 ECC_lossyYCbCr, // Mode for color conversion for compression, Unused for decompression 732 ECC_lossyYCbCr, // Mode for color conversion for compression, Unused for decompression
733 EDC_photometricInterpretation, // Perform color space conversion from YCbCr to RGB if DICOM photometric interpretation indicates YCbCr 733 EDC_photometricInterpretation, // Perform color space conversion from YCbCr to RGB if DICOM photometric interpretation indicates YCbCr
734 EUC_default, // Mode for UID creation, unused for decompression 734 EUC_default, // Mode for UID creation, unused for decompression
735 EPC_default); // Automatically determine whether color-by-plane is required from the SOP Class UID and decompressed photometric interpretation 735 EPC_default); // Automatically determine whether color-by-plane is required from the SOP Class UID and decompressed photometric interpretation
736 DJ_RPLossy representationParameter; 736 DJ_RPLossy representationParameter;
737 std::auto_ptr<DJCodecDecoder> decoder; 737 std::unique_ptr<DJCodecDecoder> decoder;
738 738
739 switch (syntax) 739 switch (syntax)
740 { 740 {
741 case EXS_JPEGProcess1: 741 case EXS_JPEGProcess1:
742 LOG(INFO) << "Decoding a JPEG baseline (process 1) DICOM image"; 742 LOG(INFO) << "Decoding a JPEG baseline (process 1) DICOM image";
797 **/ 797 **/
798 798
799 { 799 {
800 LOG(INFO) << "Decoding a compressed image by converting its transfer syntax to Little Endian"; 800 LOG(INFO) << "Decoding a compressed image by converting its transfer syntax to Little Endian";
801 801
802 std::auto_ptr<DcmDataset> converted(dynamic_cast<DcmDataset*>(dataset.clone())); 802 std::unique_ptr<DcmDataset> converted(dynamic_cast<DcmDataset*>(dataset.clone()));
803 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL); 803 converted->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
804 804
805 if (converted->canWriteXfer(EXS_LittleEndianExplicit)) 805 if (converted->canWriteXfer(EXS_LittleEndianExplicit))
806 { 806 {
807 return DecodeUncompressedImage(*converted, frame); 807 return DecodeUncompressedImage(*converted, frame);
818 return (format == PixelFormat_RGB24 || 818 return (format == PixelFormat_RGB24 ||
819 format == PixelFormat_RGBA32); 819 format == PixelFormat_RGBA32);
820 } 820 }
821 821
822 822
823 bool DicomImageDecoder::TruncateDecodedImage(std::auto_ptr<ImageAccessor>& image, 823 bool DicomImageDecoder::TruncateDecodedImage(std::unique_ptr<ImageAccessor>& image,
824 PixelFormat format, 824 PixelFormat format,
825 bool allowColorConversion) 825 bool allowColorConversion)
826 { 826 {
827 // If specified, prevent the conversion between color and 827 // If specified, prevent the conversion between color and
828 // grayscale images 828 // grayscale images
838 } 838 }
839 839
840 if (image->GetFormat() != format) 840 if (image->GetFormat() != format)
841 { 841 {
842 // A conversion is required 842 // A conversion is required
843 std::auto_ptr<ImageAccessor> target 843 std::unique_ptr<ImageAccessor> target
844 (new Image(format, image->GetWidth(), image->GetHeight(), false)); 844 (new Image(format, image->GetWidth(), image->GetHeight(), false));
845 ImageProcessing::Convert(*target, *image); 845 ImageProcessing::Convert(*target, *image);
846 image = target; 846
847 #if __cplusplus < 201103L
848 image.reset(target.release());
849 #else
850 image = std::move(target);
851 #endif
847 } 852 }
848 853
849 return true; 854 return true;
850 } 855 }
851 856
852 857
853 bool DicomImageDecoder::PreviewDecodedImage(std::auto_ptr<ImageAccessor>& image) 858 bool DicomImageDecoder::PreviewDecodedImage(std::unique_ptr<ImageAccessor>& image)
854 { 859 {
855 switch (image->GetFormat()) 860 switch (image->GetFormat())
856 { 861 {
857 case PixelFormat_RGB24: 862 case PixelFormat_RGB24:
858 { 863 {
860 return true; 865 return true;
861 } 866 }
862 867
863 case PixelFormat_RGB48: 868 case PixelFormat_RGB48:
864 { 869 {
865 std::auto_ptr<ImageAccessor> target 870 std::unique_ptr<ImageAccessor> target
866 (new Image(PixelFormat_RGB24, image->GetWidth(), image->GetHeight(), false)); 871 (new Image(PixelFormat_RGB24, image->GetWidth(), image->GetHeight(), false));
867 ImageProcessing::Convert(*target, *image); 872 ImageProcessing::Convert(*target, *image);
868 image = target; 873
874 #if __cplusplus < 201103L
875 image.reset(target.release());
876 #else
877 image = std::move(target);
878 #endif
879
869 return true; 880 return true;
870 } 881 }
871 882
872 case PixelFormat_Grayscale8: 883 case PixelFormat_Grayscale8:
873 case PixelFormat_Grayscale16: 884 case PixelFormat_Grayscale16:
889 } 900 }
890 901
891 // If the source image is not grayscale 8bpp, convert it 902 // If the source image is not grayscale 8bpp, convert it
892 if (image->GetFormat() != PixelFormat_Grayscale8) 903 if (image->GetFormat() != PixelFormat_Grayscale8)
893 { 904 {
894 std::auto_ptr<ImageAccessor> target 905 std::unique_ptr<ImageAccessor> target
895 (new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false)); 906 (new Image(PixelFormat_Grayscale8, image->GetWidth(), image->GetHeight(), false));
896 ImageProcessing::Convert(*target, *image); 907 ImageProcessing::Convert(*target, *image);
897 image = target; 908
909 #if __cplusplus < 201103L
910 image.reset(target.release());
911 #else
912 image = std::move(target);
913 #endif
898 } 914 }
899 915
900 return true; 916 return true;
901 } 917 }
902 918
904 throw OrthancException(ErrorCode_NotImplemented); 920 throw OrthancException(ErrorCode_NotImplemented);
905 } 921 }
906 } 922 }
907 923
908 924
909 void DicomImageDecoder::ApplyExtractionMode(std::auto_ptr<ImageAccessor>& image, 925 void DicomImageDecoder::ApplyExtractionMode(std::unique_ptr<ImageAccessor>& image,
910 ImageExtractionMode mode, 926 ImageExtractionMode mode,
911 bool invert) 927 bool invert)
912 { 928 {
913 if (image.get() == NULL) 929 if (image.get() == NULL)
914 { 930 {
954 } 970 }
955 } 971 }
956 972
957 973
958 void DicomImageDecoder::ExtractPamImage(std::string& result, 974 void DicomImageDecoder::ExtractPamImage(std::string& result,
959 std::auto_ptr<ImageAccessor>& image, 975 std::unique_ptr<ImageAccessor>& image,
960 ImageExtractionMode mode, 976 ImageExtractionMode mode,
961 bool invert) 977 bool invert)
962 { 978 {
963 ApplyExtractionMode(image, mode, invert); 979 ApplyExtractionMode(image, mode, invert);
964 980
966 writer.WriteToMemory(result, *image); 982 writer.WriteToMemory(result, *image);
967 } 983 }
968 984
969 #if ORTHANC_ENABLE_PNG == 1 985 #if ORTHANC_ENABLE_PNG == 1
970 void DicomImageDecoder::ExtractPngImage(std::string& result, 986 void DicomImageDecoder::ExtractPngImage(std::string& result,
971 std::auto_ptr<ImageAccessor>& image, 987 std::unique_ptr<ImageAccessor>& image,
972 ImageExtractionMode mode, 988 ImageExtractionMode mode,
973 bool invert) 989 bool invert)
974 { 990 {
975 ApplyExtractionMode(image, mode, invert); 991 ApplyExtractionMode(image, mode, invert);
976 992
980 #endif 996 #endif
981 997
982 998
983 #if ORTHANC_ENABLE_JPEG == 1 999 #if ORTHANC_ENABLE_JPEG == 1
984 void DicomImageDecoder::ExtractJpegImage(std::string& result, 1000 void DicomImageDecoder::ExtractJpegImage(std::string& result,
985 std::auto_ptr<ImageAccessor>& image, 1001 std::unique_ptr<ImageAccessor>& image,
986 ImageExtractionMode mode, 1002 ImageExtractionMode mode,
987 bool invert, 1003 bool invert,
988 uint8_t quality) 1004 uint8_t quality)
989 { 1005 {
990 if (mode != ImageExtractionMode_UInt8 && 1006 if (mode != ImageExtractionMode_UInt8 &&