Mercurial > hg > orthanc-wsi
comparison Framework/Inputs/DecodedTiledPyramid.cpp @ 0:4a7a53257c7d
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 22 Oct 2016 21:48:33 +0200 |
parents | |
children | 7a88c614be04 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a7a53257c7d |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU Affero General Public License | |
8 * as published by the Free Software Foundation, either version 3 of | |
9 * the License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Affero General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Affero General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
21 #include "DecodedTiledPyramid.h" | |
22 | |
23 #include "../ImageToolbox.h" | |
24 | |
25 #include <memory> | |
26 #include <cassert> | |
27 | |
28 namespace OrthancWSI | |
29 { | |
30 DecodedTiledPyramid::DecodedTiledPyramid() | |
31 { | |
32 SetBackgroundColor(255, 255, 255); | |
33 } | |
34 | |
35 | |
36 void DecodedTiledPyramid::SetBackgroundColor(uint8_t red, | |
37 uint8_t green, | |
38 uint8_t blue) | |
39 { | |
40 backgroundColor_[0] = red; | |
41 backgroundColor_[1] = green; | |
42 backgroundColor_[2] = blue; | |
43 } | |
44 | |
45 | |
46 void DecodedTiledPyramid::GetBackgroundColor(uint8_t& red, | |
47 uint8_t& green, | |
48 uint8_t& blue) const | |
49 { | |
50 red = backgroundColor_[0]; | |
51 green = backgroundColor_[1]; | |
52 blue = backgroundColor_[2]; | |
53 } | |
54 | |
55 | |
56 Orthanc::ImageAccessor* DecodedTiledPyramid::DecodeTile(unsigned int level, | |
57 unsigned int tileX, | |
58 unsigned int tileY) | |
59 { | |
60 unsigned int x = tileX * GetTileWidth(); | |
61 unsigned int y = tileY * GetTileHeight(); | |
62 | |
63 std::auto_ptr<Orthanc::ImageAccessor> tile | |
64 (ImageToolbox::Allocate(GetPixelFormat(), GetTileWidth(), GetTileHeight())); | |
65 | |
66 if (x >= GetLevelWidth(level) || | |
67 y >= GetLevelHeight(level)) // (*) | |
68 { | |
69 ImageToolbox::Set(*tile, backgroundColor_[0], backgroundColor_[1], backgroundColor_[2]); | |
70 return tile.release(); | |
71 } | |
72 | |
73 bool fit = true; | |
74 unsigned int regionWidth; | |
75 if (x + GetTileWidth() <= GetLevelWidth(level)) | |
76 { | |
77 regionWidth = GetTileWidth(); | |
78 } | |
79 else | |
80 { | |
81 assert(GetLevelWidth(level) >= x); // This results from (*) | |
82 regionWidth = GetLevelWidth(level) - x; | |
83 fit = false; | |
84 } | |
85 | |
86 unsigned int regionHeight; | |
87 if (y + GetTileHeight() <= GetLevelHeight(level)) | |
88 { | |
89 regionHeight = GetTileHeight(); | |
90 } | |
91 else | |
92 { | |
93 assert(GetLevelHeight(level) >= y); // This results from (*) | |
94 regionHeight = GetLevelHeight(level) - y; | |
95 fit = false; | |
96 } | |
97 | |
98 if (fit) | |
99 { | |
100 // The tile entirely lies inside the image | |
101 ReadRegion(*tile, level, x, y); | |
102 } | |
103 else | |
104 { | |
105 // The tile exceeds the size of image, decode it to a temporary buffer | |
106 std::auto_ptr<Orthanc::ImageAccessor> cropped | |
107 (ImageToolbox::Allocate(GetPixelFormat(), regionWidth, regionHeight)); | |
108 ReadRegion(*cropped, level, x, y); | |
109 | |
110 // Create a white tile, and fill it with the cropped content | |
111 ImageToolbox::Set(*tile, backgroundColor_[0], backgroundColor_[1], backgroundColor_[2]); | |
112 ImageToolbox::Embed(*tile, *cropped, 0, 0); | |
113 } | |
114 | |
115 return tile.release(); | |
116 } | |
117 } |