From d3c50419a07c92c5e2a118566800122998b9ba4e Mon Sep 17 00:00:00 2001 From: godpiao <32320029+godpiao@users.noreply.github.com> Date: Thu, 2 Dec 2021 06:30:32 +0800 Subject: [PATCH] optimization ReverseUpAndDown function (#5972) change CImageEx:: ReverseUpDown function to avoid new uint32(width*height). Signed-off-by: godpiao --- Code/Editor/Util/Image.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Code/Editor/Util/Image.cpp b/Code/Editor/Util/Image.cpp index 773bfa93d2..8b26f54075 100644 --- a/Code/Editor/Util/Image.cpp +++ b/Code/Editor/Util/Image.cpp @@ -75,17 +75,16 @@ void CImageEx::ReverseUpDown() } uint32* pPixData = GetData(); - uint32* pReversePix = new uint32[GetWidth() * GetHeight()]; - - for (int i = GetHeight() - 1, i2 = 0; i >= 0; i--, i2++) + const int height = GetHeight(); + const int width = GetWidth(); + for (int i = 0; i < height / 2; i++) { - for (int k = 0; k < GetWidth(); k++) + for (int j = 0; j < width; j++) { - pReversePix[i2 * GetWidth() + k] = pPixData[i * GetWidth() + k]; + AZStd::swap(pPixData[i * width + j], pPixData[(height - 1 - i) * width + j]); } } - Attach(pReversePix, GetWidth(), GetHeight()); } void CImageEx::FillAlpha(unsigned char value)