Mercurial > hg > orthanc
annotate Core/Images/ImageAccessor.cpp @ 3349:ef18ea68a362
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 18 Apr 2019 15:52:56 +0200 |
parents | 4e43e67f8ecf |
children | 94f4a18a79cc |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * 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
|
18 * modify file(s) with this exception, you may extend this exception to |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * 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
|
20 * 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
|
21 * version. If you delete this exception statement from all source files |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * 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
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
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 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "ImageAccessor.h" |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
37 #include "../Logging.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 #include "../OrthancException.h" |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
39 #include "../ChunkedBuffer.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 #include <stdint.h> |
860 | 42 #include <cassert> |
1397 | 43 #include <boost/lexical_cast.hpp> |
44 | |
45 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 namespace Orthanc |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 { |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
49 template <typename PixelType> |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
50 static void ToMatlabStringInternal(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
51 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
52 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
53 target.AddChunk("double([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
54 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
55 for (unsigned int y = 0; y < source.GetHeight(); y++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
56 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
57 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
58 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
59 std::string s; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
60 if (y > 0) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
61 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
62 s = "; "; |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
65 s.reserve(source.GetWidth() * 8); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
66 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
67 for (unsigned int x = 0; x < source.GetWidth(); x++, p++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
68 { |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
69 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
|
70 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
71 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
72 target.AddChunk(s); |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
75 target.AddChunk("])"); |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
79 static void RGB24ToMatlabString(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
80 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
81 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
82 assert(source.GetFormat() == PixelFormat_RGB24); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
83 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
84 target.AddChunk("double(permute(reshape([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
85 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
86 for (unsigned int y = 0; y < source.GetHeight(); y++) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
87 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
88 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
|
89 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
90 std::string s; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
91 s.reserve(source.GetWidth() * 3 * 8); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
92 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
93 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
|
94 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
95 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " "; |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
98 target.AddChunk(s); |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
101 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(source.GetHeight()) + |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
102 " " + boost::lexical_cast<std::string>(source.GetWidth()) + " ]), [ 3 2 1 ]))"); |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
105 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
106 void* ImageAccessor::GetBuffer() const |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
110 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
111 "Trying to write to a read-only image"); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 return buffer_; |
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 |
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 const void* ImageAccessor::GetConstRow(unsigned int y) const |
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 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
122 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 else |
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 return NULL; |
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 } |
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 |
800
ecedd89055db
generation of DICOM images from PNG files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
799
diff
changeset
|
131 void* ImageAccessor::GetRow(unsigned int y) const |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
135 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
136 "Trying to write to a read-only image"); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
141 return buffer_ + y * pitch_; |
798
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 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 return NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 } |
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 |
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 void ImageAccessor::AssignEmpty(PixelFormat format) |
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 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 width_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 height_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 pitch_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 buffer_ = NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 void ImageAccessor::AssignReadOnly(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 const void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 readOnly_ = true; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
172 buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer)); |
860 | 173 |
1916 | 174 if (GetBytesPerPixel() * width_ > pitch_) |
175 { | |
176 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
177 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 void ImageAccessor::AssignWritable(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
192 buffer_ = reinterpret_cast<uint8_t*>(buffer); |
860 | 193 |
1916 | 194 if (GetBytesPerPixel() * width_ > pitch_) |
195 { | |
196 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
197 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
199 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
200 |
2865
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
201 void ImageAccessor::GetWriteableAccessor(ImageAccessor& target) const |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
202 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
203 if (readOnly_) |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
204 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
205 throw OrthancException(ErrorCode_ReadOnly); |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
206 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
207 else |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
208 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
209 target.AssignWritable(format_, width_, height_, pitch_, buffer_); |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
210 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
211 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
212 |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
213 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
214 void ImageAccessor::ToMatlabString(std::string& target) const |
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 ChunkedBuffer buffer; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
217 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
218 switch (GetFormat()) |
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_Grayscale8: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
221 ToMatlabStringInternal<uint8_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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
224 case PixelFormat_Grayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
225 ToMatlabStringInternal<uint16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
226 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
227 |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
228 case PixelFormat_Grayscale32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
229 ToMatlabStringInternal<uint32_t>(buffer, *this); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
230 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
231 |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
232 case PixelFormat_Grayscale64: |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
233 ToMatlabStringInternal<uint64_t>(buffer, *this); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
234 break; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
235 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
236 case PixelFormat_SignedGrayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
237 ToMatlabStringInternal<int16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
238 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
239 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
240 case PixelFormat_Float32: |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
241 ToMatlabStringInternal<float>(buffer, *this); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
242 break; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
243 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
244 case PixelFormat_RGB24: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
245 RGB24ToMatlabString(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
246 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
247 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
248 default: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
249 throw OrthancException(ErrorCode_NotImplemented); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
250 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
251 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
252 buffer.Flatten(target); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
253 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
254 |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
255 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
256 |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
257 void ImageAccessor::GetRegion(ImageAccessor& accessor, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
258 unsigned int x, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
259 unsigned int y, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
260 unsigned int width, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
261 unsigned int height) const |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
262 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
263 if (x + width > width_ || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
264 y + height > height_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
265 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
266 throw OrthancException(ErrorCode_ParameterOutOfRange); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
267 } |
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 if (width == 0 || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
270 height == 0) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
271 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
272 accessor.AssignWritable(format_, 0, 0, 0, NULL); |
1922
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 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
275 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
276 uint8_t* p = (buffer_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
277 y * pitch_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
278 x * GetBytesPerPixel()); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
279 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
280 if (readOnly_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
281 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
282 accessor.AssignReadOnly(format_, width, height, pitch_, p); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
283 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
284 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
285 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
286 accessor.AssignWritable(format_, width, height, pitch_, p); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
287 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
288 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
289 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
290 |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
291 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
292 void ImageAccessor::SetFormat(PixelFormat format) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
293 { |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
294 if (readOnly_) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
295 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
296 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
297 "Trying to modify the format of a read-only image"); |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
298 } |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
299 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
300 if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_)) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
301 { |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
302 throw OrthancException(ErrorCode_IncompatibleImageFormat); |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
303 } |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
304 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
305 format_ = format; |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
306 } |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 } |