comparison Framework/Algorithms/TranscodeTileCommand.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 "TranscodeTileCommand.h"
22
23 #include "../Orthanc/Core/OrthancException.h"
24 #include "../Orthanc/Core/Logging.h"
25
26 #include <cassert>
27
28 namespace OrthancWSI
29 {
30 TranscodeTileCommand::TranscodeTileCommand(IPyramidWriter& target,
31 ITiledPyramid& source,
32 unsigned int level,
33 unsigned int x,
34 unsigned int y,
35 unsigned int countTilesX,
36 unsigned int countTilesY,
37 const DicomizerParameters& parameters) :
38 target_(target),
39 source_(source, level, target.GetTileWidth(), target.GetTileHeight(), parameters),
40 level_(level),
41 x_(x),
42 y_(y),
43 countTilesX_(countTilesX),
44 countTilesY_(countTilesY)
45 {
46 assert(x_ + countTilesX_ <= target_.GetCountTilesX(level_) &&
47 y_ + countTilesY_ <= target_.GetCountTilesY(level_));
48
49 if (target.GetPixelFormat() != source.GetPixelFormat())
50 {
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
52 }
53 }
54
55
56 bool TranscodeTileCommand::Execute()
57 {
58 for (unsigned int x = x_; x < x_ + countTilesX_; x++)
59 {
60 for (unsigned int y = y_; y < y_ + countTilesY_; y++)
61 {
62 LOG(INFO) << "Adding tile (" << x << "," << y << ") at level " << level_;
63 const std::string* rawTile = source_.GetRawTile(x, y);
64
65 if (rawTile != NULL)
66 {
67 // Simple transcoding
68 target_.WriteRawTile(*rawTile, source_.GetImageCompression(), level_, x, y);
69 }
70 else
71 {
72 Orthanc::ImageAccessor tile = source_.GetDecodedTile(x, y);
73
74 // Re-encoding the file
75 target_.EncodeTile(tile, level_, x, y);
76 }
77 }
78 }
79
80 return true;
81 }
82
83
84 void TranscodeTileCommand::PrepareBagOfTasks(Orthanc::BagOfTasks& tasks,
85 IPyramidWriter& target,
86 ITiledPyramid& source,
87 const DicomizerParameters& parameters)
88 {
89 const unsigned int stepX = source.GetTileWidth() / target.GetTileWidth();
90 const unsigned int stepY = source.GetTileHeight() / target.GetTileHeight();
91 assert(stepX >= 1 && stepY >= 1);
92
93 for (unsigned int level = 0; level < source.GetLevelCount(); level++)
94 {
95 const unsigned int targetCountTilesX = target.GetCountTilesX(level);
96 const unsigned int targetCountTilesY = target.GetCountTilesY(level);
97
98 for (unsigned int y = 0; y < targetCountTilesY; y += stepY)
99 {
100 unsigned int cy = stepY;
101 if (y + cy > targetCountTilesY)
102 {
103 cy = targetCountTilesY - y;
104 }
105
106 for (unsigned int x = 0; x < targetCountTilesX; x += stepX)
107 {
108 unsigned int cx = stepX;
109 if (x + cx > targetCountTilesX)
110 {
111 cx = targetCountTilesX - x;
112 }
113
114 tasks.Push(new TranscodeTileCommand
115 (target, source, level, x, y, cx, cy, parameters));
116 }
117 }
118 }
119 }
120 }