Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/ImageTests.cpp @ 5125:4a688b06db56 Orthanc-1.11.0
closing Orthanc-1.11.0
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 19 Dec 2022 15:55:37 +0100 |
parents | 43e613a7756b |
children | 255b02c68908 |
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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
7 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
827
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 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
23 |
4046
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
25 // 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
|
26 # include <OrthancFramework.h> |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
27 #endif |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
28 |
4062 | 29 #include <gtest/gtest.h> |
368 | 30 |
4046
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
31 #include "../Sources/Images/Font.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
32 #include "../Sources/Images/Image.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
33 #include "../Sources/Images/ImageProcessing.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
34 #include "../Sources/Images/JpegReader.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
35 #include "../Sources/Images/JpegWriter.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
36 #include "../Sources/Images/PngReader.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
37 #include "../Sources/Images/PngWriter.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
38 #include "../Sources/Images/PamReader.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
39 #include "../Sources/Images/PamWriter.h" |
7ff1e6c80627
moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
40 #include "../Sources/Toolbox.h" |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
41 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
42 #if ORTHANC_SANDBOXED != 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
43 # include "../Sources/SystemToolbox.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
44 # include "../Sources/TemporaryFile.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
45 #endif |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
46 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
47 #include <stdint.h> |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
48 |
368 | 49 |
50 TEST(PngWriter, ColorPattern) | |
51 { | |
52 Orthanc::PngWriter w; | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
53 unsigned int width = 17; |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
54 unsigned int height = 61; |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
55 unsigned int pitch = width * 3; |
368 | 56 |
57 std::vector<uint8_t> image(height * pitch); | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
58 for (unsigned int y = 0; y < height; y++) |
368 | 59 { |
60 uint8_t *p = &image[0] + y * pitch; | |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1612
diff
changeset
|
61 for (unsigned int x = 0; x < width; x++, p += 3) |
368 | 62 { |
63 p[0] = (y % 3 == 0) ? 255 : 0; | |
64 p[1] = (y % 3 == 1) ? 255 : 0; | |
65 p[2] = (y % 3 == 2) ? 255 : 0; | |
66 } | |
67 } | |
68 | |
1916 | 69 Orthanc::ImageAccessor accessor; |
70 accessor.AssignReadOnly(Orthanc::PixelFormat_RGB24, width, height, pitch, &image[0]); | |
71 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
72 std::string f; |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
73 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
74 #if ORTHANC_SANDBOXED == 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
75 Orthanc::IImageWriter::WriteToMemory(w, f, accessor); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
76 #else |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
77 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/ColorPattern.png", accessor); |
2140 | 78 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png"); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
79 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
80 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
81 std::string md5; |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
82 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
83 ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5); |
368 | 84 } |
85 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
86 |
368 | 87 TEST(PngWriter, Gray8Pattern) |
88 { | |
89 Orthanc::PngWriter w; | |
90 int width = 17; | |
91 int height = 256; | |
92 int pitch = width; | |
93 | |
94 std::vector<uint8_t> image(height * pitch); | |
95 for (int y = 0; y < height; y++) | |
96 { | |
97 uint8_t *p = &image[0] + y * pitch; | |
98 for (int x = 0; x < width; x++, p++) | |
99 { | |
100 *p = y; | |
101 } | |
102 } | |
103 | |
1916 | 104 Orthanc::ImageAccessor accessor; |
105 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale8, width, height, pitch, &image[0]); | |
106 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
107 std::string f; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
108 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
109 #if ORTHANC_SANDBOXED == 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
110 Orthanc::IImageWriter::WriteToMemory(w, f, accessor); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
111 #else |
4311
cb9aef006229
turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4211
diff
changeset
|
112 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray8Pattern.png", accessor); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
113 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png"); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
114 #endif |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
115 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
116 std::string md5; |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
117 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
118 ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5); |
368 | 119 } |
120 | |
121 TEST(PngWriter, Gray16Pattern) | |
122 { | |
123 Orthanc::PngWriter w; | |
124 int width = 256; | |
125 int height = 256; | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
126 int pitch = width * 2 + 16; |
368 | 127 |
128 std::vector<uint8_t> image(height * pitch); | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
129 |
368 | 130 int v = 0; |
131 for (int y = 0; y < height; y++) | |
132 { | |
133 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
134 for (int x = 0; x < width; x++, p++, v++) | |
135 { | |
136 *p = v; | |
137 } | |
138 } | |
139 | |
1916 | 140 Orthanc::ImageAccessor accessor; |
141 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); | |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
142 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
143 std::string f; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
144 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
145 #if ORTHANC_SANDBOXED == 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
146 Orthanc::IImageWriter::WriteToMemory(w, f, accessor); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
147 #else |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
148 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray16Pattern.png", accessor); |
2140 | 149 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png"); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
150 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
151 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
152 std::string md5; |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
153 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
154 ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5); |
368 | 155 } |
455 | 156 |
157 TEST(PngWriter, EndToEnd) | |
158 { | |
159 Orthanc::PngWriter w; | |
1492 | 160 unsigned int width = 256; |
161 unsigned int height = 256; | |
162 unsigned int pitch = width * 2 + 16; | |
455 | 163 |
164 std::vector<uint8_t> image(height * pitch); | |
165 | |
166 int v = 0; | |
1492 | 167 for (unsigned int y = 0; y < height; y++) |
455 | 168 { |
169 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
1492 | 170 for (unsigned int x = 0; x < width; x++, p++, v++) |
455 | 171 { |
172 *p = v; | |
173 } | |
174 } | |
175 | |
1916 | 176 Orthanc::ImageAccessor accessor; |
177 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); | |
178 | |
455 | 179 std::string s; |
4311
cb9aef006229
turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4211
diff
changeset
|
180 Orthanc::IImageWriter::WriteToMemory(w, s, accessor); |
455 | 181 |
709 | 182 { |
183 Orthanc::PngReader r; | |
184 r.ReadFromMemory(s); | |
455 | 185 |
710 | 186 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
709 | 187 ASSERT_EQ(r.GetWidth(), width); |
188 ASSERT_EQ(r.GetHeight(), height); | |
455 | 189 |
709 | 190 v = 0; |
1492 | 191 for (unsigned int y = 0; y < height; y++) |
709 | 192 { |
797
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
193 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
|
194 ASSERT_EQ(p, r.GetConstRow(y)); |
1492 | 195 for (unsigned int x = 0; x < width; x++, p++, v++) |
709 | 196 { |
197 ASSERT_EQ(*p, v); | |
198 } | |
199 } | |
200 } | |
201 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
202 #if ORTHANC_SANDBOXED != 1 |
455 | 203 { |
2140 | 204 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
|
205 tmp.Write(s); |
709 | 206 |
207 Orthanc::PngReader r2; | |
208 r2.ReadFromFile(tmp.GetPath()); | |
209 | |
710 | 210 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16); |
709 | 211 ASSERT_EQ(r2.GetWidth(), width); |
212 ASSERT_EQ(r2.GetHeight(), height); | |
710 | 213 |
214 v = 0; | |
1492 | 215 for (unsigned int y = 0; y < height; y++) |
455 | 216 { |
797
37adac56017a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
711
diff
changeset
|
217 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
|
218 ASSERT_EQ(p, r2.GetConstRow(y)); |
1492 | 219 for (unsigned int x = 0; x < width; x++, p++, v++) |
709 | 220 { |
221 ASSERT_EQ(*p, v); | |
222 } | |
455 | 223 } |
224 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
225 #endif |
455 | 226 } |
1602 | 227 |
228 | |
229 | |
230 | |
231 TEST(JpegWriter, Basic) | |
232 { | |
1604 | 233 std::string s; |
234 | |
1602 | 235 { |
2107 | 236 Orthanc::Image img(Orthanc::PixelFormat_Grayscale8, 16, 16, false); |
1604 | 237 for (unsigned int y = 0, value = 0; y < img.GetHeight(); y++) |
1602 | 238 { |
1608
adc6a5704cdb
OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1604
diff
changeset
|
239 uint8_t* p = reinterpret_cast<uint8_t*>(img.GetRow(y)); |
1604 | 240 for (unsigned int x = 0; x < img.GetWidth(); x++, p++) |
241 { | |
242 *p = value++; | |
243 } | |
244 } | |
245 | |
246 Orthanc::JpegWriter w; | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
247 Orthanc::IImageWriter::WriteToMemory(w, s, img); |
1604 | 248 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
249 #if ORTHANC_SANDBOXED != 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
250 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/hello.jpg", img); |
2140 | 251 Orthanc::SystemToolbox::WriteFile(s, "UnitTestsResults/hello2.jpg"); |
1604 | 252 |
253 std::string t; | |
2140 | 254 Orthanc::SystemToolbox::ReadFile(t, "UnitTestsResults/hello.jpg"); |
1604 | 255 ASSERT_EQ(s.size(), t.size()); |
256 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
257 #endif |
1604 | 258 } |
259 | |
260 { | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
261 Orthanc::JpegReader r1; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
262 r1.ReadFromMemory(s); |
1970 | 263 ASSERT_EQ(16u, r1.GetWidth()); |
264 ASSERT_EQ(16u, r1.GetHeight()); | |
1604 | 265 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
266 #if ORTHANC_SANDBOXED != 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
267 Orthanc::JpegReader r2; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
268 r2.ReadFromFile("UnitTestsResults/hello.jpg"); |
1970 | 269 ASSERT_EQ(16u, r2.GetWidth()); |
270 ASSERT_EQ(16u, r2.GetHeight()); | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
271 #endif |
1604 | 272 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
273 unsigned int value = 0; |
1604 | 274 for (unsigned int y = 0; y < r1.GetHeight(); y++) |
275 { | |
276 const uint8_t* p1 = reinterpret_cast<const uint8_t*>(r1.GetConstRow(y)); | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
277 #if ORTHANC_SANDBOXED != 1 |
1604 | 278 const uint8_t* p2 = reinterpret_cast<const uint8_t*>(r2.GetConstRow(y)); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
279 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
280 for (unsigned int x = 0; x < r1.GetWidth(); x++, value++) |
1604 | 281 { |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
282 ASSERT_TRUE(*p1 == value || |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
283 *p1 == value - 1 || |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
284 *p1 == value + 1); // Be tolerant to differences of +-1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
285 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
286 #if ORTHANC_SANDBOXED != 1 |
1604 | 287 ASSERT_EQ(*p1, *p2); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
288 p2++; |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
289 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
290 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
291 p1++; |
1604 | 292 } |
1602 | 293 } |
294 } | |
295 } | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
296 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1608
diff
changeset
|
297 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
298 TEST(PamWriter, ColorPattern) |
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 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
301 unsigned int width = 17; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
302 unsigned int height = 61; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
303 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
|
304 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
305 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
|
306 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
|
307 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
308 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
|
309 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
|
310 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
315 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
316 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
317 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
318 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
|
319 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
320 std::string f; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
321 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
322 #if ORTHANC_SANDBOXED == 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
323 Orthanc::IImageWriter::WriteToMemory(w, f, accessor); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
324 #else |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
325 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/ColorPattern.pam", accessor); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
326 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.pam"); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
327 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
328 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
329 std::string md5; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
330 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
|
331 ASSERT_EQ("81a3441754e88969ebbe53e69891e841", md5); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
332 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
333 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
334 TEST(PamWriter, Gray8Pattern) |
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 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
337 int width = 17; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
338 int height = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
339 int pitch = width; |
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 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
|
342 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
|
343 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
344 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
|
345 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
|
346 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
347 *p = y; |
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 } |
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 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
352 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
|
353 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
354 std::string f; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
355 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
356 #if ORTHANC_SANDBOXED == 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
357 Orthanc::IImageWriter::WriteToMemory(w, f, accessor); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
358 #else |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
359 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray8Pattern.pam", accessor); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
360 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.pam"); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
361 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
362 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
363 std::string md5; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
364 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
|
365 ASSERT_EQ("7873c408d26a9d11dd1c1de5e69cc0a3", md5); |
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 TEST(PamWriter, Gray16Pattern) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
369 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
370 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
371 int width = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
372 int height = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
373 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
|
374 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
375 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
|
376 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
377 int v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
378 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
|
379 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
380 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
|
381 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
|
382 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
383 *p = v; |
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 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
388 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
389 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
390 std::string f; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
391 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
392 #if ORTHANC_SANDBOXED == 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
393 Orthanc::IImageWriter::WriteToMemory(w, f, accessor); |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
394 #else |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
395 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray16Pattern.pam", accessor); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
396 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.pam"); |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
397 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
398 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
399 std::string md5; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
400 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
|
401 ASSERT_EQ("b268772bf28f3b2b8520ff21c5e3dcb6", md5); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
402 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
403 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
404 TEST(PamWriter, EndToEnd) |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
405 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
406 Orthanc::PamWriter w; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
407 unsigned int width = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
408 unsigned int height = 256; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
409 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
|
410 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
411 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
|
412 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
413 int v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
414 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
|
415 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
416 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
|
417 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
|
418 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
419 *p = v; |
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 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
422 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
423 Orthanc::ImageAccessor accessor; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
424 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
|
425 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
426 std::string s; |
4311
cb9aef006229
turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4211
diff
changeset
|
427 Orthanc::IImageWriter::WriteToMemory(w, s, accessor); |
2699
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 { |
4211
afad57ac30ef
enforcing parameter "enforceAligned" in PamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
430 Orthanc::PamReader r(true); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
431 r.ReadFromMemory(s); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
432 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
433 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
|
434 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
|
435 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
|
436 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
437 v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
438 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
|
439 { |
2707 | 440 const uint16_t *p = reinterpret_cast<const uint16_t*> |
441 ((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
|
442 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
|
443 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
|
444 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
445 ASSERT_EQ(v, *p); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
446 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
447 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
448 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
449 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
450 { |
3834
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
451 // 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
|
452 Orthanc::PamReader r(true); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
453 r.ReadFromMemory(s); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
454 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
459 v = 0; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
460 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
|
461 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
462 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
|
463 ((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
|
464 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
|
465 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
|
466 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
467 ASSERT_EQ(v, *p); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
468 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
469 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
470 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
471 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
472 #if ORTHANC_SANDBOXED != 1 |
3834
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
473 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
474 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
|
475 tmp.Write(s); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
476 |
4211
afad57ac30ef
enforcing parameter "enforceAligned" in PamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
477 Orthanc::PamReader r2(true); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
478 r2.ReadFromFile(tmp.GetPath()); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
479 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
484 v = 0; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
485 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
|
486 { |
2707 | 487 const uint16_t *p = reinterpret_cast<const uint16_t*> |
488 ((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
|
489 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
|
490 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
|
491 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
492 ASSERT_EQ(*p, v); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
493 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
494 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
495 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
496 #endif |
3834
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
497 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
498 #if ORTHANC_SANDBOXED != 1 |
3834
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
499 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
500 Orthanc::TemporaryFile tmp; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
501 tmp.Write(s); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
502 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
503 // 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
|
504 Orthanc::PamReader r2(true); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
505 r2.ReadFromFile(tmp.GetPath()); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
506 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
507 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
|
508 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
|
509 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
|
510 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
511 v = 0; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
512 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
|
513 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
514 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
|
515 ((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
|
516 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
|
517 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
|
518 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
519 ASSERT_EQ(*p, v); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
520 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
521 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
522 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4311
diff
changeset
|
523 #endif |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
2447
diff
changeset
|
524 } |
4642
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
525 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
526 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
527 TEST(PngWriter, Gray16Then8) |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
528 { |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
529 Orthanc::Image image16(Orthanc::PixelFormat_Grayscale16, 32, 32, false); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
530 Orthanc::Image image8(Orthanc::PixelFormat_Grayscale8, 32, 32, false); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
531 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
532 memset(image16.GetBuffer(), 0, image16.GetHeight() * image16.GetPitch()); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
533 memset(image8.GetBuffer(), 0, image8.GetHeight() * image8.GetPitch()); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
534 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
535 { |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
536 Orthanc::PamWriter w; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
537 std::string s; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
538 Orthanc::IImageWriter::WriteToMemory(w, s, image16); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
539 Orthanc::IImageWriter::WriteToMemory(w, s, image8); // No problem here |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
540 } |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
541 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
542 { |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
543 Orthanc::PamWriter w; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
544 std::string s; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
545 Orthanc::IImageWriter::WriteToMemory(w, s, image8); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
546 Orthanc::IImageWriter::WriteToMemory(w, s, image16); // No problem here |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
547 } |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
548 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
549 { |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
550 Orthanc::PngWriter w; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
551 std::string s; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
552 Orthanc::IImageWriter::WriteToMemory(w, s, image8); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
553 Orthanc::IImageWriter::WriteToMemory(w, s, image16); // No problem here |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
554 } |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
555 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
556 { |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
557 // The following call leads to "Invalid read of size 1" in Orthanc <= 1.9.2 |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
558 Orthanc::PngWriter w; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
559 std::string s; |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
560 Orthanc::IImageWriter::WriteToMemory(w, s, image16); |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
561 Orthanc::IImageWriter::WriteToMemory(w, s, image8); // Problem here |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
562 } |
69bbb4bd35cb
PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
563 } |