Mercurial > hg > orthanc
annotate UnitTests/PngWriter.cpp @ 399:4d5f0857ec9c
copyright update
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 Apr 2013 10:54:46 +0200 |
parents | 4632a044746e |
children |
rev | line source |
---|---|
368 | 1 #include "gtest/gtest.h" |
2 | |
3 #include <stdint.h> | |
4 #include "../Core/PngWriter.h" | |
5 | |
6 TEST(PngWriter, ColorPattern) | |
7 { | |
8 Orthanc::PngWriter w; | |
9 int width = 17; | |
10 int height = 61; | |
11 int pitch = width * 3; | |
12 | |
13 std::vector<uint8_t> image(height * pitch); | |
14 for (int y = 0; y < height; y++) | |
15 { | |
16 uint8_t *p = &image[0] + y * pitch; | |
17 for (int x = 0; x < width; x++, p += 3) | |
18 { | |
19 p[0] = (y % 3 == 0) ? 255 : 0; | |
20 p[1] = (y % 3 == 1) ? 255 : 0; | |
21 p[2] = (y % 3 == 2) ? 255 : 0; | |
22 } | |
23 } | |
24 | |
25 w.WriteToFile("ColorPattern.png", width, height, pitch, Orthanc::PixelFormat_RGB24, &image[0]); | |
26 } | |
27 | |
28 TEST(PngWriter, Gray8Pattern) | |
29 { | |
30 Orthanc::PngWriter w; | |
31 int width = 17; | |
32 int height = 256; | |
33 int pitch = width; | |
34 | |
35 std::vector<uint8_t> image(height * pitch); | |
36 for (int y = 0; y < height; y++) | |
37 { | |
38 uint8_t *p = &image[0] + y * pitch; | |
39 for (int x = 0; x < width; x++, p++) | |
40 { | |
41 *p = y; | |
42 } | |
43 } | |
44 | |
45 w.WriteToFile("Gray8Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale8, &image[0]); | |
46 } | |
47 | |
48 TEST(PngWriter, Gray16Pattern) | |
49 { | |
50 Orthanc::PngWriter w; | |
51 int width = 256; | |
52 int height = 256; | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
53 int pitch = width * 2 + 16; |
368 | 54 |
55 std::vector<uint8_t> image(height * pitch); | |
369
4632a044746e
simplification of the code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
368
diff
changeset
|
56 |
368 | 57 int v = 0; |
58 for (int y = 0; y < height; y++) | |
59 { | |
60 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch); | |
61 for (int x = 0; x < width; x++, p++, v++) | |
62 { | |
63 *p = v; | |
64 } | |
65 } | |
66 | |
67 w.WriteToFile("Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]); | |
68 } |