Mercurial > hg > orthanc-stone
comparison OrthancStone/UnitTestsSources/PixelTestPatternsTests.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | UnitTestsSources/PixelTestPatternsTests.cpp@1e381f2596d3 |
children |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "../Sources/Toolbox/PixelTestPatterns.h" | |
23 | |
24 #include <Images/Image.h> | |
25 #include <Images/PngWriter.h> | |
26 | |
27 #include <boost/chrono.hpp> | |
28 #include <boost/lexical_cast.hpp> | |
29 | |
30 #include <gtest/gtest.h> | |
31 #include <stdint.h> | |
32 #include <cmath> | |
33 | |
34 /* Autogenerated from prout.png */ | |
35 static const unsigned char bin2c_SimpleRedBlueHGradient_png[391] = "\211PNG\15\12\32\12\0\0\0\15IHDR\0\0\0\200\0\0\0\200\10\6\0\0\0\303>a\313\0\0\1MIDATx\234\355\322\1\15\3000\0\303\260~\3741o\7\342X\12\203|o{wgev\26Z\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p\15\200k\0\\\3\340\32\0\327\0\270\6\3005\0\256\1p?\314\262\201\3760\355r\262\0\0\0\0IEND\256B`\202"; | |
36 | |
37 TEST(PixelTestPatterns, SimpleRedHGradient) | |
38 { | |
39 std::unique_ptr<Orthanc::Image> texture; | |
40 | |
41 texture.reset(new Orthanc::Image( | |
42 Orthanc::PixelFormat_RGBA32, | |
43 128, | |
44 128, | |
45 /*forceMinimalPitch*/false)); | |
46 | |
47 Orthanc::ImageAccessor target; | |
48 texture->GetWriteableAccessor(target); | |
49 | |
50 OrthancStone::PixelTestPatterns::fillWithHGradient(target,255,0,0,0,0,255); | |
51 | |
52 Orthanc::PngWriter writer; | |
53 #if 0 | |
54 writer.WriteToFile("SimpleRedBlueHGradient.png", *texture); | |
55 #else | |
56 std::string contents; | |
57 writer.WriteToMemory(contents, *texture); | |
58 | |
59 ASSERT_EQ(1u, sizeof(unsigned char)); | |
60 ASSERT_EQ(391u, sizeof(bin2c_SimpleRedBlueHGradient_png)); | |
61 ASSERT_EQ(390u, contents.size()); | |
62 | |
63 char* resultPngBytes = &(contents[0]); | |
64 | |
65 int result = memcmp(resultPngBytes, bin2c_SimpleRedBlueHGradient_png, 390); | |
66 ASSERT_EQ(0, result); | |
67 #endif | |
68 } | |
69 | |
70 static const unsigned char bin2c_SimpleRedBlueVGradient_png[400] = "\211PNG\15\12\32\12\0\0\0\15IHDR\0\0\0\200\0\0\0\200\10\6\0\0\0\303>a\313\0\0\1VIDATx\234\355\322A\21\3000\14\300\260t7\376\220\327\301\310\303\22\2?|\356\314\35\262\336o\236\355\6\26\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\14\20g\2008\3\304\31 \316\0q\6\2103@\234\1\342\316\231\357nG\260\347\7\221\255\203\367~A)\36\0\0\0\0IEND\256B`\202"; | |
71 | |
72 | |
73 TEST(PixelTestPatterns, SimpleRedBlueVGradient) | |
74 { | |
75 std::unique_ptr<Orthanc::Image> texture; | |
76 | |
77 texture.reset(new Orthanc::Image( | |
78 Orthanc::PixelFormat_RGBA32, | |
79 128, | |
80 128, | |
81 /*forceMinimalPitch*/false)); | |
82 | |
83 Orthanc::ImageAccessor target; | |
84 texture->GetWriteableAccessor(target); | |
85 | |
86 OrthancStone::PixelTestPatterns::fillWithVGradient(target, 255, 0, 0, 0, 0, 255); | |
87 | |
88 Orthanc::PngWriter writer; | |
89 #if 0 | |
90 writer.WriteToFile("SimpleRedBlueVGradient.png", *texture); | |
91 #else | |
92 std::string contents; | |
93 writer.WriteToMemory(contents, *texture); | |
94 | |
95 ASSERT_EQ(1u, sizeof(unsigned char)); | |
96 ASSERT_EQ(400u, sizeof(bin2c_SimpleRedBlueVGradient_png)); | |
97 ASSERT_EQ(399u, contents.size()); | |
98 | |
99 char* resultPngBytes = &(contents[0]); | |
100 | |
101 int result = memcmp(resultPngBytes, bin2c_SimpleRedBlueVGradient_png, 399); | |
102 ASSERT_EQ(0, result); | |
103 #endif | |
104 } | |
105 | |
106 | |
107 /* Autogenerated from MultiGradient.png */ | |
108 static const unsigned char bin2c_MultiGradient_png[774] = "\211PNG\15\12\32\12\0\0\0\15IHDR\0\0\1\0\0\0\0\200\10\6\0\0\0\344\265\267\12\0\0\2\314IDATx\234\355\325\301\11\3030\24\5\301/\242\376+6(E$ \314\354\30\337\215\364X\2573s\6\266\316\314\226\237\365\271}\5\227\255\331{\273\357s\373\374sY\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\25\0^\13\220\2559\347\354\231Q\337\317\372\303)\276\331Ys\377\26\256.\340\3673|\261}\373\3n{\360?\240>\200\347\351\376i\5\300V\0pz\0t\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0l\5\0W\0lz\0\276!\352\302\35+U\244b\0\0\0\0IEND\256B`\202"; | |
109 | |
110 TEST(PixelTestPatterns, MultiGradient) | |
111 { | |
112 std::unique_ptr<Orthanc::Image> texture; | |
113 | |
114 const int CELLW = 64; | |
115 const int CELLH = 64; | |
116 const int NHCELLS = 4; | |
117 const int NVCELLS = 2; | |
118 const int NCELLS = NHCELLS * NVCELLS; | |
119 | |
120 texture.reset(new Orthanc::Image( | |
121 Orthanc::PixelFormat_RGBA32, | |
122 NHCELLS * CELLW, | |
123 NVCELLS * CELLH, | |
124 /*forceMinimalPitch*/false)); | |
125 | |
126 // H:R->K, V:G->W, H:B->K | |
127 | |
128 // R G B K C M Y W | |
129 uint8_t startR[NCELLS] = {255,000,000,000,000,255,255,255}; | |
130 uint8_t startG[NCELLS] = {000,255,000,000,255,000,255,255}; | |
131 uint8_t startB[NCELLS] = {000,000,255,000,255,255,000,255}; | |
132 | |
133 // K W K W W K W K | |
134 uint8_t eeendR[NCELLS] = {000,255,000,255,255,000,255,000}; | |
135 uint8_t eeendG[NCELLS] = {000,255,000,255,255,000,255,000 }; | |
136 uint8_t eeendB[NCELLS] = {000,255,000,255,255,000,255,000 }; | |
137 | |
138 for(size_t slot = 0; slot < NCELLS; ++slot) | |
139 { | |
140 int x0 = (slot % 4) * CELLW; | |
141 bool vertical = (((slot / NHCELLS) % 2) == 0) ? (slot % 2 == 0) : (slot % 2 == 1); | |
142 int y0 = static_cast<int>(slot / NHCELLS) * CELLH; | |
143 Orthanc::ImageAccessor target; | |
144 texture->GetRegion(target, x0, y0, CELLW, CELLH); | |
145 if (vertical) | |
146 OrthancStone::PixelTestPatterns::fillWithVGradient(target, startR[slot], startG[slot], startB[slot], eeendR[slot], eeendG[slot], eeendB[slot]); | |
147 else | |
148 OrthancStone::PixelTestPatterns::fillWithHGradient(target, startR[slot], startG[slot], startB[slot], eeendR[slot], eeendG[slot], eeendB[slot]); | |
149 } | |
150 | |
151 Orthanc::PngWriter writer; | |
152 #if 0 | |
153 writer.WriteToFile("MultiGradient.png", *texture); | |
154 #else | |
155 std::string contents; | |
156 writer.WriteToMemory(contents, *texture); | |
157 | |
158 ASSERT_EQ(1u, sizeof(unsigned char)); | |
159 ASSERT_EQ(774u, sizeof(bin2c_MultiGradient_png)); | |
160 ASSERT_EQ(773u, contents.size()); | |
161 | |
162 char* resultPngBytes = &(contents[0]); | |
163 | |
164 int result = memcmp(resultPngBytes, bin2c_MultiGradient_png, 773); | |
165 ASSERT_EQ(0, result); | |
166 #endif | |
167 } | |
168 |