comparison UnitTestsSources/FromDcmtkTests.cpp @ 3883:795c9ca5eb91 transcoding

DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 May 2020 14:11:47 +0200
parents 904575738462
children 83061cdc7703
comparison
equal deleted inserted replaced
3882:904575738462 3883:795c9ca5eb91
2089 throw OrthancException(ErrorCode_InternalError); 2089 throw OrthancException(ErrorCode_InternalError);
2090 } 2090 }
2091 2091
2092 DcmDataset& dataset = *dicom.getDataset(); 2092 DcmDataset& dataset = *dicom.getDataset();
2093 2093
2094 E_TransferSyntax xfer = dataset.getOriginalXfer(); 2094 E_TransferSyntax xfer = dataset.getCurrentXfer();
2095 if (xfer == EXS_Unknown) 2095 if (xfer == EXS_Unknown)
2096 { 2096 {
2097 dataset.updateOriginalXfer(); 2097 dataset.updateOriginalXfer();
2098 xfer = dataset.getOriginalXfer(); 2098 xfer = dataset.getCurrentXfer();
2099 if (xfer == EXS_Unknown) 2099 if (xfer == EXS_Unknown)
2100 { 2100 {
2101 throw OrthancException(ErrorCode_BadFileFormat, 2101 throw OrthancException(ErrorCode_BadFileFormat,
2102 "Cannot determine the transfer syntax of the DICOM instance"); 2102 "Cannot determine the transfer syntax of the DICOM instance");
2103 } 2103 }
2325 } 2325 }
2326 2326
2327 DcmDataset& dataset = *dicom_->getDataset(); 2327 DcmDataset& dataset = *dicom_->getDataset();
2328 index_.reset(new DicomFrameIndex(dataset)); 2328 index_.reset(new DicomFrameIndex(dataset));
2329 2329
2330 E_TransferSyntax xfer = dataset.getOriginalXfer(); 2330 E_TransferSyntax xfer = dataset.getCurrentXfer();
2331 if (xfer == EXS_Unknown) 2331 if (xfer == EXS_Unknown)
2332 { 2332 {
2333 dataset.updateOriginalXfer(); 2333 dataset.updateOriginalXfer();
2334 xfer = dataset.getOriginalXfer(); 2334 xfer = dataset.getCurrentXfer();
2335 if (xfer == EXS_Unknown) 2335 if (xfer == EXS_Unknown)
2336 { 2336 {
2337 throw OrthancException(ErrorCode_BadFileFormat, 2337 throw OrthancException(ErrorCode_BadFileFormat,
2338 "Cannot determine the transfer syntax of the DICOM instance"); 2338 "Cannot determine the transfer syntax of the DICOM instance");
2339 } 2339 }
2867 public: 2867 public:
2868 virtual ~IDicomTranscoder() 2868 virtual ~IDicomTranscoder()
2869 { 2869 {
2870 } 2870 }
2871 2871
2872 /**
2873 * Transcoding flavor that creates a new parsed DICOM file. A
2874 * "std::set<>" is used to give the possible plugin the
2875 * possibility to do a single parsing for all the possible
2876 * transfer syntaxes.
2877 **/
2872 virtual DcmFileFormat* Transcode(const void* buffer, 2878 virtual DcmFileFormat* Transcode(const void* buffer,
2873 size_t size, 2879 size_t size,
2874 const std::set<DicomTransferSyntax>& allowedSyntaxes, 2880 const std::set<DicomTransferSyntax>& allowedSyntaxes,
2875 bool allowNewSopInstanceUid) = 0; 2881 bool allowNewSopInstanceUid) = 0;
2876 2882
2877 // In-place transcoding. This method can return "false" if not supported, 2883 /**
2878 // in which case the "Transcode()" method should be used. 2884 * In-place transcoding. This method is used first during
2885 * C-STORE. It can return "false" if inplace is not supported, in
2886 * which case the "Transcode()" method should be used.
2887 **/
2879 virtual bool InplaceTranscode(DcmFileFormat& dicom, 2888 virtual bool InplaceTranscode(DcmFileFormat& dicom,
2880 const std::set<DicomTransferSyntax>& allowedSyntaxes, 2889 const std::set<DicomTransferSyntax>& allowedSyntaxes,
2881 bool allowNewSopInstanceUid) = 0; 2890 bool allowNewSopInstanceUid) = 0;
2882 2891
2883 /** 2892 /**
2941 else 2950 else
2942 { 2951 {
2943 transcoded.reset(transcoder.Transcode(buffer, size, uncompressedSyntaxes, false)); 2952 transcoded.reset(transcoder.Transcode(buffer, size, uncompressedSyntaxes, false));
2944 } 2953 }
2945 2954
2946 // The "dicom" variable must not be used below this point 2955 // WARNING: The "dicom" variable must not be used below this
2956 // point. The "sopInstanceUid" might also have changed (if
2957 // using lossy compression).
2947 2958
2948 if (transcoded == NULL || 2959 if (transcoded == NULL ||
2949 transcoded->getDataset() == NULL) 2960 transcoded->getDataset() == NULL)
2950 { 2961 {
2951 throw OrthancException( 2962 throw OrthancException(
2969 connection.Store(sopClassUid, sopInstanceUid, *transcoded, moveOriginatorAET, moveOriginatorID); 2980 connection.Store(sopClassUid, sopInstanceUid, *transcoded, moveOriginatorAET, moveOriginatorID);
2970 } 2981 }
2971 } 2982 }
2972 } 2983 }
2973 } 2984 }
2985
2986 static void Store(std::string& sopClassUid /* out */,
2987 std::string& sopInstanceUid /* out */,
2988 DicomStoreUserConnection& connection,
2989 IDicomTranscoder& transcoder,
2990 const void* buffer,
2991 size_t size)
2992 {
2993 Store(sopClassUid, sopInstanceUid, connection, transcoder,
2994 buffer, size, "", 0 /* Not a C-MOVE */);
2995 }
2974 }; 2996 };
2975 2997
2976 2998
2977 class DcmtkTranscoder : public IDicomTranscoder 2999 class DcmtkTranscoder : public IDicomTranscoder
2978 { 3000 {
3046 if (dicom.getDataset() == NULL) 3068 if (dicom.getDataset() == NULL)
3047 { 3069 {
3048 throw OrthancException(ErrorCode_InternalError); 3070 throw OrthancException(ErrorCode_InternalError);
3049 } 3071 }
3050 3072
3073 DicomTransferSyntax syntax;
3074 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom))
3075 {
3076 throw OrthancException(ErrorCode_BadFileFormat,
3077 "Cannot determine the transfer syntax");
3078 }
3079
3051 const uint16_t bitsStored = GetBitsStored(*dicom.getDataset()); 3080 const uint16_t bitsStored = GetBitsStored(*dicom.getDataset());
3052 3081
3053 #if 0 3082 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end())
3054
3055 if (syntax == DetectTransferSyntax(*dicom))
3056 { 3083 {
3057 // No transcoding is needed 3084 // No transcoding is needed
3058 return new Image(dicom.release(), syntax); 3085 return true;
3059 } 3086 }
3060 3087
3061 if (syntax == DicomTransferSyntax_LittleEndianImplicit && 3088 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != allowedSyntaxes.end() &&
3062 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianImplicit, NULL)) 3089 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianImplicit, NULL))
3063 { 3090 {
3064 return new Image(dicom.release(), syntax); 3091 return true;
3065 } 3092 }
3066 3093
3067 if (syntax == DicomTransferSyntax_LittleEndianExplicit && 3094 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != allowedSyntaxes.end() &&
3068 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianExplicit, NULL)) 3095 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianExplicit, NULL))
3069 { 3096 {
3070 return new Image(dicom.release(), syntax); 3097 return true;
3071 } 3098 }
3072 3099
3073 if (syntax == DicomTransferSyntax_BigEndianExplicit && 3100 if (allowedSyntaxes.find(DicomTransferSyntax_BigEndianExplicit) != allowedSyntaxes.end() &&
3074 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_BigEndianExplicit, NULL)) 3101 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_BigEndianExplicit, NULL))
3075 { 3102 {
3076 return new Image(dicom.release(), syntax); 3103 return true;
3077 } 3104 }
3078 3105
3079 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit && 3106 if (allowedSyntaxes.find(DicomTransferSyntax_DeflatedLittleEndianExplicit) != allowedSyntaxes.end() &&
3080 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL)) 3107 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL))
3081 { 3108 {
3082 return new Image(dicom.release(), syntax); 3109 return true;
3083 } 3110 }
3084 3111
3085 #if ORTHANC_ENABLE_JPEG == 1 3112 #if ORTHANC_ENABLE_JPEG == 1
3086 if (syntax == DicomTransferSyntax_JPEGProcess1 && 3113 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() &&
3087 allowNewSopInstanceUid && 3114 allowNewSopInstanceUid &&
3088 bitsStored == 8) 3115 bitsStored == 8)
3089 { 3116 {
3090 DJ_RPLossy rpLossy(lossyQuality_); 3117 DJ_RPLossy rpLossy(lossyQuality_);
3091 3118
3092 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess1, &rpLossy)) 3119 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, &rpLossy))
3093 { 3120 {
3094 return new Image(dicom.release(), syntax); 3121 return true;
3095 } 3122 }
3096 } 3123 }
3097 #endif 3124 #endif
3098 3125
3099 #if ORTHANC_ENABLE_JPEG == 1 3126 #if ORTHANC_ENABLE_JPEG == 1
3100 if (syntax == DicomTransferSyntax_JPEGProcess2_4 && 3127 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() &&
3101 allowNewSopInstanceUid && 3128 allowNewSopInstanceUid &&
3102 bitsStored <= 12) 3129 bitsStored <= 12)
3103 { 3130 {
3104 DJ_RPLossy rpLossy(lossyQuality_); 3131 DJ_RPLossy rpLossy(lossyQuality_);
3105 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess2_4, &rpLossy)) 3132 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, &rpLossy))
3106 { 3133 {
3107 return new Image(dicom.release(), syntax); 3134 return true;
3108 } 3135 }
3109 } 3136 }
3110 #endif 3137 #endif
3111 3138
3139 return false;
3140 }
3141 };
3142 }
3143
3144
3145 TEST(Toto, DISABLED_Transcode3)
3146 {
3147 DicomAssociationParameters p;
3148 p.SetRemotePort(2000);
3149
3150 DcmtkTranscoder transcoder;
3151
3152 for (int i = 0; i <= DicomTransferSyntax_XML; i++)
3153 {
3154 DicomTransferSyntax a = (DicomTransferSyntax) i;
3155
3156 std::string path = ("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
3157 std::string(GetTransferSyntaxUid(a)) + ".dcm");
3158 if (Orthanc::SystemToolbox::IsRegularFile(path))
3159 {
3160 printf("\n======= %s\n", GetTransferSyntaxUid(a));
3161
3162 std::string source;
3163 Orthanc::SystemToolbox::ReadFile(source, path);
3164
3165 DicomStoreUserConnection scu(p);
3166 scu.SetCommonClassesProposed(false);
3167 scu.SetRetiredBigEndianProposed(true);
3168
3169 std::string c, i;
3170 IDicomTranscoder::Store(c, i, scu, transcoder, source.c_str(), source.size());
3171 }
3172 }
3173 }
3174
3175
3112 #endif 3176 #endif
3113
3114 return false;
3115 }
3116 };
3117 }
3118
3119
3120 #endif