From a3ddadacc5f09e6fb4db0b5d7289bb633b8879e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 6 Jul 2021 22:43:26 +0200 Subject: [PATCH] opti in addBuffer (use of std::for_each) --- sources/PPU/PPUUtils.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sources/PPU/PPUUtils.hpp b/sources/PPU/PPUUtils.hpp index 916e403..c1799f1 100644 --- a/sources/PPU/PPUUtils.hpp +++ b/sources/PPU/PPUUtils.hpp @@ -82,12 +82,23 @@ namespace ComSquare::PPU::Utils static void addBuffer(std::array, DEST_SIZE_X> &bufferDest, const std::array, SRC_SIZE_X> &bufferSrc) { - for (unsigned long i = 0; i < bufferSrc.size(); i++) { + int i = 0; + int j = 0; + std::for_each(bufferSrc.begin(), bufferSrc.end(), [&bufferDest, &i, &j](auto &sourceRow) { + i++; + std::for_each(sourceRow.begin(), sourceRow.end(), [&bufferDest, &i, &j](auto &pixel) { + if (pixel > 0xFF) + bufferDest[i][j] = pixel; + j++; + }); + j = 0; + }); + /* for (unsigned long i = 0; i < bufferSrc.size(); i++) { for (unsigned long j = 0; j < bufferSrc[i].size(); j++) { if (bufferSrc[i][j] > 0xFF) // 0xFF correspond to a black pixel with full brightness bufferDest[i][j] = bufferSrc[i][j]; } - } + }*/ } }