Mercurial > hg > orthanc-stone
comparison Applications/Sdl/SdlOrthancSurface.cpp @ 214:1c5a47dda299
SdlOrthancSurface
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 01 Jun 2018 18:33:34 +0200 |
parents | |
children | b70e9be013e4 |
comparison
equal
deleted
inserted
replaced
213:f753a7e15a73 | 214:1c5a47dda299 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "SdlOrthancSurface.h" | |
23 | |
24 #if ORTHANC_ENABLE_SDL == 1 | |
25 | |
26 #include <Core/Logging.h> | |
27 #include <Core/OrthancException.h> | |
28 #include <Core/Images/Image.h> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 SdlOrthancSurface::SdlOrthancSurface(SdlWindow& window) : | |
33 window_(window), | |
34 sdlSurface_(NULL) | |
35 { | |
36 } | |
37 | |
38 | |
39 SdlOrthancSurface::~SdlOrthancSurface() | |
40 { | |
41 if (sdlSurface_) | |
42 { | |
43 SDL_FreeSurface(sdlSurface_); | |
44 } | |
45 } | |
46 | |
47 | |
48 void SdlOrthancSurface::SetSize(unsigned int width, | |
49 unsigned int height) | |
50 { | |
51 if (image_.get() == NULL || | |
52 image_->GetWidth() != width || | |
53 image_->GetHeight() != height) | |
54 { | |
55 image_.reset(new Orthanc::Image(Orthanc::PixelFormat_BGRA32, width, height, true)); // (*) | |
56 | |
57 if (image_->GetPitch() != image_->GetWidth() * 4) | |
58 { | |
59 // This should have been ensured by setting "forceMinimalPitch" to "true" (*) | |
60 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
61 } | |
62 | |
63 // TODO Big endian? | |
64 static const uint32_t rmask = 0x00ff0000; | |
65 static const uint32_t gmask = 0x0000ff00; | |
66 static const uint32_t bmask = 0x000000ff; | |
67 | |
68 if (sdlSurface_) | |
69 { | |
70 SDL_FreeSurface(sdlSurface_); | |
71 } | |
72 | |
73 sdlSurface_ = SDL_CreateRGBSurfaceFrom(image_->GetBuffer(), width, height, 32, | |
74 image_->GetPitch(), rmask, gmask, bmask, 0); | |
75 if (!sdlSurface_) | |
76 { | |
77 LOG(ERROR) << "Cannot create a SDL surface from a Orthanc surface"; | |
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
79 } | |
80 } | |
81 } | |
82 | |
83 | |
84 Orthanc::ImageAccessor& SdlOrthancSurface::GetImage() | |
85 { | |
86 if (image_.get() == NULL) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
89 } | |
90 | |
91 return *image_; | |
92 } | |
93 | |
94 | |
95 void SdlOrthancSurface::Render() | |
96 { | |
97 if (image_.get() == NULL) | |
98 { | |
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
100 } | |
101 | |
102 window_.Render(sdlSurface_); | |
103 } | |
104 } | |
105 | |
106 #endif |