comparison UnitTests/Png.cpp @ 454:6f47a4262618

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Jul 2013 15:18:33 +0200
parents UnitTests/PngWriter.cpp@4632a044746e
children 238a0c99ced2
comparison
equal deleted inserted replaced
453:30086c1aca30 454:6f47a4262618
1 #include "gtest/gtest.h"
2
3 #include <stdint.h>
4 #include "../Core/FileFormats/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;
53 int pitch = width * 2 + 16;
54
55 std::vector<uint8_t> image(height * pitch);
56
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 }