annotate Core/Images/PamReader.cpp @ 2703:f77c7b48f798

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 05 Jul 2018 21:02:50 +0200
parents 52217dc47a4e
children 5c18a22cb981
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
1 /**
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
40
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
41 #include <istream>
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
42 #include <sstream>
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
43 #include <fstream>
2703
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2699
diff changeset
44
2699
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
45 #if ORTHANC_SANDBOXED == 0
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
46 # include "../SystemToolbox.h"
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
47 #endif
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 #include <string.h>
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
50
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
51 namespace Orthanc
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
52 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
53 namespace
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
54 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
55 void GetPixelFormat(PixelFormat& format, unsigned int& bytesPerChannel, const unsigned int& maxValue, const unsigned int& channelCount, const char* tupleType)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
56 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
57 if (strcmp(tupleType, "GRAYSCALE") == 0 && channelCount == 1)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
58 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
59 if (maxValue == 255)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
60 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
61 format = PixelFormat_Grayscale8;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
62 bytesPerChannel = 1;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
63 return;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
64 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
65 else if (maxValue == 65535)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
66 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
67 format = PixelFormat_Grayscale16;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
68 bytesPerChannel = 2;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
69 return;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
70 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
71 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
72 else if (strcmp(tupleType, "RGB") == 0 && channelCount == 3)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
73 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
74 if (maxValue == 255)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
75 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
76 format = PixelFormat_RGB24;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
77 bytesPerChannel = 1;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
78 return;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
79 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
80 else if (maxValue == 65535)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
81 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
82 format = PixelFormat_RGB48;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
83 bytesPerChannel = 2;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
84 return;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
85 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
86 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
87 throw OrthancException(ErrorCode_NotImplemented);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
88 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
89
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
90 void ReadDelimiter(std::istream& input, const char* expectedDelimiter)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
91 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
92 std::string delimiter;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
93 input >> delimiter;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
94 if (delimiter != expectedDelimiter)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
95 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
96 throw OrthancException(ErrorCode_BadFileFormat);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
97 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
98 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
99
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
100 unsigned int ReadKeyValueUint(std::istream& input, const char* expectedKey)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
101 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
102 std::string key;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
103 unsigned int value;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
104 input >> key >> value;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
105 if (key != expectedKey)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
106 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
107 throw OrthancException(ErrorCode_BadFileFormat);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
108 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
109 return value;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
110 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
111
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
112 std::string ReadKeyValueString(std::istream& input, const char* expectedKey)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
113 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
114 std::string key;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
115 std::string value;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
116 input >> key >> value;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
117 if (key != expectedKey)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
118 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
119 throw OrthancException(ErrorCode_BadFileFormat);
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 return value;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
122 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
123 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
124
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
125 void PamReader::ReadFromStream(std::istream& input)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
126 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
127 ReadDelimiter(input, "P7");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
128 unsigned int width = ReadKeyValueUint(input, "WIDTH");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
129 unsigned int height = ReadKeyValueUint(input, "HEIGHT");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
130 unsigned int channelCount = ReadKeyValueUint(input, "DEPTH");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
131 unsigned int maxValue = ReadKeyValueUint(input, "MAXVAL");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
132 std::string tupleType = ReadKeyValueString(input, "TUPLTYPE");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
133 ReadDelimiter(input, "ENDHDR");
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
134 // skip last EOL
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
135 char tmp[16];
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
136 input.getline(tmp, 16);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
137
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
138 unsigned int bytesPerChannel;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
139 PixelFormat format;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
140 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
141
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
142 // read the pixels data
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
143 unsigned int sizeInBytes = width * height * channelCount * bytesPerChannel;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
144 data_.reserve(sizeInBytes);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
145 input.read(data_.data(), sizeInBytes);
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 AssignWritable(format, width, height, width * channelCount * bytesPerChannel, data_.data());
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
148
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
149 // swap bytes
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
150 if (Toolbox::DetectEndianness() == Endianness_Little && bytesPerChannel == 2)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
151 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
152 uint16_t* pixel = NULL;
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
153 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
154 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
155 pixel = reinterpret_cast<uint16_t*> (data_.data() + h * width * channelCount * bytesPerChannel);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
156 for (unsigned int w = 0; w < (width * channelCount); ++w, ++pixel)
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
157 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
158 *pixel = htobe16(*pixel);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
159 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
160 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
161 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
162
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
163 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
164
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
165 #if ORTHANC_SANDBOXED == 0
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
166 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
167 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
168 std::ifstream inputStream(filename, std::ofstream::binary);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
169 ReadFromStream(inputStream);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
170 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
171 #endif
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
172
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
173 void PamReader::ReadFromMemory(const void* buffer,
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
174 size_t size)
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 std::istringstream inputStream(std::string(reinterpret_cast<const char*>(buffer), size));
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
177 ReadFromStream(inputStream);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
178 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
179
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
180 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
181 {
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
182 std::istringstream inputStream(buffer);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
183 ReadFromStream(inputStream);
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
184 }
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
185
52217dc47a4e new image/pam MIME TYPE supported in /instances/../frames/../image-uint8... routes
am@osimis.io
parents:
diff changeset
186 }