comparison UnitTestsSources/FromDcmtkTests.cpp @ 3888:e46b7a997f0a transcoding

IDicomTranscoder::TranscodeToBuffer()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 May 2020 16:42:13 +0200
parents 25c122277f53
children 56ce23ba93b7
comparison
equal deleted inserted replaced
3887:25c122277f53 3888:e46b7a997f0a
1941 1941
1942 1942
1943 1943
1944 namespace Orthanc 1944 namespace Orthanc
1945 { 1945 {
1946 /**
1947 * WARNING: This class might be called from several threads at
1948 * once. Make sure to implement proper locking.
1949 **/
1950
1946 class IDicomTranscoder : public boost::noncopyable 1951 class IDicomTranscoder : public boost::noncopyable
1947 { 1952 {
1948 public: 1953 public:
1949 virtual ~IDicomTranscoder() 1954 virtual ~IDicomTranscoder()
1950 { 1955 {
1951 } 1956 }
1957
1958 virtual bool TranscodeToBuffer(std::string& target,
1959 const void* buffer,
1960 size_t size,
1961 const std::set<DicomTransferSyntax>& allowedSyntaxes,
1962 bool allowNewSopInstanceUid) = 0;
1952 1963
1953 /** 1964 /**
1954 * Transcoding flavor that creates a new parsed DICOM file. A 1965 * Transcoding flavor that creates a new parsed DICOM file. A
1955 * "std::set<>" is used to give the possible plugin the 1966 * "std::set<>" is used to give the possible plugin the
1956 * possibility to do a single parsing for all the possible 1967 * possibility to do a single parsing for all the possible
2164 } 2175 }
2165 2176
2166 virtual DcmFileFormat* Transcode(const void* buffer, 2177 virtual DcmFileFormat* Transcode(const void* buffer,
2167 size_t size, 2178 size_t size,
2168 const std::set<DicomTransferSyntax>& allowedSyntaxes, 2179 const std::set<DicomTransferSyntax>& allowedSyntaxes,
2169 bool allowNewSopInstanceUid) 2180 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
2170 { 2181 {
2171 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size)); 2182 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
2172 2183
2173 if (dicom.get() == NULL) 2184 if (dicom.get() == NULL)
2174 { 2185 {
2185 } 2196 }
2186 } 2197 }
2187 2198
2188 virtual bool InplaceTranscode(DcmFileFormat& dicom, 2199 virtual bool InplaceTranscode(DcmFileFormat& dicom,
2189 const std::set<DicomTransferSyntax>& allowedSyntaxes, 2200 const std::set<DicomTransferSyntax>& allowedSyntaxes,
2190 bool allowNewSopInstanceUid) 2201 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
2191 { 2202 {
2192 if (dicom.getDataset() == NULL) 2203 if (dicom.getDataset() == NULL)
2193 { 2204 {
2194 throw OrthancException(ErrorCode_InternalError); 2205 throw OrthancException(ErrorCode_InternalError);
2195 } 2206 }
2322 } 2333 }
2323 #endif 2334 #endif
2324 2335
2325 return false; 2336 return false;
2326 } 2337 }
2338
2339
2340 virtual bool TranscodeToBuffer(std::string& target,
2341 const void* buffer,
2342 size_t size,
2343 const std::set<DicomTransferSyntax>& allowedSyntaxes,
2344 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
2345 {
2346 std::unique_ptr<DcmFileFormat> transcoded(
2347 Transcode(buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
2348
2349 if (transcoded.get() == NULL)
2350 {
2351 return false;
2352 }
2353 else
2354 {
2355 if (transcoded->getDataset() == NULL)
2356 {
2357 throw OrthancException(ErrorCode_InternalError);
2358 }
2359
2360 FromDcmtkBridge::SaveToMemoryBuffer(target, *transcoded->getDataset());
2361 return true;
2362 }
2363 }
2327 }; 2364 };
2328 } 2365 }
2329 2366
2330 2367
2331 TEST(Toto, DISABLED_Transcode3) 2368 TEST(Toto, DISABLED_Transcode3)
2390 for (int i = 0; i <= DicomTransferSyntax_XML; i++) 2427 for (int i = 0; i <= DicomTransferSyntax_XML; i++)
2391 { 2428 {
2392 DicomTransferSyntax a = (DicomTransferSyntax) i; 2429 DicomTransferSyntax a = (DicomTransferSyntax) i;
2393 std::set<DicomTransferSyntax> s; 2430 std::set<DicomTransferSyntax> s;
2394 s.insert(a); 2431 s.insert(a);
2395 std::unique_ptr<DcmFileFormat> transcoded(transcoder.Transcode(source.c_str(), source.size(), s, true)); 2432
2396 if (transcoded.get() == NULL) 2433 std::string t;
2434
2435 if (!transcoder.TranscodeToBuffer(t, source.c_str(), source.size(), s, true))
2397 { 2436 {
2398 printf("**************** CANNOT: [%s] => [%s]\n", 2437 printf("**************** CANNOT: [%s] => [%s]\n",
2399 GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a)); 2438 GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a));
2400 } 2439 }
2401 else 2440 else
2402 { 2441 {
2403 std::string t;
2404 FromDcmtkBridge::SaveToMemoryBuffer(t, *transcoded->getDataset());
2405 printf("SIZE: %lu\n", t.size()); 2442 printf("SIZE: %lu\n", t.size());
2406
2407 const char* v = NULL;
2408 transcoded->getDataset()->findAndGetString(DCM_SOPInstanceUID, v);
2409 if (std::string(v) != "1.3.12.2.1107.5.12.1.2013021918595000.1.1")
2410 {
2411 printf("CHANGED SOP INSTANCE UID\n");
2412 }
2413 } 2443 }
2414 } 2444 }
2415 } 2445 }
2416 2446
2417 2447