annotate OrthancStone/Sources/Oracle/GetOrthancImageCommand.cpp @ 1795:39673d351ef2

fix build
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 May 2021 09:57:14 +0200
parents 9ac2a65d4172
children 3889ae96d2e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1739
9ac2a65d4172 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1572
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "GetOrthancImageCommand.h"
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1352
diff changeset
25 #include <Images/JpegReader.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1352
diff changeset
26 #include <Images/PamReader.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1352
diff changeset
27 #include <Images/PngReader.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1352
diff changeset
28 #include <OrthancException.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1352
diff changeset
29 #include <Toolbox.h>
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 GetOrthancImageCommand::GetOrthancImageCommand() :
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 uri_("/"),
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 846
diff changeset
35 timeout_(600),
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
36 hasExpectedFormat_(false),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
37 expectedFormat_(Orthanc::PixelFormat_Grayscale8)
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 void GetOrthancImageCommand::SetExpectedPixelFormat(Orthanc::PixelFormat format)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 hasExpectedFormat_ = true;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 expectedFormat_ = format;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
1152
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
49 static std::string GetFormatSuffix(Orthanc::PixelFormat pixelFormat)
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 switch (pixelFormat)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 case Orthanc::PixelFormat_RGB24:
1152
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
54 return "preview";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 case Orthanc::PixelFormat_Grayscale16:
1152
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
57 return "image-uint16";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 case Orthanc::PixelFormat_SignedGrayscale16:
1152
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
60 return "image-int16";
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 default:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
1152
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
67
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
68 void GetOrthancImageCommand::SetInstanceUri(const std::string& instance,
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
69 Orthanc::PixelFormat pixelFormat)
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
70 {
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
71 uri_ = "/instances/" + instance + "/" + GetFormatSuffix(pixelFormat);
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
72 }
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
73
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
74
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
75 void GetOrthancImageCommand::SetFrameUri(const std::string& instance,
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
76 unsigned int frame,
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
77 Orthanc::PixelFormat pixelFormat)
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
78 {
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
79 uri_ = ("/instances/" + instance + "/frames/" +
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
80 boost::lexical_cast<std::string>(frame) + "/" + GetFormatSuffix(pixelFormat));
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
81 }
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
82
78b8bfe154bc GetOrthancImageCommand::SetFrameUri()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
83
1134
87fbeb823375 allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
84 void GetOrthancImageCommand::ProcessHttpAnswer(boost::weak_ptr<IObserver> receiver,
87fbeb823375 allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
85 IMessageEmitter& emitter,
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 const std::string& answer,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 const HttpHeaders& answerHeaders) const
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
1255
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
89 for (HttpHeaders::const_iterator it = answerHeaders.begin(); it != answerHeaders.end(); ++it)
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
90 {
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
91 std::string key = Orthanc::Toolbox::StripSpaces(it->first);
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
92 Orthanc::Toolbox::ToLowerCase(key);
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
93
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
94 if (key == "content-disposition" &&
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
95 it->second == "filename=\"unsupported.png\"")
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
96 {
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
97 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat,
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
98 "Orthanc cannot decode this image");
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
99 }
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
100 }
c1c83c1fb837 GetOrthancImageCommand: handling of unsupported formats
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1152
diff changeset
101
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 Orthanc::MimeType contentType = Orthanc::MimeType_Binary;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 for (HttpHeaders::const_iterator it = answerHeaders.begin();
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 it != answerHeaders.end(); ++it)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 std::string s;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 Orthanc::Toolbox::ToLowerCase(s, it->first);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 if (s == "content-type")
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 contentType = Orthanc::StringToMimeType(it->second);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 break;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
117 std::unique_ptr<Orthanc::ImageAccessor> image;
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 switch (contentType)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 case Orthanc::MimeType_Png:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 image.reset(new Orthanc::PngReader);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(answer);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 break;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 case Orthanc::MimeType_Pam:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
1352
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
130 #ifdef __EMSCRIPTEN__
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
131 // "true" means we ask the PamReader to make an extra copy so that
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
132 // the resulting Orthanc::ImageAccessor is aligned (as malloc is).
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
133 // Indeed, even though alignment is not required in Web Assembly,
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
134 // Emscripten seems to check it and bail out if addresses are "odd"
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
135 image.reset(new Orthanc::PamReader(true));
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
136 #else
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
137 // potentially unaligned, with is faster and consumes less heap memory
1572
1b3039384972 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
138 image.reset(new Orthanc::PamReader(false));
1352
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
139 #endif
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(answer);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 break;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 case Orthanc::MimeType_Jpeg:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 image.reset(new Orthanc::JpegReader);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 dynamic_cast<Orthanc::JpegReader&>(*image).ReadFromMemory(answer);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 break;
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 default:
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 "Unsupported HTTP Content-Type for an image: " +
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 std::string(Orthanc::EnumerationToString(contentType)));
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 if (hasExpectedFormat_)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 if (expectedFormat_ == Orthanc::PixelFormat_SignedGrayscale16 &&
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 image->GetFormat() == Orthanc::PixelFormat_Grayscale16)
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 if (expectedFormat_ != image->GetFormat())
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
1352
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
171 //{
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
172 // // DEBUG DISPLAY IMAGE PROPERTIES BGO 2020-04-11
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
173 // const Orthanc::ImageAccessor& source = *image;
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
174 // const void* sourceBuffer = source.GetConstBuffer();
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
175 // intptr_t sourceBufferInt = reinterpret_cast<intptr_t>(sourceBuffer);
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
176 // int sourceWidth = source.GetWidth();
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
177 // int sourceHeight = source.GetHeight();
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
178 // int sourcePitch = source.GetPitch();
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
179
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
180 // // TODO: turn error into trace below
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
181 // LOG(ERROR) << "GetOrthancImageCommand::ProcessHttpAnswer | source:"
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
182 // << " W = " << sourceWidth << " H = " << sourceHeight
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
183 // << " P = " << sourcePitch << " B = " << sourceBufferInt
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
184 // << " B % 4 == " << sourceBufferInt % 4;
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
185 //}
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
186
159708a38af4 Enforce alignment when using PamReader to retrieve REST images,
Benjamin Golinvaux <bgo@osimis.io>
parents: 1300
diff changeset
187
1134
87fbeb823375 allocating messages from oracle commands on the stack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
188 SuccessMessage message(*this, *image, contentType);
746
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 emitter.EmitMessage(receiver, message);
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
d716bfb3e07c reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }