diff --git a/lite/utils/cv/image_convert.cc b/lite/utils/cv/image_convert.cc index 0bd8529dcc6..4c8e4802a49 100644 --- a/lite/utils/cv/image_convert.cc +++ b/lite/utils/cv/image_convert.cc @@ -465,6 +465,7 @@ inline void nv12_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) { ptr_y1 += 2; ptr_y2 += 2; ptr_vu += 2; + if (j + 1 < srcw) { *ptr_bgr2++ = b3; *ptr_bgr2++ = g3; @@ -790,9 +791,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; @@ -802,9 +805,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; + } } } LITE_PARALLEL_COMMON_END(); @@ -1130,10 +1135,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; @@ -1144,10 +1151,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; + } } } LITE_PARALLEL_COMMON_END(); @@ -1473,10 +1482,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; @@ -1487,10 +1498,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; + } } } LITE_PARALLEL_COMMON_END();