annotate UnitTestsSources/PngTests.cpp @ 1177:5b2d8c280ac2 db-changes

Plugins can monitor changes through callbacks
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 Sep 2014 17:37:44 +0200
parents dfc076546821
children 6e7e5ed91c2d
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
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
4 * Belgium
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
5 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
6 * This program is free software: you can redistribute it and/or
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
7 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
9 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
10 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
11 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
12 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
15 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
19 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
20 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
21 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
22 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
26 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
27 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
28 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
30 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
31
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
33 #include "PrecompiledHeadersUnitTests.h"
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "gtest/gtest.h"
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <stdint.h>
799
777b6b694da6 rename folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 797
diff changeset
37 #include "../Core/ImageFormats/PngReader.h"
777b6b694da6 rename folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 797
diff changeset
38 #include "../Core/ImageFormats/PngWriter.h"
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
39 #include "../Core/Toolbox.h"
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
40 #include "../Core/Uuid.h"
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
41
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 TEST(PngWriter, ColorPattern)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 int width = 17;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 int height = 61;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 int pitch = width * 3;
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 std::vector<uint8_t> image(height * pitch);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 uint8_t *p = &image[0] + y * pitch;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 for (int x = 0; x < width; x++, p += 3)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 p[0] = (y % 3 == 0) ? 255 : 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 p[1] = (y % 3 == 1) ? 255 : 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 p[2] = (y % 3 == 2) ? 255 : 0;
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 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
62 w.WriteToFile("UnitTestsResults/ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
63
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
64 std::string f, md5;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
65 Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/ColorPattern.png");
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
66 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
67 ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
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 TEST(PngWriter, Gray8Pattern)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 int width = 17;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 int height = 256;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 int pitch = width;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 std::vector<uint8_t> image(height * pitch);
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 uint8_t *p = &image[0] + y * pitch;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 for (int x = 0; x < width; x++, p++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 *p = y;
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 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
87 w.WriteToFile("UnitTestsResults/Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
88
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
89 std::string f, md5;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
90 Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray8Pattern.png");
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
91 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
92 ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5);
368
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
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 TEST(PngWriter, Gray16Pattern)
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 Orthanc::PngWriter w;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 int width = 256;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 int height = 256;
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
100 int pitch = width * 2 + 16;
368
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 std::vector<uint8_t> image(height * pitch);
369
4632a044746e simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 368
diff changeset
103
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 int v = 0;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 for (int y = 0; y < height; y++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 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
108 for (int x = 0; x < width; x++, p++, v++)
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 *p = v;
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
114 w.WriteToFile("UnitTestsResults/Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
115
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
116 std::string f, md5;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 799
diff changeset
117 Orthanc::Toolbox::ReadFile(f, "UnitTestsResults/Gray16Pattern.png");
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
118 Orthanc::Toolbox::ComputeMD5(md5, f);
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
119 ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5);
368
80011cd589e6 support of rgb images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
121
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
122 TEST(PngWriter, EndToEnd)
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
123 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
124 Orthanc::PngWriter w;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
125 int width = 256;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
126 int height = 256;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
127 int pitch = width * 2 + 16;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
128
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
129 std::vector<uint8_t> image(height * pitch);
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
130
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
131 int v = 0;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
132 for (int y = 0; y < height; y++)
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
133 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
134 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch);
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
135 for (int x = 0; x < width; x++, p++, v++)
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
136 {
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
137 *p = v;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
138 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
139 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
140
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
141 std::string s;
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
142 w.WriteToMemory(s, width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
143
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
144 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
145 Orthanc::PngReader r;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
146 r.ReadFromMemory(s);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
147
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
148 ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
149 ASSERT_EQ(r.GetWidth(), width);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
150 ASSERT_EQ(r.GetHeight(), height);
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
151
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
152 v = 0;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
153 for (int y = 0; y < height; y++)
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
154 {
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
155 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
156 ASSERT_EQ(p, r.GetConstRow(y));
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
157 for (int x = 0; x < width; x++, p++, v++)
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
158 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
159 ASSERT_EQ(*p, v);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
160 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
161 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
162 }
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
163
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
164 {
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
165 Orthanc::Toolbox::TemporaryFile tmp;
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
166 Orthanc::Toolbox::WriteFile(s, tmp.GetPath());
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
167
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
168 Orthanc::PngReader r2;
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
169 r2.ReadFromFile(tmp.GetPath());
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
170
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
171 ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16);
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
172 ASSERT_EQ(r2.GetWidth(), width);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
173 ASSERT_EQ(r2.GetHeight(), height);
710
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
174
c87a1d529e13 test pngreader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 709
diff changeset
175 v = 0;
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
176 for (int y = 0; y < height; y++)
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
177 {
797
37adac56017a ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 711
diff changeset
178 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
179 ASSERT_EQ(p, r2.GetConstRow(y));
709
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
180 for (int x = 0; x < width; x++, p++, v++)
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
181 {
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
182 ASSERT_EQ(*p, v);
6c90ce085261 zlib tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
183 }
455
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
184 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
185 }
238a0c99ced2 PNG reader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 454
diff changeset
186 }