annotate UnitTestsSources/ImageTests.cpp @ 1724:7e0b5e413c7c db-changes

C-Move SCP for studies using AccessionNumber tag
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Oct 2015 11:02:06 +0200
parents 3727a09e7b53
children b1291df2f780
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
4 * Department, University Hospital of Liege, Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
5 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
6 * This program is free software: you can redistribute it and/or
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
7 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
9 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
10 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
11 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
12 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
15 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
19 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
20 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
21 * in the program, then also delete it here.
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 * 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
24 * 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
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
26 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
27 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
28 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
30 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
31
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
33 #include "PrecompiledHeadersUnitTests.h"
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "gtest/gtest.h"
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1612
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
36 #include "../Core/Images/Font.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
37 #include "../Core/Images/Image.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
38 #include "../Core/Images/ImageProcessing.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
39 #include "../Core/Images/JpegReader.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
40 #include "../Core/Images/JpegWriter.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
41 #include "../Core/Images/PngReader.h"
96582230ddcb Core/ImageFormats folder renamed as Core/Images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1611
diff changeset
42 #include "../Core/Images/PngWriter.h"
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
43 #include "../Core/Toolbox.h"
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
44 #include "../Core/Uuid.h"
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
45 #include "../OrthancServer/OrthancInitialization.h"
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
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 TEST(PngWriter, ColorPattern)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 p[0] = (y % 3 == 0) ? 255 : 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 p[1] = (y % 3 == 1) ? 255 : 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 p[2] = (y % 3 == 2) ? 255 : 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
69 w.WriteToFile("UnitTestsResults/ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
70
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
71 std::string f, md5;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
72 Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png");
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
73 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
74 ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 TEST(PngWriter, Gray8Pattern)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 int width = 17;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 int height = 256;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 int pitch = width;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 std::vector<uint8_t> image(height * pitch);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 uint8_t *p = &image[0] + y * pitch;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 for (int x = 0; x < width; x++, p++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 *p = y;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
94 w.WriteToFile("UnitTestsResults/Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
95
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
96 std::string f, md5;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
97 Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png");
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
98 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
99 ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 TEST(PngWriter, Gray16Pattern)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 int width = 256;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 int height = 256;
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
107 int pitch = width * 2 + 16;
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 std::vector<uint8_t> image(height * pitch);
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
110
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 int v = 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 for (int x = 0; x < width; x++, p++, v++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 *p = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
121 w.WriteToFile("UnitTestsResults/Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
122
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
123 std::string f, md5;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
124 Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png");
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
125 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
126 ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
128
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
129 TEST(PngWriter, EndToEnd)
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
130 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
131 Orthanc::PngWriter w;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
132 unsigned int width = 256;
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
133 unsigned int height = 256;
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
134 unsigned int pitch = width * 2 + 16;
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
135
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
136 std::vector<uint8_t> image(height * pitch);
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
137
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
138 int v = 0;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
139 for (unsigned int y = 0; y < height; y++)
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
140 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
141 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch);
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
142 for (unsigned int x = 0; x < width; x++, p++, v++)
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
143 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
144 *p = v;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
145 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
146 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
147
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
148 std::string s;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
149 w.WriteToMemory(s, width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
150
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
151 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
152 Orthanc::PngReader r;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
153 r.ReadFromMemory(s);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
154
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
155 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
156 ASSERT_EQ(r.GetWidth(), width);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
157 ASSERT_EQ(r.GetHeight(), height);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
158
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
159 v = 0;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
160 for (unsigned int y = 0; y < height; y++)
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
161 {
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
162 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
163 ASSERT_EQ(p, r.GetConstRow(y));
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
164 for (unsigned int x = 0; x < width; x++, p++, v++)
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
165 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
166 ASSERT_EQ(*p, v);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
167 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
168 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
169 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
170
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
171 {
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
172 Orthanc::Toolbox::TemporaryFile tmp;
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
173 Orthanc::Toolbox::WriteFile(s, tmp.GetPath());
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
174
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
175 Orthanc::PngReader r2;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
176 r2.ReadFromFile(tmp.GetPath());
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
177
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
178 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
179 ASSERT_EQ(r2.GetWidth(), width);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
180 ASSERT_EQ(r2.GetHeight(), height);
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
181
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
182 v = 0;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
183 for (unsigned int y = 0; y < height; y++)
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
184 {
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
185 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
186 ASSERT_EQ(p, r2.GetConstRow(y));
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
187 for (unsigned int x = 0; x < width; x++, p++, v++)
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
188 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
189 ASSERT_EQ(*p, v);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
190 }
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
191 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
192 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
193 }
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
194
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
195
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
196
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
197
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
198 TEST(JpegWriter, Basic)
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
199 {
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
200 std::string s;
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
201
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
202 {
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1604
diff changeset
203 Orthanc::Image img(Orthanc::PixelFormat_Grayscale8, 16, 16);
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
204 for (unsigned int y = 0, value = 0; y < img.GetHeight(); y++)
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
205 {
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1604
diff changeset
206 uint8_t* p = reinterpret_cast<uint8_t*>(img.GetRow(y));
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
207 for (unsigned int x = 0; x < img.GetWidth(); x++, p++)
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
208 {
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
209 *p = value++;
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
210 }
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
211 }
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
212
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
213 Orthanc::JpegWriter w;
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1604
diff changeset
214 w.WriteToFile("UnitTestsResults/hello.jpg", img);
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
215
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1604
diff changeset
216 w.WriteToMemory(s, img);
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
217 Orthanc::Toolbox::WriteFile(s, "UnitTestsResults/hello2.jpg");
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
218
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
219 std::string t;
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
220 Orthanc::Toolbox::ReadFile(t, "UnitTestsResults/hello.jpg");
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
221 ASSERT_EQ(s.size(), t.size());
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
222 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size()));
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
223 }
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
224
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
225 {
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
226 Orthanc::JpegReader r1, r2;
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
227 r1.ReadFromFile("UnitTestsResults/hello.jpg");
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
228 ASSERT_EQ(16, r1.GetWidth());
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
229 ASSERT_EQ(16, r1.GetHeight());
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
230
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
231 r2.ReadFromMemory(s);
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
232 ASSERT_EQ(16, r2.GetWidth());
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
233 ASSERT_EQ(16, r2.GetHeight());
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
234
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
235 for (unsigned int y = 0; y < r1.GetHeight(); y++)
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
236 {
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
237 const uint8_t* p1 = reinterpret_cast<const uint8_t*>(r1.GetConstRow(y));
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
238 const uint8_t* p2 = reinterpret_cast<const uint8_t*>(r2.GetConstRow(y));
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
239 for (unsigned int x = 0; x < r1.GetWidth(); x++)
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
240 {
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
241 ASSERT_EQ(*p1, *p2);
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
242 }
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
243 }
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
244 }
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
245 }
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
246
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
247
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
248 TEST(Font, Basic)
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
249 {
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
250 Orthanc::Image s(Orthanc::PixelFormat_RGB24, 640, 480);
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
251 memset(s.GetBuffer(), 0, s.GetPitch() * s.GetHeight());
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
252
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
253 ASSERT_GE(1, Orthanc::Configuration::GetFontRegistry().GetSize());
1611
5e9b2aac8b89 fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1610
diff changeset
254 Orthanc::Configuration::GetFontRegistry().GetFont(0).Draw(s, "Hello world É\n\rComment ça va ?\nq", 50, 60, 255, 0, 0);
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
255
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
256 Orthanc::PngWriter w;
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
257 w.WriteToFile("UnitTestsResults/font.png", s);
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
258 }
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
259