# HG changeset patch # User Sebastien Jodogne # Date 1495620488 -7200 # Node ID 6546dbcc0a7df4ad1bc2c89ec267b7bc6eb4854f # Parent ffa6dded91bdcf1ce9d598fe66d36c07807ba4fe missing file diff -r ffa6dded91bd -r 6546dbcc0a7d Applications/Sdl/SdlSurface.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlSurface.cpp Wed May 24 12:08:08 2017 +0200 @@ -0,0 +1,93 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017 Osimis, 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 . + **/ + + +#include "SdlSurface.h" + +#if ORTHANC_ENABLE_SDL == 1 + +#include "../../../Resources/Orthanc/Core/Logging.h" +#include "../../../Resources/Orthanc/Core/OrthancException.h" + +namespace OrthancStone +{ + SdlSurface::SdlSurface(SdlWindow& window) : + window_(window), + sdlSurface_(NULL) + { + } + + + SdlSurface::~SdlSurface() + { + if (sdlSurface_) + { + SDL_FreeSurface(sdlSurface_); + } + } + + + void SdlSurface::SetSize(unsigned int width, + unsigned int height) + { + if (cairoSurface_.get() == NULL || + cairoSurface_->GetWidth() != width || + cairoSurface_->GetHeight() != height) + { + cairoSurface_.reset(new CairoSurface(width, height)); + + // TODO Big endian? + static const uint32_t rmask = 0x00ff0000; + static const uint32_t gmask = 0x0000ff00; + static const uint32_t bmask = 0x000000ff; + + if (sdlSurface_) + { + SDL_FreeSurface(sdlSurface_); + } + + sdlSurface_ = SDL_CreateRGBSurfaceFrom(cairoSurface_->GetBuffer(), width, height, 32, + cairoSurface_->GetPitch(), rmask, gmask, bmask, 0); + if (!sdlSurface_) + { + LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } + } + + + void SdlSurface::Render(IViewport& viewport) + { + if (cairoSurface_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + + Orthanc::ImageAccessor target = cairoSurface_->GetAccessor(); + + if (viewport.Render(target)) + { + window_.Render(sdlSurface_); + } + } +} + +#endif diff -r ffa6dded91bd -r 6546dbcc0a7d Applications/Sdl/SdlSurface.cpp~ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlSurface.cpp~ Wed May 24 12:08:08 2017 +0200 @@ -0,0 +1,134 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017 Osimis, 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 . + **/ + + +#include "SdlBuffering.h" + +#if ORTHANC_ENABLE_SDL == 1 + +#include "../../../Resources/Orthanc/Core/Logging.h" +#include "../../../Resources/Orthanc/Core/OrthancException.h" + +namespace OrthancStone +{ + SdlBuffering::SdlBuffering() : + sdlSurface_(NULL), + pendingFrame_(false) + { + } + + + SdlBuffering::~SdlBuffering() + { + if (sdlSurface_) + { + SDL_FreeSurface(sdlSurface_); + } + } + + + void SdlBuffering::SetSize(unsigned int width, + unsigned int height, + IViewport& viewport) + { + boost::mutex::scoped_lock lock(mutex_); + + viewport.SetSize(width, height); + + if (offscreenSurface_.get() == NULL || + offscreenSurface_->GetWidth() != width || + offscreenSurface_->GetHeight() != height) + { + offscreenSurface_.reset(new CairoSurface(width, height)); + } + + if (onscreenSurface_.get() == NULL || + onscreenSurface_->GetWidth() != width || + onscreenSurface_->GetHeight() != height) + { + onscreenSurface_.reset(new CairoSurface(width, height)); + + // TODO Big endian? + static const uint32_t rmask = 0x00ff0000; + static const uint32_t gmask = 0x0000ff00; + static const uint32_t bmask = 0x000000ff; + + if (sdlSurface_) + { + SDL_FreeSurface(sdlSurface_); + } + + sdlSurface_ = SDL_CreateRGBSurfaceFrom(onscreenSurface_->GetBuffer(), width, height, 32, + onscreenSurface_->GetPitch(), rmask, gmask, bmask, 0); + if (!sdlSurface_) + { + LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } + + pendingFrame_ = false; + } + + + bool SdlBuffering::RenderOffscreen(IViewport& viewport) + { + boost::mutex::scoped_lock lock(mutex_); + + if (offscreenSurface_.get() == NULL) + { + return false; + } + + Orthanc::ImageAccessor target = offscreenSurface_->GetAccessor(); + + if (viewport.Render(target) && + !pendingFrame_) + { + pendingFrame_ = true; + return true; + } + else + { + return false; + } + } + + + void SdlBuffering::SwapToScreen(SdlWindow& window) + { + if (!pendingFrame_ || + offscreenSurface_.get() == NULL || + onscreenSurface_.get() == NULL) + { + return; + } + + { + boost::mutex::scoped_lock lock(mutex_); + onscreenSurface_->Copy(*offscreenSurface_); + } + + window.Render(sdlSurface_); + pendingFrame_ = false; + } +} + +#endif diff -r ffa6dded91bd -r 6546dbcc0a7d Applications/Sdl/SdlSurface.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlSurface.h Wed May 24 12:08:08 2017 +0200 @@ -0,0 +1,53 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017 Osimis, 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 . + **/ + + +#pragma once + +#if ORTHANC_ENABLE_SDL == 1 + +#include "SdlWindow.h" +#include "../../Framework/Viewport/CairoSurface.h" +#include "../../Framework/Viewport/IViewport.h" + +#include + +namespace OrthancStone +{ + class SdlSurface : public boost::noncopyable + { + private: + std::auto_ptr cairoSurface_; + SdlWindow& window_; + SDL_Surface* sdlSurface_; + + public: + SdlSurface(SdlWindow& window); + + ~SdlSurface(); + + void SetSize(unsigned int width, + unsigned int height); + + void Render(IViewport& viewport); + }; +} + +#endif diff -r ffa6dded91bd -r 6546dbcc0a7d Applications/Sdl/SdlSurface.h~ --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlSurface.h~ Wed May 24 12:08:08 2017 +0200 @@ -0,0 +1,52 @@ +/** + * Stone of Orthanc + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017 Osimis, 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 . + **/ + + +#pragma once + +#if ORTHANC_ENABLE_SDL == 1 + +#include "SdlWindow.h" +#include "../../Framework/Viewport/CairoSurface.h" +#include "../../Framework/Viewport/IViewport.h" + +#include + +namespace OrthancStone +{ + class SdlSurface : public boost::noncopyable + { + private: + std::auto_ptr cairoSurface_; + SDL_Surface* sdlSurface_; + + public: + SdlSurface(SdlWindow& window); + + ~SdlSurface(); + + void SetSize(unsigned int width, + unsigned int height); + + void Render(IViewport& viewport); + }; +} + +#endif diff -r ffa6dded91bd -r 6546dbcc0a7d Framework/Layers/SingleFrameRendererFactory.h --- a/Framework/Layers/SingleFrameRendererFactory.h Wed May 24 11:59:24 2017 +0200 +++ b/Framework/Layers/SingleFrameRendererFactory.h Wed May 24 12:08:08 2017 +0200 @@ -22,19 +22,16 @@ #pragma once #include "ILayerRendererFactory.h" -#include "../../Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h" +#include "../Toolbox/OrthancSlicesLoader.h" namespace OrthancStone { - class SingleFrameRendererFactory : public ILayerRendererFactory + class SingleFrameRendererFactory : + public ILayerRendererFactory, + public OrthancSlicesLoader::ICallback // TODO PImpl { private: - OrthancPlugins::IOrthancConnection& orthanc_; - std::auto_ptr dicom_; - - std::string instance_; - unsigned int frame_; - Orthanc::PixelFormat format_; + OrthancSlicesLoader loader_; public: SingleFrameRendererFactory(OrthancPlugins::IOrthancConnection& orthanc,