From f2cb075e9bb6349d3bd0a83f2e80fd8ae4bf88e3 Mon Sep 17 00:00:00 2001 From: lxw950127 <1182657559@qq.com> Date: Thu, 18 Nov 2021 07:45:08 +0000 Subject: [PATCH] fix cv crash --- lite/utils/cv/image_convert.cc | 72 +++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/lite/utils/cv/image_convert.cc b/lite/utils/cv/image_convert.cc index 8a064ffcdb9..8528498894a 100644 --- a/lite/utils/cv/image_convert.cc +++ b/lite/utils/cv/image_convert.cc @@ -453,9 +453,11 @@ inline void nv12_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) { g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3; b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3; - *ptr_bgr1++ = b1; - *ptr_bgr1++ = g1; - *ptr_bgr1++ = r1; + if (j + 1 < srcw) { + *ptr_bgr1++ = b1; + *ptr_bgr1++ = g1; + *ptr_bgr1++ = r1; + } *ptr_bgr2++ = b2; *ptr_bgr2++ = g2; @@ -465,9 +467,11 @@ inline void nv12_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) { ptr_y2 += 2; ptr_vu += 2; - *ptr_bgr2++ = b3; - *ptr_bgr2++ = g3; - *ptr_bgr2++ = r3; + if (j + 1 < srcw) { + *ptr_bgr2++ = b3; + *ptr_bgr2++ = g3; + *ptr_bgr2++ = r3; + } } } delete[] zerobuf; @@ -788,9 +792,11 @@ inline void nv21_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) { g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3; b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3; - *ptr_bgr1++ = b1; - *ptr_bgr1++ = g1; - *ptr_bgr1++ = r1; + if (j + 1 < srcw) { + *ptr_bgr1++ = b1; + *ptr_bgr1++ = g1; + *ptr_bgr1++ = r1; + } *ptr_bgr2++ = b2; *ptr_bgr2++ = g2; @@ -800,9 +806,11 @@ inline void nv21_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) { ptr_y2 += 2; ptr_vu += 2; - *ptr_bgr2++ = b3; - *ptr_bgr2++ = g3; - *ptr_bgr2++ = r3; + if (j + 1 < srcw) { + *ptr_bgr2++ = b3; + *ptr_bgr2++ = g3; + *ptr_bgr2++ = r3; + } } } delete[] zerobuf; @@ -1128,10 +1136,12 @@ inline void nv12_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) { g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3; b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3; - *ptr_bgr1++ = b1; - *ptr_bgr1++ = g1; - *ptr_bgr1++ = r1; - *ptr_bgr1++ = 255; + if (j + 1 < srcw) { + *ptr_bgr1++ = b1; + *ptr_bgr1++ = g1; + *ptr_bgr1++ = r1; + *ptr_bgr1++ = 255; + } *ptr_bgr2++ = b2; *ptr_bgr2++ = g2; @@ -1142,10 +1152,12 @@ inline void nv12_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) { ptr_y2 += 2; ptr_vu += 2; - *ptr_bgr2++ = b3; - *ptr_bgr2++ = g3; - *ptr_bgr2++ = r3; - *ptr_bgr2++ = 255; + if (j + 1 < srcw) { + *ptr_bgr2++ = b3; + *ptr_bgr2++ = g3; + *ptr_bgr2++ = r3; + *ptr_bgr2++ = 255; + } } } delete[] zerobuf; @@ -1471,10 +1483,12 @@ inline void nv21_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) { g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3; b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3; - *ptr_bgr1++ = b1; - *ptr_bgr1++ = g1; - *ptr_bgr1++ = r1; - *ptr_bgr1++ = 255; + if (j + 1 < srcw) { + *ptr_bgr1++ = b1; + *ptr_bgr1++ = g1; + *ptr_bgr1++ = r1; + *ptr_bgr1++ = 255; + } *ptr_bgr2++ = b2; *ptr_bgr2++ = g2; @@ -1485,10 +1499,12 @@ inline void nv21_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) { ptr_y2 += 2; ptr_vu += 2; - *ptr_bgr2++ = b3; - *ptr_bgr2++ = g3; - *ptr_bgr2++ = r3; - *ptr_bgr2++ = 255; + if (j + 1 < srcw) { + *ptr_bgr2++ = b3; + *ptr_bgr2++ = g3; + *ptr_bgr2++ = r3; + *ptr_bgr2++ = 255; + } } } delete[] zerobuf;