comparison Core/Images/ImageAccessor.cpp @ 2954:d924f9bb61cc

taking advantage of details in OrthancException
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Dec 2018 14:35:34 +0100
parents 0f07bdae0805
children 4e43e67f8ecf
comparison
equal deleted inserted replaced
2953:210d5afd8f2b 2954:d924f9bb61cc
105 105
106 void* ImageAccessor::GetBuffer() const 106 void* ImageAccessor::GetBuffer() const
107 { 107 {
108 if (readOnly_) 108 if (readOnly_)
109 { 109 {
110 #if ORTHANC_ENABLE_LOGGING == 1 110 throw OrthancException(ErrorCode_ReadOnly,
111 LOG(ERROR) << "Trying to write on a read-only image"; 111 "Trying to write to a read-only image");
112 #endif
113
114 throw OrthancException(ErrorCode_ReadOnly);
115 } 112 }
116 113
117 return buffer_; 114 return buffer_;
118 } 115 }
119 116
133 130
134 void* ImageAccessor::GetRow(unsigned int y) const 131 void* ImageAccessor::GetRow(unsigned int y) const
135 { 132 {
136 if (readOnly_) 133 if (readOnly_)
137 { 134 {
138 #if ORTHANC_ENABLE_LOGGING == 1 135 throw OrthancException(ErrorCode_ReadOnly,
139 LOG(ERROR) << "Trying to write on a read-only image"; 136 "Trying to write to a read-only image");
140 #endif
141
142 throw OrthancException(ErrorCode_ReadOnly);
143 } 137 }
144 138
145 if (buffer_ != NULL) 139 if (buffer_ != NULL)
146 { 140 {
147 return buffer_ + y * pitch_; 141 return buffer_ + y * pitch_;
297 291
298 void ImageAccessor::SetFormat(PixelFormat format) 292 void ImageAccessor::SetFormat(PixelFormat format)
299 { 293 {
300 if (readOnly_) 294 if (readOnly_)
301 { 295 {
302 #if ORTHANC_ENABLE_LOGGING == 1 296 throw OrthancException(ErrorCode_ReadOnly,
303 LOG(ERROR) << "Trying to modify the format of a read-only image"; 297 "Trying to modify the format of a read-only image");
304 #endif
305 throw OrthancException(ErrorCode_ReadOnly);
306 } 298 }
307 299
308 if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_)) 300 if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_))
309 { 301 {
310 throw OrthancException(ErrorCode_IncompatibleImageFormat); 302 throw OrthancException(ErrorCode_IncompatibleImageFormat);