Mercurial > hg > orthanc-wsi
changeset 154:32a94bbb7d05
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Oct 2018 12:12:39 +0200 |
parents | b798d200ac90 (diff) a0a3530ff69c (current diff) |
children | 1304498491e4 |
files | Framework/Algorithms/PyramidReader.cpp Framework/Algorithms/PyramidReader.h Framework/Algorithms/ReconstructPyramidCommand.cpp Framework/Algorithms/TranscodeTileCommand.cpp Framework/ImageToolbox.cpp Framework/Inputs/SingleLevelDecodedPyramid.cpp Framework/Inputs/SingleLevelDecodedPyramid.h Framework/Jpeg2000Reader.h Framework/MultiThreading/BagOfTasks.h Framework/MultiThreading/ICommand.h Framework/Outputs/InMemoryTiledImage.cpp ViewerPlugin/CMakeLists.txt ViewerPlugin/Plugin.cpp |
diffstat | 12 files changed, 91 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Algorithms/PyramidReader.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Algorithms/PyramidReader.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -61,9 +61,10 @@ assert(tileY_ * that_.sourceTileHeight_ < that_.levelHeight_); unsigned int bottom = that_.levelHeight_ - tileY_ * that_.sourceTileHeight_; - Orthanc::ImageAccessor a = decoded_->GetRegion(0, bottom, - that_.sourceTileWidth_, - that_.sourceTileHeight_ - bottom); + Orthanc::ImageAccessor a; + decoded_->GetRegion(a, 0, bottom, + that_.sourceTileWidth_, + that_.sourceTileHeight_ - bottom); ImageToolbox::Set(a, that_.parameters_.GetBackgroundColorRed(), that_.parameters_.GetBackgroundColorGreen(), @@ -77,9 +78,10 @@ assert(tileX_ * that_.sourceTileWidth_ < that_.levelWidth_); unsigned int right = that_.levelWidth_ - tileX_ * that_.sourceTileWidth_; - Orthanc::ImageAccessor a = decoded_->GetRegion(right, 0, - that_.sourceTileWidth_ - right, - that_.sourceTileHeight_); + Orthanc::ImageAccessor a; + decoded_->GetRegion(a, right, 0, + that_.sourceTileWidth_ - right, + that_.sourceTileHeight_); ImageToolbox::Set(a, that_.parameters_.GetBackgroundColorRed(), that_.parameters_.GetBackgroundColorGreen(), @@ -283,37 +285,37 @@ } - Orthanc::ImageAccessor PyramidReader::GetDecodedTile(unsigned int tileX, - unsigned int tileY) + void PyramidReader::GetDecodedTile(Orthanc::ImageAccessor& target, + unsigned int tileX, + unsigned int tileY) { if (tileX * targetTileWidth_ >= levelWidth_ || tileY * targetTileHeight_ >= levelHeight_) { // Accessing a tile out of the source image - return GetOutsideTile(); + GetOutsideTile().GetReadOnlyAccessor(target); } + else + { + SourceTile& source = AccessSourceTile(MapTargetToSourceLocation(tileX, tileY)); + const Orthanc::ImageAccessor& tile = source.GetDecodedTile(); - SourceTile& source = AccessSourceTile(MapTargetToSourceLocation(tileX, tileY)); - const Orthanc::ImageAccessor& tile = source.GetDecodedTile(); + CheckTileSize(tile); - CheckTileSize(tile); - - assert(sourceTileWidth_ % targetTileWidth_ == 0 && - sourceTileHeight_ % targetTileHeight_ == 0); + assert(sourceTileWidth_ % targetTileWidth_ == 0 && + sourceTileHeight_ % targetTileHeight_ == 0); - unsigned int xx = tileX % (sourceTileWidth_ / targetTileWidth_); - unsigned int yy = tileY % (sourceTileHeight_ / targetTileHeight_); - - const uint8_t* bytes = - reinterpret_cast<const uint8_t*>(tile.GetConstRow(yy * targetTileHeight_)) + - GetBytesPerPixel(tile.GetFormat()) * xx * targetTileWidth_; + unsigned int xx = tileX % (sourceTileWidth_ / targetTileWidth_); + unsigned int yy = tileY % (sourceTileHeight_ / targetTileHeight_); - Orthanc::ImageAccessor region; - region.AssignReadOnly(tile.GetFormat(), - targetTileWidth_, - targetTileHeight_, - tile.GetPitch(), bytes); + const uint8_t* bytes = + reinterpret_cast<const uint8_t*>(tile.GetConstRow(yy * targetTileHeight_)) + + GetBytesPerPixel(tile.GetFormat()) * xx * targetTileWidth_; - return region; + target.AssignReadOnly(tile.GetFormat(), + targetTileWidth_, + targetTileHeight_, + tile.GetPitch(), bytes); + } } }
--- a/Framework/Algorithms/PyramidReader.h Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Algorithms/PyramidReader.h Mon Oct 08 12:12:39 2018 +0200 @@ -88,7 +88,8 @@ unsigned int tileX, unsigned int tileY); - Orthanc::ImageAccessor GetDecodedTile(unsigned int tileX, - unsigned int tileY); + void GetDecodedTile(Orthanc::ImageAccessor& target, + unsigned int tileX, + unsigned int tileY); }; }
--- a/Framework/Algorithms/ReconstructPyramidCommand.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Algorithms/ReconstructPyramidCommand.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -50,7 +50,8 @@ if (level == 0) { - result.reset(new Orthanc::ImageAccessor(source_.GetDecodedTile(x, y))); + result.reset(new Orthanc::ImageAccessor); + source_.GetDecodedTile(*result, x, y); ImageCompression compression; const std::string* rawTile = source_.GetRawTile(compression, x, y);
--- a/Framework/Algorithms/TranscodeTileCommand.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Algorithms/TranscodeTileCommand.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -73,7 +73,8 @@ } else { - Orthanc::ImageAccessor tile = source_.GetDecodedTile(x, y); + Orthanc::ImageAccessor tile; + source_.GetDecodedTile(tile, x, y); // Re-encoding the file target_.EncodeTile(tile, level_, x, y);
--- a/Framework/ImageToolbox.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/ImageToolbox.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -68,8 +68,10 @@ unsigned int h = std::min(source.GetHeight(), target.GetHeight() - y); unsigned int w = std::min(source.GetWidth(), target.GetWidth() - x); - Orthanc::ImageAccessor targetRegion = target.GetRegion(x, y, w, h); - Orthanc::ImageAccessor sourceRegion = source.GetRegion(0, 0, w, h); + Orthanc::ImageAccessor targetRegion, sourceRegion; + target.GetRegion(targetRegion, x, y, w, h); + source.GetRegion(sourceRegion, 0, 0, w, h); + Orthanc::ImageProcessing::Copy(targetRegion, sourceRegion); }
--- a/Framework/Inputs/SingleLevelDecodedPyramid.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Inputs/SingleLevelDecodedPyramid.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -32,7 +32,8 @@ unsigned int x, unsigned int y) { - Orthanc::ImageAccessor region = image_.GetRegion(x, y, target.GetWidth(), target.GetHeight()); + Orthanc::ImageAccessor region; + image_.GetRegion(region, x, y, target.GetWidth(), target.GetHeight()); ImageToolbox::Copy(target, region); }
--- a/Framework/Inputs/SingleLevelDecodedPyramid.h Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Inputs/SingleLevelDecodedPyramid.h Mon Oct 08 12:12:39 2018 +0200 @@ -35,7 +35,7 @@ protected: void SetImage(const Orthanc::ImageAccessor& image) { - image_ = image; + image.GetReadOnlyAccessor(image_); } virtual void ReadRegion(Orthanc::ImageAccessor& target,
--- a/Framework/Jpeg2000Reader.h Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Jpeg2000Reader.h Mon Oct 08 12:12:39 2018 +0200 @@ -33,9 +33,7 @@ Jpeg2000Format_Unknown }; - class Jpeg2000Reader : - public Orthanc::ImageAccessor, - public boost::noncopyable + class Jpeg2000Reader : public Orthanc::ImageAccessor { private: std::auto_ptr<Orthanc::ImageAccessor> image_;
--- a/Framework/MultiThreading/BagOfTasks.h Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/MultiThreading/BagOfTasks.h Mon Oct 08 12:12:39 2018 +0200 @@ -21,7 +21,7 @@ #pragma once -#include <Core/ICommand.h> +#include "ICommand.h" #include <list> #include <cstddef>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Framework/MultiThreading/ICommand.h Mon Oct 08 12:12:39 2018 +0200 @@ -0,0 +1,37 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include <Core/IDynamicObject.h> + +namespace Orthanc +{ + /** + * This class is the base class for the "Command" design pattern. + * http://en.wikipedia.org/wiki/Command_pattern + **/ + class ICommand : public IDynamicObject + { + public: + virtual bool Execute() = 0; + }; +}
--- a/Framework/Outputs/InMemoryTiledImage.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/Framework/Outputs/InMemoryTiledImage.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -117,7 +117,9 @@ Tiles::const_iterator it = tiles_.find(std::make_pair(tileX, tileY)); if (it != tiles_.end()) { - return new Orthanc::ImageAccessor(*it->second); + std::auto_ptr<Orthanc::ImageAccessor> result(new Orthanc::ImageAccessor); + it->second->GetReadOnlyAccessor(*result); + return result.release(); } else {
--- a/ViewerPlugin/Plugin.cpp Tue Aug 28 09:58:04 2018 +0200 +++ b/ViewerPlugin/Plugin.cpp Mon Oct 08 12:12:39 2018 +0200 @@ -28,7 +28,9 @@ #include <Core/Logging.h> #include <Core/Images/ImageProcessing.h> #include <Core/Images/PngWriter.h> +#include <Core/MultiThreading/Semaphore.h> #include <Core/OrthancException.h> +#include <Core/SystemToolbox.h> #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> #include <Plugins/Samples/Common/OrthancPluginConnection.h> @@ -40,7 +42,7 @@ std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_; std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_; -std::auto_ptr<OrthancWSI::Semaphore> transcoderSemaphore_; +std::auto_ptr<Orthanc::Semaphore> transcoderSemaphore_; static void AnswerSparseTile(OrthancPluginRestOutput* output, @@ -184,7 +186,7 @@ // decompress the raw tile std::auto_ptr<Orthanc::ImageAccessor> decoded; - OrthancWSI::Semaphore::Locker locker(*transcoderSemaphore_); + Orthanc::Semaphore::Locker locker(*transcoderSemaphore_); switch (compression) { @@ -315,14 +317,8 @@ // Limit the number of PNG transcoders to the number of available // hardware threads (e.g. number of CPUs or cores or // hyperthreading units) - unsigned int threads = boost::thread::hardware_concurrency(); - - if (threads <= 0) - { - threads = 1; - } - - transcoderSemaphore_.reset(new OrthancWSI::Semaphore(threads)); + unsigned int threads = Orthanc::SystemToolbox::GetHardwareConcurrency(); + transcoderSemaphore_.reset(new Orthanc::Semaphore(threads)); char info[1024]; sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads);