Skip to content

Commit

Permalink
Added appending alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed May 17, 2024
1 parent 9ef5610 commit b2c56c5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/yuv_to_rgba_alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{YuvRange, YuvStandardMatrix};
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
#[cfg(target_feature = "neon")]
unsafe fn premutiply_vector(v: uint8x16_t, a_values: uint8x16_t) -> uint8x16_t {
let mut acc_hi = vdupq_n_u16(255);
let mut acc_lo = vdupq_n_u16(255);
let mut acc_hi = vdupq_n_u16(127);
let mut acc_lo = vdupq_n_u16(127);
acc_hi = vmlal_high_u8(acc_hi, v, a_values);
acc_lo = vmlal_u8(acc_lo, vget_low_u8(v), vget_low_u8(a_values));
let hi = vqshrn_n_u16::<8>(acc_hi);
Expand Down Expand Up @@ -243,9 +243,9 @@ fn yuv_with_alpha_to_rgbx<const DESTINATION_CHANNELS: u8, const SAMPLING: u8>(

let a_value = a_plane[a_offset + x];
if premultiply_alpha {
r = (r * a_value as i32 + 255) >> 8;
g = (g * a_value as i32 + 255) >> 8;
b = (b * a_value as i32 + 255) >> 8;
r = (r * a_value as i32 + 127) >> 8;
g = (g * a_value as i32 + 127) >> 8;
b = (b * a_value as i32 + 127) >> 8;
}

rgba[rgba_shift + destination_channels.get_r_channel_offset()] = r as u8;
Expand All @@ -271,9 +271,9 @@ fn yuv_with_alpha_to_rgbx<const DESTINATION_CHANNELS: u8, const SAMPLING: u8>(

let a_value = a_plane[a_offset + next_px];
if premultiply_alpha {
r = (r * a_value as i32 + 255) >> 8;
g = (g * a_value as i32 + 255) >> 8;
b = (b * a_value as i32 + 255) >> 8;
r = (r * a_value as i32 + 127) >> 8;
g = (g * a_value as i32 + 127) >> 8;
b = (b * a_value as i32 + 127) >> 8;
}

rgba[rgba_shift + destination_channels.get_r_channel_offset()] = r as u8;
Expand Down

0 comments on commit b2c56c5

Please sign in to comment.