# HG changeset patch # User Sebastien Jodogne # Date 1540289119 -7200 # Node ID e80b38fb22c6db1bd7f9cf5ca23492e728f73882 # Parent 93c65e3a6bb16eb0a4efc3d0957ab83f166bda8c fix ImageProcessing::Set() for subregions diff -r 93c65e3a6bb1 -r e80b38fb22c6 Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Mon Oct 22 16:12:59 2018 +0200 +++ b/Core/Images/ImageProcessing.cpp Tue Oct 23 12:05:19 2018 +0200 @@ -134,17 +134,48 @@ } + static void MemsetZeroInternal(ImageAccessor& image) + { + const unsigned int height = image.GetHeight(); + const size_t lineSize = image.GetBytesPerPixel() * image.GetWidth(); + const size_t pitch = image.GetPitch(); + + uint8_t *p = reinterpret_cast(image.GetBuffer()); + + for (unsigned int y = 0; y < height; y++) + { + memset(p, 0, lineSize); + p += pitch; + } + } + + template static void SetInternal(ImageAccessor& image, int64_t constant) { - for (unsigned int y = 0; y < image.GetHeight(); y++) + if (constant == 0 && + (image.GetFormat() == PixelFormat_Grayscale8 || + image.GetFormat() == PixelFormat_Grayscale16 || + image.GetFormat() == PixelFormat_Grayscale32 || + image.GetFormat() == PixelFormat_Grayscale64 || + image.GetFormat() == PixelFormat_SignedGrayscale16)) { - PixelType* p = reinterpret_cast(image.GetRow(y)); + MemsetZeroInternal(image); + } + else + { + const unsigned int width = image.GetWidth(); + const unsigned int height = image.GetHeight(); - for (unsigned int x = 0; x < image.GetWidth(); x++, p++) + for (unsigned int y = 0; y < height; y++) { - *p = static_cast(constant); + PixelType* p = reinterpret_cast(image.GetRow(y)); + + for (unsigned int x = 0; x < width; x++, p++) + { + *p = static_cast(constant); + } } } } @@ -334,7 +365,7 @@ throw OrthancException(ErrorCode_IncompatibleImageFormat); } - unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth(); + unsigned int lineSize = source.GetBytesPerPixel() * source.GetWidth(); assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); @@ -701,51 +732,23 @@ switch (image.GetFormat()) { case PixelFormat_Grayscale8: - memset(image.GetBuffer(), static_cast(value), image.GetPitch() * image.GetHeight()); + SetInternal(image, value); return; case PixelFormat_Grayscale16: - if (value == 0) - { - memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); - } - else - { - SetInternal(image, value); - } + SetInternal(image, value); return; case PixelFormat_Grayscale32: - if (value == 0) - { - memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); - } - else - { - SetInternal(image, value); - } + SetInternal(image, value); return; case PixelFormat_Grayscale64: - if (value == 0) - { - memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); - } - else - { - SetInternal(image, value); - } + SetInternal(image, value); return; case PixelFormat_SignedGrayscale16: - if (value == 0) - { - memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); - } - else - { - SetInternal(image, value); - } + SetInternal(image, value); return; case PixelFormat_Float32: