From 038836412874a381fbee00a10b1c1b4755e4f7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 19 Mar 2020 09:54:20 +0100 Subject: [PATCH] TgaImporter: STL algorithms only make you write longer and slower code. And more error-prone, harder-to-debug and complex. Seriously, why even bother. --- src/MagnumPlugins/TgaImporter/TgaImporter.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index 9eed9ac4f..723c4ad0d 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -25,11 +25,11 @@ #include "TgaImporter.h" -#include #include #include #include #include +#include #include #include "Magnum/PixelFormat.h" @@ -126,7 +126,7 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt, UnsignedIn } Containers::Array data{outputSize}; - std::copy_n(_in + sizeof(Implementation::TgaHeader), outputSize, data.begin()); + Utility::copy(_in.suffix(sizeof(Implementation::TgaHeader)), data); /* Adjust pixel storage if row size is not four byte aligned */ PixelStorage storage; @@ -134,13 +134,11 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt, UnsignedIn storage.setAlignment(1); if(format == PixelFormat::RGB8Unorm) { - auto pixels = reinterpret_cast*>(data.data()); - std::transform(pixels, pixels + size.product(), pixels, - [](Math::Vector3 pixel) { return Math::gather<'b', 'g', 'r'>(pixel); }); + for(Vector3ub& pixel: Containers::arrayCast(data)) + pixel = Math::gather<'b', 'g', 'r'>(pixel); } else if(format == PixelFormat::RGBA8Unorm) { - auto pixels = reinterpret_cast*>(data.data()); - std::transform(pixels, pixels + size.product(), pixels, - [](Math::Vector4 pixel) { return Math::gather<'b', 'g', 'r', 'a'>(pixel); }); + for(Vector4ub& pixel: Containers::arrayCast(data)) + pixel = Math::gather<'b', 'g', 'r', 'a'>(pixel); } return ImageData2D{storage, format, size, std::move(data)};