annotate OrthancFramework/UnitTestsSources/ImageTests.cpp @ 4063:e00f3d089991 framework

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