Skip to content

Releases: Cykooz/fast_image_resize

[4.1.0] - 2024-07-14

14 Jul 18:28
Compare
Choose a tag to compare
  • Added support for optimization with help of SSE4.1 and AVX2 for the F32 pixel type.
  • Added support for new pixel types F32x2, F32x3 and F32x4 with optimizations for SSE4.1 and AVX2 (#30).

[4.0.0] - 2024-05-13

13 May 20:09
Compare
Choose a tag to compare

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
}

[3.0.4] - 2024-02-15

15 Feb 18:17
Compare
Choose a tag to compare

Fixed

  • Fixed error with incorrect cropping of source image.

[3.0.3] - 2024-02-07

12 Feb 18:12
Compare
Choose a tag to compare

Fixed

  • Fixed version of num-traits in the Cargo.toml.

[3.0.2] - 2024-02-07

12 Feb 18:12
Compare
Choose a tag to compare

Added

  • Added Custom variant for FilterType enum and corresponding Filter structure.
  • BREAKING: Added a new variant of enum CropBoxError::WidthOrHeightLessOrEqualToZero.

Changed

  • Slightly improved (about 3%) speed of AVX2 implementation of Convolution trait
    for U8x3 and U8x4 images.
  • BREAKING: Changed internal data type for U8x4 structure.
    Now it is [u8; 4] instead of u32.
  • Significantly improved (4.5 times on x86_64) speed of vertical convolution pass implemented
    in native Rust for U8, U8x2, U8x3 and U8x4 images.
  • Changed order of convolution passes for U8, U8x2, U8x3 and U8x4 images.
    Now a vertical pass is the first and a horizontal pass is the second.
  • BREAKING: Type of the CropBox fields has been changed to f64. Now you can use
    fractional size and position of crop box.
  • BREAKING: Type of the centering argument of ImageView::set_crop_box_to_fit_dst_size()
    and DynamicImageView::set_crop_box_to_fit_dst_size() methods has been changed to Optional<(f64, f64)>.
  • BREAKING: The crop_box argument of ImageViewMut::crop() and DynamicImageViewMut::crop()
    methods has been replaced with separate left, top, width and height arguments.

[2.7.3] - 2023-05-07

07 May 19:52
Compare
Choose a tag to compare

Fixed

  • Fixed size of rows in cropped ImageViewMut created by ImageViewMut::crop method (#17).

[2.7.2] - 2023-05-04

07 May 19:52
Compare
Choose a tag to compare

Fixed

  • Added using of (read|write)_unaligned for unaligned pointers on arm64 and wasm32 architectures (#15).

[2.7.1] - 2023-04-28

07 May 19:51
Compare
Choose a tag to compare

Fixed

  • Added using of (read|write)_unaligned for unaligned pointers on x86_64 architecture (#16).

[2.7.0] - 2023-03-24

24 Mar 21:01
Compare
Choose a tag to compare

Crate

  • Added method DynamicImageViewMut::crop() to create cropped version of DynamicImageViewMut (#13).
  • Added method ImageViewMut::crop() to create cropped version of ImageViewMut.