diff --git a/src/rgb_to_nv_p16.rs b/src/rgb_to_nv_p16.rs index 937f7ba..e4916df 100644 --- a/src/rgb_to_nv_p16.rs +++ b/src/rgb_to_nv_p16.rs @@ -117,7 +117,7 @@ fn rgbx_to_yuv_bi_planar_10_impl< let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; y_dst[0] = transform_integer::( - y_0.clamp(i_bias_y, i_cap_y), + y_0.max(i_bias_y).min(i_cap_y), ); let rgba1 = &rgba[channels..channels * 2]; @@ -129,7 +129,7 @@ fn rgbx_to_yuv_bi_planar_10_impl< let y_1 = (r1 * transform.yr + g1 * transform.yg + b1 * transform.yb + bias_y) >> PRECISION; y_dst[1] = transform_integer::( - y_1.clamp(i_bias_y, i_cap_y), + y_1.max(i_bias_y).min(i_cap_y), ); if compute_chroma { @@ -143,11 +143,11 @@ fn rgbx_to_yuv_bi_planar_10_impl< >> PRECISION; uv_dst[nv_order.get_u_position()] = transform_integer::( - cb.clamp(i_bias_y, i_cap_uv), + cb.max(i_bias_y).min(i_cap_uv), ); uv_dst[nv_order.get_v_position()] = transform_integer::( - cr.clamp(i_bias_y, i_cap_uv), + cr.max(i_bias_y).min(i_cap_uv), ); } } @@ -164,7 +164,7 @@ fn rgbx_to_yuv_bi_planar_10_impl< let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; y_dst[0] = transform_integer::( - y_0.clamp(i_bias_y, i_cap_y), + y_0.max(i_bias_y).min(i_cap_y), ); if compute_chroma { @@ -176,11 +176,11 @@ fn rgbx_to_yuv_bi_planar_10_impl< >> PRECISION; uv_dst[nv_order.get_u_position()] = transform_integer::( - cb.clamp(i_bias_y, i_cap_uv), + cb.max(i_bias_y).min(i_cap_uv), ); uv_dst[nv_order.get_v_position()] = transform_integer::( - cr.clamp(i_bias_y, i_cap_uv), + cr.max(i_bias_y).min(i_cap_uv), ); } } @@ -219,7 +219,7 @@ fn rgbx_to_yuv_bi_planar_10_impl< let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; *y_dst = transform_integer::( - y_0.clamp(i_bias_y, i_cap_y), + y_0.max(i_bias_y).min(i_cap_y), ); let cb = (r0 * transform.cb_r + g0 * transform.cb_g + b0 * transform.cb_b + bias_uv) @@ -229,11 +229,11 @@ fn rgbx_to_yuv_bi_planar_10_impl< >> PRECISION; uv_dst[nv_order.get_u_position()] = transform_integer::( - cb.clamp(i_bias_y, i_cap_uv), + cb.max(i_bias_y).min(i_cap_uv), ); uv_dst[nv_order.get_v_position()] = transform_integer::( - cr.clamp(i_bias_y, i_cap_uv), + cr.max(i_bias_y).min(i_cap_uv), ); } }); diff --git a/src/rgb_to_y.rs b/src/rgb_to_y.rs index 4f3626e..a8291e1 100644 --- a/src/rgb_to_y.rs +++ b/src/rgb_to_y.rs @@ -178,7 +178,7 @@ fn rgbx_to_y( let g = rgba[source_channels.get_g_channel_offset()] as i32; let b = rgba[source_channels.get_b_channel_offset()] as i32; let y = (r * transform.yr + g * transform.yg + b * transform.yb + bias_y) >> PRECISION; - *y_dst = y.clamp(i_bias_y, i_cap_y) as u8; + *y_dst = y.max(i_bias_y).min(i_cap_y) as u8; } }); diff --git a/src/rgb_to_yuv_p16.rs b/src/rgb_to_yuv_p16.rs index 5db8d5d..baec241 100644 --- a/src/rgb_to_yuv_p16.rs +++ b/src/rgb_to_yuv_p16.rs @@ -221,7 +221,7 @@ fn rgbx_to_yuv_ant< let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; y_dst[0] = transform_integer::( - y_0.clamp(i_bias_y, i_cap_y), + y_0.max(i_bias_y).min(i_cap_y), ); let r1 = rgba[channels + src_chans.get_r_channel_offset()] as i32; @@ -230,7 +230,7 @@ fn rgbx_to_yuv_ant< let y_1 = (r1 * transform.yr + g1 * transform.yg + b1 * transform.yb + bias_y) >> PRECISION; y_dst[1] = transform_integer::( - y_1.clamp(i_bias_y, i_cap_y), + y_1.max(i_bias_y).min(i_cap_y), ); if compute_chroma_row { @@ -243,10 +243,10 @@ fn rgbx_to_yuv_ant< let cr = (r * transform.cr_r + g * transform.cr_g + b * transform.cr_b + bias_uv) >> PRECISION; *u_dst = transform_integer::( - cb.clamp(i_bias_y, i_cap_uv), + cb.max(i_bias_y).min(i_cap_uv), ); *v_dst = transform_integer::( - cr.clamp(i_bias_y, i_cap_uv), + cr.max(i_bias_y).min(i_cap_uv), ); } } @@ -264,7 +264,7 @@ fn rgbx_to_yuv_ant< let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; *y_last = transform_integer::( - y_0.clamp(i_bias_y, i_cap_y), + y_0.max(i_bias_y).min(i_cap_y), ); if compute_chroma_row { @@ -275,10 +275,10 @@ fn rgbx_to_yuv_ant< (r0 * transform.cr_r + g0 * transform.cr_g + b0 * transform.cr_b + bias_uv) >> PRECISION; *u_last = transform_integer::( - cb.clamp(i_bias_y, i_cap_uv), + cb.max(i_bias_y).min(i_cap_uv), ); *v_last = transform_integer::( - cr.clamp(i_bias_y, i_cap_uv), + cr.max(i_bias_y).min(i_cap_uv), ); } } @@ -326,7 +326,7 @@ fn rgbx_to_yuv_ant< let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; *y_dst = transform_integer::( - y_0.clamp(i_bias_y, i_cap_y), + y_0.max(i_bias_y).min(i_cap_y), ); let cb = @@ -336,10 +336,10 @@ fn rgbx_to_yuv_ant< (r0 * transform.cr_r + g0 * transform.cr_g + b0 * transform.cr_b + bias_uv) >> PRECISION; *u_dst = transform_integer::( - cb.clamp(i_bias_y, i_cap_uv), + cb.max(i_bias_y).min(i_cap_uv), ); *v_dst = transform_integer::( - cr.clamp(i_bias_y, i_cap_uv), + cr.max(i_bias_y).min(i_cap_uv), ); } }); diff --git a/src/rgba_to_nv.rs b/src/rgba_to_nv.rs index 8237477..aee1a58 100644 --- a/src/rgba_to_nv.rs +++ b/src/rgba_to_nv.rs @@ -166,7 +166,7 @@ fn rgbx_to_nv let b0 = rgba0[src_chans.get_b_channel_offset()] as i32; let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; - y_dst[0] = y_0.clamp(i_bias_y, i_cap_y) as u8; + y_dst[0] = y_0.max(i_bias_y).min(i_cap_y) as u8; let rgba1 = &rgba[channels..channels * 2]; @@ -176,7 +176,7 @@ fn rgbx_to_nv let y_1 = (r1 * transform.yr + g1 * transform.yg + b1 * transform.yb + bias_y) >> PRECISION; - y_dst[1] = y_1.clamp(i_bias_y, i_cap_y) as u8; + y_dst[1] = y_1.max(i_bias_y).min(i_cap_y) as u8; if compute_chroma { let r = (r0 + r1 + 1) >> 1; @@ -187,8 +187,8 @@ fn rgbx_to_nv >> PRECISION; let cr = (r * transform.cr_r + g * transform.cr_g + b * transform.cr_b + bias_uv) >> PRECISION; - uv_dst[order.get_u_position()] = cb.clamp(i_bias_y, i_cap_uv) as u8; - uv_dst[order.get_v_position()] = cr.clamp(i_bias_y, i_cap_uv) as u8; + uv_dst[order.get_u_position()] = cb.max(i_bias_y).min(i_cap_uv) as u8; + uv_dst[order.get_v_position()] = cr.max(i_bias_y).min(i_cap_uv) as u8; } } @@ -203,7 +203,7 @@ fn rgbx_to_nv let b0 = rgba[src_chans.get_b_channel_offset()] as i32; let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; - y_dst[0] = y_0.clamp(i_bias_y, i_cap_y) as u8; + y_dst[0] = y_0.max(i_bias_y).min(i_cap_y) as u8; if compute_chroma { let cb = @@ -212,8 +212,8 @@ fn rgbx_to_nv let cr = (r0 * transform.cr_r + g0 * transform.cr_g + b0 * transform.cr_b + bias_uv) >> PRECISION; - uv_dst[order.get_u_position()] = cb.clamp(i_bias_y, i_cap_uv) as u8; - uv_dst[order.get_v_position()] = cr.clamp(i_bias_y, i_cap_uv) as u8; + uv_dst[order.get_u_position()] = cb.max(i_bias_y).min(i_cap_uv) as u8; + uv_dst[order.get_v_position()] = cr.max(i_bias_y).min(i_cap_uv) as u8; } } }; @@ -253,15 +253,15 @@ fn rgbx_to_nv let b0 = rgba[src_chans.get_b_channel_offset()] as i32; let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; - *y_dst = y_0.clamp(i_bias_y, i_cap_y) as u8; + *y_dst = y_0.max(i_bias_y).min(i_cap_y) as u8; let cb = (r0 * transform.cb_r + g0 * transform.cb_g + b0 * transform.cb_b + bias_uv) >> PRECISION; let cr = (r0 * transform.cr_r + g0 * transform.cr_g + b0 * transform.cr_b + bias_uv) >> PRECISION; - uv_dst[order.get_u_position()] = cb.clamp(i_bias_y, i_cap_uv) as u8; - uv_dst[order.get_v_position()] = cr.clamp(i_bias_y, i_cap_uv) as u8; + uv_dst[order.get_u_position()] = cb.max(i_bias_y).min(i_cap_uv) as u8; + uv_dst[order.get_v_position()] = cr.max(i_bias_y).min(i_cap_uv) as u8; } }); } else if chroma_subsampling == YuvChromaSubsampling::Yuv422 { diff --git a/src/rgba_to_yuv.rs b/src/rgba_to_yuv.rs index a1138b2..1bc0c4e 100644 --- a/src/rgba_to_yuv.rs +++ b/src/rgba_to_yuv.rs @@ -210,14 +210,14 @@ fn rgbx_to_yuv8( let b0 = rgba[src_chans.get_b_channel_offset()] as i32; let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; - y_dst[0] = y_0.clamp(i_bias_y, i_cap_y) as u8; + y_dst[0] = y_0.max(i_bias_y).min(i_cap_y) as u8; let r1 = rgba[channels + src_chans.get_r_channel_offset()] as i32; let g1 = rgba[channels + src_chans.get_g_channel_offset()] as i32; let b1 = rgba[channels + src_chans.get_b_channel_offset()] as i32; let y_1 = (r1 * transform.yr + g1 * transform.yg + b1 * transform.yb + bias_y) >> PRECISION; - y_dst[1] = y_1.clamp(i_bias_y, i_cap_y) as u8; + y_dst[1] = y_1.max(i_bias_y).min(i_cap_y) as u8; if compute_chroma_row { let r = (r0 + r1 + 1) >> 1; @@ -228,8 +228,8 @@ fn rgbx_to_yuv8( >> PRECISION; let cr = (r * transform.cr_r + g * transform.cr_g + b * transform.cr_b + bias_uv) >> PRECISION; - *u_dst = cb.clamp(i_bias_y, i_cap_uv) as u8; - *v_dst = cr.clamp(i_bias_y, i_cap_uv) as u8; + *u_dst = cb.max(i_bias_y).min(i_cap_uv) as u8; + *v_dst = cr.max(i_bias_y).min(i_cap_uv) as u8; } } @@ -245,7 +245,7 @@ fn rgbx_to_yuv8( let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; - *y_last = y_0.clamp(i_bias_y, i_cap_y) as u8; + *y_last = y_0.max(i_bias_y).min(i_cap_y) as u8; if compute_chroma_row { let cb = @@ -254,8 +254,8 @@ fn rgbx_to_yuv8( let cr = (r0 * transform.cr_r + g0 * transform.cr_g + b0 * transform.cr_b + bias_uv) >> PRECISION; - *u_last = cb.clamp(i_bias_y, i_cap_uv) as u8; - *v_last = cr.clamp(i_bias_y, i_cap_uv) as u8; + *u_last = cb.max(i_bias_y).min(i_cap_uv) as u8; + *v_last = cr.max(i_bias_y).min(i_cap_uv) as u8; } } }; @@ -301,7 +301,7 @@ fn rgbx_to_yuv8( let b0 = rgba[src_chans.get_b_channel_offset()] as i32; let y_0 = (r0 * transform.yr + g0 * transform.yg + b0 * transform.yb + bias_y) >> PRECISION; - *y_dst = y_0.clamp(i_bias_y, i_cap_y) as u8; + *y_dst = y_0.max(i_bias_y).min(i_cap_y) as u8; let cb = (r0 * transform.cb_r + g0 * transform.cb_g + b0 * transform.cb_b + bias_uv) @@ -309,8 +309,8 @@ fn rgbx_to_yuv8( let cr = (r0 * transform.cr_r + g0 * transform.cr_g + b0 * transform.cr_b + bias_uv) >> PRECISION; - *u_dst = cb.clamp(i_bias_y, i_cap_uv) as u8; - *v_dst = cr.clamp(i_bias_y, i_cap_uv) as u8; + *u_dst = cb.max(i_bias_y).min(i_cap_uv) as u8; + *v_dst = cr.max(i_bias_y).min(i_cap_uv) as u8; } }); } else if chroma_subsampling == YuvChromaSubsampling::Yuv422 { diff --git a/src/sharpyuv/sharp_rgba_to_yuv.rs b/src/sharpyuv/sharp_rgba_to_yuv.rs index 99af160..b21af56 100644 --- a/src/sharpyuv/sharp_rgba_to_yuv.rs +++ b/src/sharpyuv/sharp_rgba_to_yuv.rs @@ -76,7 +76,7 @@ fn sharpen_row420> PRECISION; - y_dst[0] = y_0.clamp(i_bias_y, i_cap_y) as u8; + y_dst[0] = y_0.max(i_bias_y).min(i_cap_y) as u8; let rgba_2 = &rgba[channels..channels * 2]; @@ -85,7 +85,7 @@ fn sharpen_row420> PRECISION; - y_dst[1] = y_1.clamp(i_bias_y, i_cap_y) as u8; + y_dst[1] = y_1.max(i_bias_y).min(i_cap_y) as u8; if y_even_row { let sharp_r_c = rgb_linearized[src_chans.get_r_channel_offset()]; @@ -143,8 +143,8 @@ fn sharpen_row420> PRECISION; - *u_dst = cb.clamp(i_bias_y, i_cap_uv) as u8; - *v_dst = cr.clamp(i_bias_y, i_cap_uv) as u8; + *u_dst = cb.max(i_bias_y).min(i_cap_uv) as u8; + *v_dst = cr.max(i_bias_y).min(i_cap_uv) as u8; } } @@ -158,7 +158,7 @@ fn sharpen_row420> PRECISION; - *y_last = y_1.clamp(i_bias_y, i_cap_y) as u8; + *y_last = y_1.max(i_bias_y).min(i_cap_y) as u8; if y_even_row { let rgba_lin = rgb_layout.chunks_exact(3).last().unwrap(); @@ -198,8 +198,8 @@ fn sharpen_row420> PRECISION; let u_last = u_plane.last_mut().unwrap(); let v_last = v_plane.last_mut().unwrap(); - *u_last = cb.clamp(i_bias_y, i_cap_uv) as u8; - *v_last = cr.clamp(i_bias_y, i_cap_uv) as u8; + *u_last = cb.max(i_bias_y).min(i_cap_uv) as u8; + *v_last = cr.max(i_bias_y).min(i_cap_uv) as u8; } } } @@ -242,7 +242,7 @@ fn sharpen_row422> PRECISION; - y_dst[0] = y_0.clamp(i_bias_y, i_cap_y) as u8; + y_dst[0] = y_0.max(i_bias_y).min(i_cap_y) as u8; let rgba_2 = &rgba[channels..channels * 2]; @@ -251,7 +251,7 @@ fn sharpen_row422> PRECISION; - y_dst[1] = y_1.clamp(i_bias_y, i_cap_y) as u8; + y_dst[1] = y_1.max(i_bias_y).min(i_cap_y) as u8; let rgb_linearized_2 = &rgb_linearized[3..(3 + 3)]; @@ -282,8 +282,8 @@ fn sharpen_row422> PRECISION; - *u_dst = cb.clamp(i_bias_y, i_cap_uv) as u8; - *v_dst = cr.clamp(i_bias_y, i_cap_uv) as u8; + *u_dst = cb.max(i_bias_y).min(i_cap_uv) as u8; + *v_dst = cr.max(i_bias_y).min(i_cap_uv) as u8; } let rem_rgba = rgba.chunks_exact(channels * 2).remainder(); @@ -296,7 +296,7 @@ fn sharpen_row422> PRECISION; - *y_last = y_1.clamp(i_bias_y, i_cap_y) as u8; + *y_last = y_1.max(i_bias_y).min(i_cap_y) as u8; let cb = (r0 * transform.cb_r + g0 * transform.cb_g + b0 * transform.cb_b + bias_uv) >> PRECISION; @@ -305,8 +305,8 @@ fn sharpen_row422