Skip to content

Commit 6e214ee

Browse files
authored
fix cv crash (#7674)
1 parent f05b391 commit 6e214ee

File tree

1 file changed

+44
-28
lines changed

1 file changed

+44
-28
lines changed

lite/utils/cv/image_convert.cc

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,11 @@ inline void nv12_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
453453
g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3;
454454
b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3;
455455

456-
*ptr_bgr1++ = b1;
457-
*ptr_bgr1++ = g1;
458-
*ptr_bgr1++ = r1;
456+
if (j + 1 < srcw) {
457+
*ptr_bgr1++ = b1;
458+
*ptr_bgr1++ = g1;
459+
*ptr_bgr1++ = r1;
460+
}
459461

460462
*ptr_bgr2++ = b2;
461463
*ptr_bgr2++ = g2;
@@ -465,9 +467,11 @@ inline void nv12_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
465467
ptr_y2 += 2;
466468
ptr_vu += 2;
467469

468-
*ptr_bgr2++ = b3;
469-
*ptr_bgr2++ = g3;
470-
*ptr_bgr2++ = r3;
470+
if (j + 1 < srcw) {
471+
*ptr_bgr2++ = b3;
472+
*ptr_bgr2++ = g3;
473+
*ptr_bgr2++ = r3;
474+
}
471475
}
472476
}
473477
delete[] zerobuf;
@@ -788,9 +792,11 @@ inline void nv21_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
788792
g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3;
789793
b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3;
790794

791-
*ptr_bgr1++ = b1;
792-
*ptr_bgr1++ = g1;
793-
*ptr_bgr1++ = r1;
795+
if (j + 1 < srcw) {
796+
*ptr_bgr1++ = b1;
797+
*ptr_bgr1++ = g1;
798+
*ptr_bgr1++ = r1;
799+
}
794800

795801
*ptr_bgr2++ = b2;
796802
*ptr_bgr2++ = g2;
@@ -800,9 +806,11 @@ inline void nv21_to_bgr(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
800806
ptr_y2 += 2;
801807
ptr_vu += 2;
802808

803-
*ptr_bgr2++ = b3;
804-
*ptr_bgr2++ = g3;
805-
*ptr_bgr2++ = r3;
809+
if (j + 1 < srcw) {
810+
*ptr_bgr2++ = b3;
811+
*ptr_bgr2++ = g3;
812+
*ptr_bgr2++ = r3;
813+
}
806814
}
807815
}
808816
delete[] zerobuf;
@@ -1128,10 +1136,12 @@ inline void nv12_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
11281136
g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3;
11291137
b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3;
11301138

1131-
*ptr_bgr1++ = b1;
1132-
*ptr_bgr1++ = g1;
1133-
*ptr_bgr1++ = r1;
1134-
*ptr_bgr1++ = 255;
1139+
if (j + 1 < srcw) {
1140+
*ptr_bgr1++ = b1;
1141+
*ptr_bgr1++ = g1;
1142+
*ptr_bgr1++ = r1;
1143+
*ptr_bgr1++ = 255;
1144+
}
11351145

11361146
*ptr_bgr2++ = b2;
11371147
*ptr_bgr2++ = g2;
@@ -1142,10 +1152,12 @@ inline void nv12_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
11421152
ptr_y2 += 2;
11431153
ptr_vu += 2;
11441154

1145-
*ptr_bgr2++ = b3;
1146-
*ptr_bgr2++ = g3;
1147-
*ptr_bgr2++ = r3;
1148-
*ptr_bgr2++ = 255;
1155+
if (j + 1 < srcw) {
1156+
*ptr_bgr2++ = b3;
1157+
*ptr_bgr2++ = g3;
1158+
*ptr_bgr2++ = r3;
1159+
*ptr_bgr2++ = 255;
1160+
}
11491161
}
11501162
}
11511163
delete[] zerobuf;
@@ -1471,10 +1483,12 @@ inline void nv21_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
14711483
g3 = g3 < 0 ? 0 : (g3 > 255) ? 255 : g3;
14721484
b3 = b3 < 0 ? 0 : (b3 > 255) ? 255 : b3;
14731485

1474-
*ptr_bgr1++ = b1;
1475-
*ptr_bgr1++ = g1;
1476-
*ptr_bgr1++ = r1;
1477-
*ptr_bgr1++ = 255;
1486+
if (j + 1 < srcw) {
1487+
*ptr_bgr1++ = b1;
1488+
*ptr_bgr1++ = g1;
1489+
*ptr_bgr1++ = r1;
1490+
*ptr_bgr1++ = 255;
1491+
}
14781492

14791493
*ptr_bgr2++ = b2;
14801494
*ptr_bgr2++ = g2;
@@ -1485,10 +1499,12 @@ inline void nv21_to_bgra(const uint8_t* src, uint8_t* dst, int srcw, int srch) {
14851499
ptr_y2 += 2;
14861500
ptr_vu += 2;
14871501

1488-
*ptr_bgr2++ = b3;
1489-
*ptr_bgr2++ = g3;
1490-
*ptr_bgr2++ = r3;
1491-
*ptr_bgr2++ = 255;
1502+
if (j + 1 < srcw) {
1503+
*ptr_bgr2++ = b3;
1504+
*ptr_bgr2++ = g3;
1505+
*ptr_bgr2++ = r3;
1506+
*ptr_bgr2++ = 255;
1507+
}
14921508
}
14931509
}
14941510
delete[] zerobuf;

0 commit comments

Comments
 (0)