Mercurial > hg > orthanc
annotate Core/Images/ImageAccessor.cpp @ 2022:fefbe71c2272
Possibility to use PKCS#11 authentication for hardware security modules with Orthanc peers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 17 Jun 2016 17:09:50 +0200 |
parents | e2a3ff770b48 |
children | a89ca69ec1d1 |
rev | line source |
---|---|
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
983
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * License, or (at your option) any later version. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * program give permission to link the code of its release with the |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * in the program, then also delete it here. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * General Public License for more details. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 **/ |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
33 #include "../PrecompiledHeaders.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "ImageAccessor.h" |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
36 #include "../Logging.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "../OrthancException.h" |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
38 #include "../ChunkedBuffer.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 #include <stdint.h> |
860 | 41 #include <cassert> |
1397 | 42 #include <boost/lexical_cast.hpp> |
43 | |
44 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 namespace Orthanc |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
48 template <typename PixelType> |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
49 static void ToMatlabStringInternal(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
50 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
51 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
52 target.AddChunk("double([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
53 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
54 for (unsigned int y = 0; y < source.GetHeight(); y++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
55 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
56 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
57 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
58 std::string s; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
59 if (y > 0) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
60 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
61 s = "; "; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
62 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
63 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
64 s.reserve(source.GetWidth() * 8); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
65 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
66 for (unsigned int x = 0; x < source.GetWidth(); x++, p++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
67 { |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
68 s += boost::lexical_cast<std::string>(static_cast<double>(*p)) + " "; |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
69 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
70 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
71 target.AddChunk(s); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
72 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
73 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
74 target.AddChunk("])"); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
75 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
76 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
77 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
78 static void RGB24ToMatlabString(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
79 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
80 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
81 assert(source.GetFormat() == PixelFormat_RGB24); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
82 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
83 target.AddChunk("double(permute(reshape([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
84 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
85 for (unsigned int y = 0; y < source.GetHeight(); y++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
86 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
87 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y)); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
88 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
89 std::string s; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
90 s.reserve(source.GetWidth() * 3 * 8); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
91 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
92 for (unsigned int x = 0; x < 3 * source.GetWidth(); x++, p++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
93 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
94 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " "; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
95 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
96 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
97 target.AddChunk(s); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
98 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
99 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
100 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(source.GetHeight()) + |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
101 " " + boost::lexical_cast<std::string>(source.GetWidth()) + " ]), [ 3 2 1 ]))"); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
102 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
103 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
104 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
105 void* ImageAccessor::GetBuffer() const |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 { |
1491 | 109 #if ORTHANC_ENABLE_LOGGING == 1 |
861 | 110 LOG(ERROR) << "Trying to write on a read-only image"; |
1491 | 111 #endif |
112 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 throw OrthancException(ErrorCode_ReadOnly); |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 return buffer_; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 const void* ImageAccessor::GetConstRow(unsigned int y) const |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
124 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 return NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
133 void* ImageAccessor::GetRow(unsigned int y) const |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 { |
1491 | 137 #if ORTHANC_ENABLE_LOGGING == 1 |
861 | 138 LOG(ERROR) << "Trying to write on a read-only image"; |
1491 | 139 #endif |
140 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 throw OrthancException(ErrorCode_ReadOnly); |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
146 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 return NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 void ImageAccessor::AssignEmpty(PixelFormat format) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 width_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 height_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 pitch_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 buffer_ = NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 void ImageAccessor::AssignReadOnly(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 const void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 readOnly_ = true; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
177 buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer)); |
860 | 178 |
1916 | 179 if (GetBytesPerPixel() * width_ > pitch_) |
180 { | |
181 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
182 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 void ImageAccessor::AssignWritable(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
197 buffer_ = reinterpret_cast<uint8_t*>(buffer); |
860 | 198 |
1916 | 199 if (GetBytesPerPixel() * width_ > pitch_) |
200 { | |
201 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
202 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
204 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
205 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
206 void ImageAccessor::ToMatlabString(std::string& target) const |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
207 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
208 ChunkedBuffer buffer; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
209 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
210 switch (GetFormat()) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
211 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
212 case PixelFormat_Grayscale8: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
213 ToMatlabStringInternal<uint8_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
214 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
215 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
216 case PixelFormat_Grayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
217 ToMatlabStringInternal<uint16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
218 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
219 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
220 case PixelFormat_SignedGrayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
221 ToMatlabStringInternal<int16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
222 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
223 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
224 case PixelFormat_Float32: |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
225 ToMatlabStringInternal<float>(buffer, *this); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
226 break; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
227 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
228 case PixelFormat_RGB24: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
229 RGB24ToMatlabString(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
230 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
231 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
232 default: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
233 throw OrthancException(ErrorCode_NotImplemented); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
234 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
235 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
236 buffer.Flatten(target); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
237 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
238 |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
239 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
240 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
241 ImageAccessor ImageAccessor::GetRegion(unsigned int x, |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
242 unsigned int y, |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
243 unsigned int width, |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
244 unsigned int height) const |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
245 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
246 if (x + width > width_ || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
247 y + height > height_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
248 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
249 throw OrthancException(ErrorCode_ParameterOutOfRange); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
250 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
251 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
252 ImageAccessor result; |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
253 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
254 if (width == 0 || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
255 height == 0) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
256 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
257 result.AssignWritable(format_, 0, 0, 0, NULL); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
258 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
259 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
260 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
261 uint8_t* p = (buffer_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
262 y * pitch_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
263 x * GetBytesPerPixel()); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
264 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
265 if (readOnly_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
266 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
267 result.AssignReadOnly(format_, width, height, pitch_, p); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
268 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
269 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
270 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
271 result.AssignWritable(format_, width, height, pitch_, p); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
272 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
273 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
274 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
275 return result; |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
276 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
277 |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 } |