Mercurial > hg > orthanc
comparison UnitTestsSources/FromDcmtk.cpp @ 800:ecedd89055db
generation of DICOM images from PNG files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 06 May 2014 16:33:40 +0200 |
parents | b6d6b65142e8 |
children | 82b07ab959f4 |
comparison
equal
deleted
inserted
replaced
799:777b6b694da6 | 800:ecedd89055db |
---|---|
2 | 2 |
3 #include "../OrthancServer/FromDcmtkBridge.h" | 3 #include "../OrthancServer/FromDcmtkBridge.h" |
4 #include "../OrthancServer/OrthancInitialization.h" | 4 #include "../OrthancServer/OrthancInitialization.h" |
5 #include "../OrthancServer/DicomModification.h" | 5 #include "../OrthancServer/DicomModification.h" |
6 #include "../Core/OrthancException.h" | 6 #include "../Core/OrthancException.h" |
7 #include "../Core/ImageFormats/ImageBuffer.h" | |
8 #include "../Core/ImageFormats/PngReader.h" | |
9 #include "../Core/ImageFormats/PngWriter.h" | |
7 | 10 |
8 using namespace Orthanc; | 11 using namespace Orthanc; |
9 | 12 |
10 TEST(DicomFormat, Tag) | 13 TEST(DicomFormat, Tag) |
11 { | 14 { |
45 o.Replace(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); | 48 o.Replace(DICOM_TAG_SERIES_INSTANCE_UID, "coucou"); |
46 m.Apply(*f); | 49 m.Apply(*f); |
47 f->SaveToFile(b); | 50 f->SaveToFile(b); |
48 } | 51 } |
49 } | 52 } |
53 | |
54 | |
55 #include <dcmdata/dcuid.h> | |
56 | |
57 TEST(DicomModification, Png) | |
58 { | |
59 // Red dot in http://en.wikipedia.org/wiki/Data_URI_scheme (RGBA image) | |
60 std::string s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; | |
61 | |
62 std::string m, c; | |
63 Toolbox::DecodeDataUriScheme(m, c, s); | |
64 | |
65 ASSERT_EQ("image/png", m); | |
66 ASSERT_EQ(116, c.size()); | |
67 | |
68 std::string cc = Toolbox::DecodeBase64(c); | |
69 | |
70 Toolbox::WriteFile(cc, "/tmp/tata.png"); | |
71 | |
72 PngReader reader; | |
73 reader.ReadFromMemory(cc); | |
74 | |
75 ASSERT_EQ(5, reader.GetHeight()); | |
76 ASSERT_EQ(5, reader.GetWidth()); | |
77 ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat()); | |
78 | |
79 ParsedDicomFile o; | |
80 o.EmbedImage(s); | |
81 o.SaveToFile("png1.dcm"); | |
82 | |
83 // Red dot, without alpha channel | |
84 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII="; | |
85 o.EmbedImage(s); | |
86 o.SaveToFile("png2.dcm"); | |
87 | |
88 // Check box in Graylevel8 | |
89 s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII="; | |
90 o.EmbedImage(s); | |
91 //o.Replace(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing); | |
92 o.SaveToFile("png3.dcm"); | |
93 | |
94 | |
95 { | |
96 // Gradient in Graylevel16 | |
97 | |
98 ImageBuffer img; | |
99 img.SetWidth(256); | |
100 img.SetHeight(256); | |
101 img.SetFormat(PixelFormat_Grayscale16); | |
102 | |
103 int v = 0; | |
104 for (unsigned int y = 0; y < img.GetHeight(); y++) | |
105 { | |
106 uint16_t *p = reinterpret_cast<uint16_t*>(img.GetAccessor().GetRow(y)); | |
107 for (unsigned int x = 0; x < img.GetWidth(); x++, p++, v++) | |
108 { | |
109 *p = v; | |
110 } | |
111 } | |
112 | |
113 o.EmbedImage(img.GetAccessor()); | |
114 o.SaveToFile("png4.dcm"); | |
115 } | |
116 } |