From 5e1c511dfc98554cbbd1783928f28525d4de4653 Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Fri, 4 Sep 2020 09:56:06 +0200 Subject: [PATCH] Bug fix in image loading --- libs/yocto/yocto_image.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/yocto/yocto_image.cpp b/libs/yocto/yocto_image.cpp index ce335b7bd..bf1739082 100644 --- a/libs/yocto/yocto_image.cpp +++ b/libs/yocto/yocto_image.cpp @@ -1480,8 +1480,9 @@ static vector convert_components( throw std::invalid_argument{"components not supported"}; if (components == components_to) return pixels; - auto cpixels = vector((size_t)components_to * pixels.size()); - for (auto i = 0ull; i < pixels.size(); i++) { + auto npixels = pixels.size() / (size_t)components; + auto cpixels = vector((size_t)components_to * npixels); + for (auto i = 0ull; i < npixels; i++) { auto vp = pixels.data() + i * components; auto cp = cpixels.data() + i * components_to; if (components_to > 0) cp[0] = (components > 0) ? vp[0] : 0;