Skip to content

Commit

Permalink
Fix BGR, BGRA
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jun 10, 2024
1 parent 0479069 commit be2e474
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["src/app"] }

[package]
name = "colorutils-rs"
version = "0.3.4"
version = "0.3.5"
edition = "2021"
description = "High performance utilities for color format handling and conversion."
readme = "README.md"
Expand Down
18 changes: 16 additions & 2 deletions src/neon/neon_hsv_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,24 @@ pub unsafe fn neon_hsv_u16_to_image<

if USE_ALPHA {
let a_chan = vcombine_u8(vqmovn_u16(a_chan_lo), vqmovn_u16(a_chan_hi));
let pixel_set = uint8x16x4_t(r_chan, g_chan, b_chan, a_chan);
let pixel_set = match image_configuration {
ImageConfiguration::Rgb | ImageConfiguration::Rgba => {
uint8x16x4_t(r_chan, g_chan, b_chan, a_chan)
}
ImageConfiguration::Bgra | ImageConfiguration::Bgr => {
uint8x16x4_t(b_chan, g_chan, r_chan, a_chan)
}
};
vst4q_u8(dst_ptr.add(cx * channels), pixel_set);
} else {
let pixel_set = uint8x16x3_t(r_chan, g_chan, b_chan);
let pixel_set = match image_configuration {
ImageConfiguration::Rgb | ImageConfiguration::Rgba => {
uint8x16x3_t(r_chan, g_chan, b_chan)
}
ImageConfiguration::Bgra | ImageConfiguration::Bgr => {
uint8x16x3_t(b_chan, g_chan, r_chan)
}
};
vst3q_u8(dst_ptr.add(cx * channels), pixel_set);
}

Expand Down
18 changes: 16 additions & 2 deletions src/sse/sse_hsv_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,25 @@ pub unsafe fn sse_hsv_u16_to_image<
let ptr = dst_ptr.add(cx * channels);
if USE_ALPHA {
let a_chan = _mm_packus_epi16(a_chan_lo, _mm_setzero_si128());
let (rgba0, rgba1, _, _) = sse_interleave_rgba(r_chan, g_chan, b_chan, a_chan);
let (rgba0, rgba1, _, _) = match image_configuration {
ImageConfiguration::Rgb | ImageConfiguration::Rgba => {
sse_interleave_rgba(r_chan, g_chan, b_chan, a_chan)
}
ImageConfiguration::Bgra | ImageConfiguration::Bgr => {
sse_interleave_rgba(b_chan, g_chan, r_chan, a_chan)
}
};
_mm_storeu_si128(ptr as *mut __m128i, rgba0);
_mm_storeu_si128(ptr.add(16) as *mut __m128i, rgba1);
} else {
let (rgba0, rgba1, _) = sse_interleave_rgb(r_chan, g_chan, b_chan);
let (rgba0, rgba1, _) = match image_configuration {
ImageConfiguration::Rgb | ImageConfiguration::Rgba => {
sse_interleave_rgb(r_chan, g_chan, b_chan)
}
ImageConfiguration::Bgra | ImageConfiguration::Bgr => {
sse_interleave_rgb(b_chan, g_chan, r_chan)
}
};
_mm_storeu_si128(ptr as *mut __m128i, rgba0);
std::ptr::copy_nonoverlapping(&rgba1 as *const _ as *const u8, ptr.add(16), 8);
}
Expand Down

0 comments on commit be2e474

Please sign in to comment.