Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump up Rust crate fast_image_resize to v4 #99

Merged
merged 2 commits into from
May 14, 2024

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented May 13, 2024

Mend Renovate

This PR contains the following updates:

Package Type Update Change
fast_image_resize dependencies major 3 -> 4

Release Notes

cykooz/fast_image_resize (fast_image_resize)

v4.0.0

Compare Source

Added
  • Added Gaussian filter for convolution algorithm.
  • Method PixelType::size() was made public.
  • Added new image containers:
    • ImageRef
    • TypedImageRef
    • TypedImage
    • TypedCroppedImage
    • TypedCroppedImageMut
    • CroppedImage
    • CroppedImageMut
Fixed
  • Fixed dividing image by alpha channel.
Changed

A lot of breaking changes have been done in this release:

  • Structures ImageView and ImageViewMut have been removed. They always
    did unnecessary memory allocation to store references to image rows.
    Instead of these structures, the ImageView and ImageViewMut traits
    have been added. The crate accepts any image container that provides
    these traits.
  • Also, traits IntoImageView and IntoImageViewMut have been added.
    They allow you to write runtime adapters to convert your particular
    image container into something that provides ImageView/ImageViewMut trait.
  • Resizer now has two methods for resize (dynamic and typed):
    • resize() accepts references to impl IntoImageView and impl IntoImageViewMut;
    • resize_typed() accepts references to impl ImageView and impl ImageViewMut.
  • Resize methods also accept the options argument.
    With the help of this argument, you can specify:
    • resize algorithm (default: Lanczos3);
    • how to crop the source image;
    • whether to multiply the source image by the alpha channel and
      divide the destination image by the alpha channel.
      By default, Resizer multiplies and divides by alpha channel
      images with U8x2, U8x4, U16x2 and U16x4 pixels.
  • Argument resize_alg was removed from Resizer::new() method, use
    options argument of methods to resize instead.
  • The MulDiv implementation has been changed in the same way as Resizer.
    It now has two versions of each method: dynamic and typed.
  • Type of image dimensions has been changed from NonZeroU32 into u32.
    Now you can create and use zero-sized images.
  • Image (embedded implementation of image container) moved from root of
    the crate into module images.
  • Added optional feature "image".
    It adds implementation of traits IntoImageView and IntoImageViewMut for the
    DynamicImage
    type from the image crate. This implementation allows you to use DynamicImage
    instances as arguments for methods of this crate.

Look at the difference between versions 3 and 4 on example
of resizing RGBA8 image from given u8-buffer with pixels-data.

3.x version:

use fast_image_resize::{Image, MulDiv, PixelType, Resizer};
use std::num::NonZeroU32;

fn my_resize(
    src_width: u32,
    src_height: u32,
    src_pixels: &mut [u8],
    dst_width: u32,
    dst_height: u32,
) -> Image {
    let src_width = NonZeroU32::new(src_width).unwrap();
    let src_height = NonZeroU32::new(src_height).unwrap();
    let src_image = Image::from_slice_u8(
        src_width,
        src_height,
        src_pixels,
        PixelType::U8x4,
    ).unwrap();

    // Multiple RGB channels of source image by alpha channel.
    let alpha_mul_div = MulDiv::default();
    let mut tmp_image = Image::new(
        src_width,
        src_height,
        PixelType::U8x4,
    );
    alpha_mul_div
        .multiply_alpha(
            &src_image.view(),
            &mut tmp_image.view_mut(),
        ).unwrap();

    // Create container for data of destination image.
    let dst_width = NonZeroU32::new(dst_width).unwrap();
    let dst_height = NonZeroU32::new(dst_height).unwrap();
    let mut dst_image = Image::new(
        dst_width,
        dst_height,
        PixelType::U8x4,
    );

    // Get mutable view of destination image data.
    let mut dst_view = dst_image.view_mut();

    // Create Resizer instance and resize source image
    // into buffer of destination image.
    let mut resizer = Resizer::default();
    resizer.resize(&tmp_image.view(), &mut dst_view).unwrap();

    // Divide RGB channels of destination image by alpha.
    alpha_mul_div.divide_alpha_inplace(&mut dst_view).unwrap();

    dst_image
}

4.x version:

use fast_image_resize::images::{Image, ImageRef};
use fast_image_resize::{PixelType, Resizer};

fn my_resize(
    src_width: u32,
    src_height: u32,
    src_pixels: &[u8],
    dst_width: u32,
    dst_height: u32,
) -> Image {
    let src_image = ImageRef::new(
        src_width,
        src_height,
        src_pixels,
        PixelType::U8x4,
    ).unwrap();

    // Create container for data of destination image.
    let mut dst_image = Image::new(
        dst_width,
        dst_height,
        PixelType::U8x4,
    );

    // Create Resizer instance and resize source image
    // into buffer of destination image.
    let mut resizer = Resizer::new();
    // By default, Resizer multiplies and divides by alpha channel
    // images with U8x2, U8x4, U16x2 and U16x4 pixels.
    resizer.resize(&src_image, &mut dst_image, None).unwrap();

    dst_image
}

Configuration

πŸ“… Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

Copy link

vercel bot commented May 13, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 14, 2024 6:24am

@Brooooooklyn Brooooooklyn enabled auto-merge (squash) May 14, 2024 06:23
@Brooooooklyn Brooooooklyn merged commit a1c0ced into main May 14, 2024
19 of 21 checks passed
@Brooooooklyn Brooooooklyn deleted the renovate/fast_image_resize-4.x branch May 14, 2024 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant