comparison Core/FileFormats/PngReader.cpp @ 798:e1d27ee2114a

ImageAccessor abstraction
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 May 2014 12:52:28 +0200
parents 37adac56017a
children
comparison
equal deleted inserted replaced
797:37adac56017a 798:e1d27ee2114a
222 222
223 Read(rabi); 223 Read(rabi);
224 } 224 }
225 225
226 226
227 void* ImageAccessor::GetBuffer()
228 {
229 if (readOnly_)
230 {
231 throw OrthancException(ErrorCode_ReadOnly);
232 }
233
234 return buffer_;
235 }
236
237
238 const void* ImageAccessor::GetConstRow(unsigned int y) const
239 {
240 if (buffer_ != NULL)
241 {
242 return reinterpret_cast<const uint8_t*>(buffer_) + y * pitch_;
243 }
244 else
245 {
246 return NULL;
247 }
248 }
249
250
251 void* ImageAccessor::GetRow(unsigned int y)
252 {
253 if (readOnly_)
254 {
255 throw OrthancException(ErrorCode_ReadOnly);
256 }
257
258 if (buffer_ != NULL)
259 {
260 return reinterpret_cast<uint8_t*>(buffer_) + y * pitch_;
261 }
262 else
263 {
264 return NULL;
265 }
266 }
267
268
269 void ImageAccessor::AssignEmpty(PixelFormat format)
270 {
271 readOnly_ = false;
272 format_ = format;
273 width_ = 0;
274 height_ = 0;
275 pitch_ = 0;
276 buffer_ = NULL;
277 }
278
279
280 void ImageAccessor::AssignReadOnly(PixelFormat format,
281 unsigned int width,
282 unsigned int height,
283 unsigned int pitch,
284 const void *buffer)
285 {
286 readOnly_ = true;
287 format_ = format;
288 width_ = width;
289 height_ = height;
290 pitch_ = pitch;
291 buffer_ = const_cast<void*>(buffer);
292 }
293
294
295 void ImageAccessor::AssignWritable(PixelFormat format,
296 unsigned int width,
297 unsigned int height,
298 unsigned int pitch,
299 void *buffer)
300 {
301 readOnly_ = false;
302 format_ = format;
303 width_ = width;
304 height_ = height;
305 pitch_ = pitch;
306 buffer_ = buffer;
307 }
308
309
310
311 namespace 227 namespace
312 { 228 {
313 struct MemoryBuffer 229 struct MemoryBuffer
314 { 230 {
315 const uint8_t* buffer_; 231 const uint8_t* buffer_;