Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/ImageAccessor.cpp @ 5560:c80dbbae3f60
Removed potential PHI from the logs when Orthanc encounters an error while creating a zip file
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 22 Apr 2024 10:50:33 +0200 |
parents | 48b8dae6dc77 |
children | f7adfb22e20e |
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 |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * 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
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 **/ |
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 |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
800
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "ImageAccessor.h" |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1397
diff
changeset
|
27 #include "../Logging.h" |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include "../OrthancException.h" |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
29 #include "../ChunkedBuffer.h" |
798
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 #include <stdint.h> |
860 | 32 #include <cassert> |
1397 | 33 #include <boost/lexical_cast.hpp> |
34 | |
35 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 namespace Orthanc |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 { |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
39 template <typename PixelType> |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
40 static void ToMatlabStringInternal(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
41 const ImageAccessor& source) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
42 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
43 target.AddChunk("double([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
44 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
45 const unsigned int width = source.GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
46 const unsigned int height = source.GetHeight(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
47 |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
48 for (unsigned int y = 0; y < height; y++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
49 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
50 const PixelType* p = reinterpret_cast<const PixelType*>(source.GetConstRow(y)); |
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 std::string s; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
53 if (y > 0) |
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 s = "; "; |
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 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
58 s.reserve(width * 8); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
59 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
60 for (unsigned int x = 0; x < width; x++, p++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
61 { |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
62 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
|
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 target.AddChunk(s); |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
68 target.AddChunk("])"); |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
72 static void RGB24ToMatlabString(ChunkedBuffer& target, |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
73 const ImageAccessor& source) |
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 assert(source.GetFormat() == PixelFormat_RGB24); |
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 target.AddChunk("double(permute(reshape([ "); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
78 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
79 const unsigned int width = source.GetWidth(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
80 const unsigned int height = source.GetHeight(); |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
81 |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
82 for (unsigned int y = 0; y < height; y++) |
874
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 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
|
85 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
86 std::string s; |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
87 s.reserve(width * 3 * 8); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
88 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
89 for (unsigned int x = 0; x < 3 * width; x++, p++) |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
90 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
91 s += boost::lexical_cast<std::string>(static_cast<int>(*p)) + " "; |
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 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
94 target.AddChunk(s); |
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 |
4278
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
97 target.AddChunk("], [ 3 " + boost::lexical_cast<std::string>(height) + |
9279de56a405
avoid multiple calls to GetWidth() and GetHeight() on pixel loops
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
98 " " + boost::lexical_cast<std::string>(width) + " ]), [ 3 2 1 ]))"); |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
99 } |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
100 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
101 |
4300 | 102 ImageAccessor::ImageAccessor() |
103 { | |
104 AssignEmpty(PixelFormat_Grayscale8); | |
105 } | |
106 | |
107 ImageAccessor::~ImageAccessor() | |
108 { | |
109 } | |
110 | |
111 bool ImageAccessor::IsReadOnly() const | |
112 { | |
113 return readOnly_; | |
114 } | |
115 | |
116 PixelFormat ImageAccessor::GetFormat() const | |
117 { | |
118 return format_; | |
119 } | |
120 | |
121 unsigned int ImageAccessor::GetBytesPerPixel() const | |
122 { | |
123 return ::Orthanc::GetBytesPerPixel(format_); | |
124 } | |
125 | |
126 unsigned int ImageAccessor::GetWidth() const | |
127 { | |
128 return width_; | |
129 } | |
130 | |
131 unsigned int ImageAccessor::GetHeight() const | |
132 { | |
133 return height_; | |
134 } | |
135 | |
136 unsigned int ImageAccessor::GetPitch() const | |
137 { | |
138 return pitch_; | |
139 } | |
140 | |
141 unsigned int ImageAccessor::GetSize() const | |
142 { | |
143 return GetHeight() * GetPitch(); | |
144 } | |
145 | |
146 const void *ImageAccessor::GetConstBuffer() const | |
147 { | |
148 return buffer_; | |
149 } | |
150 | |
4201 | 151 void* ImageAccessor::GetBuffer() |
798
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 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
155 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
156 "Trying to write to a read-only image"); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 } |
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 return buffer_; |
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 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 const void* ImageAccessor::GetConstRow(unsigned int y) const |
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 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
167 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 return NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 |
4201 | 176 void* ImageAccessor::GetRow(unsigned int y) |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 if (readOnly_) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
180 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
181 "Trying to write to a read-only image"); |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 } |
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 if (buffer_ != NULL) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 { |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
186 return buffer_ + y * pitch_; |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 else |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 return NULL; |
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 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 void ImageAccessor::AssignEmpty(PixelFormat format) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 width_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 height_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 pitch_ = 0; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 buffer_ = NULL; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 void ImageAccessor::AssignReadOnly(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 const void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 readOnly_ = true; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
217 buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer)); |
860 | 218 |
1916 | 219 if (GetBytesPerPixel() * width_ > pitch_) |
220 { | |
221 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
222 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 } |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 |
4300 | 225 void ImageAccessor::GetReadOnlyAccessor(ImageAccessor &target) const |
226 { | |
227 target.AssignReadOnly(format_, width_, height_, pitch_, buffer_); | |
228 } | |
229 | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 void ImageAccessor::AssignWritable(PixelFormat format, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 unsigned int width, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 unsigned int height, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 unsigned int pitch, |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 void *buffer) |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 { |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 readOnly_ = false; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 format_ = format; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 width_ = width; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 height_ = height; |
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 pitch_ = pitch; |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
242 buffer_ = reinterpret_cast<uint8_t*>(buffer); |
860 | 243 |
1916 | 244 if (GetBytesPerPixel() * width_ > pitch_) |
245 { | |
246 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
247 } | |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 } |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
249 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
250 |
2865
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
251 void ImageAccessor::GetWriteableAccessor(ImageAccessor& target) const |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
252 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
253 if (readOnly_) |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
254 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
255 throw OrthancException(ErrorCode_ReadOnly); |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
256 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
257 else |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
258 { |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
259 target.AssignWritable(format_, width_, height_, pitch_, buffer_); |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
260 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
261 } |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
262 |
0f07bdae0805
ImageAccessor::GetWriteableAccessor() and GetReadOnlyAccessor()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2861
diff
changeset
|
263 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
264 void ImageAccessor::ToMatlabString(std::string& target) const |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
265 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
266 ChunkedBuffer buffer; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
267 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
268 switch (GetFormat()) |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
269 { |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
270 case PixelFormat_Grayscale8: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
271 ToMatlabStringInternal<uint8_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
272 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
273 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
274 case PixelFormat_Grayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
275 ToMatlabStringInternal<uint16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
276 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
277 |
2415
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
278 case PixelFormat_Grayscale32: |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
279 ToMatlabStringInternal<uint32_t>(buffer, *this); |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
280 break; |
7e217a1cc63f
PixelFormat_Float32
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
281 |
2645
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
282 case PixelFormat_Grayscale64: |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
283 ToMatlabStringInternal<uint64_t>(buffer, *this); |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
284 break; |
89b789366596
Grayscale64 pixel format
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
285 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
286 case PixelFormat_SignedGrayscale16: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
287 ToMatlabStringInternal<int16_t>(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
288 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
289 |
1993
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
290 case PixelFormat_Float32: |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
291 ToMatlabStringInternal<float>(buffer, *this); |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
292 break; |
e2a3ff770b48
introducing float32 images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1922
diff
changeset
|
293 |
874
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
294 case PixelFormat_RGB24: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
295 RGB24ToMatlabString(buffer, *this); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
296 break; |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
297 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
298 default: |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
299 throw OrthancException(ErrorCode_NotImplemented); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
300 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
301 |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
302 buffer.Flatten(target); |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
303 } |
87791ebc1f50
download matlab images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
861
diff
changeset
|
304 |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
305 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
306 |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
307 void ImageAccessor::GetRegion(ImageAccessor& accessor, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
308 unsigned int x, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
309 unsigned int y, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
310 unsigned int width, |
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
311 unsigned int height) const |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
312 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
313 if (x + width > width_ || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
314 y + height > height_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
315 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
316 throw OrthancException(ErrorCode_ParameterOutOfRange); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
317 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
318 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
319 if (width == 0 || |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
320 height == 0) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
321 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
322 accessor.AssignWritable(format_, 0, 0, 0, NULL); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
323 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
324 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
325 { |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
326 uint8_t* p = (buffer_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
327 y * pitch_ + |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
328 x * GetBytesPerPixel()); |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
329 |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
330 if (readOnly_) |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
331 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
332 accessor.AssignReadOnly(format_, width, height, pitch_, p); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
333 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
334 else |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
335 { |
2861
9b4251721f22
ImageAccessor now non-copyable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2645
diff
changeset
|
336 accessor.AssignWritable(format_, width, height, pitch_, p); |
1922
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
337 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
338 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
339 } |
369897749653
ImageAccessor::GetRegion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
340 |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
341 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
342 void ImageAccessor::SetFormat(PixelFormat format) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
343 { |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
344 if (readOnly_) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
345 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
346 throw OrthancException(ErrorCode_ReadOnly, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2865
diff
changeset
|
347 "Trying to modify the format of a read-only image"); |
2103
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
348 } |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
349 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
350 if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_)) |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
351 { |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
352 throw OrthancException(ErrorCode_IncompatibleImageFormat); |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
353 } |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
354 |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
355 format_ = format; |
a89ca69ec1d1
ImageAccessor::SetFormat
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1993
diff
changeset
|
356 } |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
357 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
358 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
359 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
360 void* ImageAccessor::GetBuffer() const |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
361 { |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
362 return const_cast<ImageAccessor&>(*this).GetBuffer(); |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
363 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
364 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
365 void* ImageAccessor::GetRow(unsigned int y) const |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
366 { |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
367 return const_cast<ImageAccessor&>(*this).GetRow(y); |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
368 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4201
diff
changeset
|
369 #endif |
798
e1d27ee2114a
ImageAccessor abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 } |