Mercurial > hg > orthanc
diff UnitTestsSources/ImageTests.cpp @ 3834:219de90c1f43
Added a flag to use an extra buffer in PamReader
to ensure (malloc-like) alignment of the image
buffer. This flag is NOT turned on by default and,
in Orthanc, is only used by the Unit tests.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 15 Apr 2020 16:58:28 +0200 |
parents | 94f4a18a79cc |
children |
line wrap: on
line diff
--- a/UnitTestsSources/ImageTests.cpp Fri Apr 10 17:56:12 2020 +0200 +++ b/UnitTestsSources/ImageTests.cpp Wed Apr 15 16:58:28 2020 +0200 @@ -410,6 +410,28 @@ } { + // true means "enforce alignment by using a temporary buffer" + Orthanc::PamReader r(true); + r.ReadFromMemory(s); + + ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16); + ASSERT_EQ(r.GetWidth(), width); + ASSERT_EQ(r.GetHeight(), height); + + v = 0; + for (unsigned int y = 0; y < height; y++) + { + const uint16_t* p = reinterpret_cast<const uint16_t*> + ((const uint8_t*)r.GetConstBuffer() + y * r.GetPitch()); + ASSERT_EQ(p, r.GetConstRow(y)); + for (unsigned int x = 0; x < width; x++, p++, v++) + { + ASSERT_EQ(v, *p); + } + } + } + + { Orthanc::TemporaryFile tmp; tmp.Write(s); @@ -432,4 +454,30 @@ } } } + + { + Orthanc::TemporaryFile tmp; + tmp.Write(s); + + // true means "enforce alignment by using a temporary buffer" + Orthanc::PamReader r2(true); + r2.ReadFromFile(tmp.GetPath()); + + ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16); + ASSERT_EQ(r2.GetWidth(), width); + ASSERT_EQ(r2.GetHeight(), height); + + v = 0; + for (unsigned int y = 0; y < height; y++) + { + const uint16_t* p = reinterpret_cast<const uint16_t*> + ((const uint8_t*)r2.GetConstBuffer() + y * r2.GetPitch()); + ASSERT_EQ(p, r2.GetConstRow(y)); + for (unsigned int x = 0; x < width; x++, p++, v++) + { + ASSERT_EQ(*p, v); + } + } + } + }