Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtkTests.cpp @ 3871:5797d184de67 transcoding
fix the name of some transfer syntaxes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 Apr 2020 14:38:20 +0200 |
parents | d5be23fc0106 |
children | b40dfa6dc8da |
comparison
equal
deleted
inserted
replaced
3870:09798f2b985f | 3871:5797d184de67 |
---|---|
1931 #include <dcmtk/dcmdata/dcpxitem.h> | 1931 #include <dcmtk/dcmdata/dcpxitem.h> |
1932 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy | 1932 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy |
1933 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless | 1933 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless |
1934 | 1934 |
1935 | 1935 |
1936 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG) | |
1937 # error Macro ORTHANC_ENABLE_DCMTK_JPEG must be defined | |
1938 #endif | |
1939 | |
1940 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS) | |
1941 # error Macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined | |
1942 #endif | |
1943 | |
1944 | |
1945 | |
1936 namespace Orthanc | 1946 namespace Orthanc |
1937 { | 1947 { |
1938 class IDicomTranscoder : public boost::noncopyable | 1948 class IDicomTranscoder : public boost::noncopyable |
1939 { | 1949 { |
1940 public: | 1950 public: |
1958 unsigned int frame) = 0; | 1968 unsigned int frame) = 0; |
1959 | 1969 |
1960 // NB: Transcoding can change the value of "GetSopInstanceUid()" | 1970 // NB: Transcoding can change the value of "GetSopInstanceUid()" |
1961 // and "GetTransferSyntax()" if lossy compression is applied | 1971 // and "GetTransferSyntax()" if lossy compression is applied |
1962 virtual bool Transcode(std::string& target, | 1972 virtual bool Transcode(std::string& target, |
1963 std::set<DicomTransferSyntax> syntaxes, | 1973 DicomTransferSyntax syntax, |
1964 bool allowNewSopInstanceUid) = 0; | 1974 bool allowNewSopInstanceUid) = 0; |
1965 | 1975 |
1966 virtual void WriteToMemoryBuffer(std::string& target) = 0; | 1976 virtual void WriteToMemoryBuffer(std::string& target) = 0; |
1967 }; | 1977 }; |
1968 | 1978 |
2120 { | 2130 { |
2121 index_->GetRawFrame(target, frame); | 2131 index_->GetRawFrame(target, frame); |
2122 } | 2132 } |
2123 | 2133 |
2124 virtual bool Transcode(std::string& target, | 2134 virtual bool Transcode(std::string& target, |
2125 std::set<DicomTransferSyntax> syntaxes, | 2135 DicomTransferSyntax syntax, |
2126 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE | 2136 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE |
2127 { | 2137 { |
2128 assert(dicom_ != NULL && | 2138 assert(dicom_ != NULL && |
2129 dicom_->getDataset() != NULL); | 2139 dicom_->getDataset() != NULL); |
2130 | 2140 |
2131 if (syntaxes.find(GetTransferSyntax()) != syntaxes.end()) | 2141 if (syntax == GetTransferSyntax()) |
2132 { | 2142 { |
2133 printf("NO TRANSCODING\n"); | 2143 printf("NO TRANSCODING\n"); |
2134 | 2144 |
2135 // No change in the transfer syntax => simply serialize the current dataset | 2145 // No change in the transfer syntax => simply serialize the current dataset |
2136 WriteToMemoryBuffer(target); | 2146 WriteToMemoryBuffer(target); |
2137 return true; | 2147 return true; |
2138 } | 2148 } |
2139 | 2149 |
2140 printf(">> %d\n", bitsStored_); | 2150 printf(">> %d\n", bitsStored_); |
2141 | 2151 |
2142 DJ_RPLossy rpLossy(lossyQuality_); | 2152 if (syntax == DicomTransferSyntax_LittleEndianImplicit && |
2143 | |
2144 if (syntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != syntaxes.end() && | |
2145 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_LittleEndianImplicit, NULL)) | 2153 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_LittleEndianImplicit, NULL)) |
2146 { | 2154 { |
2147 transferSyntax_ = DicomTransferSyntax_LittleEndianImplicit; | 2155 transferSyntax_ = DicomTransferSyntax_LittleEndianImplicit; |
2148 return true; | 2156 return true; |
2149 } | 2157 } |
2150 else if (syntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != syntaxes.end() && | 2158 |
2151 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_LittleEndianExplicit, NULL)) | 2159 if (syntax == DicomTransferSyntax_LittleEndianExplicit && |
2160 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_LittleEndianExplicit, NULL)) | |
2152 { | 2161 { |
2153 transferSyntax_ = DicomTransferSyntax_LittleEndianExplicit; | 2162 transferSyntax_ = DicomTransferSyntax_LittleEndianExplicit; |
2154 return true; | 2163 return true; |
2155 } | 2164 } |
2156 else if (syntaxes.find(DicomTransferSyntax_BigEndianExplicit) != syntaxes.end() && | 2165 |
2157 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_BigEndianExplicit, NULL)) | 2166 if (syntax == DicomTransferSyntax_BigEndianExplicit && |
2167 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_BigEndianExplicit, NULL)) | |
2158 { | 2168 { |
2159 transferSyntax_ = DicomTransferSyntax_BigEndianExplicit; | 2169 transferSyntax_ = DicomTransferSyntax_BigEndianExplicit; |
2160 return true; | 2170 return true; |
2161 } | 2171 } |
2162 else if (syntaxes.find(DicomTransferSyntax_JPEGProcess1) != syntaxes.end() && | 2172 |
2163 allowNewSopInstanceUid && | 2173 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit && |
2164 GetBitsStored() == 8 && | 2174 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL)) |
2165 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_JPEGProcess1, &rpLossy)) | 2175 { |
2166 { | 2176 transferSyntax_ = DicomTransferSyntax_DeflatedLittleEndianExplicit; |
2167 transferSyntax_ = DicomTransferSyntax_JPEGProcess1; | |
2168 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID); | |
2169 return true; | 2177 return true; |
2170 } | 2178 } |
2171 else if (syntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != syntaxes.end() && | 2179 |
2172 allowNewSopInstanceUid && | 2180 #if ORTHANC_ENABLE_JPEG == 1 |
2173 GetBitsStored() <= 12 && | 2181 if (syntax == DicomTransferSyntax_JPEGProcess1 && |
2174 FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_JPEGProcess2_4, &rpLossy)) | 2182 allowNewSopInstanceUid && |
2175 { | 2183 GetBitsStored() == 8) |
2176 transferSyntax_ = DicomTransferSyntax_JPEGProcess2_4; | 2184 { |
2177 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID); | 2185 DJ_RPLossy rpLossy(lossyQuality_); |
2178 return true; | 2186 |
2179 } | 2187 if (FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_JPEGProcess1, &rpLossy)) |
2180 else | 2188 { |
2181 { | 2189 transferSyntax_ = DicomTransferSyntax_JPEGProcess1; |
2182 return false; | 2190 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID); |
2183 } | 2191 return true; |
2192 } | |
2193 } | |
2194 #endif | |
2195 | |
2196 #if ORTHANC_ENABLE_JPEG == 1 | |
2197 if (syntax == DicomTransferSyntax_JPEGProcess2_4 && | |
2198 allowNewSopInstanceUid && | |
2199 GetBitsStored() <= 12) | |
2200 { | |
2201 DJ_RPLossy rpLossy(lossyQuality_); | |
2202 if (FromDcmtkBridge::Transcode(target, *dicom_, DicomTransferSyntax_JPEGProcess2_4, &rpLossy)) | |
2203 { | |
2204 transferSyntax_ = DicomTransferSyntax_JPEGProcess2_4; | |
2205 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID); | |
2206 return true; | |
2207 } | |
2208 } | |
2209 #endif | |
2210 | |
2211 return false; | |
2184 } | 2212 } |
2185 }; | 2213 }; |
2186 } | 2214 } |
2187 | 2215 |
2188 | 2216 |
2312 | 2340 |
2313 { | 2341 { |
2314 std::string a = transcoder.GetSopInstanceUid(); | 2342 std::string a = transcoder.GetSopInstanceUid(); |
2315 DicomTransferSyntax b = transcoder.GetTransferSyntax(); | 2343 DicomTransferSyntax b = transcoder.GetTransferSyntax(); |
2316 | 2344 |
2317 std::set<DicomTransferSyntax> syntaxes; | 2345 DicomTransferSyntax syntax = DicomTransferSyntax_JPEGProcess2_4; |
2318 syntaxes.insert(DicomTransferSyntax_JPEGProcess2_4); | 2346 //DicomTransferSyntax syntax = DicomTransferSyntax_LittleEndianExplicit; |
2319 //syntaxes.insert(DicomTransferSyntax_LittleEndianExplicit); | |
2320 | 2347 |
2321 std::string t; | 2348 std::string t; |
2322 bool ok = transcoder.Transcode(t, syntaxes, true); | 2349 bool ok = transcoder.Transcode(t, syntax, true); |
2323 printf("Transcoding: %d\n", ok); | 2350 printf("Transcoding: %d\n", ok); |
2324 | 2351 |
2325 if (ok) | 2352 if (ok) |
2326 { | 2353 { |
2327 printf("[%s] => [%s]\n", a.c_str(), transcoder.GetSopInstanceUid().c_str()); | 2354 printf("[%s] => [%s]\n", a.c_str(), transcoder.GetSopInstanceUid().c_str()); |
2341 } | 2368 } |
2342 | 2369 |
2343 printf("\n"); | 2370 printf("\n"); |
2344 } | 2371 } |
2345 | 2372 |
2346 TEST(Toto, DISABLED_Transcode) | 2373 TEST(Toto, Transcode) |
2347 { | 2374 { |
2348 //OFLog::configure(OFLogger::DEBUG_LOG_LEVEL); | 2375 //OFLog::configure(OFLogger::DEBUG_LOG_LEVEL); |
2349 | 2376 |
2350 if (0) | 2377 if (0) |
2351 { | 2378 { |