Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/PixelTestPatterns.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Toolbox/PixelTestPatterns.h@30deba7bc8e2 |
children | 8563ea5d8ae4 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 // PixelTestPatterns.h | |
22 | |
23 #pragma once | |
24 | |
25 #include "../StoneException.h" | |
26 | |
27 #include <Images/ImageAccessor.h> | |
28 | |
29 #include <string> | |
30 #include <stdint.h> | |
31 #include <math.h> | |
32 | |
33 namespace OrthancStone | |
34 { | |
35 namespace PixelTestPatterns | |
36 { | |
37 template<typename T, typename U> | |
38 inline uint8_t byteAddClip(T v1, U v2) | |
39 { | |
40 double tmp = static_cast<double>(v1) + static_cast<double>(v2); | |
41 if (tmp > 255.0) | |
42 tmp = 255; | |
43 if (tmp < 0.0) | |
44 tmp = 0; | |
45 return static_cast<uint8_t>(tmp+0.5); | |
46 } | |
47 | |
48 // fills the area with a horizontal gradient. | |
49 // leftmost pixels are filled with r0 g0 b0 | |
50 // rightmost pixels are filled with r1 g1 b1 | |
51 // linear interpolation in-between | |
52 inline void fillWithHGradient(Orthanc::ImageAccessor& target, | |
53 uint8_t r0, uint8_t g0, uint8_t b0, | |
54 uint8_t r1, uint8_t g1, uint8_t b1) | |
55 { | |
56 if (target.GetFormat() != Orthanc::PixelFormat_RGBA32) { | |
57 ORTHANC_ASSERT(false, "Wrong pixel format"); | |
58 } | |
59 const unsigned int width = target.GetWidth(); | |
60 const unsigned int height = target.GetHeight(); | |
61 | |
62 ORTHANC_ASSERT(width > 0); | |
63 ORTHANC_ASSERT(height > 0); | |
64 | |
65 double invWidth = 1.0 / static_cast<double>(target.GetWidth()); | |
66 double rIncr = (static_cast<double>(r1) - static_cast<double>(r0))* invWidth; | |
67 double gIncr = (static_cast<double>(g1) - static_cast<double>(g0))* invWidth; | |
68 double bIncr = (static_cast<double>(b1) - static_cast<double>(b0))* invWidth; | |
69 | |
70 for (unsigned int y = 0; y < height; y++) | |
71 { | |
72 uint8_t r = r0; | |
73 uint8_t g = g0; | |
74 uint8_t b = b0; | |
75 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
76 for (unsigned int x = 0; x < width; x++) | |
77 { | |
78 q[0] = r; | |
79 q[1] = g; | |
80 q[2] = b; | |
81 q[3] = 255; | |
82 r = byteAddClip(r, rIncr); | |
83 g = byteAddClip(g, gIncr); | |
84 b = byteAddClip(b, bIncr); | |
85 q += 4; | |
86 } | |
87 } | |
88 } | |
89 | |
90 inline void fillWithVGradient(Orthanc::ImageAccessor& target, | |
91 uint8_t r0, uint8_t g0, uint8_t b0, | |
92 uint8_t r1, uint8_t g1, uint8_t b1) | |
93 { | |
94 if (target.GetFormat() != Orthanc::PixelFormat_RGBA32) { | |
95 ORTHANC_ASSERT(false, "Wrong pixel format"); | |
96 } | |
97 const unsigned int width = target.GetWidth(); | |
98 const unsigned int height = target.GetHeight(); | |
99 | |
100 ORTHANC_ASSERT(width > 0); | |
101 ORTHANC_ASSERT(height > 0); | |
102 | |
103 double invHeight = 1.0 / static_cast<double>(target.GetHeight()); | |
104 double rIncr = (static_cast<double>(r1) - static_cast<double>(r0))* invHeight; | |
105 double gIncr = (static_cast<double>(g1) - static_cast<double>(g0))* invHeight; | |
106 double bIncr = (static_cast<double>(b1) - static_cast<double>(b0))* invHeight; | |
107 | |
108 uint8_t r = r0; | |
109 uint8_t g = g0; | |
110 uint8_t b = b0; | |
111 for (unsigned int y = 0; y < height; y++) | |
112 { | |
113 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); | |
114 for (unsigned int x = 0; x < width; x++) | |
115 { | |
116 q[0] = r; | |
117 q[1] = g; | |
118 q[2] = b; | |
119 q[3] = 255; | |
120 q += 4; | |
121 } | |
122 r = byteAddClip(r, rIncr); | |
123 g = byteAddClip(g, gIncr); | |
124 b = byteAddClip(b, bIncr); | |
125 } | |
126 } | |
127 | |
128 } | |
129 } | |
130 |