Files
opencv-MIRROR/modules/core/src
pranayr710 34b8868876 core: saturate when narrowing 64-bit and 32U sources in convertTo
v_pack() narrows 64-bit lanes by truncation: at the 8/16/32-bit widths
v_pack saturates, but the 64->32 forms are defined with static_cast (see
OPENCV_HAL_IMPL_C_PACK in intrin_cpp.hpp) because no backend offers a
saturating 64->32 pack. The vectorized conversion helpers packed straight
from a 64-bit source, so a value outside the 32-bit range wrapped, and the
saturating narrow that followed then clamped the WRAPPED value - landing at
the wrong end of the destination's range. The same happened one width down,
where a CV_32U source was reinterpreted as signed without clamping.

Only the vector loop was affected, so the answer depended on how long the
array was: below the vector width the scalar path saturated correctly.

  Mat src(1, n, CV_64U, Scalar(4294967295));
  src.convertTo(dst, CV_8U);       // n < 16: 255      n >= 16: 0
  src.convertTo(dst, CV_16U);      // n < 16: 65535    n >= 16: 0

Clamp into the destination's range before packing. The unsigned-source
helpers test the high bits with a shift instead of an ordering compare,
since unsigned 64-bit comparison is not uniformly available across the SIMD
backends, and v_select() has no 64-bit form so the blend goes through the
comparison mask by hand.

Affects CV_64U/CV_64S -> CV_8U/CV_8S/CV_16U/CV_16S/CV_32S and
CV_32U -> CV_8S/CV_16S.
2026-10-01 20:29:06 +05:30
..
2026-05-20 17:57:51 +03:00
2026-07-09 12:17:24 +03:00
2023-01-09 11:08:02 +00:00
2024-11-14 08:33:22 +03:00
2018-09-07 20:33:52 +09:00
2026-05-20 17:29:34 +05:30
2026-05-20 17:29:34 +05:30
2019-03-05 14:47:04 +03:00
2026-07-28 20:28:24 +05:30
2022-03-03 07:21:53 +09:00
2026-07-22 11:44:27 +02:00
2025-09-26 12:10:49 +03:00
2026-07-09 12:17:24 +03:00
2025-05-07 13:17:42 +03:00
2026-07-09 12:17:24 +03:00
2024-02-12 14:20:35 +03:00
2024-11-14 08:33:22 +03:00
2026-07-09 12:17:24 +03:00
2026-09-23 14:28:55 +02:00
2018-02-12 14:14:08 +03:00
2018-08-27 14:42:18 +03:00
2025-06-10 10:16:50 +03:00
2026-07-09 12:17:24 +03:00
2014-08-15 12:09:16 +04:00
2026-08-21 01:07:25 +02:00
2022-02-22 19:55:26 +00:00