Mercurial > hg > orthanc
annotate Core/Images/PamReader.cpp @ 3294:801075411128
BOOST_LOCALE_BACKEND is not advanced
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 21 Feb 2019 21:58:33 +0100 |
parents | 4e43e67f8ecf |
children | ce29644acd19 |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2919
diff
changeset
|
5 * Copyright (C) 2017-2019 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 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
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 * In addition, as a special exception, the copyright holders of this |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
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 * 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
|
25 * 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
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
27 * General Public License for more details. |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
28 * |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
31 **/ |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
32 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
33 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
35 #include "PamReader.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
36 |
2703 | 37 #include "../Endianness.h" |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
38 #include "../OrthancException.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
39 #include "../Toolbox.h" |
2703 | 40 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
41 #if ORTHANC_SANDBOXED == 0 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
42 # include "../SystemToolbox.h" |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
43 #endif |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
44 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
45 #include <boost/algorithm/string/find.hpp> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
46 #include <boost/lexical_cast.hpp> |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
47 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
48 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
49 namespace Orthanc |
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 static void GetPixelFormat(PixelFormat& format, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
52 unsigned int& bytesPerChannel, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
53 const unsigned int& maxValue, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
54 const unsigned int& channelCount, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
55 const std::string& tupleType) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
56 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
57 if (tupleType == "GRAYSCALE" && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
58 channelCount == 1) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
59 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
60 switch (maxValue) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
61 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
62 case 255: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
63 format = PixelFormat_Grayscale8; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
64 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
65 return; |
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 case 65535: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
68 format = PixelFormat_Grayscale16; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
69 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
70 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
71 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
72 default: |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
73 throw OrthancException(ErrorCode_NotImplemented); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
74 } |
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 else if (tupleType == "RGB" && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
77 channelCount == 3) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
78 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
79 switch (maxValue) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
80 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
81 case 255: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
82 format = PixelFormat_RGB24; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
83 bytesPerChannel = 1; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
84 return; |
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 case 65535: |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
87 format = PixelFormat_RGB48; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
88 bytesPerChannel = 2; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
89 return; |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
90 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
91 default: |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
92 throw OrthancException(ErrorCode_NotImplemented); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
93 } |
2705
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 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
96 { |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
97 throw OrthancException(ErrorCode_NotImplemented); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
98 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
99 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
100 |
2705
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 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
|
103 |
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 static std::string LookupStringParameter(const Parameters& parameters, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
106 const std::string& key) |
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 Parameters::const_iterator found = parameters.find(key); |
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 if (found == parameters.end()) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
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 else |
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 return found->second; |
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 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
119 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
120 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
121 static unsigned int LookupIntegerParameter(const Parameters& parameters, |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
122 const std::string& key) |
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 try |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
125 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
126 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
|
127 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
128 if (value < 0) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
129 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
130 throw OrthancException(ErrorCode_BadFileFormat); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
131 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
132 else |
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 return static_cast<unsigned int>(value); |
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 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
137 catch (boost::bad_lexical_cast&) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
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 } |
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 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
144 void PamReader::ParseContent() |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
145 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
146 static const std::string headerDelimiter = "ENDHDR\n"; |
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 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
|
149 boost::algorithm::find_first(content_, headerDelimiter); |
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 (!headerRange) |
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 throw OrthancException(ErrorCode_BadFileFormat); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
154 } |
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 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
|
157 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
158 std::vector<std::string> lines; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
159 Toolbox::TokenizeString(lines, header, '\n'); |
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 if (lines.size() < 2 || |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
162 lines.front() != "P7" || |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
163 !lines.back().empty()) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
164 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
165 throw OrthancException(ErrorCode_BadFileFormat); |
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 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
168 Parameters parameters; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
169 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
170 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
|
171 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
172 std::vector<std::string> tokens; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
173 Toolbox::TokenizeString(tokens, lines[i], ' '); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
174 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
175 if (tokens.size() != 2) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
176 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
177 throw OrthancException(ErrorCode_BadFileFormat); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
178 } |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
179 else |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
180 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
181 parameters[tokens[0]] = tokens[1]; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
182 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
183 } |
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 const unsigned int width = LookupIntegerParameter(parameters, "WIDTH"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
186 const unsigned int height = LookupIntegerParameter(parameters, "HEIGHT"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
187 const unsigned int channelCount = LookupIntegerParameter(parameters, "DEPTH"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
188 const unsigned int maxValue = LookupIntegerParameter(parameters, "MAXVAL"); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
189 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
|
190 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
191 unsigned int bytesPerChannel; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
192 PixelFormat format; |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
193 GetPixelFormat(format, bytesPerChannel, maxValue, channelCount, tupleType.c_str()); |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
194 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
195 unsigned int pitch = width * channelCount * bytesPerChannel; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
196 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
197 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
|
198 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
199 throw OrthancException(ErrorCode_BadFileFormat); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
200 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
201 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
202 size_t offset = content_.size() - pitch * height; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
203 AssignWritable(format, width, height, pitch, &content_[offset]); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
204 |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
205 // Byte swapping if needed |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
206 if (bytesPerChannel != 1 && |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
207 bytesPerChannel != 2) |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
208 { |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
209 throw OrthancException(ErrorCode_NotImplemented); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
210 } |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
211 |
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
|
212 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
|
213 bytesPerChannel == 2) |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
214 { |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
215 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
|
216 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
217 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
|
218 |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
219 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
|
220 { |
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
|
221 // 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
|
222 // "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
|
223 // 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
|
224 // 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
|
225 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
|
226 memcpy(pixel, &v, sizeof(v)); |
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 } |
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 } |
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 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
233 #if ORTHANC_SANDBOXED == 0 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
234 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
|
235 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
236 SystemToolbox::ReadFile(content_, filename); |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
237 ParseContent(); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
238 } |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
239 #endif |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
240 |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
241 |
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
242 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
|
243 { |
2705
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
244 content_ = buffer; |
5c18a22cb981
fix portability of PAM reader/writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2703
diff
changeset
|
245 ParseContent(); |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
246 } |
2919
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
247 |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
248 void PamReader::ReadFromMemory(const void* buffer, |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
249 size_t size) |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
250 { |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
251 content_.assign(reinterpret_cast<const char*>(buffer), size); |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
252 ParseContent(); |
2ca9cd064b15
PamReader::ReadFromMemory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2807
diff
changeset
|
253 } |
2699
52217dc47a4e
new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff
changeset
|
254 } |