Mercurial > hg > orthanc
annotate UnitTestsSources/Png.cpp @ 632:17815b9d4280
rename the UnitTests directory to avoid clashes in filenames
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Oct 2013 16:26:51 +0100 |
parents | UnitTests/Png.cpp@238a0c99ced2 |
children | 51892be15618 |
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" |
368 | 6 |
7 TEST(PngWriter, ColorPattern) | |
8 { | |
9 Orthanc::PngWriter w; | |
10 int width = 17; | |
11 int height = 61; | |
12 int pitch = width * 3; | |
13 | |
14 std::vector<uint8_t> image(height * pitch); | |
15 for (int y = 0; y < height; y++) | |
16 { | |
17 uint8_t *p = &image[0] + y * pitch; | |
18 for (int x = 0; x < width; x++, p += 3) | |
19 { | |
20 p[0] = (y % 3 == 0) ? 255 : 0; | |
21 p[1] = (y % 3 == 1) ? 255 : 0; | |
22 p[2] = (y % 3 == 2) ? 255 : 0; | |
23 } | |
24 } | |
25 | |
26 w.WriteToFile("ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]); | |
27 } | |
28 | |
29 TEST(PngWriter, Gray8Pattern) | |
30 { | |
31 Orthanc::PngWriter w; | |
32 int width = 17; | |
33 int height = 256; | |
34 int pitch = width; | |
35 | |
36 std::vector<uint8_t> image(height * pitch); | |
37 for (int y = 0; y < height; y++) | |
38 { | |
39 uint8_t *p = &image[0] + y * pitch; | |
40 for (int x = 0; x < width; x++, p++) | |
41 { | |
42 *p = y; | |
43 } | |
44 } | |
45 | |
46 w.WriteToFile("Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]); | |
47 } | |
48 | |
49 TEST(PngWriter, Gray16Pattern) | |
50 { | |
51 Orthanc::PngWriter w; | |
52 int width = 256; | |
53 int height = 256; | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
54 int pitch = width * 2 + 16; |
368 | 55 |
56 std::vector<uint8_t> image(height * pitch); | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
57 |
368 | 58 int v = 0; |
59 for (int y = 0; y < height; y++) | |
60 { | |
61 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
62 for (int x = 0; x < width; x++, p++, v++) | |
63 { | |
64 *p = v; | |
65 } | |
66 } | |
67 | |
68 w.WriteToFile("Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]); | |
69 } | |
455 | 70 |
71 TEST(PngWriter, EndToEnd) | |
72 { | |
73 Orthanc::PngWriter w; | |
74 int width = 256; | |
75 int height = 256; | |
76 int pitch = width * 2 + 16; | |
77 | |
78 std::vector<uint8_t> image(height * pitch); | |
79 | |
80 int v = 0; | |
81 for (int y = 0; y < height; y++) | |
82 { | |
83 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
84 for (int x = 0; x < width; x++, p++, v++) | |
85 { | |
86 *p = v; | |
87 } | |
88 } | |
89 | |
90 std::string s; | |
91 w.WriteToMemory(s, width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]); | |
92 | |
93 Orthanc::PngReader r; | |
94 r.ReadFromMemory(s); | |
95 | |
96 ASSERT_EQ(r.GetWidth(), width); | |
97 ASSERT_EQ(r.GetHeight(), height); | |
98 | |
99 v = 0; | |
100 for (int y = 0; y < height; y++) | |
101 { | |
102 uint16_t *p = reinterpret_cast<uint16_t*>((uint8_t*) r.GetBuffer() + y * r.GetPitch()); | |
103 for (int x = 0; x < width; x++, p++, v++) | |
104 { | |
105 ASSERT_EQ(*p, v); | |
106 } | |
107 } | |
108 | |
109 } |