Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtk.cpp @ 930:27d256e0b458 mac
integration mainline -> mac
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 24 Jun 2014 16:47:18 +0200 |
parents | 84513f2ee1f3 |
children |
comparison
equal
deleted
inserted
replaced
928:882833632b1f | 930:27d256e0b458 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, | |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "PrecompiledHeadersUnitTests.h" | |
34 #include "gtest/gtest.h" | |
35 | |
36 #include "../OrthancServer/FromDcmtkBridge.h" | |
37 #include "../OrthancServer/OrthancInitialization.h" | |
38 #include "../OrthancServer/DicomModification.h" | |
39 #include "../Core/OrthancException.h" | |
40 #include "../Core/ImageFormats/ImageBuffer.h" | |
41 #include "../Core/ImageFormats/PngReader.h" | |
42 #include "../Core/ImageFormats/PngWriter.h" | |
43 | |
44 using namespace Orthanc; | |
45 | |
46 TEST(DicomFormat, Tag) | |
47 { | |
48 ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010))); | |
49 | |
50 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription"); | |
51 ASSERT_EQ(0x0008, t.GetGroup()); | |
52 ASSERT_EQ(0x103E, t.GetElement()); | |
53 | |
54 t = FromDcmtkBridge::ParseTag("0020-e040"); | |
55 ASSERT_EQ(0x0020, t.GetGroup()); | |
56 ASSERT_EQ(0xe040, t.GetElement()); | |
57 | |
58 // Test ==() and !=() operators | |
59 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020)); | |
60 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020)); | |
61 } | |
62 | |
63 | |
64 TEST(DicomModification, Basic) | |
65 { | |
66 DicomModification m; | |
67 m.SetupAnonymization(); | |
68 //m.SetLevel(DicomRootLevel_Study); | |
69 //m.Replace(DICOM_TAG_PATIENT_ID, "coucou"); | |
70 //m.Replace(DICOM_TAG_PATIENT_NAME, "coucou"); | |
71 | |
72 ParsedDicomFile o; | |
73 o.SaveToFile("UnitTestsResults/anon.dcm"); | |
74 | |
75 for (int i = 0; i < 10; i++) | |
76 { | |
77 char b[1024]; | |
78 sprintf(b, "UnitTestsResults/anon%06d.dcm", i); | |
79 std::auto_ptr<ParsedDicomFile> f(o.Clone()); | |
80 if (i > 4) | |
81 o.Replace(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); | |
82 m.Apply(*f); | |
83 f->SaveToFile(b); | |
84 } | |
85 } | |
86 | |
87 | |
88 #include <dcmtk/dcmdata/dcuid.h> | |
89 | |
90 TEST(DicomModification, Png) | |
91 { | |
92 // Red dot in http://en.wikipedia.org/wiki/Data_URI_scheme (RGBA image) | |
93 std::string s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; | |
94 | |
95 std::string m, c; | |
96 Toolbox::DecodeDataUriScheme(m, c, s); | |
97 | |
98 ASSERT_EQ("image/png", m); | |
99 ASSERT_EQ(116, c.size()); | |
100 | |
101 std::string cc; | |
102 Toolbox::DecodeBase64(cc, c); | |
103 PngReader reader; | |
104 reader.ReadFromMemory(cc); | |
105 | |
106 ASSERT_EQ(5, reader.GetHeight()); | |
107 ASSERT_EQ(5, reader.GetWidth()); | |
108 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat()); | |
109 | |
110 ParsedDicomFile o; | |
111 o.EmbedImage(s); | |
112 o.SaveToFile("UnitTestsResults/png1.dcm"); | |
113 | |
114 // Red dot, without alpha channel | |
115 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII="; | |
116 o.EmbedImage(s); | |
117 o.SaveToFile("UnitTestsResults/png2.dcm"); | |
118 | |
119 // Check box in Graylevel8 | |
120 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="; | |
121 o.EmbedImage(s); | |
122 //o.Replace(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing); | |
123 o.SaveToFile("UnitTestsResults/png3.dcm"); | |
124 | |
125 | |
126 { | |
127 // Gradient in Graylevel16 | |
128 | |
129 ImageBuffer img; | |
130 img.SetWidth(256); | |
131 img.SetHeight(256); | |
132 img.SetFormat(PixelFormat_Grayscale16); | |
133 | |
134 int v = 0; | |
135 for (unsigned int y = 0; y < img.GetHeight(); y++) | |
136 { | |
137 uint16_t *p = reinterpret_cast<uint16_t*>(img.GetAccessor().GetRow(y)); | |
138 for (unsigned int x = 0; x < img.GetWidth(); x++, p++, v++) | |
139 { | |
140 *p = v; | |
141 } | |
142 } | |
143 | |
144 o.EmbedImage(img.GetAccessor()); | |
145 o.SaveToFile("UnitTestsResults/png4.dcm"); | |
146 } | |
147 } |