comparison Core/Images/ImageAccessor.cpp @ 1922:369897749653

ImageAccessor::GetRegion
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Mar 2016 17:53:19 +0100
parents 5bcf721bde4f
children e2a3ff770b48
comparison
equal deleted inserted replaced
1921:5e1ee8f4fc9e 1922:369897749653
119 119
120 const void* ImageAccessor::GetConstRow(unsigned int y) const 120 const void* ImageAccessor::GetConstRow(unsigned int y) const
121 { 121 {
122 if (buffer_ != NULL) 122 if (buffer_ != NULL)
123 { 123 {
124 return reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_; 124 return buffer_ + y * pitch_;
125 } 125 }
126 else 126 else
127 { 127 {
128 return NULL; 128 return NULL;
129 } 129 }
141 throw OrthancException(ErrorCode_ReadOnly); 141 throw OrthancException(ErrorCode_ReadOnly);
142 } 142 }
143 143
144 if (buffer_ != NULL) 144 if (buffer_ != NULL)
145 { 145 {
146 return reinterpret_cast<uint8_t*>(buffer_) + y * pitch_; 146 return buffer_ + y * pitch_;
147 } 147 }
148 else 148 else
149 { 149 {
150 return NULL; 150 return NULL;
151 } 151 }
172 readOnly_ = true; 172 readOnly_ = true;
173 format_ = format; 173 format_ = format;
174 width_ = width; 174 width_ = width;
175 height_ = height; 175 height_ = height;
176 pitch_ = pitch; 176 pitch_ = pitch;
177 buffer_ = const_cast<void*>(buffer); 177 buffer_ = reinterpret_cast<uint8_t*>(const_cast<void*>(buffer));
178 178
179 if (GetBytesPerPixel() * width_ > pitch_) 179 if (GetBytesPerPixel() * width_ > pitch_)
180 { 180 {
181 throw OrthancException(ErrorCode_ParameterOutOfRange); 181 throw OrthancException(ErrorCode_ParameterOutOfRange);
182 } 182 }
192 readOnly_ = false; 192 readOnly_ = false;
193 format_ = format; 193 format_ = format;
194 width_ = width; 194 width_ = width;
195 height_ = height; 195 height_ = height;
196 pitch_ = pitch; 196 pitch_ = pitch;
197 buffer_ = buffer; 197 buffer_ = reinterpret_cast<uint8_t*>(buffer);
198 198
199 if (GetBytesPerPixel() * width_ > pitch_) 199 if (GetBytesPerPixel() * width_ > pitch_)
200 { 200 {
201 throw OrthancException(ErrorCode_ParameterOutOfRange); 201 throw OrthancException(ErrorCode_ParameterOutOfRange);
202 } 202 }
230 } 230 }
231 231
232 buffer.Flatten(target); 232 buffer.Flatten(target);
233 } 233 }
234 234
235
236
237 ImageAccessor ImageAccessor::GetRegion(unsigned int x,
238 unsigned int y,
239 unsigned int width,
240 unsigned int height) const
241 {
242 if (x + width > width_ ||
243 y + height > height_)
244 {
245 throw OrthancException(ErrorCode_ParameterOutOfRange);
246 }
247
248 ImageAccessor result;
249
250 if (width == 0 ||
251 height == 0)
252 {
253 result.AssignWritable(format_, 0, 0, 0, NULL);
254 }
255 else
256 {
257 uint8_t* p = (buffer_ +
258 y * pitch_ +
259 x * GetBytesPerPixel());
260
261 if (readOnly_)
262 {
263 result.AssignReadOnly(format_, width, height, pitch_, p);
264 }
265 else
266 {
267 result.AssignWritable(format_, width, height, pitch_, p);
268 }
269 }
270
271 return result;
272 }
273
235 } 274 }