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
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
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
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
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
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace OrthancStone
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 SdlOrthancSurface::SdlOrthancSurface(SdlWindow& window) :
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 window_(window),
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 sdlSurface_(NULL)
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
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 SdlOrthancSurface::~SdlOrthancSurface()
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 if (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 SDL_FreeSurface(sdlSurface_);
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
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 void SdlOrthancSurface::SetSize(unsigned int width,
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 unsigned int height)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 if (image_.get() == NULL ||
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 image_->GetWidth() != width ||
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 image_->GetHeight() != height)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 image_.reset(new Orthanc::Image(Orthanc::PixelFormat_BGRA32, width, height, true)); // (*)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if (image_->GetPitch() != image_->GetWidth() * 4)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 // This should have been ensured by setting "forceMinimalPitch" to "true" (*)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 // TODO Big endian?
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 static const uint32_t rmask = 0x00ff0000;
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 static const uint32_t gmask = 0x0000ff00;
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 static const uint32_t bmask = 0x000000ff;
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if (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 SDL_FreeSurface(sdlSurface_);
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 sdlSurface_ = SDL_CreateRGBSurfaceFrom(image_->GetBuffer(), width, height, 32,
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 image_->GetPitch(), rmask, gmask, bmask, 0);
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (!sdlSurface_)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 LOG(ERROR) << "Cannot create a SDL surface from a Orthanc surface";
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
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
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 Orthanc::ImageAccessor& SdlOrthancSurface::GetImage()
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 if (image_.get() == NULL)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 return *image_;
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 void SdlOrthancSurface::Render()
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 if (image_.get() == NULL)
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 window_.Render(sdlSurface_);
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
1c5a47dda299 SdlOrthancSurface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 #endif