annotate OrthancFramework/UnitTestsSources/ImageTests.cpp @ 5312:b43a3f0b57b2

updated API version to 21
author Alain Mazy <am@osimis.io>
date Fri, 16 Jun 2023 09:27:17 +0200
parents 0ea402b4d901
children 91b3154bd4e1
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5054
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5054
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
7 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
11 * the License, or (at your option) any later version.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
12 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
13 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
16 * Lesser General Public License for more details.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
20 * <http://www.gnu.org/licenses/>.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
21 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
22
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
23
4046
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
25 // Must be the first to be sure to use the Orthanc framework shared library
4046
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
26 # include <OrthancFramework.h>
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
27 #endif
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
28
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4046
diff changeset
29 #include <gtest/gtest.h>
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
4046
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
31 #include "../Sources/Images/Font.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
32 #include "../Sources/Images/Image.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
33 #include "../Sources/Images/ImageProcessing.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #include "../Sources/Images/JpegReader.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
35 #include "../Sources/Images/JpegWriter.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 #include "../Sources/Images/PngReader.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 #include "../Sources/Images/PngWriter.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
38 #include "../Sources/Images/PamReader.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
39 #include "../Sources/Images/PamWriter.h"
7ff1e6c80627 moving ImageTests.cpp to framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
40 #include "../Sources/Toolbox.h"
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
41
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
42 #if ORTHANC_SANDBOXED != 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
43 # include "../Sources/SystemToolbox.h"
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
44 # include "../Sources/TemporaryFile.h"
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
45 #endif
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
46
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
47 #include <stdint.h>
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
48
368
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
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
69 Orthanc::ImageAccessor accessor;
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
70 accessor.AssignReadOnly(Orthanc::PixelFormat_RGB24, width, height, pitch, &image[0]);
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
71
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
72 std::string f;
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
73
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
74 #if ORTHANC_SANDBOXED == 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
75 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
76 #else
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
77 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/ColorPattern.png", accessor);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
78 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png");
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
79 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
80
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
81 std::string md5;
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
82 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
83 ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
5054
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
86 TEST(PngWriter, Color16Pattern)
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
87 {
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
88 Orthanc::PngWriter w;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
89 unsigned int width = 17;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
90 unsigned int height = 61;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
91 unsigned int pitch = width * 8;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
92
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
93 std::vector<uint8_t> image(height * pitch);
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
94 for (unsigned int y = 0; y < height; y++)
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
95 {
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
96 uint8_t *p = &image[0] + y * pitch;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
97 for (unsigned int x = 0; x < width; x++, p += 8)
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
98 {
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
99 p[0] = (y % 8 == 0) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
100 p[1] = (y % 8 == 1) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
101 p[2] = (y % 8 == 2) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
102 p[3] = (y % 8 == 3) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
103 p[4] = (y % 8 == 4) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
104 p[5] = (y % 8 == 5) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
105 p[6] = (y % 8 == 6) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
106 p[7] = (y % 8 == 7) ? 255 : 0;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
107 }
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
108 }
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
109
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
110 Orthanc::ImageAccessor accessor;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
111 accessor.AssignReadOnly(Orthanc::PixelFormat_RGBA64, width, height, pitch, &image[0]);
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
112
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
113 std::string f;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
114
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
115 #if ORTHANC_SANDBOXED == 1
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
116 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
117 #else
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
118 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Color16Pattern.png", accessor);
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
119 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Color16Pattern.png");
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
120 #endif
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
121
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
122 std::string md5;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
123 Orthanc::Toolbox::ComputeMD5(md5, f);
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
124 ASSERT_EQ("1cca552b6bd152b6fdab35c4a9f02c2a", md5);
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
125 }
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
126
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
127
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 TEST(PngWriter, Gray8Pattern)
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 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 int width = 17;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 int height = 256;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 int pitch = width;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 std::vector<uint8_t> image(height * pitch);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 uint8_t *p = &image[0] + y * pitch;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 for (int x = 0; x < width; x++, p++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 *p = y;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
145 Orthanc::ImageAccessor accessor;
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
146 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale8, width, height, pitch, &image[0]);
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
147
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
148 std::string f;
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
149
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
150 #if ORTHANC_SANDBOXED == 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
151 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
152 #else
4311
cb9aef006229 turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4211
diff changeset
153 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray8Pattern.png", accessor);
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
154 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png");
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
155 #endif
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
156
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
157 std::string md5;
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
158 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
159 ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 TEST(PngWriter, Gray16Pattern)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 int width = 256;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 int height = 256;
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
167 int pitch = width * 2 + 16;
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 std::vector<uint8_t> image(height * pitch);
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
170
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 int v = 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 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
175 for (int x = 0; x < width; x++, p++, v++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 *p = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
181 Orthanc::ImageAccessor accessor;
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
182 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
183
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
184 std::string f;
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
185
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
186 #if ORTHANC_SANDBOXED == 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
187 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
188 #else
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
189 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray16Pattern.png", accessor);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
190 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png");
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
191 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
192
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
193 std::string md5;
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
194 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
195 ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
197
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
198 TEST(PngWriter, EndToEnd)
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
199 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
200 Orthanc::PngWriter w;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
201 unsigned int width = 256;
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
202 unsigned int height = 256;
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
203 unsigned int pitch = width * 2 + 16;
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
204
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
205 std::vector<uint8_t> image(height * pitch);
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
206
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
207 int v = 0;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
208 for (unsigned int y = 0; y < height; y++)
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 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch);
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
211 for (unsigned int x = 0; x < width; x++, p++, v++)
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
212 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
213 *p = v;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
214 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
215 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
216
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
217 Orthanc::ImageAccessor accessor;
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
218 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
219
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
220 std::string s;
4311
cb9aef006229 turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4211
diff changeset
221 Orthanc::IImageWriter::WriteToMemory(w, s, accessor);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
222
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
223 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
224 Orthanc::PngReader r;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
225 r.ReadFromMemory(s);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
226
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
227 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
228 ASSERT_EQ(r.GetWidth(), width);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
229 ASSERT_EQ(r.GetHeight(), height);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
230
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
231 v = 0;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
232 for (unsigned int y = 0; y < height; y++)
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
233 {
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
234 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
235 ASSERT_EQ(p, r.GetConstRow(y));
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
236 for (unsigned int x = 0; x < width; x++, p++, v++)
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
237 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
238 ASSERT_EQ(*p, v);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
239 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
240 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
241 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
242
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
243 #if ORTHANC_SANDBOXED != 1
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
244 {
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
245 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
246 tmp.Write(s);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
247
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
248 Orthanc::PngReader r2;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
249 r2.ReadFromFile(tmp.GetPath());
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
250
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
251 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
252 ASSERT_EQ(r2.GetWidth(), width);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
253 ASSERT_EQ(r2.GetHeight(), height);
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
254
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
255 v = 0;
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
256 for (unsigned int y = 0; y < height; y++)
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
257 {
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
258 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
259 ASSERT_EQ(p, r2.GetConstRow(y));
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1288
diff changeset
260 for (unsigned int x = 0; x < width; x++, p++, v++)
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
261 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
262 ASSERT_EQ(*p, v);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
263 }
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
264 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
265 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
266 #endif
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
267 }
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
268
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
269
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
270
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
271
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
272 TEST(JpegWriter, Basic)
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
273 {
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
274 std::string s;
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
275
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
276 {
2107
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1970
diff changeset
277 Orthanc::Image img(Orthanc::PixelFormat_Grayscale8, 16, 16, false);
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
278 for (unsigned int y = 0, value = 0; y < img.GetHeight(); y++)
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
279 {
1608
adc6a5704cdb OrthancPluginConvertPixelFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1604
diff changeset
280 uint8_t* p = reinterpret_cast<uint8_t*>(img.GetRow(y));
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
281 for (unsigned int x = 0; x < img.GetWidth(); x++, p++)
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
282 {
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
283 *p = value++;
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
284 }
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
285 }
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
286
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
287 Orthanc::JpegWriter w;
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
288 Orthanc::IImageWriter::WriteToMemory(w, s, img);
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
289
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
290 #if ORTHANC_SANDBOXED != 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
291 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/hello.jpg", img);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
292 Orthanc::SystemToolbox::WriteFile(s, "UnitTestsResults/hello2.jpg");
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
293
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
294 std::string t;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2107
diff changeset
295 Orthanc::SystemToolbox::ReadFile(t, "UnitTestsResults/hello.jpg");
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
296 ASSERT_EQ(s.size(), t.size());
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
297 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size()));
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
298 #endif
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
299 }
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
300
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
301 {
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
302 Orthanc::JpegReader r1;
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
303 r1.ReadFromMemory(s);
1970
a1c1c606ce98 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
304 ASSERT_EQ(16u, r1.GetWidth());
a1c1c606ce98 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
305 ASSERT_EQ(16u, r1.GetHeight());
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
306
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
307 #if ORTHANC_SANDBOXED != 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
308 Orthanc::JpegReader r2;
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
309 r2.ReadFromFile("UnitTestsResults/hello.jpg");
1970
a1c1c606ce98 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
310 ASSERT_EQ(16u, r2.GetWidth());
a1c1c606ce98 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1916
diff changeset
311 ASSERT_EQ(16u, r2.GetHeight());
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
312 #endif
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
313
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
314 unsigned int value = 0;
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
315 for (unsigned int y = 0; y < r1.GetHeight(); y++)
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
316 {
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
317 const uint8_t* p1 = reinterpret_cast<const uint8_t*>(r1.GetConstRow(y));
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
318 #if ORTHANC_SANDBOXED != 1
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
319 const uint8_t* p2 = reinterpret_cast<const uint8_t*>(r2.GetConstRow(y));
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
320 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
321 for (unsigned int x = 0; x < r1.GetWidth(); x++, value++)
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
322 {
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
323 ASSERT_TRUE(*p1 == value ||
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
324 *p1 == value - 1 ||
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
325 *p1 == value + 1); // Be tolerant to differences of +-1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
326
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
327 #if ORTHANC_SANDBOXED != 1
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
328 ASSERT_EQ(*p1, *p2);
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
329 p2++;
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
330 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
331
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
332 p1++;
1604
1f5d6a2f9638 JpegReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1602
diff changeset
333 }
1602
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
334 }
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
335 }
292bce3f54ed JpegWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1492
diff changeset
336 }
1610
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
337
2dff2bdffdb8 font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1608
diff changeset
338
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
339 TEST(PamWriter, ColorPattern)
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 Orthanc::PamWriter w;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
342 unsigned int width = 17;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
343 unsigned int height = 61;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
344 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
345
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
346 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
347 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
348 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
349 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
350 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
351 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
352 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
353 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
354 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
355 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
356 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
357
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
358 Orthanc::ImageAccessor accessor;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
359 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
360
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
361 std::string f;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
362
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
363 #if ORTHANC_SANDBOXED == 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
364 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
365 #else
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
366 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/ColorPattern.pam", accessor);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
367 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/ColorPattern.pam");
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
368 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
369
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
370 std::string md5;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
371 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
372 ASSERT_EQ("81a3441754e88969ebbe53e69891e841", md5);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
373 }
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 TEST(PamWriter, Gray8Pattern)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
376 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
377 Orthanc::PamWriter w;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
378 int width = 17;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
379 int height = 256;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
380 int pitch = width;
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 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
383 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
384 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
385 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
386 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
387 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
388 *p = y;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
389 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
390 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
391
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
392 Orthanc::ImageAccessor accessor;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
393 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
394
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
395 std::string f;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
396
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
397 #if ORTHANC_SANDBOXED == 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
398 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
399 #else
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
400 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray8Pattern.pam", accessor);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
401 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.pam");
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
402 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
403
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
404 std::string md5;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
405 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
406 ASSERT_EQ("7873c408d26a9d11dd1c1de5e69cc0a3", md5);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
407 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
408
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
409 TEST(PamWriter, Gray16Pattern)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
410 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
411 Orthanc::PamWriter w;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
412 int width = 256;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
413 int height = 256;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
414 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
415
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
416 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
417
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
418 int v = 0;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
419 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
420 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
421 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
422 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
423 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
424 *p = v;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
425 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
426 }
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 Orthanc::ImageAccessor accessor;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
429 accessor.AssignReadOnly(Orthanc::PixelFormat_Grayscale16, width, height, pitch, &image[0]);
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
430
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
431 std::string f;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
432
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
433 #if ORTHANC_SANDBOXED == 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
434 Orthanc::IImageWriter::WriteToMemory(w, f, accessor);
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
435 #else
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
436 Orthanc::IImageWriter::WriteToFile(w, "UnitTestsResults/Gray16Pattern.pam", accessor);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
437 Orthanc::SystemToolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.pam");
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
438 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
439
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
440 std::string md5;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
441 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
442 ASSERT_EQ("b268772bf28f3b2b8520ff21c5e3dcb6", md5);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
443 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
444
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
445 TEST(PamWriter, EndToEnd)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
446 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
447 Orthanc::PamWriter w;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
448 unsigned int width = 256;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
449 unsigned int height = 256;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
450 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
451
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
452 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
453
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
454 int v = 0;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
455 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
456 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
457 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
458 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
459 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
460 *p = v;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
461 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
462 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
463
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
464 Orthanc::ImageAccessor accessor;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
465 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
466
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
467 std::string s;
4311
cb9aef006229 turning IImageWriter into a pure interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4211
diff changeset
468 Orthanc::IImageWriter::WriteToMemory(w, s, accessor);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
469
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
470 {
4211
afad57ac30ef enforcing parameter "enforceAligned" in PamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
471 Orthanc::PamReader r(true);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
472 r.ReadFromMemory(s);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
473
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
474 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
475 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
476 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
477
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
478 v = 0;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
479 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
480 {
2707
38a3054b22ff improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
481 const uint16_t *p = reinterpret_cast<const uint16_t*>
38a3054b22ff improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
482 ((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
483 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
484 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
485 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
486 ASSERT_EQ(v, *p);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
487 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
488 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
489 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
490
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
491 {
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
492 // 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
493 Orthanc::PamReader r(true);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
494 r.ReadFromMemory(s);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
495
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
496 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
497 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
498 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
499
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
500 v = 0;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
501 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
502 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
503 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
504 ((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
505 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
506 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
507 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
508 ASSERT_EQ(v, *p);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
509 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
510 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
511 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
512
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
513 #if ORTHANC_SANDBOXED != 1
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
514 {
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
515 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
516 tmp.Write(s);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
517
4211
afad57ac30ef enforcing parameter "enforceAligned" in PamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
518 Orthanc::PamReader r2(true);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
519 r2.ReadFromFile(tmp.GetPath());
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
520
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
521 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
522 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
523 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
524
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
525 v = 0;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
526 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
527 {
2707
38a3054b22ff improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
528 const uint16_t *p = reinterpret_cast<const uint16_t*>
38a3054b22ff improvement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
529 ((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
530 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
531 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
532 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
533 ASSERT_EQ(*p, v);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
534 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
535 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
536 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
537 #endif
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
538
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
539 #if ORTHANC_SANDBOXED != 1
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
540 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
541 Orthanc::TemporaryFile tmp;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
542 tmp.Write(s);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
543
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
544 // 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
545 Orthanc::PamReader r2(true);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
546 r2.ReadFromFile(tmp.GetPath());
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
547
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
548 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
549 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
550 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
551
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
552 v = 0;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
553 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
554 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
555 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
556 ((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
557 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
558 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
559 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
560 ASSERT_EQ(*p, v);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
561 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
562 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
563 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4311
diff changeset
564 #endif
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents: 2447
diff changeset
565 }
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
566
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
567
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
568 TEST(PngWriter, Gray16Then8)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
569 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
570 Orthanc::Image image16(Orthanc::PixelFormat_Grayscale16, 32, 32, false);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
571 Orthanc::Image image8(Orthanc::PixelFormat_Grayscale8, 32, 32, false);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
572
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
573 memset(image16.GetBuffer(), 0, image16.GetHeight() * image16.GetPitch());
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
574 memset(image8.GetBuffer(), 0, image8.GetHeight() * image8.GetPitch());
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
575
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
576 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
577 Orthanc::PamWriter w;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
578 std::string s;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
579 Orthanc::IImageWriter::WriteToMemory(w, s, image16);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
580 Orthanc::IImageWriter::WriteToMemory(w, s, image8); // No problem here
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
581 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
582
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
583 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
584 Orthanc::PamWriter w;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
585 std::string s;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
586 Orthanc::IImageWriter::WriteToMemory(w, s, image8);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
587 Orthanc::IImageWriter::WriteToMemory(w, s, image16); // No problem here
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
588 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
589
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
590 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
591 Orthanc::PngWriter w;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
592 std::string s;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
593 Orthanc::IImageWriter::WriteToMemory(w, s, image8);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
594 Orthanc::IImageWriter::WriteToMemory(w, s, image16); // No problem here
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
595 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
596
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
597 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
598 // The following call leads to "Invalid read of size 1" in Orthanc <= 1.9.2
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
599 Orthanc::PngWriter w;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
600 std::string s;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
601 Orthanc::IImageWriter::WriteToMemory(w, s, image16);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
602 Orthanc::IImageWriter::WriteToMemory(w, s, image8); // Problem here
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
603 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
604 }