Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/PamReader.cpp @ 4640:66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 26 Apr 2021 15:22:44 +0200 |
parents | d9473bd5ed43 |
children | 7053502fbf97 |
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 |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4325
diff
changeset
|
5 * Copyright (C) 2017-2021 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 | 26 #include "../Endianness.h" |
4304 | 27 #include "../Logging.h" |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
28 #include "../OrthancException.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
29 #include "../Toolbox.h" |
2703 | 30 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
31 #if ORTHANC_SANDBOXED == 0 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
32 # include "../SystemToolbox.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
33 #endif |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
34 |
3838 | 35 #include <stdlib.h> // For malloc/free |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
36 #include <boost/algorithm/string/find.hpp> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
37 #include <boost/lexical_cast.hpp> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
38 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
39 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
40 namespace Orthanc |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
41 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
42 static void GetPixelFormat(PixelFormat& format, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
43 unsigned int& bytesPerChannel, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
44 const unsigned int& maxValue, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
45 const unsigned int& channelCount, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
46 const std::string& tupleType) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
47 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
48 if (tupleType == "GRAYSCALE" && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
49 channelCount == 1) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
50 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
51 switch (maxValue) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
52 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
53 case 255: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
54 format = PixelFormat_Grayscale8; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
55 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
56 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
57 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
58 case 65535: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
59 format = PixelFormat_Grayscale16; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
60 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
61 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
62 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
63 default: |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
64 throw OrthancException(ErrorCode_NotImplemented); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
65 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
66 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
67 else if (tupleType == "RGB" && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
68 channelCount == 3) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
69 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
70 switch (maxValue) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
71 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
72 case 255: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
73 format = PixelFormat_RGB24; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
74 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
75 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
76 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
77 case 65535: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
78 format = PixelFormat_RGB48; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
79 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
80 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
81 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
82 default: |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
83 throw OrthancException(ErrorCode_NotImplemented); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
84 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
85 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
86 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
87 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
88 throw OrthancException(ErrorCode_NotImplemented); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
89 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
90 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
91 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
92 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
93 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
|
94 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
95 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
96 static std::string LookupStringParameter(const Parameters& parameters, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
97 const std::string& key) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
98 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
99 Parameters::const_iterator found = parameters.find(key); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
100 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
101 if (found == parameters.end()) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
102 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
103 throw OrthancException(ErrorCode_BadFileFormat); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
104 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
105 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
106 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
107 return found->second; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
108 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
109 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
110 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
111 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
112 static unsigned int LookupIntegerParameter(const Parameters& parameters, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
113 const std::string& key) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
114 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
115 try |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
116 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
117 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
|
118 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
119 if (value < 0) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
120 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
121 throw OrthancException(ErrorCode_BadFileFormat); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
122 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
123 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
124 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
125 return static_cast<unsigned int>(value); |
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 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
128 catch (boost::bad_lexical_cast&) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
129 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
130 throw OrthancException(ErrorCode_BadFileFormat); |
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 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
135 void PamReader::ParseContent() |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
136 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
137 static const std::string headerDelimiter = "ENDHDR\n"; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
138 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
139 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
|
140 boost::algorithm::find_first(content_, headerDelimiter); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
141 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
142 if (!headerRange) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
143 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
144 throw OrthancException(ErrorCode_BadFileFormat); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
145 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
146 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
147 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
|
148 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
149 std::vector<std::string> lines; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
150 Toolbox::TokenizeString(lines, header, '\n'); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
151 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
152 if (lines.size() < 2 || |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
153 lines.front() != "P7" || |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
154 !lines.back().empty()) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
155 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
156 throw OrthancException(ErrorCode_BadFileFormat); |
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 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
159 Parameters parameters; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
160 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
161 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
|
162 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
163 std::vector<std::string> tokens; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
164 Toolbox::TokenizeString(tokens, lines[i], ' '); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
165 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
166 if (tokens.size() != 2) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
167 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
168 throw OrthancException(ErrorCode_BadFileFormat); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
169 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
170 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
171 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
172 parameters[tokens[0]] = tokens[1]; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
173 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
174 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
175 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
176 const unsigned int width = LookupIntegerParameter(parameters, "WIDTH"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
177 const unsigned int height = LookupIntegerParameter(parameters, "HEIGHT"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
178 const unsigned int channelCount = LookupIntegerParameter(parameters, "DEPTH"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
179 const unsigned int maxValue = LookupIntegerParameter(parameters, "MAXVAL"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
180 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
|
181 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
182 unsigned int bytesPerChannel; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
183 PixelFormat format; |
4201 | 184 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
|
185 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
186 unsigned int pitch = width * channelCount * bytesPerChannel; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
187 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
188 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
|
189 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
190 throw OrthancException(ErrorCode_BadFileFormat); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
191 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
192 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
193 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
|
194 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
195 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
196 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
|
197 if((bufferAddr % 8) == 0) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
198 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
|
199 else |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
200 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
|
201 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
202 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
203 // 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
|
204 // 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
|
205 if (enforceAligned_) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
206 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
207 if (alignedImageBuffer_ != NULL) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
208 free(alignedImageBuffer_); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
209 alignedImageBuffer_ = malloc(pitch * height); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
210 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
|
211 content_ = ""; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
212 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
|
213 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
214 else |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
215 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
216 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
|
217 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
218 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
219 // Byte swapping if needed |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
220 if (bytesPerChannel != 1 && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
221 bytesPerChannel != 2) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
222 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
223 throw OrthancException(ErrorCode_NotImplemented); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
224 } |
3487
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
225 |
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
|
226 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
|
227 bytesPerChannel == 2) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
228 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
229 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
|
230 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
231 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
|
232 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
233 for (unsigned int w = 0; w < width; ++w, ++pixel) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
234 { |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
235 /** |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
236 * This is Little-Endian computer, and PAM uses |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
237 * Big-Endian. Need to do a 16-bit swap. We DON'T use |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
238 * "htobe16()", as the latter only works if the "pixel" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
239 * pointer is 16-bit aligned (which is not the case if |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
240 * "offset" is an odd number), and the trick that was used |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
241 * in Orthanc <= 1.8.0 (i.e. make a "memcpy()" to a local |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
242 * uint16_t variable) doesn't seem work for WebAssembly. We |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
243 * thus use a plain old C implementation. Check out issue |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
244 * #99: https://bugs.orthanc-server.com/show_bug.cgi?id=99 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
245 * |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
246 * Here is the crash log on WebAssembly (2019-08-05): |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
247 * |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
248 * Uncaught abort(alignment fault) at Error |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
249 * at jsStackTrace |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
250 * at stackTrace |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
251 * at abort |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
252 * at alignfault |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
253 * at SAFE_HEAP_LOAD_i32_2_2 (wasm-function[251132]:39) |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
254 * at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088) |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
255 **/ |
3487
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
256 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
|
257 uint8_t tmp = srcdst[0]; |
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
258 srcdst[0] = srcdst[1]; |
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
259 srcdst[1] = tmp; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
260 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
261 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
262 } |
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 |
4300 | 265 PamReader::PamReader(bool enforceAligned) : |
266 enforceAligned_(enforceAligned), | |
267 alignedImageBuffer_(NULL) | |
268 { | |
269 } | |
270 | |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
271 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
272 #if ORTHANC_SANDBOXED == 0 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
273 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
|
274 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
275 SystemToolbox::ReadFile(content_, filename); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
276 ParseContent(); |
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 #endif |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
279 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
280 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
281 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
|
282 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
283 content_ = buffer; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
284 ParseContent(); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
285 } |
2919
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 void PamReader::ReadFromMemory(const void* buffer, |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
288 size_t size) |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
289 { |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
290 content_.assign(reinterpret_cast<const char*>(buffer), size); |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
291 ParseContent(); |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
292 } |
3838 | 293 |
294 PamReader::~PamReader() | |
295 { | |
296 if (alignedImageBuffer_ != NULL) | |
297 { | |
298 free(alignedImageBuffer_); | |
299 } | |
300 } | |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
301 } |