annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1860
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1091
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3518
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
7 * This program is free software: you can redistribute it and/or
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
8 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
10 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
12 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
13 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
16 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
20 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
21 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
22 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
23 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
27 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
28 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
29 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
31 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
32
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 809
diff changeset
33
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
34 #include "PrecompiledHeadersUnitTests.h"
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "gtest/gtest.h"
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
37 #include "../Core/Compatibility.h"
3083
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
38 #include "../Core/DicomNetworking/DicomFindAnswers.h"
2382
7284093111b0 big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2381
diff changeset
39 #include "../Core/DicomParsing/DicomModification.h"
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
40 #include "../Core/DicomParsing/DicomWebJsonVisitor.h"
3083
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
41 #include "../Core/DicomParsing/FromDcmtkBridge.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
42 #include "../Core/DicomParsing/Internals/DicomImageDecoder.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
43 #include "../Core/DicomParsing/ToDcmtkBridge.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
44 #include "../Core/Endianness.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
45 #include "../Core/Images/Image.h"
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
46 #include "../Core/Images/ImageBuffer.h"
3083
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
47 #include "../Core/Images/ImageProcessing.h"
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
48 #include "../Core/Images/PngReader.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1562
diff changeset
49 #include "../Core/Images/PngWriter.h"
3083
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
50 #include "../Core/OrthancException.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
51 #include "../Core/SystemToolbox.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
52 #include "../OrthancServer/ServerToolbox.h"
683d572424b6 IDatabaseWrapper::SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
53 #include "../Plugins/Engine/PluginsEnumerations.h"
1088
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
54 #include "../Resources/EncodingTests.h"
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
56 #include <dcmtk/dcmdata/dcelem.h>
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
57 #include <dcmtk/dcmdata/dcdeftag.h>
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
58 #include <boost/algorithm/string/predicate.hpp>
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
59
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
60 #if ORTHANC_ENABLE_PUGIXML == 1
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
61 # include <pugixml.hpp>
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
62 #endif
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
63
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 using namespace Orthanc;
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 TEST(DicomFormat, Tag)
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
68 ASSERT_EQ("PatientName", FromDcmtkBridge::GetTagName(DicomTag(0x0010, 0x0010), ""));
782
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription");
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ASSERT_EQ(0x0008, t.GetGroup());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ASSERT_EQ(0x103E, t.GetElement());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 t = FromDcmtkBridge::ParseTag("0020-e040");
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ASSERT_EQ(0x0020, t.GetGroup());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ASSERT_EQ(0xe040, t.GetElement());
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 // Test ==() and !=() operators
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020));
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020));
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
a60040857ce6 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
84 TEST(DicomModification, Basic)
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
85 {
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
86 DicomModification m;
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
87 m.SetupAnonymization(DicomVersion_2008);
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
88 //m.SetLevel(DicomRootLevel_Study);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
89 //m.ReplacePlainString(DICOM_TAG_PATIENT_ID, "coucou");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
90 //m.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "coucou");
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
91
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
92 ParsedDicomFile o(true);
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 802
diff changeset
93 o.SaveToFile("UnitTestsResults/anon.dcm");
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
94
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
95 for (int i = 0; i < 10; i++)
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
96 {
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
97 char b[1024];
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 802
diff changeset
98 sprintf(b, "UnitTestsResults/anon%06d.dcm", i);
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
99 std::unique_ptr<ParsedDicomFile> f(o.Clone(false));
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
100 if (i > 4)
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
101 o.ReplacePlainString(DICOM_TAG_SERIES_INSTANCE_UID, "coucou");
784
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
102 m.Apply(*f);
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
103 f->SaveToFile(b);
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
104 }
efd0215736d9 start of anonymization refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 782
diff changeset
105 }
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
106
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
107
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
108 TEST(DicomModification, Anonymization)
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
109 {
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
110 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, FromDcmtkBridge::ParseTag("PatientName"));
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
111
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
112 const DicomTag privateTag(0x0045, 0x1010);
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
113 const DicomTag privateTag2(FromDcmtkBridge::ParseTag("0031-1020"));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
114 ASSERT_TRUE(privateTag.IsPrivate());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
115 ASSERT_TRUE(privateTag2.IsPrivate());
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
116 ASSERT_EQ(0x0031, privateTag2.GetGroup());
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
117 ASSERT_EQ(0x1020, privateTag2.GetElement());
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
118
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
119 std::string s;
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
120 ParsedDicomFile o(true);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
121 o.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "coucou");
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
122 ASSERT_FALSE(o.GetTagValue(s, privateTag));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
123 o.Insert(privateTag, "private tag", false, "OrthancCreator");
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
124 ASSERT_TRUE(o.GetTagValue(s, privateTag));
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
125 ASSERT_STREQ("private tag", s.c_str());
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
126
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
127 ASSERT_FALSE(o.GetTagValue(s, privateTag2));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
128 ASSERT_THROW(o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_ThrowIfAbsent, "OrthancCreator"), OrthancException);
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
129 ASSERT_FALSE(o.GetTagValue(s, privateTag2));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
130 o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_IgnoreIfAbsent, "OrthancCreator");
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
131 ASSERT_FALSE(o.GetTagValue(s, privateTag2));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
132 o.Replace(privateTag2, std::string("hello"), false, DicomReplaceMode_InsertIfAbsent, "OrthancCreator");
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
133 ASSERT_TRUE(o.GetTagValue(s, privateTag2));
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
134 ASSERT_STREQ("hello", s.c_str());
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
135 o.Replace(privateTag2, std::string("hello world"), false, DicomReplaceMode_InsertIfAbsent, "OrthancCreator");
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
136 ASSERT_TRUE(o.GetTagValue(s, privateTag2));
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
137 ASSERT_STREQ("hello world", s.c_str());
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
138
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
139 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME));
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
140 ASSERT_FALSE(Toolbox::IsUuid(s));
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
141
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
142 DicomModification m;
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
143 m.SetupAnonymization(DicomVersion_2008);
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
144 m.Keep(privateTag);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
145
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
146 m.Apply(o);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
147
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
148 ASSERT_TRUE(o.GetTagValue(s, DICOM_TAG_PATIENT_NAME));
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
149 ASSERT_TRUE(Toolbox::IsUuid(s));
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
150 ASSERT_TRUE(o.GetTagValue(s, privateTag));
1307
f796207e3df1 Fix replacement and insertion of private DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
151 ASSERT_STREQ("private tag", s.c_str());
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
152
2309
4dc313b9a20a Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
153 m.SetupAnonymization(DicomVersion_2008);
991
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
154 m.Apply(o);
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
155 ASSERT_FALSE(o.GetTagValue(s, privateTag));
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
156 }
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
157
2f76b92addd4 keep private tags during anonymization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
158
802
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
159 #include <dcmtk/dcmdata/dcuid.h>
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
160
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
161 TEST(DicomModification, Png)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
162 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
163 // Red dot in http://en.wikipedia.org/wiki/Data_URI_scheme (RGBA image)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
164 std::string s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
165
1641
4e56b5a206b7 Support of binary tags encoded using data URI scheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
166 std::string m, cc;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1971
diff changeset
167 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(m, cc, s));
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
168
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
169 ASSERT_EQ("image/png", m);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
170
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
171 PngReader reader;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
172 reader.ReadFromMemory(cc);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
173
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1417
diff changeset
174 ASSERT_EQ(5u, reader.GetHeight());
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1417
diff changeset
175 ASSERT_EQ(5u, reader.GetWidth());
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
176 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat());
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
177
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
178 ParsedDicomFile o(true);
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
179 o.EmbedContent(s);
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 802
diff changeset
180 o.SaveToFile("UnitTestsResults/png1.dcm");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
181
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
182 // Red dot, without alpha channel
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
183 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII=";
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
184 o.EmbedContent(s);
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 802
diff changeset
185 o.SaveToFile("UnitTestsResults/png2.dcm");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
186
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
187 // Check box in Graylevel8
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
188 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII=";
1562
2084b7c20478 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
189 o.EmbedContent(s);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
190 //o.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing);
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 802
diff changeset
191 o.SaveToFile("UnitTestsResults/png3.dcm");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
192
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
193
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
194 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
195 // Gradient in Graylevel16
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
196
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
197 ImageBuffer img;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
198 img.SetWidth(256);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
199 img.SetHeight(256);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
200 img.SetFormat(PixelFormat_Grayscale16);
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
201
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
202 ImageAccessor accessor;
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
203 img.GetWriteableAccessor(accessor);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
204
1654
3727a09e7b53 fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1641
diff changeset
205 uint16_t v = 0;
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
206 for (unsigned int y = 0; y < img.GetHeight(); y++)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
207 {
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
208 uint16_t *p = reinterpret_cast<uint16_t*>(accessor.GetRow(y));
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
209 for (unsigned int x = 0; x < img.GetWidth(); x++, p++, v++)
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
210 {
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
211 *p = v;
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
212 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
213 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
214
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
215 o.EmbedImage(accessor);
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 802
diff changeset
216 o.SaveToFile("UnitTestsResults/png4.dcm");
800
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
217 }
ecedd89055db generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 786
diff changeset
218 }
1088
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
219
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
220
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
221 TEST(FromDcmtkBridge, Encodings1)
1088
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
222 {
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
223 for (unsigned int i = 0; i < testEncodingsCount; i++)
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
224 {
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
225 std::string source(testEncodingsEncoded[i]);
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
226 std::string expected(testEncodingsExpected[i]);
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
227 std::string s = Toolbox::ConvertToUtf8(source, testEncodings[i], false);
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
228 //std::cout << EnumerationToString(testEncodings[i]) << std::endl;
1089
5ea0b56e850d logging in test
jodogne
parents: 1088
diff changeset
229 EXPECT_EQ(expected, s);
1088
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
230 }
6fd4434c1bcf unit tests for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 991
diff changeset
231 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
232
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
233
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
234 TEST(FromDcmtkBridge, Enumerations)
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
235 {
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
236 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
237 Encoding e;
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
238
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
239 ASSERT_FALSE(GetDicomEncoding(e, ""));
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
240 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 6")); ASSERT_EQ(Encoding_Ascii, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
241
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
242 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-2
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
243 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 100")); ASSERT_EQ(Encoding_Latin1, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
244 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 101")); ASSERT_EQ(Encoding_Latin2, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
245 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 109")); ASSERT_EQ(Encoding_Latin3, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
246 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 110")); ASSERT_EQ(Encoding_Latin4, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
247 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 144")); ASSERT_EQ(Encoding_Cyrillic, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
248 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 127")); ASSERT_EQ(Encoding_Arabic, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
249 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 126")); ASSERT_EQ(Encoding_Greek, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
250 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 138")); ASSERT_EQ(Encoding_Hebrew, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
251 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 148")); ASSERT_EQ(Encoding_Latin5, e);
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
252 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 13")); ASSERT_EQ(Encoding_Japanese, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
253 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 166")); ASSERT_EQ(Encoding_Thai, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
254
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
255 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-3
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
256 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 6")); ASSERT_EQ(Encoding_Ascii, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
257 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 100")); ASSERT_EQ(Encoding_Latin1, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
258 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 101")); ASSERT_EQ(Encoding_Latin2, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
259 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 109")); ASSERT_EQ(Encoding_Latin3, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
260 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 110")); ASSERT_EQ(Encoding_Latin4, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
261 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 144")); ASSERT_EQ(Encoding_Cyrillic, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
262 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 127")); ASSERT_EQ(Encoding_Arabic, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
263 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 126")); ASSERT_EQ(Encoding_Greek, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
264 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 138")); ASSERT_EQ(Encoding_Hebrew, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
265 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 148")); ASSERT_EQ(Encoding_Latin5, e);
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
266 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 13")); ASSERT_EQ(Encoding_Japanese, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
267 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 166")); ASSERT_EQ(Encoding_Thai, e);
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
268
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
269 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-4
3219
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3217
diff changeset
270 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 87")); ASSERT_EQ(Encoding_JapaneseKanji, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
271 ASSERT_FALSE(GetDicomEncoding(e, "ISO 2022 IR 159")); //ASSERT_EQ(Encoding_JapaneseKanjiSupplementary, e);
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
272 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 149")); ASSERT_EQ(Encoding_Korean, e);
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
273 ASSERT_TRUE(GetDicomEncoding(e, "ISO 2022 IR 58")); ASSERT_EQ(Encoding_SimplifiedChinese, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
274
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
275 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#table_C.12-5
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
276 ASSERT_TRUE(GetDicomEncoding(e, "ISO_IR 192")); ASSERT_EQ(Encoding_Utf8, e);
1908
5096681efce6 direct hyperlinks to the DICOM standard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
277 ASSERT_TRUE(GetDicomEncoding(e, "GB18030")); ASSERT_EQ(Encoding_Chinese, e);
2401
a051aba0037c Use "GBK" (frequently used in China) as an alias for "GB18030"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
278 ASSERT_TRUE(GetDicomEncoding(e, "GBK")); ASSERT_EQ(Encoding_Chinese, e);
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
279 }
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
280
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
281
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
282 TEST(FromDcmtkBridge, Encodings3)
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
283 {
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
284 for (unsigned int i = 0; i < testEncodingsCount; i++)
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
285 {
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
286 //std::cout << EnumerationToString(testEncodings[i]) << std::endl;
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
287 std::string dicom;
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
288
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
289 {
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
290 ParsedDicomFile f(true);
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
291 f.SetEncoding(testEncodings[i]);
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
292
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
293 std::string s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false);
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
294 f.Insert(DICOM_TAG_PATIENT_NAME, s, false, "");
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
295 f.SaveToMemoryBuffer(dicom);
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
296 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
297
1347
60cc0ee61edb fix issue 32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1334
diff changeset
298 if (testEncodings[i] != Encoding_Windows1251)
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
299 {
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
300 ParsedDicomFile g(dicom);
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
301
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
302 if (testEncodings[i] != Encoding_Ascii)
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
303 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
304 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
305 ASSERT_EQ(testEncodings[i], g.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
306 ASSERT_FALSE(hasCodeExtensions);
1091
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
307 }
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
308
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
309 std::string tag;
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
310 ASSERT_TRUE(g.GetTagValue(tag, DICOM_TAG_PATIENT_NAME));
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
311 ASSERT_EQ(std::string(testEncodingsExpected[i]), tag);
a66224eec125 encoding tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1090
diff changeset
312 }
1090
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
313 }
e494ceb8d763 support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1089
diff changeset
314 }
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1347
diff changeset
315
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1347
diff changeset
316
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
317 TEST(FromDcmtkBridge, ValueRepresentation)
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1347
diff changeset
318 {
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
319 ASSERT_EQ(ValueRepresentation_PersonName,
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
320 FromDcmtkBridge::LookupValueRepresentation(DICOM_TAG_PATIENT_NAME));
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
321 ASSERT_EQ(ValueRepresentation_Date,
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
322 FromDcmtkBridge::LookupValueRepresentation(DicomTag(0x0008, 0x0020) /* StudyDate */));
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
323 ASSERT_EQ(ValueRepresentation_Time,
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
324 FromDcmtkBridge::LookupValueRepresentation(DicomTag(0x0008, 0x0030) /* StudyTime */));
1417
8e23f16a198d fix issues 35 and 37
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1360
diff changeset
325 ASSERT_EQ(ValueRepresentation_DateTime,
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
326 FromDcmtkBridge::LookupValueRepresentation(DicomTag(0x0008, 0x002a) /* AcquisitionDateTime */));
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
327 ASSERT_EQ(ValueRepresentation_NotSupported,
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
328 FromDcmtkBridge::LookupValueRepresentation(DicomTag(0x0001, 0x0001) /* some private tag */));
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
329 }
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
330
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
331
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
332 TEST(FromDcmtkBridge, ValueRepresentationConversions)
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
333 {
3048
8b331be57606 fix build without plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
334 #if ORTHANC_ENABLE_PLUGINS == 1
2006
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
335 ASSERT_EQ(1, ValueRepresentation_ApplicationEntity);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
336 ASSERT_EQ(1, OrthancPluginValueRepresentation_AE);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
337
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
338 for (int i = ValueRepresentation_ApplicationEntity;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
339 i <= ValueRepresentation_NotSupported; i++)
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
340 {
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
341 ValueRepresentation vr = static_cast<ValueRepresentation>(i);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
342
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
343 if (vr == ValueRepresentation_NotSupported)
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
344 {
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
345 ASSERT_THROW(ToDcmtkBridge::Convert(vr), OrthancException);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
346 ASSERT_THROW(Plugins::Convert(vr), OrthancException);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
347 }
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
348 else if (vr == ValueRepresentation_OtherDouble ||
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
349 vr == ValueRepresentation_OtherLong ||
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
350 vr == ValueRepresentation_UniversalResource ||
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
351 vr == ValueRepresentation_UnlimitedCharacters)
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
352 {
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
353 // These VR are not supported as of DCMTK 3.6.0
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
354 ASSERT_THROW(ToDcmtkBridge::Convert(vr), OrthancException);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
355 ASSERT_EQ(OrthancPluginValueRepresentation_UN, Plugins::Convert(vr));
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
356 }
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
357 else
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
358 {
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
359 ASSERT_EQ(vr, FromDcmtkBridge::Convert(ToDcmtkBridge::Convert(vr)));
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
360
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
361 OrthancPluginValueRepresentation plugins = Plugins::Convert(vr);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
362 ASSERT_EQ(vr, Plugins::Convert(plugins));
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
363 }
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
364 }
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
365
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
366 for (int i = OrthancPluginValueRepresentation_AE;
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
367 i <= OrthancPluginValueRepresentation_UT; i++)
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
368 {
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
369 OrthancPluginValueRepresentation plugins = static_cast<OrthancPluginValueRepresentation>(i);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
370 ValueRepresentation orthanc = Plugins::Convert(plugins);
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
371 ASSERT_EQ(plugins, Plugins::Convert(orthanc));
6301bbcbcaed more generic support of value representations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1982
diff changeset
372 }
3048
8b331be57606 fix build without plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2861
diff changeset
373 #endif
1360
0649c5aef34a DicomFindQuery
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1347
diff changeset
374 }
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
375
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
376
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
377
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
378 static const DicomTag REFERENCED_STUDY_SEQUENCE(0x0008, 0x1110);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
379 static const DicomTag REFERENCED_PATIENT_SEQUENCE(0x0008, 0x1120);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
380
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
381 static void CreateSampleJson(Json::Value& a)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
382 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
383 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
384 Json::Value b = Json::objectValue;
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
385 b["PatientName"] = "Hello";
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
386 b["PatientID"] = "World";
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
387 b["StudyDescription"] = "Toto";
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
388 a.append(b);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
389 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
390
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
391 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
392 Json::Value b = Json::objectValue;
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
393 b["PatientName"] = "data:application/octet-stream;base64,SGVsbG8y"; // echo -n "Hello2" | base64
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
394 b["PatientID"] = "World2";
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
395 a.append(b);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
396 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
397 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
398
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
399
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
400 namespace Orthanc
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
401 {
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
402 // Namespace for the "FRIEND_TEST()" directive in "FromDcmtkBridge" to apply:
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
403 // https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#private-class-members
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
404 TEST(FromDcmtkBridge, FromJson)
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
405 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
406 std::unique_ptr<DcmElement> element;
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
407
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
408 {
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
409 Json::Value a;
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
410 a = "Hello";
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
411 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8, ""));
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
412
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
413 Json::Value b;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
414 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
415 ignoreTagLength.insert(DICOM_TAG_PATIENT_ID);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
416
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
417 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
418 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength);
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
419 ASSERT_TRUE(b.isMember("0010,0010"));
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
420 ASSERT_EQ("Hello", b["0010,0010"].asString());
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
421
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
422 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
423 DicomToJsonFlags_Default, 3, Encoding_Ascii, false, ignoreTagLength);
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
424 ASSERT_TRUE(b["0010,0010"].isNull()); // "Hello" has more than 3 characters
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
425
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
426 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
427 DicomToJsonFlags_Default, 3, Encoding_Ascii, false, ignoreTagLength);
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
428 ASSERT_TRUE(b["0010,0010"].isObject());
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
429 ASSERT_EQ("PatientName", b["0010,0010"]["Name"].asString());
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
430 ASSERT_EQ("TooLong", b["0010,0010"]["Type"].asString());
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
431 ASSERT_TRUE(b["0010,0010"]["Value"].isNull());
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
432
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
433 ignoreTagLength.insert(DICOM_TAG_PATIENT_NAME);
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
434 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
435 DicomToJsonFlags_Default, 3, Encoding_Ascii, false, ignoreTagLength);
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
436 ASSERT_EQ("Hello", b["0010,0010"].asString());
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
437 }
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
438
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
439 {
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
440 Json::Value a;
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
441 a = "Hello";
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
442 // Cannot assign a string to a sequence
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
443 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, false, Encoding_Utf8, "")), OrthancException);
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
444 }
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
445
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
446 {
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
447 Json::Value a = Json::arrayValue;
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
448 a.append("Hello");
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
449 // Cannot assign an array to a string
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
450 ASSERT_THROW(element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, false, Encoding_Utf8, "")), OrthancException);
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
451 }
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
452
1692
4eaf164dd574 test SimplifyTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
453 {
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
454 Json::Value a;
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
455 a = "data:application/octet-stream;base64,SGVsbG8="; // echo -n "Hello" | base64
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
456 element.reset(FromDcmtkBridge::FromJson(DICOM_TAG_PATIENT_NAME, a, true, Encoding_Utf8, ""));
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
457
1692
4eaf164dd574 test SimplifyTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
458 Json::Value b;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
459 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
460 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
461 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength);
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
462 ASSERT_EQ("Hello", b["0010,0010"].asString());
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
463 }
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
464
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
465 {
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
466 Json::Value a = Json::arrayValue;
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
467 CreateSampleJson(a);
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
468 element.reset(FromDcmtkBridge::FromJson(REFERENCED_STUDY_SEQUENCE, a, true, Encoding_Utf8, ""));
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
469
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
470 {
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
471 Json::Value b;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
472 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
473 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Short,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
474 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength);
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
475 ASSERT_EQ(Json::arrayValue, b["0008,1110"].type());
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
476 ASSERT_EQ(2u, b["0008,1110"].size());
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
477
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
478 Json::Value::ArrayIndex i = (b["0008,1110"][0]["0010,0010"].asString() == "Hello") ? 0 : 1;
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
479
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
480 ASSERT_EQ(3u, b["0008,1110"][i].size());
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
481 ASSERT_EQ(2u, b["0008,1110"][1 - i].size());
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
482 ASSERT_EQ(b["0008,1110"][i]["0010,0010"].asString(), "Hello");
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
483 ASSERT_EQ(b["0008,1110"][i]["0010,0020"].asString(), "World");
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
484 ASSERT_EQ(b["0008,1110"][i]["0008,1030"].asString(), "Toto");
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
485 ASSERT_EQ(b["0008,1110"][1 - i]["0010,0010"].asString(), "Hello2");
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
486 ASSERT_EQ(b["0008,1110"][1 - i]["0010,0020"].asString(), "World2");
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
487 }
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
488
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
489 {
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
490 Json::Value b;
2409
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
491 std::set<DicomTag> ignoreTagLength;
e4045b3c9772 ignore-length argument if retrieving DICOM tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2401
diff changeset
492 FromDcmtkBridge::ElementToJson(b, *element, DicomToJsonFormat_Full,
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
493 DicomToJsonFlags_Default, 0, Encoding_Ascii, false, ignoreTagLength);
2126
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
494
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
495 Json::Value c;
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
496 ServerToolbox::SimplifyTags(c, b, DicomToJsonFormat_Human);
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
497
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
498 a[1]["PatientName"] = "Hello2"; // To remove the Data URI Scheme encoding
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
499 ASSERT_EQ(0, c["ReferencedStudySequence"].compare(a));
03b065778fc3 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2120
diff changeset
500 }
1692
4eaf164dd574 test SimplifyTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
501 }
4eaf164dd574 test SimplifyTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1691
diff changeset
502 }
1690
ae09132e4237 FromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
503 }
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
504
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
505
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
506 TEST(ParsedDicomFile, InsertReplaceStrings)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
507 {
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
508 ParsedDicomFile f(true);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
509
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
510 f.Insert(DICOM_TAG_PATIENT_NAME, "World", false, "");
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
511 ASSERT_THROW(f.Insert(DICOM_TAG_PATIENT_ID, "Hello", false, ""), OrthancException); // Already existing tag
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
512 f.ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, "Toto"); // (*)
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
513 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "Tata"); // (**)
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
514
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
515 std::string s;
2209
e3fd5bc429a2 URI to reconstruct the main DICOM tags, the JSON summary and the metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2207
diff changeset
516 ASSERT_FALSE(f.LookupTransferSyntax(s));
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
517
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
518 ASSERT_THROW(f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"),
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
519 false, DicomReplaceMode_ThrowIfAbsent, ""), OrthancException);
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
520 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_IgnoreIfAbsent, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
521 ASSERT_FALSE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
522 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_InsertIfAbsent, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
523 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
524 ASSERT_EQ(s, "Accession");
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
525 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession2"), false, DicomReplaceMode_IgnoreIfAbsent, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
526 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
527 ASSERT_EQ(s, "Accession2");
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
528 f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession3"), false, DicomReplaceMode_ThrowIfAbsent, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
529 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
530 ASSERT_EQ(s, "Accession3");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
531
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
532 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_PATIENT_NAME));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
533 ASSERT_EQ(s, "World");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
534 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_SOP_INSTANCE_UID));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
535 ASSERT_EQ(s, "Toto");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
536 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID)); // Implicitly modified by (*)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
537 ASSERT_EQ(s, "Toto");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
538 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_SOP_CLASS_UID));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
539 ASSERT_EQ(s, "Tata");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
540 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID)); // Implicitly modified by (**)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
541 ASSERT_EQ(s, "Tata");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
542 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
543
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
544
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
545
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
546
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
547 TEST(ParsedDicomFile, InsertReplaceJson)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
548 {
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
549 ParsedDicomFile f(true);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
550
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
551 Json::Value a;
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
552 CreateSampleJson(a);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
553
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
554 ASSERT_FALSE(f.HasTag(REFERENCED_STUDY_SEQUENCE));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
555 f.Remove(REFERENCED_STUDY_SEQUENCE); // No effect
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
556 f.Insert(REFERENCED_STUDY_SEQUENCE, a, true, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
557 ASSERT_TRUE(f.HasTag(REFERENCED_STUDY_SEQUENCE));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
558 ASSERT_THROW(f.Insert(REFERENCED_STUDY_SEQUENCE, a, true, ""), OrthancException);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
559 f.Remove(REFERENCED_STUDY_SEQUENCE);
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
560 ASSERT_FALSE(f.HasTag(REFERENCED_STUDY_SEQUENCE));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
561 f.Insert(REFERENCED_STUDY_SEQUENCE, a, true, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
562 ASSERT_TRUE(f.HasTag(REFERENCED_STUDY_SEQUENCE));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
563
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
564 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
565 ASSERT_THROW(f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_ThrowIfAbsent, ""), OrthancException);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
566 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
567 f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_IgnoreIfAbsent, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
568 ASSERT_FALSE(f.HasTag(REFERENCED_PATIENT_SEQUENCE));
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
569 f.Replace(REFERENCED_PATIENT_SEQUENCE, a, false, DicomReplaceMode_InsertIfAbsent, "");
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
570 ASSERT_TRUE(f.HasTag(REFERENCED_PATIENT_SEQUENCE));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
571
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
572 {
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
573 Json::Value b;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
574 f.DatasetToJson(b, DicomToJsonFormat_Full, DicomToJsonFlags_Default, 0);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
575
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
576 Json::Value c;
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2117
diff changeset
577 ServerToolbox::SimplifyTags(c, b, DicomToJsonFormat_Human);
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
578
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
579 ASSERT_EQ(0, c["ReferencedPatientSequence"].compare(a));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
580 ASSERT_NE(0, c["ReferencedStudySequence"].compare(a)); // Because Data URI Scheme decoding was enabled
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
581 }
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
582
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
583 a = "data:application/octet-stream;base64,VGF0YQ=="; // echo -n "Tata" | base64
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
584 f.Replace(DICOM_TAG_SOP_INSTANCE_UID, a, false, DicomReplaceMode_InsertIfAbsent, ""); // (*)
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
585 f.Replace(DICOM_TAG_SOP_CLASS_UID, a, true, DicomReplaceMode_InsertIfAbsent, ""); // (**)
1693
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
586
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
587 std::string s;
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
588 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_SOP_INSTANCE_UID));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
589 ASSERT_EQ(s, a.asString());
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
590 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID)); // Implicitly modified by (*)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
591 ASSERT_EQ(s, a.asString());
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
592 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_SOP_CLASS_UID));
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
593 ASSERT_EQ(s, "Tata");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
594 ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_MEDIA_STORAGE_SOP_CLASS_UID)); // Implicitly modified by (**)
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
595 ASSERT_EQ(s, "Tata");
558b25228a23 creation of tag hierarchy from json
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1692
diff changeset
596 }
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
597
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
598
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
599 TEST(ParsedDicomFile, JsonEncoding)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
600 {
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
601 ParsedDicomFile f(true);
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
602
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
603 for (unsigned int i = 0; i < testEncodingsCount; i++)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
604 {
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
605 if (testEncodings[i] != Encoding_Windows1251)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
606 {
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
607 //std::cout << EnumerationToString(testEncodings[i]) << std::endl;
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
608 f.SetEncoding(testEncodings[i]);
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
609
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
610 if (testEncodings[i] != Encoding_Ascii)
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
611 {
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
612 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
613 ASSERT_EQ(testEncodings[i], f.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
614 ASSERT_FALSE(hasCodeExtensions);
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
615 }
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
616
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
617 Json::Value s = Toolbox::ConvertToUtf8(testEncodingsEncoded[i], testEncodings[i], false);
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
618 f.Replace(DICOM_TAG_PATIENT_NAME, s, false, DicomReplaceMode_InsertIfAbsent, "");
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
619
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
620 Json::Value v;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
621 f.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0);
1695
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
622 ASSERT_EQ(v["PatientName"].asString(), std::string(testEncodingsExpected[i]));
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
623 }
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
624 }
18c02c6987d5 fix for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1693
diff changeset
625 }
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
626
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
627
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
628 TEST(ParsedDicomFile, ToJsonFlags1)
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
629 {
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
630 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7053, 0x1000), ValueRepresentation_OtherByte, "MyPrivateTag", 1, 1, "OrthancCreator");
2115
a657f7772e69 Handling of private tags/creators in the "Dictionary" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
631 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), ValueRepresentation_PersonName, "Declared public tag", 1, 1, "");
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
632
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
633 ParsedDicomFile f(true);
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
634 f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false, ""); // Even group => public tag
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
635 f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false, ""); // Even group => public, unknown tag
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
636 f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false, "OrthancCreator"); // Odd group => private tag
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
637
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
638 Json::Value v;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
639 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
640 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
641 ASSERT_EQ(6u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
642 ASSERT_FALSE(v.isMember("7052,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
643 ASSERT_FALSE(v.isMember("7053,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
644 ASSERT_TRUE(v.isMember("7050,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
645 ASSERT_EQ(Json::stringValue, v["7050,1000"].type());
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
646 ASSERT_EQ("Some public tag", v["7050,1000"].asString());
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
647
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
648 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeBinary | DicomToJsonFlags_ConvertBinaryToNull), 0);
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
649 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
650 ASSERT_EQ(7u, v.getMemberNames().size());
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
651 ASSERT_FALSE(v.isMember("7052,1000"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
652 ASSERT_TRUE(v.isMember("7050,1000"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
653 ASSERT_TRUE(v.isMember("7053,1000"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
654 ASSERT_EQ("Some public tag", v["7050,1000"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
655 ASSERT_EQ(Json::nullValue, v["7053,1000"].type());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
656
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
657 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags), 0);
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
658 ASSERT_EQ(Json::objectValue, v.type());
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
659 ASSERT_EQ(6u, v.getMemberNames().size());
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
660 ASSERT_FALSE(v.isMember("7052,1000"));
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
661 ASSERT_TRUE(v.isMember("7050,1000"));
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
662 ASSERT_FALSE(v.isMember("7053,1000"));
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
663
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
664 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeBinary), 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
665 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
666 ASSERT_EQ(7u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
667 ASSERT_FALSE(v.isMember("7052,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
668 ASSERT_TRUE(v.isMember("7050,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
669 ASSERT_TRUE(v.isMember("7053,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
670 ASSERT_EQ("Some public tag", v["7050,1000"].asString());
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
671 std::string mime, content;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
672 ASSERT_EQ(Json::stringValue, v["7053,1000"].type());
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1971
diff changeset
673 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7053,1000"].asString()));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
674 ASSERT_EQ("application/octet-stream", mime);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
675 ASSERT_EQ("Some private tag", content);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
676
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
677 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludeBinary | DicomToJsonFlags_ConvertBinaryToNull), 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
678 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
679 ASSERT_EQ(7u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
680 ASSERT_TRUE(v.isMember("7050,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
681 ASSERT_TRUE(v.isMember("7052,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
682 ASSERT_FALSE(v.isMember("7053,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
683 ASSERT_EQ("Some public tag", v["7050,1000"].asString());
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
684 ASSERT_EQ(Json::nullValue, v["7052,1000"].type());
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
685
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
686 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludeBinary), 0);
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
687 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
688 ASSERT_EQ(7u, v.getMemberNames().size());
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
689 ASSERT_TRUE(v.isMember("7050,1000"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
690 ASSERT_TRUE(v.isMember("7052,1000"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
691 ASSERT_FALSE(v.isMember("7053,1000"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
692 ASSERT_EQ("Some public tag", v["7050,1000"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
693 ASSERT_EQ(Json::stringValue, v["7052,1000"].type());
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1971
diff changeset
694 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7052,1000"].asString()));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
695 ASSERT_EQ("application/octet-stream", mime);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
696 ASSERT_EQ("Some unknown tag", content);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
697
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
698 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_IncludeBinary | DicomToJsonFlags_ConvertBinaryToNull), 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
699 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
700 ASSERT_EQ(8u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
701 ASSERT_TRUE(v.isMember("7050,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
702 ASSERT_TRUE(v.isMember("7052,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
703 ASSERT_TRUE(v.isMember("7053,1000"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
704 ASSERT_EQ("Some public tag", v["7050,1000"].asString());
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
705 ASSERT_EQ(Json::nullValue, v["7052,1000"].type());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
706 ASSERT_EQ(Json::nullValue, v["7053,1000"].type());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
707 }
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
708
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
709
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
710 TEST(ParsedDicomFile, ToJsonFlags2)
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
711 {
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
712 ParsedDicomFile f(true);
3832
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
713
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
714 {
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
715 // "ParsedDicomFile" uses Little Endian => 'B' (least significant
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
716 // byte) will be stored first in the memory buffer and in the
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
717 // file, then 'A'. Hence the expected "BA" value below.
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
718 Uint16 v[] = { 'A' * 256 + 'B', 0 };
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
719 ASSERT_TRUE(f.GetDcmtkObject().getDataset()->putAndInsertUint16Array(DCM_PixelData, v, 2).good());
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
720 }
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
721
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
722 Json::Value v;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
723 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
724 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
725 ASSERT_EQ(5u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
726 ASSERT_FALSE(v.isMember("7fe0,0010"));
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
727
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
728 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData | DicomToJsonFlags_ConvertBinaryToNull), 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
729 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
730 ASSERT_EQ(6u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
731 ASSERT_TRUE(v.isMember("7fe0,0010"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
732 ASSERT_EQ(Json::nullValue, v["7fe0,0010"].type());
1736
b953c6eef28d ToJson: IncludePrivateTags and IncludeUnknownTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1735
diff changeset
733
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
734 f.DatasetToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData | DicomToJsonFlags_ConvertBinaryToAscii), 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
735 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
736 ASSERT_EQ(6u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
737 ASSERT_TRUE(v.isMember("7fe0,0010"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
738 ASSERT_EQ(Json::stringValue, v["7fe0,0010"].type());
3832
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
739 ASSERT_EQ("BA", v["7fe0,0010"].asString().substr(0, 2));
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
740
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
741 f.DatasetToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePixelData, 0);
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
742 ASSERT_EQ(Json::objectValue, v.type());
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
743 ASSERT_EQ(6u, v.getMemberNames().size());
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
744 ASSERT_TRUE(v.isMember("7fe0,0010"));
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
745 ASSERT_EQ(Json::stringValue, v["7fe0,0010"].type());
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
746 std::string mime, content;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1971
diff changeset
747 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, v["7fe0,0010"].asString()));
1739
df331354cea2 include binary in ToJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1736
diff changeset
748 ASSERT_EQ("application/octet-stream", mime);
3832
ab9a0d1e0cc1 Fix unit test ParsedDicomFile.ToJsonFlags2 on big-endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3767
diff changeset
749 ASSERT_EQ("BA", content.substr(0, 2));
1735
a001f6226c7c primitives for flags in dicom-to-json conversions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1701
diff changeset
750 }
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
751
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
752
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
753 TEST(DicomFindAnswers, Basic)
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
754 {
2059
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2007
diff changeset
755 DicomFindAnswers a(false);
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
756
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
757 {
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
758 DicomMap m;
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
759 m.SetValue(DICOM_TAG_PATIENT_ID, "hello", false);
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
760 a.Add(m);
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
761 }
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
762
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
763 {
1805
f08978b1f45b c-find scu for modality worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
764 ParsedDicomFile d(true);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
765 d.ReplacePlainString(DICOM_TAG_PATIENT_ID, "my");
1789
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
766 a.Add(d);
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
767 }
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
768
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
769 {
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
770 DicomMap m;
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2006
diff changeset
771 m.SetValue(DICOM_TAG_PATIENT_ID, "world", false);
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
772 a.Add(m);
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
773 }
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
774
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
775 Json::Value j;
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
776 a.ToJson(j, true);
1789
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
777 ASSERT_EQ(3u, j.size());
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
778
bdcc1dba4a53 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1787
diff changeset
779 //std::cout << j;
1787
1b1d5470233f refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
780 }
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
781
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
782
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
783 TEST(ParsedDicomFile, FromJson)
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
784 {
2117
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
785 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7057, 0x1000), ValueRepresentation_OtherByte, "MyPrivateTag2", 1, 1, "ORTHANC");
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
786 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7059, 0x1000), ValueRepresentation_OtherByte, "MyPrivateTag3", 1, 1, "");
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
787 FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), ValueRepresentation_PersonName, "Declared public tag2", 1, 1, "");
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
788
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
789 Json::Value v;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
790 const std::string sopClassUid = "1.2.840.10008.5.1.4.1.1.1"; // CR Image Storage:
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
791
2117
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
792 // Test the private creator
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
793 ASSERT_EQ(DcmTag_ERROR_TagName, FromDcmtkBridge::GetTagName(DicomTag(0x7057, 0x1000), "NOPE"));
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
794 ASSERT_EQ("MyPrivateTag2", FromDcmtkBridge::GetTagName(DicomTag(0x7057, 0x1000), "ORTHANC"));
87b395a77c41 fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2115
diff changeset
795
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
796 {
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
797 v["SOPClassUID"] = sopClassUid;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
798 v["SpecificCharacterSet"] = "ISO_IR 148"; // This is latin-5
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
799 v["PatientName"] = "Sébastien";
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
800 v["7050-1000"] = "Some public tag"; // Even group => public tag
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
801 v["7052-1000"] = "Some unknown tag"; // Even group => public, unknown tag
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
802 v["7057-1000"] = "Some private tag"; // Odd group => private tag
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
803 v["7059-1000"] = "Some private tag2"; // Odd group => private tag, with an odd length to test padding
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
804
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
805 std::string s;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
806 Toolbox::EncodeDataUriScheme(s, "application/octet-stream", "Sebastien");
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
807 v["StudyDescription"] = s;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
808
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
809 v["PixelData"] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; // A red dot of 5x5 pixels
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
810 v["0040,0100"] = Json::arrayValue; // ScheduledProcedureStepSequence
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
811
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
812 Json::Value vv;
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
813 vv["Modality"] = "MR";
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
814 v["0040,0100"].append(vv);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
815
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
816 vv["Modality"] = "CT";
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
817 v["0040,0100"].append(vv);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
818 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
819
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
820 const DicomToJsonFlags toJsonFlags = static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeBinary |
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
821 DicomToJsonFlags_IncludePixelData |
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
822 DicomToJsonFlags_IncludePrivateTags |
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
823 DicomToJsonFlags_IncludeUnknownTags |
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
824 DicomToJsonFlags_ConvertBinaryToAscii);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
825
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
826
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
827 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
828 std::unique_ptr<ParsedDicomFile> dicom
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
829 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), ""));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
830
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
831 Json::Value vv;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
832 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, toJsonFlags, 0);
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
833
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
834 ASSERT_EQ(vv["SOPClassUID"].asString(), sopClassUid);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
835 ASSERT_EQ(vv["MediaStorageSOPClassUID"].asString(), sopClassUid);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
836 ASSERT_TRUE(vv.isMember("SOPInstanceUID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
837 ASSERT_TRUE(vv.isMember("SeriesInstanceUID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
838 ASSERT_TRUE(vv.isMember("StudyInstanceUID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
839 ASSERT_TRUE(vv.isMember("PatientID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
840 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
841
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
842
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
843 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
844 std::unique_ptr<ParsedDicomFile> dicom
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
845 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_GenerateIdentifiers), ""));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
846
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
847 Json::Value vv;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
848 dicom->DatasetToJson(vv, DicomToJsonFormat_Human, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData), 0);
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
849
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
850 std::string mime, content;
1981
4b545a8b1f95 return code in Toolbox::DecodeDataUriScheme
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1971
diff changeset
851 ASSERT_TRUE(Toolbox::DecodeDataUriScheme(mime, content, vv["PixelData"].asString()));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
852 ASSERT_EQ("application/octet-stream", mime);
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
853 ASSERT_EQ(5u * 5u * 3u /* the red dot is 5x5 pixels in RGB24 */ + 1 /* for padding */, content.size());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
854 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
855
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
856
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
857 {
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
858 std::unique_ptr<ParsedDicomFile> dicom
3691
4922bdd046dd Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
859 (ParsedDicomFile::CreateFromJson(v, static_cast<DicomFromJsonFlags>(DicomFromJsonFlags_DecodeDataUriScheme), ""));
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
860
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
861 Json::Value vv;
2128
9329ba17a069 Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2126
diff changeset
862 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, toJsonFlags, 0);
1818
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
863
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
864 ASSERT_FALSE(vv.isMember("SOPInstanceUID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
865 ASSERT_FALSE(vv.isMember("SeriesInstanceUID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
866 ASSERT_FALSE(vv.isMember("StudyInstanceUID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
867 ASSERT_FALSE(vv.isMember("PatientID"));
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
868 ASSERT_EQ(2u, vv["0040,0100"].size());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
869 ASSERT_EQ("MR", vv["0040,0100"][0]["0008,0060"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
870 ASSERT_EQ("CT", vv["0040,0100"][1]["0008,0060"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
871 ASSERT_EQ("Some public tag", vv["7050,1000"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
872 ASSERT_EQ("Some unknown tag", vv["7052,1000"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
873 ASSERT_EQ("Some private tag", vv["7057,1000"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
874 ASSERT_EQ("Some private tag2", vv["7059,1000"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
875 ASSERT_EQ("Sébastien", vv["0010,0010"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
876 ASSERT_EQ("Sebastien", vv["0008,1030"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
877 ASSERT_EQ("ISO_IR 148", vv["0008,0005"].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
878 ASSERT_EQ("5", vv[DICOM_TAG_ROWS.Format()].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
879 ASSERT_EQ("5", vv[DICOM_TAG_COLUMNS.Format()].asString());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
880 ASSERT_TRUE(vv[DICOM_TAG_PIXEL_DATA.Format()].asString().empty());
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
881 }
1065401501fb ParsedDicomFile::CreateFromJson
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
882 }
1937
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
883
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
884
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
885
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
886 TEST(TestImages, PatternGrayscale8)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
887 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
888 static const char* PATH = "UnitTestsResults/PatternGrayscale8.dcm";
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
889
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
890 Orthanc::Image image(Orthanc::PixelFormat_Grayscale8, 256, 256, false);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
891
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
892 for (int y = 0; y < 256; y++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
893 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
894 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y));
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
895 for (int x = 0; x < 256; x++, p++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
896 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
897 *p = y;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
898 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
899 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
900
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
901 Orthanc::ImageAccessor r;
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
902
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
903 image.GetRegion(r, 32, 32, 64, 192);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
904 Orthanc::ImageProcessing::Set(r, 0);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
905
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
906 image.GetRegion(r, 160, 32, 64, 192);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
907 Orthanc::ImageProcessing::Set(r, 255);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
908
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
909 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
910 ParsedDicomFile f(true);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
911 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
912 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
913 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
914 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
915 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
916 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale8");
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
917 f.EmbedImage(image);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
918
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
919 f.SaveToFile(PATH);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
920 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
921
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
922 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
923 std::string s;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
924 Orthanc::SystemToolbox::ReadFile(s, PATH);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
925 Orthanc::ParsedDicomFile f(s);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
926
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
927 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
928 ASSERT_EQ(256u, decoded->GetWidth());
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
929 ASSERT_EQ(256u, decoded->GetHeight());
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
930 ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat());
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
931
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
932 for (int y = 0; y < 256; y++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
933 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
934 const void* a = image.GetConstRow(y);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
935 const void* b = decoded->GetConstRow(y);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
936 ASSERT_EQ(0, memcmp(a, b, 256));
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
937 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
938 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
939 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
940
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
942 TEST(TestImages, PatternRGB)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
943 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
944 static const char* PATH = "UnitTestsResults/PatternRGB24.dcm";
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
945
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
946 Orthanc::Image image(Orthanc::PixelFormat_RGB24, 384, 256, false);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
947
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
948 for (int y = 0; y < 256; y++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
949 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
950 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetRow(y));
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
951 for (int x = 0; x < 128; x++, p += 3)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
952 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
953 p[0] = y;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
954 p[1] = 0;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
955 p[2] = 0;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
956 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
957 for (int x = 128; x < 128 * 2; x++, p += 3)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
958 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
959 p[0] = 0;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
960 p[1] = 255 - y;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
961 p[2] = 0;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
962 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
963 for (int x = 128 * 2; x < 128 * 3; x++, p += 3)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
964 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
965 p[0] = 0;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
966 p[1] = 0;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
967 p[2] = y;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
968 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
969 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
970
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
971 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
972 ParsedDicomFile f(true);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
973 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
974 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
975 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
976 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
977 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
978 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "RGB24");
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
979 f.EmbedImage(image);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
980
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
981 f.SaveToFile(PATH);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
982 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
983
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
984 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
985 std::string s;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
986 Orthanc::SystemToolbox::ReadFile(s, PATH);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
987 Orthanc::ParsedDicomFile f(s);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
988
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
989 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
990 ASSERT_EQ(384u, decoded->GetWidth());
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
991 ASSERT_EQ(256u, decoded->GetHeight());
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
992 ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat());
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
993
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
994 for (int y = 0; y < 256; y++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
995 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
996 const void* a = image.GetConstRow(y);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
997 const void* b = decoded->GetConstRow(y);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
998 ASSERT_EQ(0, memcmp(a, b, 3 * 384));
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
999 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1000 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1001 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1002
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1003
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1004 TEST(TestImages, PatternUint16)
1937
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1005 {
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1006 static const char* PATH = "UnitTestsResults/PatternGrayscale16.dcm";
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1007
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
1008 Orthanc::Image image(Orthanc::PixelFormat_Grayscale16, 256, 256, false);
1937
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1009
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1010 uint16_t v = 0;
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1011 for (int y = 0; y < 256; y++)
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1012 {
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1013 uint16_t *p = reinterpret_cast<uint16_t*>(image.GetRow(y));
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1014 for (int x = 0; x < 256; x++, v++, p++)
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1015 {
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1016 *p = htole16(v); // Orthanc uses Little-Endian transfer syntax to encode images
1937
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1017 }
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1018 }
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1019
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1020 Orthanc::ImageAccessor r;
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1021
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1022 image.GetRegion(r, 32, 32, 64, 192);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1023 Orthanc::ImageProcessing::Set(r, 0);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1024
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1025 image.GetRegion(r, 160, 32, 64, 192);
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1026 Orthanc::ImageProcessing::Set(r, 65535);
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1027
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1028 {
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1029 ParsedDicomFile f(true);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1030 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1031 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1032 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1033 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1034 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1035 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "Grayscale16");
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1036 f.EmbedImage(image);
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1037
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1038 f.SaveToFile(PATH);
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1039 }
1937
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1040
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1041 {
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1042 std::string s;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
1043 Orthanc::SystemToolbox::ReadFile(s, PATH);
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1044 Orthanc::ParsedDicomFile f(s);
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1045
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1046 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
1047 ASSERT_EQ(256u, decoded->GetWidth());
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
1048 ASSERT_EQ(256u, decoded->GetHeight());
1940
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1049 ASSERT_EQ(Orthanc::PixelFormat_Grayscale16, decoded->GetFormat());
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1050
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1051 for (int y = 0; y < 256; y++)
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1052 {
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1053 const void* a = image.GetConstRow(y);
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1054 const void* b = decoded->GetConstRow(y);
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1055 ASSERT_EQ(0, memcmp(a, b, 512));
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1056 }
5514d37176b4 PatternUint16
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1937
diff changeset
1057 }
1937
3756bedaaa36 test pattern
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1908
diff changeset
1058 }
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1059
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1060
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1061 TEST(TestImages, PatternInt16)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1062 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1063 static const char* PATH = "UnitTestsResults/PatternSignedGrayscale16.dcm";
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1064
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2059
diff changeset
1065 Orthanc::Image image(Orthanc::PixelFormat_SignedGrayscale16, 256, 256, false);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1066
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1067 int16_t v = -32768;
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1068 for (int y = 0; y < 256; y++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1069 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1070 int16_t *p = reinterpret_cast<int16_t*>(image.GetRow(y));
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1071 for (int x = 0; x < 256; x++, v++, p++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1072 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1073 *p = htole16(v); // Orthanc uses Little-Endian transfer syntax to encode images
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1074 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1075 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1076
2861
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1077 Orthanc::ImageAccessor r;
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1078 image.GetRegion(r, 32, 32, 64, 192);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1079 Orthanc::ImageProcessing::Set(r, -32768);
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1080
9b4251721f22 ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2521
diff changeset
1081 image.GetRegion(r, 160, 32, 64, 192);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1082 Orthanc::ImageProcessing::Set(r, 32767);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1083
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1084 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1085 ParsedDicomFile f(true);
1982
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1086 f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "1.2.840.10008.5.1.4.1.1.7");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1087 f.ReplacePlainString(DICOM_TAG_STUDY_INSTANCE_UID, "1.2.276.0.7230010.3.1.2.2831176407.321.1458901422.884998");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1088 f.ReplacePlainString(DICOM_TAG_PATIENT_ID, "ORTHANC");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1089 f.ReplacePlainString(DICOM_TAG_PATIENT_NAME, "Orthanc");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1090 f.ReplacePlainString(DICOM_TAG_STUDY_DESCRIPTION, "Patterns");
b5d4f9c156ad Modification of instances can now replace PixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1981
diff changeset
1091 f.ReplacePlainString(DICOM_TAG_SERIES_DESCRIPTION, "SignedGrayscale16");
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1092 f.EmbedImage(image);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1093
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1094 f.SaveToFile(PATH);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1095 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1096
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1097 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1098 std::string s;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2128
diff changeset
1099 Orthanc::SystemToolbox::ReadFile(s, PATH);
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1100 Orthanc::ParsedDicomFile f(s);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1101
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3691
diff changeset
1102 std::unique_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
1971
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
1103 ASSERT_EQ(256u, decoded->GetWidth());
869a87c08673 fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
1104 ASSERT_EQ(256u, decoded->GetHeight());
1941
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1105 ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat());
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1106
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1107 for (int y = 0; y < 256; y++)
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1108 {
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1109 const void* a = image.GetConstRow(y);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1110 const void* b = decoded->GetConstRow(y);
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1111 ASSERT_EQ(0, memcmp(a, b, 512));
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1112 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1113 }
d7b176f7dd1b test dicom patterns
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1940
diff changeset
1114 }
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1115
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1116
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1117
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1118 static void CheckEncoding(const ParsedDicomFile& dicom,
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1119 Encoding expected)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1120 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1121 const char* value = NULL;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1122 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_SpecificCharacterSet, value).good());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1123
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1124 Encoding encoding;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1125 ASSERT_TRUE(GetDicomEncoding(encoding, value));
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1126 ASSERT_EQ(expected, encoding);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1127 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1128
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1129
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1130 TEST(ParsedDicomFile, DicomMapEncodings1)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1131 {
2381
b8969010b534 uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2326
diff changeset
1132 SetDefaultDicomEncoding(Encoding_Ascii);
b8969010b534 uncoupling DCMTK primitives from Orthanc::Configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2326
diff changeset
1133 ASSERT_EQ(Encoding_Ascii, GetDefaultDicomEncoding());
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1134
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1135 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1136 DicomMap m;
3342
63f59ad9381a Fix issue #136 (C-Find request fails when found DICOM file does not have certain tags)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3311
diff changeset
1137 ParsedDicomFile dicom(m, GetDefaultDicomEncoding(), false);
2411
82d5e305fbd9 fix gcc warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2409
diff changeset
1138 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card());
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1139 CheckEncoding(dicom, Encoding_Ascii);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1140 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1141
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1142 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1143 DicomMap m;
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1144 ParsedDicomFile dicom(m, Encoding_Latin4, false);
2411
82d5e305fbd9 fix gcc warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2409
diff changeset
1145 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card());
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1146 CheckEncoding(dicom, Encoding_Latin4);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1147 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1148
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1149 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1150 DicomMap m;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1151 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 148", false);
3342
63f59ad9381a Fix issue #136 (C-Find request fails when found DICOM file does not have certain tags)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3311
diff changeset
1152 ParsedDicomFile dicom(m, GetDefaultDicomEncoding(), false);
2411
82d5e305fbd9 fix gcc warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2409
diff changeset
1153 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card());
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1154 CheckEncoding(dicom, Encoding_Latin5);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1155 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1156
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1157 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1158 DicomMap m;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1159 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 148", false);
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1160 ParsedDicomFile dicom(m, Encoding_Latin1, false);
2411
82d5e305fbd9 fix gcc warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2409
diff changeset
1161 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card());
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1162 CheckEncoding(dicom, Encoding_Latin5);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1163 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1164 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1165
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1166
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1167 TEST(ParsedDicomFile, DicomMapEncodings2)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1168 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1169 const char* utf8 = NULL;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1170 for (unsigned int i = 0; i < testEncodingsCount; i++)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1171 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1172 if (testEncodings[i] == Encoding_Utf8)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1173 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1174 utf8 = testEncodingsEncoded[i];
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1175 break;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1176 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1177 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1178
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1179 ASSERT_TRUE(utf8 != NULL);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1180
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1181 for (unsigned int i = 0; i < testEncodingsCount; i++)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1182 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1183 // 1251 codepage is not supported by the core DICOM standard, ignore it
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1184 if (testEncodings[i] != Encoding_Windows1251)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1185 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1186 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1187 // Sanity check to test the proper behavior of "EncodingTests.py"
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1188 std::string encoded = Toolbox::ConvertFromUtf8(testEncodingsExpected[i], testEncodings[i]);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1189 ASSERT_STREQ(testEncodingsEncoded[i], encoded.c_str());
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1190 std::string decoded = Toolbox::ConvertToUtf8(encoded, testEncodings[i], false);
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1191 ASSERT_STREQ(testEncodingsExpected[i], decoded.c_str());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1192
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1193 if (testEncodings[i] != Encoding_Chinese)
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1194 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1195 // A specific source string is used in "EncodingTests.py" to
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1196 // test against Chinese, it is normal that it does not correspond to UTF8
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1197
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1198 std::string encoded = Toolbox::ConvertToUtf8(Toolbox::ConvertFromUtf8(utf8, testEncodings[i]), testEncodings[i], false);
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1199 ASSERT_STREQ(testEncodingsExpected[i], encoded.c_str());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1200 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1201 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1203
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1204 Json::Value v;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1205
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1206 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1207 DicomMap m;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1208 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1209
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1210 ParsedDicomFile dicom(m, testEncodings[i], false);
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1211
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1212 const char* encoded = NULL;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1213 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_PatientName, encoded).good());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1214 ASSERT_STREQ(testEncodingsEncoded[i], encoded);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1215
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1216 dicom.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1217
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1218 Encoding encoding;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1219 ASSERT_TRUE(GetDicomEncoding(encoding, v["SpecificCharacterSet"].asCString()));
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1220 ASSERT_EQ(encoding, testEncodings[i]);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1221 ASSERT_STREQ(testEncodingsExpected[i], v["PatientName"].asCString());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1222 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1223
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1224
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1225 {
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1226 DicomMap m;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1227 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, GetDicomSpecificCharacterSet(testEncodings[i]), false);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1228 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1229
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1230 ParsedDicomFile dicom(m, testEncodings[i], false);
2202
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1231
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1232 Json::Value v2;
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1233 dicom.DatasetToJson(v2, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0);
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1234
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1235 ASSERT_EQ(v2["PatientName"].asString(), v["PatientName"].asString());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1236 ASSERT_EQ(v2["SpecificCharacterSet"].asString(), v["SpecificCharacterSet"].asString());
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1237 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1238 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1239 }
9b373b7d6713 Fix handling of encodings in C-FIND requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2142
diff changeset
1240 }
2207
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1241
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1242
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1243 TEST(ParsedDicomFile, ChangeEncoding)
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1244 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1245 for (unsigned int i = 0; i < testEncodingsCount; i++)
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1246 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1247 // 1251 codepage is not supported by the core DICOM standard, ignore it
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1248 if (testEncodings[i] != Encoding_Windows1251)
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1249 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1250 DicomMap m;
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1251 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1252
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1253 std::string tag;
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1254
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1255 ParsedDicomFile dicom(m, Encoding_Utf8, false);
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1256 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1257 ASSERT_EQ(Encoding_Utf8, dicom.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1258 ASSERT_FALSE(hasCodeExtensions);
2207
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1259 ASSERT_TRUE(dicom.GetTagValue(tag, DICOM_TAG_PATIENT_NAME));
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1260 ASSERT_EQ(tag, testEncodingsExpected[i]);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1261
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1262 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1263 Json::Value v;
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1264 dicom.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1265 ASSERT_STREQ(v["SpecificCharacterSet"].asCString(), "ISO_IR 192");
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1266 ASSERT_STREQ(v["PatientName"].asCString(), testEncodingsExpected[i]);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1267 }
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1268
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1269 dicom.ChangeEncoding(testEncodings[i]);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1270
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1271 ASSERT_EQ(testEncodings[i], dicom.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1272 ASSERT_FALSE(hasCodeExtensions);
2207
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1273
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1274 const char* c = NULL;
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1275 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_PatientName, c).good());
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1276 EXPECT_STREQ(c, testEncodingsEncoded[i]);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1277
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1278 ASSERT_TRUE(dicom.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); // Decodes to UTF-8
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1279 EXPECT_EQ(tag, testEncodingsExpected[i]);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1280
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1281 {
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1282 Json::Value v;
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1283 dicom.DatasetToJson(v, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1284 ASSERT_STREQ(v["SpecificCharacterSet"].asCString(), GetDicomSpecificCharacterSet(testEncodings[i]));
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1285 ASSERT_STREQ(v["PatientName"].asCString(), testEncodingsExpected[i]);
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1286 }
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1287 }
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1288 }
6dc3bdb4088b Fix handling of encodings in C-FIND for worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2202
diff changeset
1289 }
2326
423d3b692bb9 Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
1290
423d3b692bb9 Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
1291
423d3b692bb9 Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
1292 TEST(Toolbox, CaseWithAccents)
423d3b692bb9 Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
1293 {
423d3b692bb9 Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
1294 ASSERT_EQ(toUpperResult, Toolbox::ToUpperCaseWithAccents(toUpperSource));
423d3b692bb9 Upgrade to Boost 1.64.0, and Toolbox::ToUpperCaseWithAccents
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2309
diff changeset
1295 }
2445
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1296
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1297
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1298
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1299 TEST(ParsedDicomFile, InvalidCharacterSets)
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1300 {
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1301 {
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1302 // No encoding provided, fallback to default encoding
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1303 DicomMap m;
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1304 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1305
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1306 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */, false);
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1307
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1308 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1309 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1310 ASSERT_FALSE(hasCodeExtensions);
2445
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1311 }
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1312
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1313 {
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1314 // Valid encoding, "ISO_IR 13" is Japanese
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1315 DicomMap m;
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1316 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1317 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1318
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1319 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */, false);
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1320
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1321 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1322 ASSERT_EQ(Encoding_Japanese, d.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1323 ASSERT_FALSE(hasCodeExtensions);
2445
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1324 }
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1325
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1326 {
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1327 // Invalid value for an encoding ("nope" is not in the DICOM standard)
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1328 DicomMap m;
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1329 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "nope", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1330 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1331
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1332 ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3, false), OrthancException);
2445
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1333 }
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1334
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1335 {
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1336 // Invalid encoding, as provided as a binary string
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1337 DicomMap m;
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1338 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", true);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1339 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1340
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1341 ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3, false), OrthancException);
2445
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1342 }
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1343
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1344 {
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1345 // Encoding provided as an empty string, fallback to default encoding
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1346 // In Orthanc <= 1.3.1, this test was throwing an exception
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1347 DicomMap m;
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1348 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1349 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1350
3276
9b0e67161600 More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3229
diff changeset
1351 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */, false);
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1352
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1353 bool hasCodeExtensions;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1354 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1355 ASSERT_FALSE(hasCodeExtensions);
2445
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1356 }
6e5bc5c6d1a4 Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2411
diff changeset
1357 }
3217
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1358
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1359
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1360
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1361 TEST(Toolbox, RemoveIso2022EscapeSequences)
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1362 {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1363 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1364 // | one-byte control messages |
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1365 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1366
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1367 static const uint8_t iso2022_cstr_oneByteControl[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1368 0x0f, 0x41,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1369 0x0e, 0x42,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1370 0x8e, 0x1b, 0x4e, 0x43,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1371 0x8f, 0x1b, 0x4f, 0x44,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1372 0x8e, 0x1b, 0x4a, 0x45,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1373 0x8f, 0x1b, 0x4a, 0x46,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1374 0x50, 0x51, 0x52, 0x00
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1375 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1376
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1377 static const uint8_t iso2022_cstr_oneByteControl_ref[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1378 0x41,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1379 0x42,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1380 0x43,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1381 0x44,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1382 0x8e, 0x1b, 0x4a, 0x45,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1383 0x8f, 0x1b, 0x4a, 0x46,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1384 0x50, 0x51, 0x52, 0x00
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1385 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1386
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1387 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1388 // | two-byte control messages |
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1389 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1390
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1391 static const uint8_t iso2022_cstr_twoByteControl[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1392 0x1b, 0x6e, 0x41,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1393 0x1b, 0x6f, 0x42,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1394 0x1b, 0x4e, 0x43,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1395 0x1b, 0x4f, 0x44,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1396 0x1b, 0x7e, 0x45,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1397 0x1b, 0x7d, 0x46,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1398 0x1b, 0x7c, 0x47, 0x00
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1399 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1400
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1401 static const uint8_t iso2022_cstr_twoByteControl_ref[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1402 0x41,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1403 0x42,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1404 0x43,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1405 0x44,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1406 0x45,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1407 0x46,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1408 0x47, 0x00
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1409 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1410
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1411 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1412 // | various-length escape sequences |
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1413 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1414
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1415 static const uint8_t iso2022_cstr_escapeSequence[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1416 0x1b, 0x40, 0x41, // 1b and 40 should not be removed (invalid esc seq)
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1417 0x1b, 0x50, 0x42, // ditto
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1418 0x1b, 0x7f, 0x43, // ditto
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1419 0x1b, 0x21, 0x4a, 0x44, // this will match
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1420 0x1b, 0x20, 0x21, 0x2f, 0x40, 0x45, // this will match
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1421 0x1b, 0x20, 0x21, 0x2f, 0x2f, 0x40, 0x46, // this will match too
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1422 0x1b, 0x20, 0x21, 0x2f, 0x1f, 0x47, 0x48, 0x00 // this will NOT match!
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1423 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1424
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1425 static const uint8_t iso2022_cstr_escapeSequence_ref[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1426 0x1b, 0x40, 0x41, // 1b and 40 should not be removed (invalid esc seq)
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1427 0x1b, 0x50, 0x42, // ditto
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1428 0x1b, 0x7f, 0x43, // ditto
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1429 0x44, // this will match
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1430 0x45, // this will match
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1431 0x46, // this will match too
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1432 0x1b, 0x20, 0x21, 0x2f, 0x1f, 0x47, 0x48, 0x00 // this will NOT match!
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1433 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1434
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1435
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1436 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1437 // | a real-world japanese sample |
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1438 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1439
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1440 static const uint8_t iso2022_cstr_real_ir13[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1441 0xd4, 0xcf, 0xc0, 0xde, 0x5e, 0xc0, 0xdb, 0xb3,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1442 0x3d, 0x1b, 0x24, 0x42, 0x3b, 0x33, 0x45, 0x44,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1443 0x1b, 0x28, 0x4a, 0x5e, 0x1b, 0x24, 0x42, 0x42,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1444 0x40, 0x4f, 0x3a, 0x1b, 0x28, 0x4a, 0x3d, 0x1b,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1445 0x24, 0x42, 0x24, 0x64, 0x24, 0x5e, 0x24, 0x40,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1446 0x1b, 0x28, 0x4a, 0x5e, 0x1b, 0x24, 0x42, 0x24,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1447 0x3f, 0x24, 0x6d, 0x24, 0x26, 0x1b, 0x28, 0x4a, 0x00
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1448 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1449
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1450 static const uint8_t iso2022_cstr_real_ir13_ref[] = {
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1451 0xd4, 0xcf, 0xc0, 0xde, 0x5e, 0xc0, 0xdb, 0xb3,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1452 0x3d,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1453 0x3b, 0x33, 0x45, 0x44,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1454 0x5e,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1455 0x42,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1456 0x40, 0x4f, 0x3a,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1457 0x3d,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1458 0x24, 0x64, 0x24, 0x5e, 0x24, 0x40,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1459 0x5e,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1460 0x24,
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1461 0x3f, 0x24, 0x6d, 0x24, 0x26, 0x00
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1462 };
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1463
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1464
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1465
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1466 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1467 // | the actual test |
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1468 // +----------------------------------+
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1469
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1470 std::string iso2022_str_oneByteControl(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1471 reinterpret_cast<const char*>(iso2022_cstr_oneByteControl));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1472 std::string iso2022_str_oneByteControl_ref(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1473 reinterpret_cast<const char*>(iso2022_cstr_oneByteControl_ref));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1474 std::string iso2022_str_twoByteControl(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1475 reinterpret_cast<const char*>(iso2022_cstr_twoByteControl));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1476 std::string iso2022_str_twoByteControl_ref(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1477 reinterpret_cast<const char*>(iso2022_cstr_twoByteControl_ref));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1478 std::string iso2022_str_escapeSequence(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1479 reinterpret_cast<const char*>(iso2022_cstr_escapeSequence));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1480 std::string iso2022_str_escapeSequence_ref(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1481 reinterpret_cast<const char*>(iso2022_cstr_escapeSequence_ref));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1482 std::string iso2022_str_real_ir13(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1483 reinterpret_cast<const char*>(iso2022_cstr_real_ir13));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1484 std::string iso2022_str_real_ir13_ref(
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1485 reinterpret_cast<const char*>(iso2022_cstr_real_ir13_ref));
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1486
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1487 std::string dest;
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1488
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1489 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_oneByteControl);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1490 ASSERT_EQ(dest, iso2022_str_oneByteControl_ref);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1491
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1492 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_twoByteControl);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1493 ASSERT_EQ(dest, iso2022_str_twoByteControl_ref);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1494
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1495 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_escapeSequence);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1496 ASSERT_EQ(dest, iso2022_str_escapeSequence_ref);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1497
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1498 Toolbox::RemoveIso2022EscapeSequences(dest, iso2022_str_real_ir13);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1499 ASSERT_EQ(dest, iso2022_str_real_ir13_ref);
cf8cbeb35f33 preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3083
diff changeset
1500 }
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1501
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1502
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1503
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1504 static std::string DecodeFromSpecification(const std::string& s)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1505 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1506 std::vector<std::string> tokens;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1507 Toolbox::TokenizeString(tokens, s, ' ');
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1508
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1509 std::string result;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1510 result.resize(tokens.size());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1511
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1512 for (size_t i = 0; i < tokens.size(); i++)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1513 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1514 std::vector<std::string> components;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1515 Toolbox::TokenizeString(components, tokens[i], '/');
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1516
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1517 if (components.size() != 2)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1518 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1519 throw;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1520 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1521
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1522 int a = boost::lexical_cast<int>(components[0]);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1523 int b = boost::lexical_cast<int>(components[1]);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1524 if (a < 0 || a > 15 ||
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1525 b < 0 || b > 15 ||
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1526 (a == 0 && b == 0))
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1527 {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1528 throw;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1529 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1530
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1531 result[i] = static_cast<uint8_t>(a * 16 + b);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1532 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1533
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1534 return result;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1535 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1536
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1537
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1538
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1539 // Compatibility wrapper
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1540 static pugi::xpath_node SelectNode(const pugi::xml_document& doc,
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1541 const char* xpath)
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1542 {
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1543 #if PUGIXML_VERSION <= 140
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1544 return doc.select_single_node(xpath); // Deprecated in pugixml 1.5
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1545 #else
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1546 return doc.select_node(xpath);
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1547 #endif
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1548 }
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1549
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1550
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1551 TEST(Toolbox, EncodingsKorean)
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1552 {
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1553 // http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part05/sect_I.2.html
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1554
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1555 std::string korean = DecodeFromSpecification(
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1556 "04/08 06/15 06/14 06/07 05/14 04/07 06/09 06/12 06/04 06/15 06/14 06/07 03/13 "
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1557 "01/11 02/04 02/09 04/03 15/11 15/03 05/14 01/11 02/04 02/09 04/03 13/01 12/14 "
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1558 "13/04 13/07 03/13 01/11 02/04 02/09 04/03 12/08 10/11 05/14 01/11 02/04 02/09 "
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1559 "04/03 11/01 14/06 11/05 11/15");
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1560
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1561 // This array can be re-generated using command-line:
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1562 // echo -n "Hong^Gildong=..." | hexdump -v -e '14/1 "0x%02x, "' -e '"\n"'
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1563 static const uint8_t utf8raw[] = {
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1564 0x48, 0x6f, 0x6e, 0x67, 0x5e, 0x47, 0x69, 0x6c, 0x64, 0x6f, 0x6e, 0x67, 0x3d, 0xe6,
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1565 0xb4, 0xaa, 0x5e, 0xe5, 0x90, 0x89, 0xe6, 0xb4, 0x9e, 0x3d, 0xed, 0x99, 0x8d, 0x5e,
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1566 0xea, 0xb8, 0xb8, 0xeb, 0x8f, 0x99
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1567 };
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1568
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1569 std::string utf8(reinterpret_cast<const char*>(utf8raw), sizeof(utf8raw));
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1570
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1571 ParsedDicomFile dicom(false);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1572 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "\\ISO 2022 IR 149");
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1573 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1574 (DCM_PatientName, korean.c_str(), OFBool(true)).good());
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1575
3225
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1576 bool hasCodeExtensions;
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1577 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1578 ASSERT_EQ(Encoding_Korean, encoding);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1579 ASSERT_TRUE(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1580
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1581 std::string value;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1582 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_NAME));
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1583 ASSERT_EQ(utf8, value);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1584
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1585 DicomWebJsonVisitor visitor;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1586 dicom.Apply(visitor);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1587 ASSERT_EQ(utf8.substr(0, 12), visitor.GetResult()["00100010"]["Value"][0]["Alphabetic"].asString());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1588 ASSERT_EQ(utf8.substr(13, 10), visitor.GetResult()["00100010"]["Value"][0]["Ideographic"].asString());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1589 ASSERT_EQ(utf8.substr(24), visitor.GetResult()["00100010"]["Value"][0]["Phonetic"].asString());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1590
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1591 #if ORTHANC_ENABLE_PUGIXML == 1
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1592 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.3.html#table_F.3.1-1
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1593 std::string xml;
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1594 visitor.FormatXml(xml);
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1595
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1596 pugi::xml_document doc;
3222
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3221
diff changeset
1597 doc.load_buffer(xml.c_str(), xml.size());
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1598
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1599 pugi::xpath_node node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]/Value");
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3342
diff changeset
1600 ASSERT_STREQ("ISO 2022 IR 149", node.node().text().as_string());
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1601
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1602 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1603 ASSERT_STREQ("CS", node.node().attribute("vr").value());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1604
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1605 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1606 ASSERT_STREQ("PN", node.node().attribute("vr").value());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1607
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1608 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Alphabetic/FamilyName");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1609 ASSERT_STREQ("Hong", node.node().text().as_string());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1610
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1611 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Alphabetic/GivenName");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1612 ASSERT_STREQ("Gildong", node.node().text().as_string());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1613
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1614 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Ideographic/FamilyName");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1615 ASSERT_EQ(utf8.substr(13, 3), node.node().text().as_string());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1616
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1617 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Ideographic/GivenName");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1618 ASSERT_EQ(utf8.substr(17, 6), node.node().text().as_string());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1619
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1620 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/FamilyName");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1621 ASSERT_EQ(utf8.substr(24, 3), node.node().text().as_string());
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1622
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1623 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/GivenName");
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1624 ASSERT_EQ(utf8.substr(28), node.node().text().as_string());
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1625 #endif
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1626
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1627 {
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1628 DicomMap m;
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1629 m.FromDicomWeb(visitor.GetResult());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1630 ASSERT_EQ(2u, m.GetSize());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1631
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1632 std::string s;
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3496
diff changeset
1633 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_SPECIFIC_CHARACTER_SET, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1634 ASSERT_EQ("ISO 2022 IR 149", s);
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1635
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3496
diff changeset
1636 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1637 std::vector<std::string> v;
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1638 Toolbox::TokenizeString(v, s, '=');
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1639 ASSERT_EQ(3u, v.size());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1640 ASSERT_EQ("Hong^Gildong", v[0]);
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1641 ASSERT_EQ(utf8, s);
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1642 }
3221
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1643 }
4be505c2ac56 Separation of ideographic and phonetic characters in DICOMweb JSON and XML
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3219
diff changeset
1644
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1645
3225
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1646 TEST(Toolbox, EncodingsJapaneseKanji)
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1647 {
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1648 // http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part05/sect_H.3.html
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1649
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1650 std::string japanese = DecodeFromSpecification(
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1651 "05/09 06/01 06/13 06/01 06/04 06/01 05/14 05/04 06/01 07/02 06/15 07/05 03/13 "
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1652 "01/11 02/04 04/02 03/11 03/03 04/05 04/04 01/11 02/08 04/02 05/14 01/11 02/04 "
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1653 "04/02 04/02 04/00 04/15 03/10 01/11 02/08 04/02 03/13 01/11 02/04 04/02 02/04 "
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1654 "06/04 02/04 05/14 02/04 04/00 01/11 02/08 04/02 05/14 01/11 02/04 04/02 02/04 "
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1655 "03/15 02/04 06/13 02/04 02/06 01/11 02/08 04/02");
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1656
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1657 // This array can be re-generated using command-line:
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1658 // echo -n "Yamada^Tarou=..." | hexdump -v -e '14/1 "0x%02x, "' -e '"\n"'
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1659 static const uint8_t utf8raw[] = {
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1660 0x59, 0x61, 0x6d, 0x61, 0x64, 0x61, 0x5e, 0x54, 0x61, 0x72, 0x6f, 0x75, 0x3d, 0xe5,
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1661 0xb1, 0xb1, 0xe7, 0x94, 0xb0, 0x5e, 0xe5, 0xa4, 0xaa, 0xe9, 0x83, 0x8e, 0x3d, 0xe3,
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1662 0x82, 0x84, 0xe3, 0x81, 0xbe, 0xe3, 0x81, 0xa0, 0x5e, 0xe3, 0x81, 0x9f, 0xe3, 0x82,
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1663 0x8d, 0xe3, 0x81, 0x86
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1664 };
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1665
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1666 std::string utf8(reinterpret_cast<const char*>(utf8raw), sizeof(utf8raw));
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1667
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1668 ParsedDicomFile dicom(false);
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1669 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "\\ISO 2022 IR 87");
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1670 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1671 (DCM_PatientName, japanese.c_str(), OFBool(true)).good());
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1672
3225
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1673 bool hasCodeExtensions;
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1674 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1675 ASSERT_EQ(Encoding_JapaneseKanji, encoding);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1676 ASSERT_TRUE(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1677
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1678 std::string value;
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1679 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_NAME));
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1680 ASSERT_EQ(utf8, value);
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1681
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1682 DicomWebJsonVisitor visitor;
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1683 dicom.Apply(visitor);
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1684 ASSERT_EQ(utf8.substr(0, 12), visitor.GetResult()["00100010"]["Value"][0]["Alphabetic"].asString());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1685 ASSERT_EQ(utf8.substr(13, 13), visitor.GetResult()["00100010"]["Value"][0]["Ideographic"].asString());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1686 ASSERT_EQ(utf8.substr(27), visitor.GetResult()["00100010"]["Value"][0]["Phonetic"].asString());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1687
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1688 #if ORTHANC_ENABLE_PUGIXML == 1
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1689 // http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_F.3.html#table_F.3.1-1
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1690 std::string xml;
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1691 visitor.FormatXml(xml);
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1692
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1693 pugi::xml_document doc;
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1694 doc.load_buffer(xml.c_str(), xml.size());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1695
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1696 pugi::xpath_node node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]/Value");
3420
0a0e7eca95ae fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3342
diff changeset
1697 ASSERT_STREQ("ISO 2022 IR 87", node.node().text().as_string());
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1698
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1699 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00080005\"]");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1700 ASSERT_STREQ("CS", node.node().attribute("vr").value());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1701
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1702 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1703 ASSERT_STREQ("PN", node.node().attribute("vr").value());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1704
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1705 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Alphabetic/FamilyName");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1706 ASSERT_STREQ("Yamada", node.node().text().as_string());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1707
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1708 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Alphabetic/GivenName");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1709 ASSERT_STREQ("Tarou", node.node().text().as_string());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1710
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1711 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Ideographic/FamilyName");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1712 ASSERT_EQ(utf8.substr(13, 6), node.node().text().as_string());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1713
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1714 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Ideographic/GivenName");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1715 ASSERT_EQ(utf8.substr(20, 6), node.node().text().as_string());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1716
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1717 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/FamilyName");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1718 ASSERT_EQ(utf8.substr(27, 9), node.node().text().as_string());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1719
3311
f2f8aa6f78aa compatibility with pugixml <= 1.4.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3298
diff changeset
1720 node = SelectNode(doc, "//NativeDicomModel/DicomAttribute[@tag=\"00100010\"]/PersonName/Phonetic/GivenName");
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1721 ASSERT_EQ(utf8.substr(37), node.node().text().as_string());
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1722 #endif
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1723
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1724 {
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1725 DicomMap m;
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1726 m.FromDicomWeb(visitor.GetResult());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1727 ASSERT_EQ(2u, m.GetSize());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1728
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1729 std::string s;
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3496
diff changeset
1730 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_SPECIFIC_CHARACTER_SET, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1731 ASSERT_EQ("ISO 2022 IR 87", s);
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1732
3518
a57c8163d9ae DicomMap::GetStringValue()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3496
diff changeset
1733 ASSERT_TRUE(m.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false));
3496
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1734 std::vector<std::string> v;
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1735 Toolbox::TokenizeString(v, s, '=');
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1736 ASSERT_EQ(3u, v.size());
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1737 ASSERT_EQ("Yamada^Tarou", v[0]);
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1738 ASSERT_EQ(utf8, s);
109631ed3564 DicomMap::FromDicomWeb()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3420
diff changeset
1739 }
3223
c94f23198946 unit testing japanese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3222
diff changeset
1740 }
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1741
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1742
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1743
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1744 TEST(Toolbox, EncodingsChinese3)
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1745 {
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1746 // http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part05/sect_J.3.html
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1747
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1748 static const uint8_t chinese[] = {
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1749 0x57, 0x61, 0x6e, 0x67, 0x5e, 0x58, 0x69, 0x61, 0x6f, 0x44, 0x6f,
3229
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3228
diff changeset
1750 0x6e, 0x67, 0x3d, 0xcd, 0xf5, 0x5e, 0xd0, 0xa1, 0xb6, 0xab, 0x3d, 0x00
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1751 };
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1752
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1753 ParsedDicomFile dicom(false);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1754 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "GB18030");
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1755 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1756 (DCM_PatientName, reinterpret_cast<const char*>(chinese), OFBool(true)).good());
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1757
3225
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1758 bool hasCodeExtensions;
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1759 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1760 ASSERT_EQ(Encoding_Chinese, encoding);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1761 ASSERT_FALSE(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1762
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1763 std::string value;
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1764 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_NAME));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1765
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1766 std::vector<std::string> tokens;
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1767 Orthanc::Toolbox::TokenizeString(tokens, value, '=');
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1768 ASSERT_EQ(3u, tokens.size());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1769 ASSERT_EQ("Wang^XiaoDong", tokens[0]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1770 ASSERT_TRUE(tokens[2].empty());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1771
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1772 std::vector<std::string> middle;
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1773 Orthanc::Toolbox::TokenizeString(middle, tokens[1], '^');
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1774 ASSERT_EQ(2u, middle.size());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1775 ASSERT_EQ(3u, middle[0].size());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1776 ASSERT_EQ(6u, middle[1].size());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1777
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1778 // CDF5 in GB18030
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1779 ASSERT_EQ(static_cast<char>(0xe7), middle[0][0]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1780 ASSERT_EQ(static_cast<char>(0x8e), middle[0][1]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1781 ASSERT_EQ(static_cast<char>(0x8b), middle[0][2]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1782
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1783 // D0A1 in GB18030
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1784 ASSERT_EQ(static_cast<char>(0xe5), middle[1][0]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1785 ASSERT_EQ(static_cast<char>(0xb0), middle[1][1]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1786 ASSERT_EQ(static_cast<char>(0x8f), middle[1][2]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1787
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1788 // B6AB in GB18030
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1789 ASSERT_EQ(static_cast<char>(0xe4), middle[1][3]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1790 ASSERT_EQ(static_cast<char>(0xb8), middle[1][4]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1791 ASSERT_EQ(static_cast<char>(0x9c), middle[1][5]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1792 }
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1793
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1794
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1795 TEST(Toolbox, EncodingsChinese4)
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1796 {
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1797 // http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part05/sect_J.4.html
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1798
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1799 static const uint8_t chinese[] = {
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1800 0x54, 0x68, 0x65, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x6c, 0x69, 0x6e,
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1801 0x65, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x73, 0xd6, 0xd0, 0xce,
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1802 0xc4, 0x2e, 0x0d, 0x0a, 0x54, 0x68, 0x65, 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e,
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1803 0x64, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64,
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1804 0x65, 0x73, 0xd6, 0xd0, 0xce, 0xc4, 0x2c, 0x20, 0x74, 0x6f, 0x6f, 0x2e, 0x0d,
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1805 0x0a, 0x54, 0x68, 0x65, 0x20, 0x74, 0x68, 0x69, 0x72, 0x64, 0x20, 0x6c, 0x69,
3229
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3228
diff changeset
1806 0x6e, 0x65, 0x2e, 0x0d, 0x0a, 0x00
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1807 };
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1808
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1809 static const uint8_t patternRaw[] = {
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1810 0xe4, 0xb8, 0xad, 0xe6, 0x96, 0x87
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1811 };
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1812
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1813 const std::string pattern(reinterpret_cast<const char*>(patternRaw), sizeof(patternRaw));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1814
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1815 ParsedDicomFile dicom(false);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1816 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "GB18030");
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1817 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1818 (DCM_PatientComments, reinterpret_cast<const char*>(chinese), OFBool(true)).good());
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1819
3225
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1820 bool hasCodeExtensions;
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1821 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1822 ASSERT_EQ(Encoding_Chinese, encoding);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1823 ASSERT_FALSE(hasCodeExtensions);
c85510b5f21d unit testing ParsedDicomFile::DetectEncoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3224
diff changeset
1824
3224
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1825 std::string value;
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1826 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_COMMENTS));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1827
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1828 std::vector<std::string> lines;
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1829 Orthanc::Toolbox::TokenizeString(lines, value, '\n');
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1830 ASSERT_EQ(4u, lines.size());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1831 ASSERT_TRUE(boost::starts_with(lines[0], "The first line includes"));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1832 ASSERT_TRUE(boost::ends_with(lines[0], ".\r"));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1833 ASSERT_TRUE(lines[0].find(pattern) != std::string::npos);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1834 ASSERT_TRUE(boost::starts_with(lines[1], "The second line includes"));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1835 ASSERT_TRUE(boost::ends_with(lines[1], ", too.\r"));
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1836 ASSERT_TRUE(lines[1].find(pattern) != std::string::npos);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1837 ASSERT_EQ("The third line.\r", lines[2]);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1838 ASSERT_FALSE(lines[1].find(pattern) == std::string::npos);
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1839 ASSERT_TRUE(lines[3].empty());
6399f5f25498 unit testing simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3223
diff changeset
1840 }
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1841
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1842
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1843 TEST(Toolbox, EncodingsSimplifiedChinese2)
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1844 {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1845 // http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part05/sect_K.2.html
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1846
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1847 static const uint8_t chinese[] = {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1848 0x5a, 0x68, 0x61, 0x6e, 0x67, 0x5e, 0x58, 0x69, 0x61, 0x6f, 0x44, 0x6f,
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1849 0x6e, 0x67, 0x3d, 0x1b, 0x24, 0x29, 0x41, 0xd5, 0xc5, 0x5e, 0x1b, 0x24,
3229
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3228
diff changeset
1850 0x29, 0x41, 0xd0, 0xa1, 0xb6, 0xab, 0x3d, 0x20, 0x00
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1851 };
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1852
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1853 // echo -n "Zhang^XiaoDong=..." | hexdump -v -e '14/1 "0x%02x, "' -e '"\n"'
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1854 static const uint8_t utf8[] = {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1855 0x5a, 0x68, 0x61, 0x6e, 0x67, 0x5e, 0x58, 0x69, 0x61, 0x6f, 0x44, 0x6f, 0x6e, 0x67,
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1856 0x3d, 0xe5, 0xbc, 0xa0, 0x5e, 0xe5, 0xb0, 0x8f, 0xe4, 0xb8, 0x9c, 0x3d
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1857 };
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1858
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1859 ParsedDicomFile dicom(false);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1860 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "\\ISO 2022 IR 58");
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1861 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1862 (DCM_PatientName, reinterpret_cast<const char*>(chinese), OFBool(true)).good());
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1863
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1864 bool hasCodeExtensions;
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1865 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1866 ASSERT_EQ(Encoding_SimplifiedChinese, encoding);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1867 ASSERT_TRUE(hasCodeExtensions);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1868
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1869 std::string value;
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1870 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_NAME));
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1871 ASSERT_EQ(value, std::string(reinterpret_cast<const char*>(utf8), sizeof(utf8)));
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1872 }
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1873
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1874
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1875 TEST(Toolbox, EncodingsSimplifiedChinese3)
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1876 {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1877 // http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part05/sect_K.2.html
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1878
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1879 static const uint8_t chinese[] = {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1880 0x31, 0x2e, 0x1b, 0x24, 0x29, 0x41, 0xb5, 0xda, 0xd2, 0xbb, 0xd0, 0xd0, 0xce, 0xc4, 0xd7, 0xd6, 0xa1, 0xa3, 0x0d, 0x0a,
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1881 0x32, 0x2e, 0x1b, 0x24, 0x29, 0x41, 0xb5, 0xda, 0xb6, 0xfe, 0xd0, 0xd0, 0xce, 0xc4, 0xd7, 0xd6, 0xa1, 0xa3, 0x0d, 0x0a,
3229
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3228
diff changeset
1882 0x33, 0x2e, 0x1b, 0x24, 0x29, 0x41, 0xb5, 0xda, 0xc8, 0xfd, 0xd0, 0xd0, 0xce, 0xc4, 0xd7, 0xd6, 0xa1, 0xa3, 0x0d, 0x0a, 0x00
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1883 };
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1884
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1885 static const uint8_t line1[] = {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1886 0x31, 0x2e, 0xe7, 0xac, 0xac, 0xe4, 0xb8, 0x80, 0xe8, 0xa1, 0x8c, 0xe6, 0x96, 0x87,
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1887 0xe5, 0xad, 0x97, 0xe3, 0x80, 0x82, '\r'
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1888 };
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1889
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1890 static const uint8_t line2[] = {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1891 0x32, 0x2e, 0xe7, 0xac, 0xac, 0xe4, 0xba, 0x8c, 0xe8, 0xa1, 0x8c, 0xe6, 0x96, 0x87,
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1892 0xe5, 0xad, 0x97, 0xe3, 0x80, 0x82, '\r'
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1893 };
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1894
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1895 static const uint8_t line3[] = {
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1896 0x33, 0x2e, 0xe7, 0xac, 0xac, 0xe4, 0xb8, 0x89, 0xe8, 0xa1, 0x8c, 0xe6, 0x96, 0x87,
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1897 0xe5, 0xad, 0x97, 0xe3, 0x80, 0x82, '\r'
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1898 };
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1899
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1900 ParsedDicomFile dicom(false);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1901 dicom.ReplacePlainString(DICOM_TAG_SPECIFIC_CHARACTER_SET, "\\ISO 2022 IR 58");
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1902 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->putAndInsertString
3228
4b9cfd92d1ae preparing for libicu
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3226
diff changeset
1903 (DCM_PatientName, reinterpret_cast<const char*>(chinese), OFBool(true)).good());
3226
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1904
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1905 bool hasCodeExtensions;
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1906 Encoding encoding = dicom.DetectEncoding(hasCodeExtensions);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1907 ASSERT_EQ(Encoding_SimplifiedChinese, encoding);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1908 ASSERT_TRUE(hasCodeExtensions);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1909
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1910 std::string value;
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1911 ASSERT_TRUE(dicom.GetTagValue(value, DICOM_TAG_PATIENT_NAME));
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1912
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1913 std::vector<std::string> lines;
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1914 Toolbox::TokenizeString(lines, value, '\n');
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1915 ASSERT_EQ(4u, lines.size());
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1916 ASSERT_EQ(std::string(reinterpret_cast<const char*>(line1), sizeof(line1)), lines[0]);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1917 ASSERT_EQ(std::string(reinterpret_cast<const char*>(line2), sizeof(line2)), lines[1]);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1918 ASSERT_EQ(std::string(reinterpret_cast<const char*>(line3), sizeof(line3)), lines[2]);
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1919 ASSERT_TRUE(lines[3].empty());
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1920 }
45e1631febbb support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3225
diff changeset
1921
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1922
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1923
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1924
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1925 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
1926
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
1927 #include "../Core/DicomParsing/Internals/DicomFrameIndex.h"
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
1928
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
1929 #include <dcmtk/dcmdata/dcostrmb.h>
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
1930 #include <dcmtk/dcmdata/dcpixel.h>
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
1931 #include <dcmtk/dcmdata/dcpxitem.h>
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
1932 #include <dcmtk/dcmjpeg/djrploss.h> // for DJ_RPLossy
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
1933 #include <dcmtk/dcmjpeg/djrplol.h> // for DJ_RPLossless
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
1934
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
1935
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1936 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG)
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1937 # error Macro ORTHANC_ENABLE_DCMTK_JPEG must be defined
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1938 #endif
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1939
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1940 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS)
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1941 # error Macro ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS must be defined
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1942 #endif
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1943
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1944
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
1945
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
1946 namespace Orthanc
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
1947 {
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1948 class IParsedDicomImage : public boost::noncopyable
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1949 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1950 public:
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1951 virtual ~IParsedDicomImage()
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1952 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1953 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1954
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1955 virtual DicomTransferSyntax GetTransferSyntax() = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1956
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1957 virtual std::string GetSopClassUid() = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1958
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1959 virtual std::string GetSopInstanceUid() = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1960
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1961 virtual unsigned int GetFramesCount() = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1962
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1963 // Can return NULL, for compressed transfer syntaxes
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1964 virtual ImageAccessor* GetUncompressedFrame(unsigned int frame) = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1965
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1966 virtual void GetCompressedFrame(std::string& target,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1967 unsigned int frame) = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1968
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1969 virtual void WriteToMemoryBuffer(std::string& target) = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1970 };
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1971
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1972
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1973 class IDicomImageReader : public boost::noncopyable
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1974 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1975 public:
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1976 virtual ~IDicomImageReader()
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1977 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1978 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1979
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1980 virtual IParsedDicomImage* Read(const void* data,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1981 size_t size) = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1982
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1983 virtual IParsedDicomImage* Transcode(const void* data,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1984 size_t size,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1985 DicomTransferSyntax syntax,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1986 bool allowNewSopInstanceUid) = 0;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1987 };
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1988
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1989
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1990 class DcmtkImageReader : public IDicomImageReader
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1991 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1992 private:
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1993 class Image : public IParsedDicomImage
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1994 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1995 private:
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1996 std::unique_ptr<DcmFileFormat> dicom_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1997 std::unique_ptr<DicomFrameIndex> index_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1998 DicomTransferSyntax transferSyntax_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
1999 std::string sopClassUid_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2000 std::string sopInstanceUid_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2001
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2002 static std::string GetStringTag(DcmDataset& dataset,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2003 const DcmTagKey& tag)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2004 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2005 const char* value = NULL;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2006
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2007 if (!dataset.findAndGetString(tag, value).good() ||
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2008 value == NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2009 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2010 throw OrthancException(ErrorCode_BadFileFormat,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2011 "Missing SOP class/instance UID in DICOM instance");
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2012 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2013 else
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2014 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2015 return std::string(value);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2016 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2017 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2018
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2019 public:
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2020 Image(DcmFileFormat* dicom,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2021 DicomTransferSyntax syntax) :
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2022 dicom_(dicom),
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2023 transferSyntax_(syntax)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2024 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2025 if (dicom == NULL ||
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2026 dicom_->getDataset() == NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2027 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2028 throw OrthancException(ErrorCode_NullPointer);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2029 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2030
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2031 DcmDataset& dataset = *dicom_->getDataset();
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2032 index_.reset(new DicomFrameIndex(dataset));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2033
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2034 sopClassUid_ = GetStringTag(dataset, DCM_SOPClassUID);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2035 sopInstanceUid_ = GetStringTag(dataset, DCM_SOPInstanceUID);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2036 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2037
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2038 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2039 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2040 return transferSyntax_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2041 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2042
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2043 virtual std::string GetSopClassUid() ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2044 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2045 return sopClassUid_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2046 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2047
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2048 virtual std::string GetSopInstanceUid() ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2049 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2050 return sopInstanceUid_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2051 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2052
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2053 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2054 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2055 return index_->GetFramesCount();
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2056 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2057
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2058 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2059 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2060 assert(dicom_.get() != NULL);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2061 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, transferSyntax_))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2062 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2063 throw OrthancException(ErrorCode_InternalError,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2064 "Cannot write the DICOM instance to a memory buffer");
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2065 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2066 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2067
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2068 virtual ImageAccessor* GetUncompressedFrame(unsigned int frame) ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2069 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2070 assert(dicom_.get() != NULL &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2071 dicom_->getDataset() != NULL);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2072 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2073 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2074
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2075 virtual void GetCompressedFrame(std::string& target,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2076 unsigned int frame) ORTHANC_OVERRIDE
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2077 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2078 assert(index_.get() != NULL);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2079 index_->GetRawFrame(target, frame);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2080 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2081 };
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2082
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2083 unsigned int lossyQuality_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2084
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2085 static DicomTransferSyntax DetectTransferSyntax(DcmFileFormat& dicom)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2086 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2087 if (dicom.getDataset() == NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2088 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2089 throw OrthancException(ErrorCode_InternalError);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2090 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2091
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2092 DcmDataset& dataset = *dicom.getDataset();
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2093
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2094 E_TransferSyntax xfer = dataset.getCurrentXfer();
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2095 if (xfer == EXS_Unknown)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2096 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2097 dataset.updateOriginalXfer();
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2098 xfer = dataset.getCurrentXfer();
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2099 if (xfer == EXS_Unknown)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2100 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2101 throw OrthancException(ErrorCode_BadFileFormat,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2102 "Cannot determine the transfer syntax of the DICOM instance");
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2103 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2104 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2105
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2106 DicomTransferSyntax syntax;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2107 if (FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, xfer))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2108 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2109 return syntax;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2110 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2111 else
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2112 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2113 throw OrthancException(
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2114 ErrorCode_BadFileFormat,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2115 "Unsupported transfer syntax: " + boost::lexical_cast<std::string>(xfer));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2116 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2117 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2118
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2119
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2120 static uint16_t GetBitsStored(DcmFileFormat& dicom)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2121 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2122 if (dicom.getDataset() == NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2123 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2124 throw OrthancException(ErrorCode_InternalError);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2125 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2126
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2127 uint16_t bitsStored;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2128 if (dicom.getDataset()->findAndGetUint16(DCM_BitsStored, bitsStored).good())
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2129 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2130 return bitsStored;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2131 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2132 else
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2133 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2134 throw OrthancException(ErrorCode_BadFileFormat,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2135 "Missing \"Bits Stored\" tag in DICOM instance");
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2136 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2137 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2138
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2139
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2140 public:
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2141 DcmtkImageReader() :
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2142 lossyQuality_(90)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2143 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2144 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2145
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2146 void SetLossyQuality(unsigned int quality)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2147 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2148 if (quality <= 0 ||
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2149 quality > 100)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2150 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2151 throw OrthancException(ErrorCode_ParameterOutOfRange);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2152 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2153 else
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2154 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2155 lossyQuality_ = quality;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2156 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2157 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2158
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2159 unsigned int GetLossyQuality() const
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2160 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2161 return lossyQuality_;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2162 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2163
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2164 virtual IParsedDicomImage* Read(const void* data,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2165 size_t size)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2166 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2167 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(data, size));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2168 if (dicom.get() == NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2169 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2170 throw OrthancException(ErrorCode_BadFileFormat);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2171 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2172
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2173 DicomTransferSyntax transferSyntax = DetectTransferSyntax(*dicom);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2174
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2175 return new Image(dicom.release(), transferSyntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2176 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2177
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2178 virtual IParsedDicomImage* Transcode(const void* data,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2179 size_t size,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2180 DicomTransferSyntax syntax,
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2181 bool allowNewSopInstanceUid)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2182 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2183 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(data, size));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2184 if (dicom.get() == NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2185 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2186 throw OrthancException(ErrorCode_BadFileFormat);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2187 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2188
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2189 const uint16_t bitsStored = GetBitsStored(*dicom);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2190
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2191 if (syntax == DetectTransferSyntax(*dicom))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2192 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2193 // No transcoding is needed
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2194 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2195 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2196
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2197 if (syntax == DicomTransferSyntax_LittleEndianImplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2198 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianImplicit, NULL))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2199 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2200 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2201 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2202
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2203 if (syntax == DicomTransferSyntax_LittleEndianExplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2204 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_LittleEndianExplicit, NULL))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2205 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2206 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2207 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2208
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2209 if (syntax == DicomTransferSyntax_BigEndianExplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2210 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_BigEndianExplicit, NULL))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2211 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2212 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2213 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2214
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2215 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2216 FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2217 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2218 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2219 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2220
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2221 #if ORTHANC_ENABLE_JPEG == 1
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2222 if (syntax == DicomTransferSyntax_JPEGProcess1 &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2223 allowNewSopInstanceUid &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2224 bitsStored == 8)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2225 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2226 DJ_RPLossy rpLossy(lossyQuality_);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2227
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2228 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess1, &rpLossy))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2229 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2230 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2231 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2232 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2233 #endif
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2234
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2235 #if ORTHANC_ENABLE_JPEG == 1
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2236 if (syntax == DicomTransferSyntax_JPEGProcess2_4 &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2237 allowNewSopInstanceUid &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2238 bitsStored <= 12)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2239 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2240 DJ_RPLossy rpLossy(lossyQuality_);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2241 if (FromDcmtkBridge::Transcode(*dicom, DicomTransferSyntax_JPEGProcess2_4, &rpLossy))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2242 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2243 return new Image(dicom.release(), syntax);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2244 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2245 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2246 #endif
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2247
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2248 //LOG(INFO) << "Unable to transcode DICOM image using the built-in reader";
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2249 return NULL;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2250 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2251 };
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2252
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2253
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2254
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2255 class IDicomTranscoder1 : public boost::noncopyable
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2256 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2257 public:
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2258 virtual ~IDicomTranscoder1()
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2259 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2260 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2261
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2262 virtual DcmFileFormat& GetDicom() = 0;
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2263
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2264 virtual DicomTransferSyntax GetTransferSyntax() = 0;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2265
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2266 virtual std::string GetSopClassUid() = 0;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2267
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2268 virtual std::string GetSopInstanceUid() = 0;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2269
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2270 virtual unsigned int GetFramesCount() = 0;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2271
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2272 virtual ImageAccessor* DecodeFrame(unsigned int frame) = 0;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2273
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2274 virtual void GetCompressedFrame(std::string& target,
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2275 unsigned int frame) = 0;
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2276
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2277 // NB: Transcoding can change the value of "GetSopInstanceUid()"
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2278 // and "GetTransferSyntax()" if lossy compression is applied
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2279 virtual bool Transcode(std::string& target,
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2280 DicomTransferSyntax syntax,
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2281 bool allowNewSopInstanceUid) = 0;
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2282
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2283 virtual void WriteToMemoryBuffer(std::string& target) = 0;
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2284 };
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2285
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2286
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2287 class DcmtkTranscoder2 : public IDicomTranscoder1
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2288 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2289 private:
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2290 std::unique_ptr<DcmFileFormat> dicom_;
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2291 std::unique_ptr<DicomFrameIndex> index_;
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2292 DicomTransferSyntax transferSyntax_;
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2293 std::string sopClassUid_;
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2294 std::string sopInstanceUid_;
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2295 uint16_t bitsStored_;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2296 unsigned int lossyQuality_;
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2297
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2298 static std::string GetStringTag(DcmDataset& dataset,
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2299 const DcmTagKey& tag)
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2300 {
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2301 const char* value = NULL;
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2302
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2303 if (!dataset.findAndGetString(tag, value).good() ||
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2304 value == NULL)
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2305 {
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2306 throw OrthancException(ErrorCode_BadFileFormat,
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2307 "Missing SOP class/instance UID in DICOM instance");
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2308 }
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2309 else
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2310 {
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2311 return std::string(value);
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2312 }
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2313 }
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2314
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2315 void Setup(DcmFileFormat* dicom)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2316 {
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2317 lossyQuality_ = 90;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2318
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2319 dicom_.reset(dicom);
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2320
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2321 if (dicom == NULL ||
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2322 dicom_->getDataset() == NULL)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2323 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2324 throw OrthancException(ErrorCode_NullPointer);
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2325 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2326
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2327 DcmDataset& dataset = *dicom_->getDataset();
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2328 index_.reset(new DicomFrameIndex(dataset));
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2329
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2330 E_TransferSyntax xfer = dataset.getCurrentXfer();
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2331 if (xfer == EXS_Unknown)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2332 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2333 dataset.updateOriginalXfer();
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2334 xfer = dataset.getCurrentXfer();
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2335 if (xfer == EXS_Unknown)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2336 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2337 throw OrthancException(ErrorCode_BadFileFormat,
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2338 "Cannot determine the transfer syntax of the DICOM instance");
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2339 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2340 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2341
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2342 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(transferSyntax_, xfer))
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2343 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2344 throw OrthancException(
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2345 ErrorCode_BadFileFormat,
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2346 "Unsupported transfer syntax: " + boost::lexical_cast<std::string>(xfer));
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2347 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2348
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2349 if (!dataset.findAndGetUint16(DCM_BitsStored, bitsStored_).good())
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2350 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2351 throw OrthancException(ErrorCode_BadFileFormat,
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2352 "Missing \"Bits Stored\" tag in DICOM instance");
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2353 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2354
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2355 sopClassUid_ = GetStringTag(dataset, DCM_SOPClassUID);
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2356 sopInstanceUid_ = GetStringTag(dataset, DCM_SOPInstanceUID);
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2357 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2358
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2359 public:
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2360 DcmtkTranscoder2(DcmFileFormat* dicom) // Takes ownership
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2361 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2362 Setup(dicom);
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2363 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2364
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2365 DcmtkTranscoder2(const void* dicom,
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2366 size_t size)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2367 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2368 Setup(FromDcmtkBridge::LoadFromMemoryBuffer(dicom, size));
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2369 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2370
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2371 void SetLossyQuality(unsigned int quality)
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2372 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2373 if (quality <= 0 ||
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2374 quality > 100)
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2375 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2376 throw OrthancException(ErrorCode_ParameterOutOfRange);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2377 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2378 else
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2379 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2380 lossyQuality_ = quality;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2381 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2382 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2383
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2384 unsigned int GetLossyQuality() const
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2385 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2386 return lossyQuality_;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2387 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2388
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2389 unsigned int GetBitsStored() const
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2390 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2391 return bitsStored_;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2392 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2393
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2394 virtual DcmFileFormat& GetDicom()
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2395 {
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2396 assert(dicom_ != NULL);
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2397 return *dicom_;
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2398 }
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2399
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2400 virtual DicomTransferSyntax GetTransferSyntax() ORTHANC_OVERRIDE
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2401 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2402 return transferSyntax_;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2403 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2404
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2405 virtual std::string GetSopClassUid() ORTHANC_OVERRIDE
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2406 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2407 return sopClassUid_;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2408 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2409
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2410 virtual std::string GetSopInstanceUid() ORTHANC_OVERRIDE
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2411 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2412 return sopInstanceUid_;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2413 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2414
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2415 virtual unsigned int GetFramesCount() ORTHANC_OVERRIDE
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2416 {
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2417 return index_->GetFramesCount();
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2418 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2419
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2420 virtual void WriteToMemoryBuffer(std::string& target) ORTHANC_OVERRIDE
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2421 {
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2422 if (!FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_))
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2423 {
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2424 throw OrthancException(ErrorCode_InternalError,
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2425 "Cannot write the DICOM instance to a memory buffer");
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2426 }
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2427 }
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2428
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2429 virtual ImageAccessor* DecodeFrame(unsigned int frame) ORTHANC_OVERRIDE
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2430 {
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2431 assert(dicom_->getDataset() != NULL);
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2432 return DicomImageDecoder::Decode(*dicom_->getDataset(), frame);
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2433 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2434
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2435 virtual void GetCompressedFrame(std::string& target,
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2436 unsigned int frame) ORTHANC_OVERRIDE
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2437 {
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2438 index_->GetRawFrame(target, frame);
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2439 }
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2440
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2441 virtual bool Transcode(std::string& target,
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2442 DicomTransferSyntax syntax,
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2443 bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2444 {
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2445 assert(dicom_ != NULL &&
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2446 dicom_->getDataset() != NULL);
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2447
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2448 if (syntax == GetTransferSyntax())
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2449 {
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2450 printf("NO TRANSCODING\n");
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2451
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2452 // No change in the transfer syntax => simply serialize the current dataset
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2453 WriteToMemoryBuffer(target);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2454 return true;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2455 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2456
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2457 printf(">> %d\n", bitsStored_);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2458
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2459 if (syntax == DicomTransferSyntax_LittleEndianImplicit &&
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2460 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2461 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2462 {
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2463 transferSyntax_ = DicomTransferSyntax_LittleEndianImplicit;
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2464 return true;
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2465 }
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2466
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2467 if (syntax == DicomTransferSyntax_LittleEndianExplicit &&
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2468 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2469 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2470 {
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2471 transferSyntax_ = DicomTransferSyntax_LittleEndianExplicit;
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2472 return true;
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2473 }
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2474
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2475 if (syntax == DicomTransferSyntax_BigEndianExplicit &&
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2476 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2477 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2478 {
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2479 transferSyntax_ = DicomTransferSyntax_BigEndianExplicit;
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2480 return true;
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2481 }
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2482
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2483 if (syntax == DicomTransferSyntax_DeflatedLittleEndianExplicit &&
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2484 FromDcmtkBridge::Transcode(*dicom_, syntax, NULL) &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2485 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2486 {
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2487 transferSyntax_ = DicomTransferSyntax_DeflatedLittleEndianExplicit;
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2488 return true;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2489 }
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2490
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2491 #if ORTHANC_ENABLE_JPEG == 1
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2492 if (syntax == DicomTransferSyntax_JPEGProcess1 &&
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2493 allowNewSopInstanceUid &&
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2494 GetBitsStored() == 8)
3812
abd3a1d114c0 transcoding to 1.2.840.10008.1.2.4.51
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3770
diff changeset
2495 {
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2496 DJ_RPLossy rpLossy(lossyQuality_);
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2497
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2498 if (FromDcmtkBridge::Transcode(*dicom_, syntax, &rpLossy) &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2499 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2500 {
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2501 transferSyntax_ = DicomTransferSyntax_JPEGProcess1;
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2502 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID);
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2503 return true;
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2504 }
3812
abd3a1d114c0 transcoding to 1.2.840.10008.1.2.4.51
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3770
diff changeset
2505 }
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2506 #endif
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2507
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2508 #if ORTHANC_ENABLE_JPEG == 1
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2509 if (syntax == DicomTransferSyntax_JPEGProcess2_4 &&
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2510 allowNewSopInstanceUid &&
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2511 GetBitsStored() <= 12)
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2512 {
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2513 DJ_RPLossy rpLossy(lossyQuality_);
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2514 if (FromDcmtkBridge::Transcode(*dicom_, syntax, &rpLossy) &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2515 FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom_, syntax))
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2516 {
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2517 transferSyntax_ = DicomTransferSyntax_JPEGProcess2_4;
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2518 sopInstanceUid_ = GetStringTag(*dicom_->getDataset(), DCM_SOPInstanceUID);
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2519 return true;
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2520 }
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2521 }
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2522 #endif
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2523
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2524 return false;
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2525 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2526 };
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2527 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2528
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2529
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2530
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
2531
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2532 #include <boost/filesystem.hpp>
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2533
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2534
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2535 static void TestFile(const std::string& path)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2536 {
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2537 static unsigned int count = 0;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2538 count++;
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2539
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2540
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2541 printf("** %s\n", path.c_str());
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2542
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2543 std::string s;
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2544 SystemToolbox::ReadFile(s, path);
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2545
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2546 Orthanc::DcmtkTranscoder2 transcoder(s.c_str(), s.size());
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2547
3812
abd3a1d114c0 transcoding to 1.2.840.10008.1.2.4.51
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3770
diff changeset
2548 /*if (transcoder.GetBitsStored() != 8) // TODO
abd3a1d114c0 transcoding to 1.2.840.10008.1.2.4.51
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3770
diff changeset
2549 return; */
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2550
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2551 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2552 char buf[1024];
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2553 sprintf(buf, "/tmp/source-%06d.dcm", count);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2554 printf(">> %s\n", buf);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2555 Orthanc::SystemToolbox::WriteFile(s, buf);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2556 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2557
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2558 printf("[%s] [%s] [%s] %d %d\n", GetTransferSyntaxUid(transcoder.GetTransferSyntax()),
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2559 transcoder.GetSopClassUid().c_str(), transcoder.GetSopInstanceUid().c_str(),
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2560 transcoder.GetFramesCount(), transcoder.GetTransferSyntax());
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2561
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2562 for (size_t i = 0; i < transcoder.GetFramesCount(); i++)
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2563 {
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2564 std::string f;
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2565 transcoder.GetCompressedFrame(f, i);
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2566
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2567 if (i == 0)
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2568 {
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2569 char buf[1024];
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2570 sprintf(buf, "/tmp/frame-%06d.raw", count);
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2571 printf(">> %s\n", buf);
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2572 Orthanc::SystemToolbox::WriteFile(f, buf);
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2573 }
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2574 }
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2575
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2576 {
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2577 std::string t;
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2578 transcoder.WriteToMemoryBuffer(t);
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2579
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2580 Orthanc::DcmtkTranscoder2 transcoder2(t.c_str(), t.size());
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2581 printf(">> %d %d ; %lu bytes\n", transcoder.GetTransferSyntax(), transcoder2.GetTransferSyntax(), t.size());
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2582 }
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2583
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2584 {
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2585 std::string a = transcoder.GetSopInstanceUid();
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2586 DicomTransferSyntax b = transcoder.GetTransferSyntax();
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2587
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2588 DicomTransferSyntax syntax = DicomTransferSyntax_JPEGProcess2_4;
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2589 //DicomTransferSyntax syntax = DicomTransferSyntax_LittleEndianExplicit;
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2590
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2591 std::string t;
3871
5797d184de67 fix the name of some transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3868
diff changeset
2592 bool ok = transcoder.Transcode(t, syntax, true);
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2593 printf("Transcoding: %d\n", ok);
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2594
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2595 if (ok)
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2596 {
3819
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2597 printf("[%s] => [%s]\n", a.c_str(), transcoder.GetSopInstanceUid().c_str());
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2598 printf("[%s] => [%s]\n", GetTransferSyntaxUid(b),
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2599 GetTransferSyntaxUid(transcoder.GetTransferSyntax()));
1237bd0bbdb2 update sop class/instance uid if transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3812
diff changeset
2600
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2601 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2602 char buf[1024];
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2603 sprintf(buf, "/tmp/transcoded-%06d.dcm", count);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2604 printf(">> %s\n", buf);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2605 Orthanc::SystemToolbox::WriteFile(t, buf);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2606 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2607
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2608 Orthanc::DcmtkTranscoder2 transcoder2(t.c_str(), t.size());
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2609 printf(" => transcoded transfer syntax %d ; %lu bytes\n", transcoder2.GetTransferSyntax(), t.size());
3748
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2610 }
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2611 }
ca36e3f1112c transcoding to uncompressed transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3745
diff changeset
2612
3744
accf1b60b108 accessing raw pixel data
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3743
diff changeset
2613 printf("\n");
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2614 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2615
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2616 TEST(Toto, DISABLED_Transcode)
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
2617 {
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2618 //OFLog::configure(OFLogger::DEBUG_LOG_LEVEL);
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2619
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2620 if (1)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2621 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2622 const char* const PATH = "/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes";
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2623
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2624 for (boost::filesystem::directory_iterator it(PATH);
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2625 it != boost::filesystem::directory_iterator(); ++it)
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2626 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2627 if (boost::filesystem::is_regular_file(it->status()))
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2628 {
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2629 TestFile(it->path().string());
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2630 }
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2631 }
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2632 }
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2633
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2634 if (0)
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2635 {
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2636 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/Multiframe.dcm");
3745
113a7b994a12 extracting the raw frame in the transcoder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3744
diff changeset
2637 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/Issue44/Monochrome1-Jpeg.dcm");
3743
33c19a6643e1 creating IDicomTranscoder abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3727
diff changeset
2638 }
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2639
3812
abd3a1d114c0 transcoding to 1.2.840.10008.1.2.4.51
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3770
diff changeset
2640 if (0)
3765
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2641 {
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2642 TestFile("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/1.2.840.10008.1.2.1.dcm");
4a25727401cd first transcoding to jpeg 8bpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3764
diff changeset
2643 }
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
2644 }
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
2645
3820
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2646
3872
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2647 TEST(Toto, DISABLED_Transcode2)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2648 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2649 for (int i = 0; i <= DicomTransferSyntax_XML; i++)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2650 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2651 DicomTransferSyntax a = (DicomTransferSyntax) i;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2652
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2653 std::string path = ("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2654 std::string(GetTransferSyntaxUid(a)) + ".dcm");
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2655 if (Orthanc::SystemToolbox::IsRegularFile(path))
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2656 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2657 printf("\n======= %s\n", GetTransferSyntaxUid(a));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2658
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2659 std::string source;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2660 Orthanc::SystemToolbox::ReadFile(source, path);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2661
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2662 DcmtkImageReader reader;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2663
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2664 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2665 std::unique_ptr<IParsedDicomImage> image(
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2666 reader.Read(source.c_str(), source.size()));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2667 ASSERT_TRUE(image.get() != NULL);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2668 ASSERT_EQ(a, image->GetTransferSyntax());
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2669
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2670 std::string target;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2671 image->WriteToMemoryBuffer(target);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2672 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2673
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2674 for (int j = 0; j <= DicomTransferSyntax_XML; j++)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2675 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2676 DicomTransferSyntax b = (DicomTransferSyntax) j;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2677 //if (a == b) continue;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2678
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2679 std::unique_ptr<IParsedDicomImage> image(
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2680 reader.Transcode(source.c_str(), source.size(), b, true));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2681 if (image.get() != NULL)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2682 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2683 printf("[%s] -> [%s]\n", GetTransferSyntaxUid(a), GetTransferSyntaxUid(b));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2684
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2685 std::string target;
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2686 image->WriteToMemoryBuffer(target);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2687
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2688 char buf[1024];
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2689 sprintf(buf, "/tmp/%s-%s.dcm", GetTransferSyntaxUid(a), GetTransferSyntaxUid(b));
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2690
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2691 SystemToolbox::WriteFile(target, buf);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2692 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2693 else if (a != DicomTransferSyntax_JPEG2000 &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2694 a != DicomTransferSyntax_JPEG2000LosslessOnly)
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2695 {
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2696 ASSERT_TRUE(b != DicomTransferSyntax_LittleEndianImplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2697 b != DicomTransferSyntax_LittleEndianExplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2698 b != DicomTransferSyntax_BigEndianExplicit &&
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2699 b != DicomTransferSyntax_DeflatedLittleEndianExplicit);
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2700 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2701 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2702 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2703 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2704 }
b40dfa6dc8da working on a simpler abstraction for transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3871
diff changeset
2705
3820
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2706
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2707 #include "../Core/DicomNetworking/DicomAssociation.h"
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2708 #include "../Core/DicomNetworking/DicomControlUserConnection.h"
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2709 #include "../Core/DicomNetworking/DicomStoreUserConnection.h"
3820
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2710
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2711 TEST(Toto, DISABLED_DicomAssociation)
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2712 {
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2713 DicomAssociationParameters params;
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2714 params.SetLocalApplicationEntityTitle("ORTHANC");
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2715 params.SetRemoteApplicationEntityTitle("PACS");
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2716 params.SetRemotePort(2001);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2717
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2718 #if 0
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2719 DicomAssociation assoc;
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2720 assoc.ProposeGenericPresentationContext(UID_StorageCommitmentPushModelSOPClass);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2721 assoc.ProposeGenericPresentationContext(UID_VerificationSOPClass);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2722 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2723 DicomTransferSyntax_JPEGProcess1);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2724 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2725 DicomTransferSyntax_JPEGProcess2_4);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2726 assoc.ProposePresentationContext(UID_ComputedRadiographyImageStorage,
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2727 DicomTransferSyntax_JPEG2000);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2728
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2729 assoc.Open(params);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2730
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2731 int presID = ASC_findAcceptedPresentationContextID(&assoc.GetDcmtkAssociation(), UID_ComputedRadiographyImageStorage);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2732 printf(">> %d\n", presID);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2733
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2734 std::map<DicomTransferSyntax, uint8_t> pc;
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2735 printf(">> %d\n", assoc.LookupAcceptedPresentationContext(pc, UID_ComputedRadiographyImageStorage));
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2736
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2737 for (std::map<DicomTransferSyntax, uint8_t>::const_iterator
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2738 it = pc.begin(); it != pc.end(); ++it)
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2739 {
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2740 printf("[%s] => %d\n", GetTransferSyntaxUid(it->first), it->second);
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2741 }
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2742 #else
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2743 {
3823
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2744 DicomControlUserConnection assoc(params);
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2745
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2746 try
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2747 {
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2748 printf(">> %d\n", assoc.Echo());
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2749 }
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2750 catch (OrthancException&)
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2751 {
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2752 }
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2753 }
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2754
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2755 params.SetRemoteApplicationEntityTitle("PACS");
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2756 params.SetRemotePort(2000);
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2757
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2758 {
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2759 DicomControlUserConnection assoc(params);
3820
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2760 printf(">> %d\n", assoc.Echo());
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2761 }
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2762
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2763 #endif
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2764 }
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2765
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2766 static void TestTranscode(DicomStoreUserConnection& scu,
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2767 const std::string& sopClassUid,
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2768 DicomTransferSyntax transferSyntax)
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2769 {
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2770 std::set<DicomTransferSyntax> accepted;
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2771
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2772 scu.LookupTranscoding(accepted, sopClassUid, transferSyntax);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2773 if (accepted.empty())
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2774 {
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2775 throw OrthancException(ErrorCode_NetworkProtocol,
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2776 "The SOP class is not supported by the remote modality");
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2777 }
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2778
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2779 {
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2780 unsigned int count = 0;
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2781 for (std::set<DicomTransferSyntax>::const_iterator
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2782 it = accepted.begin(); it != accepted.end(); ++it)
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2783 {
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2784 LOG(INFO) << "available for transcoding " << (count++) << ": " << sopClassUid
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2785 << " / " << GetTransferSyntaxUid(*it);
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2786 }
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2787 }
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2788
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2789 if (accepted.find(transferSyntax) != accepted.end())
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2790 {
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2791 printf("**** OK, without transcoding !! [%s]\n", GetTransferSyntaxUid(transferSyntax));
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2792 }
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2793 else
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2794 {
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2795 // Transcoding - only in Orthanc >= 1.7.0
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2796
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2797 const DicomTransferSyntax uncompressed[] = {
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2798 DicomTransferSyntax_LittleEndianImplicit, // Default transfer syntax
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2799 DicomTransferSyntax_LittleEndianExplicit,
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2800 DicomTransferSyntax_BigEndianExplicit
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2801 };
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2802
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2803 bool found = false;
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2804 for (size_t i = 0; i < 3; i++)
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2805 {
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2806 if (accepted.find(uncompressed[i]) != accepted.end())
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2807 {
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2808 printf("**** TRANSCODING to %s\n", GetTransferSyntaxUid(uncompressed[i]));
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2809 found = true;
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2810 break;
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2811 }
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2812 }
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2813
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2814 if (!found)
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2815 {
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2816 printf("**** KO KO KO\n");
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2817 }
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2818 }
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2819 }
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2820
3820
f89eac983c9b refactoring DicomUserConnection as DicomAssociation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3819
diff changeset
2821
3823
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2822 TEST(Toto, DISABLED_Store)
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2823 {
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2824 DicomAssociationParameters params;
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2825 params.SetLocalApplicationEntityTitle("ORTHANC");
3862
594263db316a DicomModalityStoreJob now uses DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3839
diff changeset
2826 params.SetRemoteApplicationEntityTitle("STORESCP");
3823
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2827 params.SetRemotePort(2000);
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2828
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2829 DicomStoreUserConnection assoc(params);
3868
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2830 assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_JPEGProcess1);
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2831 assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_JPEGProcess2_4);
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2832 //assoc.RegisterStorageClass(UID_MRImageStorage, DicomTransferSyntax_LittleEndianExplicit);
3823
897ca3103253 new class: DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3822
diff changeset
2833
3862
594263db316a DicomModalityStoreJob now uses DicomStoreUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3839
diff changeset
2834 //assoc.SetUncompressedSyntaxesProposed(false); // Necessary for transcoding
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2835 assoc.SetCommonClassesProposed(false);
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2836 assoc.SetRetiredBigEndianProposed(true);
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2837 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_LittleEndianExplicit);
3827
638906dcfe32 integration mainline->transcoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3824
diff changeset
2838 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_JPEG2000);
3880
cdd0cb5ec4e4 DicomStoreUserConnection::LookupTranscoding()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3872
diff changeset
2839 TestTranscode(assoc, UID_MRImageStorage, DicomTransferSyntax_JPEG2000);
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
2840 }
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
2841
3868
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2842
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2843 TEST(Toto, DISABLED_Store2)
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2844 {
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2845 DicomAssociationParameters params;
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2846 params.SetLocalApplicationEntityTitle("ORTHANC");
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2847 params.SetRemoteApplicationEntityTitle("STORESCP");
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2848 params.SetRemotePort(2000);
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2849
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2850 DicomStoreUserConnection assoc(params);
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2851 //assoc.SetCommonClassesProposed(false);
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2852 assoc.SetRetiredBigEndianProposed(true);
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2853
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2854 std::string s;
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2855 Orthanc::SystemToolbox::ReadFile(s, "/tmp/i/" + std::string(GetTransferSyntaxUid(DicomTransferSyntax_BigEndianExplicit)) +".dcm");
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2856
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2857 std::string c, i;
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2858 assoc.Store(c, i, s.c_str(), s.size());
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2859 printf("[%s] [%s]\n", c.c_str(), i.c_str());
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2860 }
d5be23fc0106 better negotiation of transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3862
diff changeset
2861
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2862
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2863 namespace Orthanc
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2864 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2865 class IDicomTranscoder : public boost::noncopyable
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2866 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2867 public:
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2868 virtual ~IDicomTranscoder()
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2869 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2870 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2871
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2872 /**
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2873 * Transcoding flavor that creates a new parsed DICOM file. A
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2874 * "std::set<>" is used to give the possible plugin the
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2875 * possibility to do a single parsing for all the possible
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2876 * transfer syntaxes.
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2877 **/
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2878 virtual DcmFileFormat* Transcode(const void* buffer,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2879 size_t size,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2880 const std::set<DicomTransferSyntax>& allowedSyntaxes,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2881 bool allowNewSopInstanceUid) = 0;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2882
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2883 /**
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2884 * In-place transcoding. This method is used first during
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2885 * C-STORE. It can return "false" if inplace is not supported, in
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2886 * which case the "Transcode()" method should be used.
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2887 **/
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2888 virtual bool InplaceTranscode(DcmFileFormat& dicom,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2889 const std::set<DicomTransferSyntax>& allowedSyntaxes,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2890 bool allowNewSopInstanceUid) = 0;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2891
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2892 /**
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2893 * Important: Transcoding over the DICOM protocol is only
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2894 * implemented towards uncompressed transfer syntaxes.
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2895 **/
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2896 static void Store(std::string& sopClassUid /* out */,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2897 std::string& sopInstanceUid /* out */,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2898 DicomStoreUserConnection& connection,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2899 IDicomTranscoder& transcoder,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2900 const void* buffer,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2901 size_t size,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2902 const std::string& moveOriginatorAET,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2903 uint16_t moveOriginatorID)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2904 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2905 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2906 if (dicom.get() == NULL ||
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2907 dicom->getDataset() == NULL)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2908 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2909 throw OrthancException(ErrorCode_NullPointer);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2910 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2911
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2912 DicomTransferSyntax inputSyntax;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2913 connection.LookupParameters(sopClassUid, sopInstanceUid, inputSyntax, *dicom);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2914
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2915 std::set<DicomTransferSyntax> accepted;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2916 connection.LookupTranscoding(accepted, sopClassUid, inputSyntax);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2917
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2918 if (accepted.find(inputSyntax) != accepted.end())
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2919 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2920 // No need for transcoding
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2921 connection.Store(sopClassUid, sopInstanceUid, *dicom, moveOriginatorAET, moveOriginatorID);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2922 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2923 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2924 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2925 // Transcoding is needed
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2926 std::set<DicomTransferSyntax> uncompressedSyntaxes;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2927
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2928 if (accepted.find(DicomTransferSyntax_LittleEndianImplicit) != accepted.end())
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2929 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2930 uncompressedSyntaxes.insert(DicomTransferSyntax_LittleEndianImplicit);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2931 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2932
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2933 if (accepted.find(DicomTransferSyntax_LittleEndianExplicit) != accepted.end())
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2934 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2935 uncompressedSyntaxes.insert(DicomTransferSyntax_LittleEndianExplicit);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2936 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2937
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2938 if (accepted.find(DicomTransferSyntax_BigEndianExplicit) != accepted.end())
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2939 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2940 uncompressedSyntaxes.insert(DicomTransferSyntax_BigEndianExplicit);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2941 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2942
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2943 std::unique_ptr<DcmFileFormat> transcoded;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2944
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2945 if (transcoder.InplaceTranscode(*dicom, uncompressedSyntaxes, false))
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2946 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2947 // In-place transcoding is supported
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2948 transcoded.reset(dicom.release());
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2949 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2950 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2951 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2952 transcoded.reset(transcoder.Transcode(buffer, size, uncompressedSyntaxes, false));
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2953 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2954
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2955 // WARNING: The "dicom" variable must not be used below this
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2956 // point. The "sopInstanceUid" might also have changed (if
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2957 // using lossy compression).
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2958
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2959 if (transcoded == NULL ||
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2960 transcoded->getDataset() == NULL)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2961 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2962 throw OrthancException(
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2963 ErrorCode_NotImplemented,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2964 "Cannot transcode from \"" + std::string(GetTransferSyntaxUid(inputSyntax)) +
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2965 "\" to an uncompressed syntax for modality: " +
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2966 connection.GetParameters().GetRemoteModality().GetApplicationEntityTitle());
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2967 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2968 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2969 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2970 DicomTransferSyntax transcodedSyntax;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2971
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2972 // Sanity check
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2973 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(transcodedSyntax, *transcoded) ||
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2974 accepted.find(transcodedSyntax) == accepted.end())
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2975 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2976 throw OrthancException(ErrorCode_InternalError);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2977 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2978 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2979 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2980 connection.Store(sopClassUid, sopInstanceUid, *transcoded, moveOriginatorAET, moveOriginatorID);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2981 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2982 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2983 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2984 }
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2985
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2986 static void Store(std::string& sopClassUid /* out */,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2987 std::string& sopInstanceUid /* out */,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2988 DicomStoreUserConnection& connection,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2989 IDicomTranscoder& transcoder,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2990 const void* buffer,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2991 size_t size)
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2992 {
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2993 Store(sopClassUid, sopInstanceUid, connection, transcoder,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2994 buffer, size, "", 0 /* Not a C-MOVE */);
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
2995 }
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2996 };
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2997
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2998
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
2999 class DcmtkTranscoder : public IDicomTranscoder
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3000 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3001 private:
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3002 unsigned int lossyQuality_;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3003
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3004 static uint16_t GetBitsStored(DcmDataset& dataset)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3005 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3006 uint16_t bitsStored;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3007 if (dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good())
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3008 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3009 return bitsStored;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3010 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3011 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3012 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3013 throw OrthancException(ErrorCode_BadFileFormat,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3014 "Missing \"Bits Stored\" tag in DICOM instance");
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3015 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3016 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3017
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3018 public:
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3019 DcmtkTranscoder() :
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3020 lossyQuality_(90)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3021 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3022 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3023
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3024 void SetLossyQuality(unsigned int quality)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3025 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3026 if (quality <= 0 ||
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3027 quality > 100)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3028 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3029 throw OrthancException(ErrorCode_ParameterOutOfRange);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3030 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3031 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3032 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3033 lossyQuality_ = quality;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3034 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3035 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3036
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3037 unsigned int GetLossyQuality() const
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3038 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3039 return lossyQuality_;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3040 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3041
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3042 virtual DcmFileFormat* Transcode(const void* buffer,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3043 size_t size,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3044 const std::set<DicomTransferSyntax>& allowedSyntaxes,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3045 bool allowNewSopInstanceUid)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3046 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3047 std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3048
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3049 if (dicom.get() == NULL)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3050 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3051 throw OrthancException(ErrorCode_InternalError);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3052 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3053
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3054 if (InplaceTranscode(*dicom, allowedSyntaxes, allowNewSopInstanceUid))
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3055 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3056 return dicom.release();
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3057 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3058 else
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3059 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3060 return NULL;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3061 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3062 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3063
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3064 virtual bool InplaceTranscode(DcmFileFormat& dicom,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3065 const std::set<DicomTransferSyntax>& allowedSyntaxes,
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3066 bool allowNewSopInstanceUid)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3067 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3068 if (dicom.getDataset() == NULL)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3069 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3070 throw OrthancException(ErrorCode_InternalError);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3071 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3072
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3073 DicomTransferSyntax syntax;
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3074 if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom))
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3075 {
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3076 throw OrthancException(ErrorCode_BadFileFormat,
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3077 "Cannot determine the transfer syntax");
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3078 }
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3079
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3080 const uint16_t bitsStored = GetBitsStored(*dicom.getDataset());
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3081
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3082 if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end())
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3083 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3084 // No transcoding is needed
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3085 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3086 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3087
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3088 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianImplicit) != allowedSyntaxes.end() &&
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3089 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianImplicit, NULL))
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3090 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3091 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3092 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3093
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3094 if (allowedSyntaxes.find(DicomTransferSyntax_LittleEndianExplicit) != allowedSyntaxes.end() &&
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3095 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_LittleEndianExplicit, NULL))
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3096 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3097 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3098 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3099
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3100 if (allowedSyntaxes.find(DicomTransferSyntax_BigEndianExplicit) != allowedSyntaxes.end() &&
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3101 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_BigEndianExplicit, NULL))
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3102 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3103 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3104 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3105
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3106 if (allowedSyntaxes.find(DicomTransferSyntax_DeflatedLittleEndianExplicit) != allowedSyntaxes.end() &&
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3107 FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_DeflatedLittleEndianExplicit, NULL))
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3108 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3109 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3110 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3111
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3112 #if ORTHANC_ENABLE_JPEG == 1
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3113 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() &&
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3114 allowNewSopInstanceUid &&
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3115 bitsStored == 8)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3116 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3117 DJ_RPLossy rpLossy(lossyQuality_);
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3118
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3119 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, &rpLossy))
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3120 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3121 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3122 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3123 }
3727
090022f1b5e1 auto-generation of primitives to handle transfer syntaxes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
3124 #endif
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3125
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3126 #if ORTHANC_ENABLE_JPEG == 1
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3127 if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() &&
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3128 allowNewSopInstanceUid &&
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3129 bitsStored <= 12)
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3130 {
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3131 DJ_RPLossy rpLossy(lossyQuality_);
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3132 if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, &rpLossy))
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3133 {
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3134 return true;
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3135 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3136 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3137 #endif
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3138
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3139 return false;
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3140 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3141 };
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3142 }
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3143
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3144
3883
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3145 TEST(Toto, DISABLED_Transcode3)
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3146 {
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3147 DicomAssociationParameters p;
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3148 p.SetRemotePort(2000);
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3149
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3150 DcmtkTranscoder transcoder;
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3151
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3152 for (int i = 0; i <= DicomTransferSyntax_XML; i++)
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3153 {
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3154 DicomTransferSyntax a = (DicomTransferSyntax) i;
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3155
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3156 std::string path = ("/home/jodogne/Subversion/orthanc-tests/Database/TransferSyntaxes/" +
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3157 std::string(GetTransferSyntaxUid(a)) + ".dcm");
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3158 if (Orthanc::SystemToolbox::IsRegularFile(path))
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3159 {
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3160 printf("\n======= %s\n", GetTransferSyntaxUid(a));
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3161
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3162 std::string source;
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3163 Orthanc::SystemToolbox::ReadFile(source, path);
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3164
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3165 DicomStoreUserConnection scu(p);
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3166 scu.SetCommonClassesProposed(false);
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3167 scu.SetRetiredBigEndianProposed(true);
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3168
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3169 std::string c, i;
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3170 IDicomTranscoder::Store(c, i, scu, transcoder, source.c_str(), source.size());
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3171 }
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3172 }
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3173 }
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3174
795c9ca5eb91 DANGEROUS changeset: replaced "getOriginalXfer()" by "getCurrentXfer()" throughout Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3882
diff changeset
3175
3882
904575738462 implemented IDicomTranscoder::Store()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3880
diff changeset
3176 #endif