Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/ImageTests.cpp @ 4159:2e540919aac9 Orthanc-1.7.3
Orthanc-1.7.3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 23 Aug 2020 20:17:18 +0200 |
parents | bf7b9edf6b81 |
children | afad57ac30ef |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3181
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:
803
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
10 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
12 * 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:
803
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
15 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
20 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
21 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
22 |
4046
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
24 // Must be the first to be sure to use the Orthanc framework shared library |
4046
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
25 # include <OrthancFramework.h> |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
26 #endif |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
27 |
4062 | 28 #include <gtest/gtest.h> |
368 | 29 |
4046
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
30 #include "../Sources/Images/Font.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
31 #include "../Sources/Images/Image.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
32 #include "../Sources/Images/ImageProcessing.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
33 #include "../Sources/Images/JpegReader.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
34 #include "../Sources/Images/JpegWriter.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
35 #include "../Sources/Images/PngReader.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
36 #include "../Sources/Images/PngWriter.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
37 #include "../Sources/Images/PamReader.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
38 #include "../Sources/Images/PamWriter.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
39 #include "../Sources/SystemToolbox.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
40 #include "../Sources/Toolbox.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
41 #include "../Sources/TemporaryFile.h" |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
42 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
43 #include <stdint.h> |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
44 |
368 | 45 |
46 TEST(PngWriter, ColorPattern) | |
47 { | |
48 Orthanc::PngWriter w; | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
49 unsigned int width = 17; |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
50 unsigned int height = 61; |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
51 unsigned int pitch = width * 3; |
368 | 52 |
53 std::vector<uint8_t> image(height * pitch); | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
54 for (unsigned int y = 0; y < height; y++) |
368 | 55 { |
56 uint8_t *p = &image[0] + y * pitch; | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
57 for (unsigned int x = 0; x < width; x++, p += 3) |
368 | 58 { |
59 p[0] = (y % 3 == 0) ? 255 : 0; | |
60 p[1] = (y % 3 == 1) ? 255 : 0; | |
61 p[2] = (y % 3 == 2) ? 255 : 0; | |
62 } | |
63 } | |
64 | |
1916 | 65 Orthanc::ImageAccessor accessor; |
66 accessor.AssignReadOnly(Orthanc::PixelFormat_RGB24, width, height, pitch, &image[0]); | |
67 | |
68 w.WriteToFile("UnitTestsResults/ColorPattern.png", accessor); | |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
69 |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
70 std::string f, md5; |
2140 | 71 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png"); |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
72 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
73 ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5); |
368 | 74 } |
75 | |
76 TEST(PngWriter, Gray8Pattern) | |
77 { | |
78 Orthanc::PngWriter w; | |
79 int width = 17; | |
80 int height = 256; | |
81 int pitch = width; | |
82 | |
83 std::vector<uint8_t> image(height * pitch); | |
84 for (int y = 0; y < height; y++) | |
85 { | |
86 uint8_t *p = &image[0] + y * pitch; | |
87 for (int x = 0; x < width; x++, p++) | |
88 { | |
89 *p = y; | |
90 } | |
91 } | |
92 | |
1916 | 93 Orthanc::ImageAccessor accessor; |
94 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale8, width, height, pitch, &image[0]); | |
95 | |
96 w.WriteToFile("UnitTestsResults/Gray8Pattern.png", accessor); | |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
97 |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
98 std::string f, md5; |
2140 | 99 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png"); |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
100 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
101 ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5); |
368 | 102 } |
103 | |
104 TEST(PngWriter, Gray16Pattern) | |
105 { | |
106 Orthanc::PngWriter w; | |
107 int width = 256; | |
108 int height = 256; | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
109 int pitch = width * 2 + 16; |
368 | 110 |
111 std::vector<uint8_t> image(height * pitch); | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
112 |
368 | 113 int v = 0; |
114 for (int y = 0; y < height; y++) | |
115 { | |
116 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
117 for (int x = 0; x < width; x++, p++, v++) | |
118 { | |
119 *p = v; | |
120 } | |
121 } | |
122 | |
1916 | 123 Orthanc::ImageAccessor accessor; |
124 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); | |
125 w.WriteToFile("UnitTestsResults/Gray16Pattern.png", accessor); | |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
126 |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
127 std::string f, md5; |
2140 | 128 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png"); |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
129 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
130 ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5); |
368 | 131 } |
455 | 132 |
133 TEST(PngWriter, EndToEnd) | |
134 { | |
135 Orthanc::PngWriter w; | |
1492 | 136 unsigned int width = 256; |
137 unsigned int height = 256; | |
138 unsigned int pitch = width * 2 + 16; | |
455 | 139 |
140 std::vector<uint8_t> image(height * pitch); | |
141 | |
142 int v = 0; | |
1492 | 143 for (unsigned int y = 0; y < height; y++) |
455 | 144 { |
145 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
1492 | 146 for (unsigned int x = 0; x < width; x++, p++, v++) |
455 | 147 { |
148 *p = v; | |
149 } | |
150 } | |
151 | |
1916 | 152 Orthanc::ImageAccessor accessor; |
153 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); | |
154 | |
455 | 155 std::string s; |
1916 | 156 w.WriteToMemory(s, accessor); |
455 | 157 |
709 | 158 { |
159 Orthanc::PngReader r; | |
160 r.ReadFromMemory(s); | |
455 | 161 |
710 | 162 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
709 | 163 ASSERT_EQ(r.GetWidth(), width); |
164 ASSERT_EQ(r.GetHeight(), height); | |
455 | 165 |
709 | 166 v = 0; |
1492 | 167 for (unsigned int y = 0; y < height; y++) |
709 | 168 { |
797
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
169 const uint16_t *p = reinterpret_cast<const uint16_t*>((const uint8_t*) r.GetConstBuffer() + y * r.GetPitch()); |
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
170 ASSERT_EQ(p, r.GetConstRow(y)); |
1492 | 171 for (unsigned int x = 0; x < width; x++, p++, v++) |
709 | 172 { |
173 ASSERT_EQ(*p, v); | |
174 } | |
175 } | |
176 } | |
177 | |
455 | 178 { |
2140 | 179 Orthanc::TemporaryFile tmp; |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
180 tmp.Write(s); |
709 | 181 |
182 Orthanc::PngReader r2; | |
183 r2.ReadFromFile(tmp.GetPath()); | |
184 | |
710 | 185 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
709 | 186 ASSERT_EQ(r2.GetWidth(), width); |
187 ASSERT_EQ(r2.GetHeight(), height); | |
710 | 188 |
189 v = 0; | |
1492 | 190 for (unsigned int y = 0; y < height; y++) |
455 | 191 { |
797
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
192 const uint16_t *p = reinterpret_cast<const uint16_t*>((const uint8_t*) r2.GetConstBuffer() + y * r2.GetPitch()); |
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
193 ASSERT_EQ(p, r2.GetConstRow(y)); |
1492 | 194 for (unsigned int x = 0; x < width; x++, p++, v++) |
709 | 195 { |
196 ASSERT_EQ(*p, v); | |
197 } | |
455 | 198 } |
199 } | |
200 } | |
1602 | 201 |
202 | |
203 | |
204 | |
205 TEST(JpegWriter, Basic) | |
206 { | |
1604 | 207 std::string s; |
208 | |
1602 | 209 { |
2107 | 210 Orthanc::Image img(Orthanc::PixelFormat_Grayscale8, 16, 16, false); |
1604 | 211 for (unsigned int y = 0, value = 0; y < img.GetHeight(); y++) |
1602 | 212 { |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1604
diff
changeset
|
213 uint8_t* p = reinterpret_cast<uint8_t*>(img.GetRow(y)); |
1604 | 214 for (unsigned int x = 0; x < img.GetWidth(); x++, p++) |
215 { | |
216 *p = value++; | |
217 } | |
218 } | |
219 | |
220 Orthanc::JpegWriter w; | |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1604
diff
changeset
|
221 w.WriteToFile("UnitTestsResults/hello.jpg", img); |
1604 | 222 |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1604
diff
changeset
|
223 w.WriteToMemory(s, img); |
2140 | 224 Orthanc::SystemToolbox::WriteFile(s, "UnitTestsResults/hello2.jpg"); |
1604 | 225 |
226 std::string t; | |
2140 | 227 Orthanc::SystemToolbox::ReadFile(t, "UnitTestsResults/hello.jpg"); |
1604 | 228 ASSERT_EQ(s.size(), t.size()); |
229 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); | |
230 } | |
231 | |
232 { | |
233 Orthanc::JpegReader r1, r2; | |
234 r1.ReadFromFile("UnitTestsResults/hello.jpg"); | |
1970 | 235 ASSERT_EQ(16u, r1.GetWidth()); |
236 ASSERT_EQ(16u, r1.GetHeight()); | |
1604 | 237 |
238 r2.ReadFromMemory(s); | |
1970 | 239 ASSERT_EQ(16u, r2.GetWidth()); |
240 ASSERT_EQ(16u, r2.GetHeight()); | |
1604 | 241 |
242 for (unsigned int y = 0; y < r1.GetHeight(); y++) | |
243 { | |
244 const uint8_t* p1 = reinterpret_cast<const uint8_t*>(r1.GetConstRow(y)); | |
245 const uint8_t* p2 = reinterpret_cast<const uint8_t*>(r2.GetConstRow(y)); | |
246 for (unsigned int x = 0; x < r1.GetWidth(); x++) | |
247 { | |
248 ASSERT_EQ(*p1, *p2); | |
249 } | |
1602 | 250 } |
251 } | |
252 } | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
253 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
254 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
255 TEST(PamWriter, ColorPattern) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
256 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
257 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
258 unsigned int width = 17; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
259 unsigned int height = 61; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
260 unsigned int pitch = width * 3; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
261 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
262 std::vector<uint8_t> image(height * pitch); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
263 for (unsigned int y = 0; y < height; y++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
264 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
265 uint8_t *p = &image[0] + y * pitch; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
266 for (unsigned int x = 0; x < width; x++, p += 3) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
267 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
268 p[0] = (y % 3 == 0) ? 255 : 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
269 p[1] = (y % 3 == 1) ? 255 : 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
270 p[2] = (y % 3 == 2) ? 255 : 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
271 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
272 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
273 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
274 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
275 accessor.AssignReadOnly(Orthanc::PixelFormat_RGB24, width, height, pitch, &image[0]); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
276 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
277 w.WriteToFile("UnitTestsResults/ColorPattern.pam", accessor); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
278 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
279 std::string f, md5; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
280 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.pam"); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
281 Orthanc::Toolbox::ComputeMD5(md5, f); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
282 ASSERT_EQ("81a3441754e88969ebbe53e69891e841", md5); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
283 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
284 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
285 TEST(PamWriter, Gray8Pattern) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
286 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
287 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
288 int width = 17; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
289 int height = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
290 int pitch = width; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
291 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
292 std::vector<uint8_t> image(height * pitch); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
293 for (int y = 0; y < height; y++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
294 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
295 uint8_t *p = &image[0] + y * pitch; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
296 for (int x = 0; x < width; x++, p++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
297 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
298 *p = y; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
299 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
300 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
301 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
302 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
303 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale8, width, height, pitch, &image[0]); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
304 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
305 w.WriteToFile("UnitTestsResults/Gray8Pattern.pam", accessor); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
306 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
307 std::string f, md5; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
308 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.pam"); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
309 Orthanc::Toolbox::ComputeMD5(md5, f); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
310 ASSERT_EQ("7873c408d26a9d11dd1c1de5e69cc0a3", md5); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
311 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
312 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
313 TEST(PamWriter, Gray16Pattern) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
314 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
315 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
316 int width = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
317 int height = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
318 int pitch = width * 2 + 16; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
319 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
320 std::vector<uint8_t> image(height * pitch); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
321 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
322 int v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
323 for (int y = 0; y < height; y++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
324 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
325 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
326 for (int x = 0; x < width; x++, p++, v++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
327 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
328 *p = v; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
329 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
330 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
331 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
332 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
333 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
334 w.WriteToFile("UnitTestsResults/Gray16Pattern.pam", accessor); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
335 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
336 std::string f, md5; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
337 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.pam"); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
338 Orthanc::Toolbox::ComputeMD5(md5, f); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
339 ASSERT_EQ("b268772bf28f3b2b8520ff21c5e3dcb6", md5); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
340 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
341 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
342 TEST(PamWriter, EndToEnd) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
343 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
344 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
345 unsigned int width = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
346 unsigned int height = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
347 unsigned int pitch = width * 2 + 16; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
348 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
349 std::vector<uint8_t> image(height * pitch); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
350 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
351 int v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
352 for (unsigned int y = 0; y < height; y++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
353 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
354 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
355 for (unsigned int x = 0; x < width; x++, p++, v++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
356 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
357 *p = v; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
358 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
359 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
360 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
361 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
362 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
363 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
364 std::string s; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
365 w.WriteToMemory(s, accessor); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
366 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
367 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
368 Orthanc::PamReader r; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
369 r.ReadFromMemory(s); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
370 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
371 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
372 ASSERT_EQ(r.GetWidth(), width); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
373 ASSERT_EQ(r.GetHeight(), height); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
374 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
375 v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
376 for (unsigned int y = 0; y < height; y++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
377 { |
2707 | 378 const uint16_t *p = reinterpret_cast<const uint16_t*> |
379 ((const uint8_t*) r.GetConstBuffer() + y * r.GetPitch()); | |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
380 ASSERT_EQ(p, r.GetConstRow(y)); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
381 for (unsigned int x = 0; x < width; x++, p++, v++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
382 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
383 ASSERT_EQ(v, *p); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
384 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
385 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
386 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
387 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
388 { |
3834
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
389 // true means "enforce alignment by using a temporary buffer" |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
390 Orthanc::PamReader r(true); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
391 r.ReadFromMemory(s); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
392 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
393 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
394 ASSERT_EQ(r.GetWidth(), width); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
395 ASSERT_EQ(r.GetHeight(), height); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
396 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
397 v = 0; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
398 for (unsigned int y = 0; y < height; y++) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
399 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
400 const uint16_t* p = reinterpret_cast<const uint16_t*> |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
401 ((const uint8_t*)r.GetConstBuffer() + y * r.GetPitch()); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
402 ASSERT_EQ(p, r.GetConstRow(y)); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
403 for (unsigned int x = 0; x < width; x++, p++, v++) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
404 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
405 ASSERT_EQ(v, *p); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
406 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
407 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
408 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
409 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
410 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
411 Orthanc::TemporaryFile tmp; |
3181
6fd38327e777
Fix issue #130 (Orthanc failed to start when /tmp partition was full)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
412 tmp.Write(s); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
413 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
414 Orthanc::PamReader r2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
415 r2.ReadFromFile(tmp.GetPath()); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
416 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
417 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
418 ASSERT_EQ(r2.GetWidth(), width); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
419 ASSERT_EQ(r2.GetHeight(), height); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
420 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
421 v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
422 for (unsigned int y = 0; y < height; y++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
423 { |
2707 | 424 const uint16_t *p = reinterpret_cast<const uint16_t*> |
425 ((const uint8_t*) r2.GetConstBuffer() + y * r2.GetPitch()); | |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
426 ASSERT_EQ(p, r2.GetConstRow(y)); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
427 for (unsigned int x = 0; x < width; x++, p++, v++) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
428 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
429 ASSERT_EQ(*p, v); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
430 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
431 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
432 } |
3834
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
433 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
434 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
435 Orthanc::TemporaryFile tmp; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
436 tmp.Write(s); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
437 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
438 // true means "enforce alignment by using a temporary buffer" |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
439 Orthanc::PamReader r2(true); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
440 r2.ReadFromFile(tmp.GetPath()); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
441 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
442 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
443 ASSERT_EQ(r2.GetWidth(), width); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
444 ASSERT_EQ(r2.GetHeight(), height); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
445 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
446 v = 0; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
447 for (unsigned int y = 0; y < height; y++) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
448 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
449 const uint16_t* p = reinterpret_cast<const uint16_t*> |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
450 ((const uint8_t*)r2.GetConstBuffer() + y * r2.GetPitch()); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
451 ASSERT_EQ(p, r2.GetConstRow(y)); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
452 for (unsigned int x = 0; x < width; x++, p++, v++) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
453 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
454 ASSERT_EQ(*p, v); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
455 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
456 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
457 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
458 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
459 } |