From 6c2cee818668bc19ce3fbcd68e3964283050554b Mon Sep 17 00:00:00 2001 From: nihuini Date: Fri, 5 Nov 2021 17:02:32 +0800 Subject: [PATCH] fix mat clone with atypical source cstep --- src/mat.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mat.cpp b/src/mat.cpp index eaeb8c5b1..b430f8a07 100644 --- a/src/mat.cpp +++ b/src/mat.cpp @@ -48,7 +48,17 @@ Mat Mat::clone(Allocator* _allocator) const if (total() > 0) { - memcpy(m.data, data, total() * elemsize); + if (cstep == m.cstep) + memcpy(m.data, data, total() * elemsize); + else + { + // copy by channel for differnet cstep + size_t size = w * h; + for (int i = 0; i < c; i++) + { + memcpy(m.channel(i), channel(i), size * elemsize); + } + } } return m;