Mercurial > hg > orthanc
annotate UnitTestsSources/Png.cpp @ 684:96d8410c56cd
newlines
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 Jan 2014 16:58:03 +0100 |
parents | 51892be15618 |
children | 6c90ce085261 |
rev | line source |
---|---|
368 | 1 #include "gtest/gtest.h" |
2 | |
3 #include <stdint.h> | |
455 | 4 #include "../Core/FileFormats/PngReader.h" |
454 | 5 #include "../Core/FileFormats/PngWriter.h" |
639
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
6 #include "../Core/Toolbox.h" |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
7 |
368 | 8 |
9 TEST(PngWriter, ColorPattern) | |
10 { | |
11 Orthanc::PngWriter w; | |
12 int width = 17; | |
13 int height = 61; | |
14 int pitch = width * 3; | |
15 | |
16 std::vector<uint8_t> image(height * pitch); | |
17 for (int y = 0; y < height; y++) | |
18 { | |
19 uint8_t *p = &image[0] + y * pitch; | |
20 for (int x = 0; x < width; x++, p += 3) | |
21 { | |
22 p[0] = (y % 3 == 0) ? 255 : 0; | |
23 p[1] = (y % 3 == 1) ? 255 : 0; | |
24 p[2] = (y % 3 == 2) ? 255 : 0; | |
25 } | |
26 } | |
27 | |
28 w.WriteToFile("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
|
29 |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
30 std::string f, md5; |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
31 Orthanc::Toolbox::ReadFile(f, "ColorPattern.png"); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
32 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
33 ASSERT_EQ("604e785f53c99cae6ea4584870b2c41d", md5); |
368 | 34 } |
35 | |
36 TEST(PngWriter, Gray8Pattern) | |
37 { | |
38 Orthanc::PngWriter w; | |
39 int width = 17; | |
40 int height = 256; | |
41 int pitch = width; | |
42 | |
43 std::vector<uint8_t> image(height * pitch); | |
44 for (int y = 0; y < height; y++) | |
45 { | |
46 uint8_t *p = &image[0] + y * pitch; | |
47 for (int x = 0; x < width; x++, p++) | |
48 { | |
49 *p = y; | |
50 } | |
51 } | |
52 | |
53 w.WriteToFile("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
|
54 |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
55 std::string f, md5; |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
56 Orthanc::Toolbox::ReadFile(f, "Gray8Pattern.png"); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
57 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
58 ASSERT_EQ("5a9b98bea3d0a6d983980cc38bfbcdb3", md5); |
368 | 59 } |
60 | |
61 TEST(PngWriter, Gray16Pattern) | |
62 { | |
63 Orthanc::PngWriter w; | |
64 int width = 256; | |
65 int height = 256; | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
66 int pitch = width * 2 + 16; |
368 | 67 |
68 std::vector<uint8_t> image(height * pitch); | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
69 |
368 | 70 int v = 0; |
71 for (int y = 0; y < height; y++) | |
72 { | |
73 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
74 for (int x = 0; x < width; x++, p++, v++) | |
75 { | |
76 *p = v; | |
77 } | |
78 } | |
79 | |
80 w.WriteToFile("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
|
81 |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
82 std::string f, md5; |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
83 Orthanc::Toolbox::ReadFile(f, "Gray16Pattern.png"); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
84 Orthanc::Toolbox::ComputeMD5(md5, f); |
51892be15618
fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
85 ASSERT_EQ("0785866a08bf0a02d2eeff87f658571c", md5); |
368 | 86 } |
455 | 87 |
88 TEST(PngWriter, EndToEnd) | |
89 { | |
90 Orthanc::PngWriter w; | |
91 int width = 256; | |
92 int height = 256; | |
93 int pitch = width * 2 + 16; | |
94 | |
95 std::vector<uint8_t> image(height * pitch); | |
96 | |
97 int v = 0; | |
98 for (int y = 0; y < height; y++) | |
99 { | |
100 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
101 for (int x = 0; x < width; x++, p++, v++) | |
102 { | |
103 *p = v; | |
104 } | |
105 } | |
106 | |
107 std::string s; | |
108 w.WriteToMemory(s, width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]); | |
109 | |
110 Orthanc::PngReader r; | |
111 r.ReadFromMemory(s); | |
112 | |
113 ASSERT_EQ(r.GetWidth(), width); | |
114 ASSERT_EQ(r.GetHeight(), height); | |
115 | |
116 v = 0; | |
117 for (int y = 0; y < height; y++) | |
118 { | |
119 uint16_t *p = reinterpret_cast<uint16_t*>((uint8_t*) r.GetBuffer() + y * r.GetPitch()); | |
120 for (int x = 0; x < width; x++, p++, v++) | |
121 { | |
122 ASSERT_EQ(*p, v); | |
123 } | |
124 } | |
125 } |