Skip to content

Commit b191e49

Browse files
authored
Merge pull request micro-manager#899 from mehta-lab/optimize-image-flip-y
Optimize ImageFlipY for large images
2 parents e63b802 + 4471939 commit b191e49

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

DeviceAdapters/DemoCamera/DemoCamera.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
#include <string>
3636
#include <map>
3737
#include <algorithm>
38+
#include <cstring>
3839
#include <stdint.h>
3940
#include <future>
41+
#include <vector>
4042

4143
//////////////////////////////////////////////////////////////////////////////
4244
// Error codes
@@ -967,18 +969,16 @@ class ImageFlipY : public CImageProcessorBase<ImageFlipY>
967969
template <typename PixelType>
968970
int Flip(PixelType* pI, unsigned int width, unsigned int height)
969971
{
970-
PixelType tmp;
971-
int ret = DEVICE_OK;
972-
for( unsigned long ix = 0; ix < width ; ++ix)
972+
std::vector<PixelType> rowBuf(width);
973+
for (unsigned int iy = 0; iy < height / 2; ++iy)
973974
{
974-
for( unsigned long iy = 0; iy < (height>>1); ++iy)
975-
{
976-
tmp = pI[ ix + iy*width];
977-
pI[ ix + iy*width] = pI[ ix + (height - 1 - iy)*width];
978-
pI[ ix + (height - 1 - iy)*width] = tmp;
979-
}
975+
PixelType* topRow = pI + iy * width;
976+
PixelType* botRow = pI + (height - 1 - iy) * width;
977+
std::memcpy(rowBuf.data(), topRow, width * sizeof(PixelType));
978+
std::memcpy(topRow, botRow, width * sizeof(PixelType));
979+
std::memcpy(botRow, rowBuf.data(), width * sizeof(PixelType));
980980
}
981-
return ret;
981+
return DEVICE_OK;
982982
}
983983

984984

0 commit comments

Comments
 (0)