mirror of
https://github.com/Cykooz/fast_image_resize.git
synced 2026-11-29 04:01:35 +00:00
Fixed UB in `divide_alpha_inplace() function for U8x2` (#65).
This commit is contained in:
1 parent
30a46b5dab
commit
1b0d75b4ec
2 files changed
+18
-9
No files matched your search
+4
-1
@@ -16,7 +16,10 @@
|
||||
### Fixed
|
||||
|
||||
- Fixed integer overflow in `check_crop_box()` function.
|
||||
- Fixed temp image size calculation during resize ([#63](https://github.com/Cykooz/fast_image_resize/issues/63)).
|
||||
- Fixed temp image size calculation during
|
||||
resize ([#63](https://github.com/Cykooz/fast_image_resize/issues/63)).
|
||||
- Fixed UB in ``divide_alpha_inplace()`` function
|
||||
for ``U8x2`` ([#65](https://github.com/Cykooz/fast_image_resize/issues/65)).
|
||||
|
||||
## [6.1.0] - 2026-07-21
|
||||
|
||||
|
||||
@@ -55,21 +55,27 @@ pub(crate) fn divide_alpha(
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn divide_alpha_inplace(image_view: &mut impl ImageViewMut<Pixel = U8x2>) {
|
||||
for dst_row in image_view.iter_rows_mut(0) {
|
||||
let src_row = unsafe { core::slice::from_raw_parts(dst_row.as_ptr(), dst_row.len()) };
|
||||
divide_alpha_row(src_row, dst_row);
|
||||
for row in image_view.iter_rows_mut(0) {
|
||||
for pixel in row {
|
||||
pixel.0 = divide_alpha_pixel(pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn divide_alpha_row(src_row: &[U8x2], dst_row: &mut [U8x2]) {
|
||||
fn divide_alpha_row(src_row: &[U8x2], dst_row: &mut [U8x2]) {
|
||||
src_row
|
||||
.iter()
|
||||
.zip(dst_row)
|
||||
.for_each(|(src_pixel, dst_pixel)| {
|
||||
let components: [u8; 2] = src_pixel.0;
|
||||
let alpha = components[1];
|
||||
let recip_alpha = RECIP_ALPHA[alpha as usize];
|
||||
dst_pixel.0 = [div_and_clip(components[0], recip_alpha), alpha];
|
||||
dst_pixel.0 = divide_alpha_pixel(src_pixel);
|
||||
});
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn divide_alpha_pixel(pixel: &U8x2) -> [u8; 2] {
|
||||
let components: [u8; 2] = pixel.0;
|
||||
let alpha = components[1];
|
||||
let recip_alpha = RECIP_ALPHA[alpha as usize];
|
||||
[div_and_clip(components[0], recip_alpha), alpha]
|
||||
}
|
||||
Reference in new issue
Block a user