Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/PamReader.cpp @ 5161:b6dc4606ab04
release notes for 1.11.3
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 03 Feb 2023 14:24:43 +0100 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
7 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * 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
|
17 * |
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
|
18 * 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
|
19 * 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
|
20 * <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
|
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 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
25 #include "PamReader.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
26 |
2703 | 27 #include "../Endianness.h" |
4304 | 28 #include "../Logging.h" |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
29 #include "../OrthancException.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
30 #include "../Toolbox.h" |
2703 | 31 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
32 #if ORTHANC_SANDBOXED == 0 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
33 # include "../SystemToolbox.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
34 #endif |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
35 |
3838 | 36 #include <stdlib.h> // For malloc/free |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
37 #include <boost/algorithm/string/find.hpp> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
38 #include <boost/lexical_cast.hpp> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
39 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
40 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
41 namespace Orthanc |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
42 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
43 static void GetPixelFormat(PixelFormat& format, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
44 unsigned int& bytesPerChannel, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
45 const unsigned int& maxValue, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
46 const unsigned int& channelCount, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
47 const std::string& tupleType) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
48 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
49 if (tupleType == "GRAYSCALE" && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
50 channelCount == 1) |
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 switch (maxValue) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
53 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
54 case 255: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
55 format = PixelFormat_Grayscale8; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
56 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
57 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
58 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
59 case 65535: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
60 format = PixelFormat_Grayscale16; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
61 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
62 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
63 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
64 default: |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
65 throw OrthancException(ErrorCode_NotImplemented); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
66 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
67 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
68 else if (tupleType == "RGB" && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
69 channelCount == 3) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
70 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
71 switch (maxValue) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
72 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
73 case 255: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
74 format = PixelFormat_RGB24; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
75 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
76 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
77 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
78 case 65535: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
79 format = PixelFormat_RGB48; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
80 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
81 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
82 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
83 default: |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
84 throw OrthancException(ErrorCode_NotImplemented); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
85 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
86 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
87 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
88 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
89 throw OrthancException(ErrorCode_NotImplemented); |
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 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
92 |
2705
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 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
|
95 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
96 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
97 static std::string LookupStringParameter(const Parameters& parameters, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
98 const std::string& 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 Parameters::const_iterator found = parameters.find(key); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
101 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
102 if (found == parameters.end()) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
103 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
104 throw OrthancException(ErrorCode_BadFileFormat); |
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 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
107 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
108 return found->second; |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
109 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
110 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
111 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
112 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
113 static unsigned int LookupIntegerParameter(const Parameters& parameters, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
114 const std::string& key) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
115 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
116 try |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
117 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
118 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
|
119 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
120 if (value < 0) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
121 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
122 throw OrthancException(ErrorCode_BadFileFormat); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
123 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
124 else |
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 return static_cast<unsigned int>(value); |
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 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
129 catch (boost::bad_lexical_cast&) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
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 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
136 void PamReader::ParseContent() |
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 static const std::string headerDelimiter = "ENDHDR\n"; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
139 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
140 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
|
141 boost::algorithm::find_first(content_, headerDelimiter); |
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 if (!headerRange) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
144 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
145 throw OrthancException(ErrorCode_BadFileFormat); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
146 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
147 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
148 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
|
149 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
150 std::vector<std::string> lines; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
151 Toolbox::TokenizeString(lines, header, '\n'); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
152 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
153 if (lines.size() < 2 || |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
154 lines.front() != "P7" || |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
155 !lines.back().empty()) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
156 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
157 throw OrthancException(ErrorCode_BadFileFormat); |
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 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
160 Parameters parameters; |
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 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
|
163 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
164 std::vector<std::string> tokens; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
165 Toolbox::TokenizeString(tokens, lines[i], ' '); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
166 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
167 if (tokens.size() != 2) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
168 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
169 throw OrthancException(ErrorCode_BadFileFormat); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
170 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
171 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
172 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
173 parameters[tokens[0]] = tokens[1]; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
174 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
175 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
176 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
177 const unsigned int width = LookupIntegerParameter(parameters, "WIDTH"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
178 const unsigned int height = LookupIntegerParameter(parameters, "HEIGHT"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
179 const unsigned int channelCount = LookupIntegerParameter(parameters, "DEPTH"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
180 const unsigned int maxValue = LookupIntegerParameter(parameters, "MAXVAL"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
181 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
|
182 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
183 unsigned int bytesPerChannel; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
184 PixelFormat format; |
4201 | 185 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
|
186 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
187 unsigned int pitch = width * channelCount * bytesPerChannel; |
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 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
|
190 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
191 throw OrthancException(ErrorCode_BadFileFormat); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
192 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
193 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
194 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
|
195 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
196 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
197 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
|
198 if((bufferAddr % 8) == 0) |
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; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
200 else |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
201 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
|
202 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
203 |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
204 // 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
|
205 // 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
|
206 if (enforceAligned_) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
207 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
208 if (alignedImageBuffer_ != NULL) |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
209 free(alignedImageBuffer_); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
210 alignedImageBuffer_ = malloc(pitch * height); |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
211 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
|
212 content_ = ""; |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
213 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
|
214 } |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
215 else |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
216 { |
219de90c1f43
Added a flag to use an extra buffer in PamReader
Benjamin Golinvaux <bgo@osimis.io>
parents:
3640
diff
changeset
|
217 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
|
218 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
219 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
220 // Byte swapping if needed |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
221 if (bytesPerChannel != 1 && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
222 bytesPerChannel != 2) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
223 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
224 throw OrthancException(ErrorCode_NotImplemented); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
225 } |
3487
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
226 |
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
|
227 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
|
228 bytesPerChannel == 2) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
229 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
230 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
|
231 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
232 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
|
233 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
234 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
|
235 { |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
236 /** |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
237 * 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
|
238 * 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
|
239 * "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
|
240 * 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
|
241 * "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
|
242 * 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
|
243 * 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
|
244 * 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
|
245 * #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
|
246 * |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
247 * 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
|
248 * |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
249 * Uncaught abort(alignment fault) at Error |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
250 * at jsStackTrace |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
251 * at stackTrace |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
252 * at abort |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
253 * at alignfault |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
254 * 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
|
255 * at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088) |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4304
diff
changeset
|
256 **/ |
3487
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
257 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
|
258 uint8_t tmp = srcdst[0]; |
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
259 srcdst[0] = srcdst[1]; |
ce29644acd19
Prevented unaligned memcpy when using Web Assembly
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
260 srcdst[1] = tmp; |
2699
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 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
265 |
4300 | 266 PamReader::PamReader(bool enforceAligned) : |
267 enforceAligned_(enforceAligned), | |
268 alignedImageBuffer_(NULL) | |
269 { | |
270 } | |
271 | |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
272 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
273 #if ORTHANC_SANDBOXED == 0 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
274 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
|
275 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
276 SystemToolbox::ReadFile(content_, filename); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
277 ParseContent(); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
278 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
279 #endif |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
280 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
281 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
282 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
|
283 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
284 content_ = buffer; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
285 ParseContent(); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
286 } |
2919
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
287 |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
288 void PamReader::ReadFromMemory(const void* buffer, |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
289 size_t size) |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
290 { |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
291 content_.assign(reinterpret_cast<const char*>(buffer), size); |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
292 ParseContent(); |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
293 } |
3838 | 294 |
295 PamReader::~PamReader() | |
296 { | |
297 if (alignedImageBuffer_ != NULL) | |
298 { | |
299 free(alignedImageBuffer_); | |
300 } | |
301 } | |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
302 } |