Mercurial > hg > orthanc
comparison Core/Images/ImageProcessing.cpp @ 2902:e80b38fb22c6
fix ImageProcessing::Set() for subregions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 23 Oct 2018 12:05:19 +0200 |
parents | da43ef7ff32a |
children | 0dd54ee073db |
comparison
equal
deleted
inserted
replaced
2901:93c65e3a6bb1 | 2902:e80b38fb22c6 |
---|---|
132 } | 132 } |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 static void MemsetZeroInternal(ImageAccessor& image) | |
138 { | |
139 const unsigned int height = image.GetHeight(); | |
140 const size_t lineSize = image.GetBytesPerPixel() * image.GetWidth(); | |
141 const size_t pitch = image.GetPitch(); | |
142 | |
143 uint8_t *p = reinterpret_cast<uint8_t*>(image.GetBuffer()); | |
144 | |
145 for (unsigned int y = 0; y < height; y++) | |
146 { | |
147 memset(p, 0, lineSize); | |
148 p += pitch; | |
149 } | |
150 } | |
151 | |
152 | |
137 template <typename PixelType> | 153 template <typename PixelType> |
138 static void SetInternal(ImageAccessor& image, | 154 static void SetInternal(ImageAccessor& image, |
139 int64_t constant) | 155 int64_t constant) |
140 { | 156 { |
141 for (unsigned int y = 0; y < image.GetHeight(); y++) | 157 if (constant == 0 && |
142 { | 158 (image.GetFormat() == PixelFormat_Grayscale8 || |
143 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | 159 image.GetFormat() == PixelFormat_Grayscale16 || |
144 | 160 image.GetFormat() == PixelFormat_Grayscale32 || |
145 for (unsigned int x = 0; x < image.GetWidth(); x++, p++) | 161 image.GetFormat() == PixelFormat_Grayscale64 || |
146 { | 162 image.GetFormat() == PixelFormat_SignedGrayscale16)) |
147 *p = static_cast<PixelType>(constant); | 163 { |
164 MemsetZeroInternal(image); | |
165 } | |
166 else | |
167 { | |
168 const unsigned int width = image.GetWidth(); | |
169 const unsigned int height = image.GetHeight(); | |
170 | |
171 for (unsigned int y = 0; y < height; y++) | |
172 { | |
173 PixelType* p = reinterpret_cast<PixelType*>(image.GetRow(y)); | |
174 | |
175 for (unsigned int x = 0; x < width; x++, p++) | |
176 { | |
177 *p = static_cast<PixelType>(constant); | |
178 } | |
148 } | 179 } |
149 } | 180 } |
150 } | 181 } |
151 | 182 |
152 | 183 |
332 if (target.GetFormat() != source.GetFormat()) | 363 if (target.GetFormat() != source.GetFormat()) |
333 { | 364 { |
334 throw OrthancException(ErrorCode_IncompatibleImageFormat); | 365 throw OrthancException(ErrorCode_IncompatibleImageFormat); |
335 } | 366 } |
336 | 367 |
337 unsigned int lineSize = GetBytesPerPixel(source.GetFormat()) * source.GetWidth(); | 368 unsigned int lineSize = source.GetBytesPerPixel() * source.GetWidth(); |
338 | 369 |
339 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); | 370 assert(source.GetPitch() >= lineSize && target.GetPitch() >= lineSize); |
340 | 371 |
341 for (unsigned int y = 0; y < source.GetHeight(); y++) | 372 for (unsigned int y = 0; y < source.GetHeight(); y++) |
342 { | 373 { |
699 int64_t value) | 730 int64_t value) |
700 { | 731 { |
701 switch (image.GetFormat()) | 732 switch (image.GetFormat()) |
702 { | 733 { |
703 case PixelFormat_Grayscale8: | 734 case PixelFormat_Grayscale8: |
704 memset(image.GetBuffer(), static_cast<uint8_t>(value), image.GetPitch() * image.GetHeight()); | 735 SetInternal<uint8_t>(image, value); |
705 return; | 736 return; |
706 | 737 |
707 case PixelFormat_Grayscale16: | 738 case PixelFormat_Grayscale16: |
708 if (value == 0) | 739 SetInternal<uint16_t>(image, value); |
709 { | |
710 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); | |
711 } | |
712 else | |
713 { | |
714 SetInternal<uint16_t>(image, value); | |
715 } | |
716 return; | 740 return; |
717 | 741 |
718 case PixelFormat_Grayscale32: | 742 case PixelFormat_Grayscale32: |
719 if (value == 0) | 743 SetInternal<uint32_t>(image, value); |
720 { | |
721 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); | |
722 } | |
723 else | |
724 { | |
725 SetInternal<uint32_t>(image, value); | |
726 } | |
727 return; | 744 return; |
728 | 745 |
729 case PixelFormat_Grayscale64: | 746 case PixelFormat_Grayscale64: |
730 if (value == 0) | 747 SetInternal<uint64_t>(image, value); |
731 { | |
732 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); | |
733 } | |
734 else | |
735 { | |
736 SetInternal<uint64_t>(image, value); | |
737 } | |
738 return; | 748 return; |
739 | 749 |
740 case PixelFormat_SignedGrayscale16: | 750 case PixelFormat_SignedGrayscale16: |
741 if (value == 0) | 751 SetInternal<int16_t>(image, value); |
742 { | |
743 memset(image.GetBuffer(), 0, image.GetPitch() * image.GetHeight()); | |
744 } | |
745 else | |
746 { | |
747 SetInternal<int16_t>(image, value); | |
748 } | |
749 return; | 752 return; |
750 | 753 |
751 case PixelFormat_Float32: | 754 case PixelFormat_Float32: |
752 assert(sizeof(float) == 4); | 755 assert(sizeof(float) == 4); |
753 SetInternal<float>(image, value); | 756 SetInternal<float>(image, value); |