# HG changeset patch # User Sebastien Jodogne # Date 1527870814 -7200 # Node ID 1c5a47dda2999af543ff4fa466f71aa963b08c65 # Parent f753a7e15a73350d9296629c8742a4127042d459 SdlOrthancSurface diff -r f753a7e15a73 -r 1c5a47dda299 Applications/IBasicApplication.cpp --- a/Applications/IBasicApplication.cpp Fri Jun 01 18:09:09 2018 +0200 +++ b/Applications/IBasicApplication.cpp Fri Jun 01 18:33:34 2018 +0200 @@ -87,7 +87,7 @@ Orthanc::Logging::Initialize(); Orthanc::HttpClient::InitializeOpenSsl(); Orthanc::HttpClient::GlobalInitialize(); - SdlEngine::GlobalInitialize(); + SdlWindow::GlobalInitialize(); /****************************************************************** @@ -280,7 +280,7 @@ * Finalize all the subcomponents of Orthanc Stone ******************************************************************/ - SdlEngine::GlobalFinalize(); + SdlWindow::GlobalFinalize(); Orthanc::HttpClient::GlobalFinalize(); Orthanc::HttpClient::FinalizeOpenSsl(); diff -r f753a7e15a73 -r 1c5a47dda299 Applications/Sdl/SdlEngine.cpp --- a/Applications/Sdl/SdlEngine.cpp Fri Jun 01 18:09:09 2018 +0200 +++ b/Applications/Sdl/SdlEngine.cpp Fri Jun 01 18:33:34 2018 +0200 @@ -269,18 +269,6 @@ SDL_Delay(1); } } - - - void SdlEngine::GlobalInitialize() - { - SDL_Init(SDL_INIT_VIDEO); - } - - - void SdlEngine::GlobalFinalize() - { - SDL_Quit(); - } } #endif diff -r f753a7e15a73 -r 1c5a47dda299 Applications/Sdl/SdlEngine.h --- a/Applications/Sdl/SdlEngine.h Fri Jun 01 18:09:09 2018 +0200 +++ b/Applications/Sdl/SdlEngine.h Fri Jun 01 18:33:34 2018 +0200 @@ -57,10 +57,6 @@ } void Run(); - - static void GlobalInitialize(); - - static void GlobalFinalize(); }; } diff -r f753a7e15a73 -r 1c5a47dda299 Applications/Sdl/SdlOrthancSurface.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlOrthancSurface.cpp Fri Jun 01 18:33:34 2018 +0200 @@ -0,0 +1,106 @@ +/** + * Stone of Orthanc + * 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 . + **/ + + +#include "SdlOrthancSurface.h" + +#if ORTHANC_ENABLE_SDL == 1 + +#include +#include +#include + +namespace OrthancStone +{ + SdlOrthancSurface::SdlOrthancSurface(SdlWindow& window) : + window_(window), + sdlSurface_(NULL) + { + } + + + SdlOrthancSurface::~SdlOrthancSurface() + { + if (sdlSurface_) + { + SDL_FreeSurface(sdlSurface_); + } + } + + + void SdlOrthancSurface::SetSize(unsigned int width, + unsigned int height) + { + if (image_.get() == NULL || + image_->GetWidth() != width || + image_->GetHeight() != height) + { + image_.reset(new Orthanc::Image(Orthanc::PixelFormat_BGRA32, width, height, true)); // (*) + + if (image_->GetPitch() != image_->GetWidth() * 4) + { + // This should have been ensured by setting "forceMinimalPitch" to "true" (*) + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + + // 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(image_->GetBuffer(), width, height, 32, + image_->GetPitch(), rmask, gmask, bmask, 0); + if (!sdlSurface_) + { + LOG(ERROR) << "Cannot create a SDL surface from a Orthanc surface"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } + } + + + Orthanc::ImageAccessor& SdlOrthancSurface::GetImage() + { + if (image_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + + return *image_; + } + + + void SdlOrthancSurface::Render() + { + if (image_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + + window_.Render(sdlSurface_); + } +} + +#endif diff -r f753a7e15a73 -r 1c5a47dda299 Applications/Sdl/SdlOrthancSurface.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Applications/Sdl/SdlOrthancSurface.h Fri Jun 01 18:33:34 2018 +0200 @@ -0,0 +1,54 @@ +/** + * Stone of Orthanc + * 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 . + **/ + + +#pragma once + +#if ORTHANC_ENABLE_SDL == 1 + +#include "SdlWindow.h" + +#include +#include + +namespace OrthancStone +{ + class SdlOrthancSurface : public boost::noncopyable + { + private: + std::auto_ptr image_; + SdlWindow& window_; + SDL_Surface* sdlSurface_; + + public: + SdlOrthancSurface(SdlWindow& window); + + ~SdlOrthancSurface(); + + void SetSize(unsigned int width, + unsigned int height); + + Orthanc::ImageAccessor& GetImage(); + + void Render(); + }; +} + +#endif diff -r f753a7e15a73 -r 1c5a47dda299 Applications/Sdl/SdlWindow.cpp --- a/Applications/Sdl/SdlWindow.cpp Fri Jun 01 18:09:09 2018 +0200 +++ b/Applications/Sdl/SdlWindow.cpp Fri Jun 01 18:33:34 2018 +0200 @@ -26,6 +26,8 @@ #include #include +#include + namespace OrthancStone { SdlWindow::SdlWindow(const char* title, @@ -145,6 +147,22 @@ maximized_ = true; } } + + + void SdlWindow::GlobalInitialize() + { + if (SDL_Init(SDL_INIT_VIDEO) != 0) + { + LOG(ERROR) << "Cannot initialize SDL"; + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); + } + } + + + void SdlWindow::GlobalFinalize() + { + SDL_Quit(); + } } #endif diff -r f753a7e15a73 -r 1c5a47dda299 Applications/Sdl/SdlWindow.h --- a/Applications/Sdl/SdlWindow.h Fri Jun 01 18:09:09 2018 +0200 +++ b/Applications/Sdl/SdlWindow.h Fri Jun 01 18:33:34 2018 +0200 @@ -51,6 +51,10 @@ void Render(SDL_Surface* surface); void ToggleMaximize(); + + static void GlobalInitialize(); + + static void GlobalFinalize(); }; } diff -r f753a7e15a73 -r 1c5a47dda299 Resources/CMake/OrthancStoneConfiguration.cmake --- a/Resources/CMake/OrthancStoneConfiguration.cmake Fri Jun 01 18:09:09 2018 +0200 +++ b/Resources/CMake/OrthancStoneConfiguration.cmake Fri Jun 01 18:33:34 2018 +0200 @@ -147,6 +147,7 @@ ${ORTHANC_STONE_DIR}/Applications/IBasicApplication.cpp ${ORTHANC_STONE_DIR}/Applications/Sdl/SdlEngine.cpp ${ORTHANC_STONE_DIR}/Applications/Sdl/SdlCairoSurface.cpp + ${ORTHANC_STONE_DIR}/Applications/Sdl/SdlOrthancSurface.cpp ${ORTHANC_STONE_DIR}/Applications/Sdl/SdlWindow.cpp ) endif()