# HG changeset patch # User Sebastien Jodogne # Date 1476351750 -7200 # Node ID a89ca69ec1d1dbd88194693c18ddb5b3978f363b # Parent f0544ab9396bad1a80c9b8f41fdf1073415ad47f ImageAccessor::SetFormat diff -r f0544ab9396b -r a89ca69ec1d1 Core/Images/ImageAccessor.cpp --- a/Core/Images/ImageAccessor.cpp Wed Oct 12 19:35:31 2016 +0200 +++ b/Core/Images/ImageAccessor.cpp Thu Oct 13 11:42:30 2016 +0200 @@ -275,4 +275,22 @@ return result; } + + void ImageAccessor::SetFormat(PixelFormat format) + { + if (readOnly_) + { +#if ORTHANC_ENABLE_LOGGING == 1 + LOG(ERROR) << "Trying to modify the format of a read-only image"; +#endif + throw OrthancException(ErrorCode_ReadOnly); + } + + if (::Orthanc::GetBytesPerPixel(format) != ::Orthanc::GetBytesPerPixel(format_)) + { + throw OrthancException(ErrorCode_IncompatibleImageFormat); + } + + format_ = format; + } } diff -r f0544ab9396b -r a89ca69ec1d1 Core/Images/ImageAccessor.h --- a/Core/Images/ImageAccessor.h Wed Oct 12 19:35:31 2016 +0200 +++ b/Core/Images/ImageAccessor.h Thu Oct 13 11:42:30 2016 +0200 @@ -125,5 +125,7 @@ unsigned int y, unsigned int width, unsigned int height) const; + + void SetFormat(PixelFormat format); }; }