comparison UnitTests/PngWriter.cpp @ 368:80011cd589e6

support of rgb images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 18 Feb 2013 16:07:28 +0100
parents
children 4632a044746e
comparison
equal deleted inserted replaced
367:301f2831489c 368:80011cd589e6
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;
53 int pitch = width * 2 + 17;
54
55 std::vector<uint8_t> image(height * pitch);
56 int v = 0;
57 for (int y = 0; y < height; y++)
58 {
59 uint16_t *p = reinterpret_cast<uint16_t*>(&image[0] + y * pitch);
60 for (int x = 0; x < width; x++, p++, v++)
61 {
62 *p = v;
63 }
64 }
65
66 w.WriteToFile("Gray16Pattern.png", width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
67 }