annotate OrthancFramework/Sources/Images/PamReader.cpp @ 4224:38d446c9ee1d

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Sep 2020 17:59:09 +0200
parents 2d5209153b32
children 9279de56a405
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
1 /**
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3487
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
6 *
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
10 * the License, or (at your option) any later version.
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
11 *
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
15 * Lesser General Public License for more details.
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4071
diff changeset
19 * <http://www.gnu.org/licenses/>.
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
20 **/
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
21
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
22
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
23 #include "../PrecompiledHeaders.h"
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
24 #include "PamReader.h"
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
25
2703
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
26 #include "../Endianness.h"
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
27 #include "../OrthancException.h"
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
28 #include "../Toolbox.h"
2703
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
29
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
30 #if ORTHANC_SANDBOXED == 0
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
31 # include "../SystemToolbox.h"
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
32 #endif
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
33
3838
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
34 #include <stdlib.h> // For malloc/free
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
35 #include <boost/algorithm/string/find.hpp>
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
36 #include <boost/lexical_cast.hpp>
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
37
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
38
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
39 namespace Orthanc
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
40 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
41 static void GetPixelFormat(PixelFormat& format,
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
42 unsigned int& bytesPerChannel,
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
43 const unsigned int& maxValue,
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
44 const unsigned int& channelCount,
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
45 const std::string& tupleType)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
46 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
47 if (tupleType == "GRAYSCALE" &&
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
48 channelCount == 1)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
49 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
50 switch (maxValue)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
51 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
52 case 255:
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
53 format = PixelFormat_Grayscale8;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
54 bytesPerChannel = 1;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
55 return;
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
56
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
57 case 65535:
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
58 format = PixelFormat_Grayscale16;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
59 bytesPerChannel = 2;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
60 return;
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
61
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
62 default:
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
63 throw OrthancException(ErrorCode_NotImplemented);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
64 }
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
65 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
66 else if (tupleType == "RGB" &&
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
67 channelCount == 3)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
68 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
69 switch (maxValue)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
70 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
71 case 255:
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
72 format = PixelFormat_RGB24;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
73 bytesPerChannel = 1;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
74 return;
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
75
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
76 case 65535:
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
77 format = PixelFormat_RGB48;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
78 bytesPerChannel = 2;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
79 return;
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
80
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
81 default:
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
82 throw OrthancException(ErrorCode_NotImplemented);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
83 }
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
84 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
85 else
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
86 {
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
87 throw OrthancException(ErrorCode_NotImplemented);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
88 }
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
89 }
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
90
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
91
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
92 typedef std::map<std::string, std::string> Parameters;
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
93
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
94
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
95 static std::string LookupStringParameter(const Parameters& parameters,
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
96 const std::string& key)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
97 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
98 Parameters::const_iterator found = parameters.find(key);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
99
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
100 if (found == parameters.end())
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
101 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
102 throw OrthancException(ErrorCode_BadFileFormat);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
103 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
104 else
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
105 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
106 return found->second;
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
107 }
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
108 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
109
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
110
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
111 static unsigned int LookupIntegerParameter(const Parameters& parameters,
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
112 const std::string& key)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
113 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
114 try
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
115 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
116 int value = boost::lexical_cast<int>(LookupStringParameter(parameters, key));
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
117
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
118 if (value < 0)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
119 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
120 throw OrthancException(ErrorCode_BadFileFormat);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
121 }
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
122 else
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
123 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
124 return static_cast<unsigned int>(value);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
125 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
126 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
127 catch (boost::bad_lexical_cast&)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
128 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
129 throw OrthancException(ErrorCode_BadFileFormat);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
130 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
131 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
132
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
133
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
134 void PamReader::ParseContent()
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
135 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
136 static const std::string headerDelimiter = "ENDHDR\n";
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
137
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
138 boost::iterator_range<std::string::const_iterator> headerRange =
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
139 boost::algorithm::find_first(content_, headerDelimiter);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
140
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
141 if (!headerRange)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
142 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
143 throw OrthancException(ErrorCode_BadFileFormat);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
144 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
145
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
146 std::string header(static_cast<const std::string&>(content_).begin(), headerRange.begin());
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
147
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
148 std::vector<std::string> lines;
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
149 Toolbox::TokenizeString(lines, header, '\n');
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
150
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
151 if (lines.size() < 2 ||
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
152 lines.front() != "P7" ||
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
153 !lines.back().empty())
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
154 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
155 throw OrthancException(ErrorCode_BadFileFormat);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
156 }
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
157
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
158 Parameters parameters;
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
159
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
160 for (size_t i = 1; i + 1 < lines.size(); i++)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
161 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
162 std::vector<std::string> tokens;
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
163 Toolbox::TokenizeString(tokens, lines[i], ' ');
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
164
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
165 if (tokens.size() != 2)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
166 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
167 throw OrthancException(ErrorCode_BadFileFormat);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
168 }
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
169 else
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
170 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
171 parameters[tokens[0]] = tokens[1];
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
172 }
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
173 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
174
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
175 const unsigned int width = LookupIntegerParameter(parameters, "WIDTH");
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
176 const unsigned int height = LookupIntegerParameter(parameters, "HEIGHT");
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
177 const unsigned int channelCount = LookupIntegerParameter(parameters, "DEPTH");
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
178 const unsigned int maxValue = LookupIntegerParameter(parameters, "MAXVAL");
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
179 const std::string tupleType = LookupStringParameter(parameters, "TUPLTYPE");
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
180
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
181 unsigned int bytesPerChannel;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
182 PixelFormat format;
4201
2d5209153b32 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
183 GetPixelFormat(format, bytesPerChannel, maxValue, channelCount, tupleType);
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
184
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
185 unsigned int pitch = width * channelCount * bytesPerChannel;
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
186
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
187 if (content_.size() != header.size() + headerDelimiter.size() + pitch * height)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
188 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
189 throw OrthancException(ErrorCode_BadFileFormat);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
190 }
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
191
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
192 size_t offset = content_.size() - pitch * height;
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
193
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
194 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
195 intptr_t bufferAddr = reinterpret_cast<intptr_t>(&content_[offset]);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
196 if((bufferAddr % 8) == 0)
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
197 LOG(TRACE) << "PamReader::ParseContent() image address = " << bufferAddr;
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
198 else
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
199 LOG(TRACE) << "PamReader::ParseContent() image address = " << bufferAddr << " (not a multiple of 8!)";
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
200 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
201
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
202 // if we want to enforce alignment, we need to use a freshly allocated
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
203 // buffer, since we have no alignment guarantees on the original one
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
204 if (enforceAligned_)
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
205 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
206 if (alignedImageBuffer_ != NULL)
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
207 free(alignedImageBuffer_);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
208 alignedImageBuffer_ = malloc(pitch * height);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
209 memcpy(alignedImageBuffer_, &content_[offset], pitch* height);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
210 content_ = "";
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
211 AssignWritable(format, width, height, pitch, alignedImageBuffer_);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
212 }
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
213 else
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
214 {
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
215 AssignWritable(format, width, height, pitch, &content_[offset]);
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
216 }
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
217
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
218 // Byte swapping if needed
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
219 if (bytesPerChannel != 1 &&
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
220 bytesPerChannel != 2)
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
221 {
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
222 throw OrthancException(ErrorCode_NotImplemented);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
223 }
3487
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
224
2807
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
225 if (Toolbox::DetectEndianness() == Endianness_Little &&
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
226 bytesPerChannel == 2)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
227 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
228 for (unsigned int h = 0; h < height; ++h)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
229 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
230 uint16_t* pixel = reinterpret_cast<uint16_t*>(GetRow(h));
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
231
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
232 for (unsigned int w = 0; w < GetWidth(); ++w, ++pixel)
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
233 {
4071
d6b7fb0f9652 improved DownloadOrthancFramework.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
234 #if defined(__EMSCRIPTEN__) // For WebAssembly
3487
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
235 /*
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
236
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
237 crash (2019-08-05):
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
238
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
239 Uncaught abort(alignment fault) at Error
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
240 at jsStackTrace
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
241 at stackTrace
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
242 at abort
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
243 at alignfault
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
244 at SAFE_HEAP_LOAD_i32_2_2 (wasm-function[251132]:39)
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
245 at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088)
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
246
3834
219de90c1f43 Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents: 3640
diff changeset
247 Web Assembly IS LITTLE ENDIAN!
3487
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
248
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
249 Perhaps in htobe16 ?
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
250 */
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
251 uint8_t* srcdst = reinterpret_cast<uint8_t*>(pixel);
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
252 uint8_t tmp = srcdst[0];
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
253 srcdst[0] = srcdst[1];
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
254 srcdst[1] = tmp;
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
255 #else
2807
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
256 // memcpy() is necessary to avoid segmentation fault if the
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
257 // "pixel" pointer is not 16-bit aligned (which is the case
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
258 // if "offset" is an odd number). Check out issue #99:
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
259 // https://bitbucket.org/sjodogne/orthanc/issues/99
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
260 uint16_t v = htobe16(*pixel);
6356e2ceb493 Fix issue #99 (PamWriter test segfaults on alpine linux with gcc 6.4.0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2705
diff changeset
261 memcpy(pixel, &v, sizeof(v));
3487
ce29644acd19 Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents: 3060
diff changeset
262 #endif
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
263 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
264 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
265 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
266 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
267
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
268
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
269 #if ORTHANC_SANDBOXED == 0
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
270 void PamReader::ReadFromFile(const std::string& filename)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
271 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
272 SystemToolbox::ReadFile(content_, filename);
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
273 ParseContent();
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
274 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
275 #endif
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
276
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
277
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
278 void PamReader::ReadFromMemory(const std::string& buffer)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
279 {
2705
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
280 content_ = buffer;
5c18a22cb981 fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2703
diff changeset
281 ParseContent();
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
282 }
2919
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
283
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
284 void PamReader::ReadFromMemory(const void* buffer,
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
285 size_t size)
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
286 {
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
287 content_.assign(reinterpret_cast<const char*>(buffer), size);
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
288 ParseContent();
2ca9cd064b15 PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2807
diff changeset
289 }
3838
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
290
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
291 PamReader::~PamReader()
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
292 {
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
293 if (alignedImageBuffer_ != NULL)
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
294 {
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
295 free(alignedImageBuffer_);
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
296 }
95083d2f6819 fix build on os x
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3834
diff changeset
297 }
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
298 }