Mercurial > hg > orthanc-stone
annotate Applications/Sdl/SdlOrthancSurface.cpp @ 1347:bfd77672d825 broker
Moved Application/Samples/* to Application/Samples/Deprecated/*
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 07 Apr 2020 14:29:01 +0200 |
parents | 7ec8fea061b9 |
children |
rev | line source |
---|---|
214 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
214 | 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 | |
1198
4cc997207d8a
fix compatibility between SDL and DCMTK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
30 #include <SDL_render.h> |
4cc997207d8a
fix compatibility between SDL and DCMTK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
31 |
214 | 32 namespace OrthancStone |
33 { | |
34 SdlOrthancSurface::SdlOrthancSurface(SdlWindow& window) : | |
35 window_(window), | |
36 sdlSurface_(NULL) | |
37 { | |
38 } | |
39 | |
40 | |
41 SdlOrthancSurface::~SdlOrthancSurface() | |
42 { | |
43 if (sdlSurface_) | |
44 { | |
45 SDL_FreeSurface(sdlSurface_); | |
46 } | |
47 } | |
48 | |
49 | |
50 void SdlOrthancSurface::SetSize(unsigned int width, | |
51 unsigned int height) | |
52 { | |
53 if (image_.get() == NULL || | |
54 image_->GetWidth() != width || | |
55 image_->GetHeight() != height) | |
56 { | |
57 image_.reset(new Orthanc::Image(Orthanc::PixelFormat_BGRA32, width, height, true)); // (*) | |
58 | |
59 if (image_->GetPitch() != image_->GetWidth() * 4) | |
60 { | |
61 // This should have been ensured by setting "forceMinimalPitch" to "true" (*) | |
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
63 } | |
64 | |
65 // TODO Big endian? | |
66 static const uint32_t rmask = 0x00ff0000; | |
67 static const uint32_t gmask = 0x0000ff00; | |
68 static const uint32_t bmask = 0x000000ff; | |
69 | |
70 if (sdlSurface_) | |
71 { | |
72 SDL_FreeSurface(sdlSurface_); | |
73 } | |
74 | |
75 sdlSurface_ = SDL_CreateRGBSurfaceFrom(image_->GetBuffer(), width, height, 32, | |
76 image_->GetPitch(), rmask, gmask, bmask, 0); | |
77 if (!sdlSurface_) | |
78 { | |
79 LOG(ERROR) << "Cannot create a SDL surface from a Orthanc surface"; | |
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
81 } | |
82 } | |
83 } | |
84 | |
85 | |
86 Orthanc::ImageAccessor& SdlOrthancSurface::GetImage() | |
87 { | |
88 if (image_.get() == NULL) | |
89 { | |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
91 } | |
92 | |
93 return *image_; | |
94 } | |
95 | |
96 | |
97 void SdlOrthancSurface::Render() | |
98 { | |
99 if (image_.get() == NULL) | |
100 { | |
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
102 } | |
103 | |
104 window_.Render(sdlSurface_); | |
105 } | |
106 } | |
107 | |
108 #endif |