annotate Applications/Sdl/SdlOrthancSurface.cpp @ 879:12b591d5d63c am-dev

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