Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rust library for fast image resizing with using of SIMD instructions.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

Cykooz/fast_image_resize

Repository files navigation

githubcrates.iodocs.rs

Rust library for fast image resizing with using of SIMD instructions.

CHANGELOG

Supported pixel formats and available optimizations:

FormatDescriptionSSE4.1AVX2NeonWasm32 SIMD128
U8Oneu8 component per pixel (e.g. L)++++
U8x2Twou8 components per pixel (e.g. LA)++++
U8x3Threeu8 components per pixel (e.g. RGB)++++
U8x4Fouru8 components per pixel (e.g. RGBA, RGBx, CMYK)++++
U16Oneu16 components per pixel (e.g. L16)++++
U16x2Twou16 components per pixel (e.g. LA16)++++
U16x3Threeu16 components per pixel (e.g. RGB16)++++
U16x4Fouru16 components per pixel (e.g. RGBA16, RGBx16, CMYK16)++++
I32Onei32 component per pixel (e.g. L32)----
F32Onef32 component per pixel (e.g. L32F)++--
F32x2Twof32 components per pixel (e.g. LA32F)++--
F32x3Threef32 components per pixel (e.g. RGB32F)++--
F32x4Fourf32 components per pixel (e.g. RGBA32F)++--

Colorspace

Resizer from this crate does not convert image into linear colorspaceduring a resize process. If it is important for you to resize images with anon-linear color space (e.g. sRGB) correctly, then you have to convertit to a linear color space before resizing and convert back to the color space ofresult image.Read moreabout resizing with respect to color space.

This crate provides thePixelComponentMapperstructure that allows you to create colorspace converters for imageswhose pixels based onu8 andu16 components.

In addition, the crate contains functionscreate_gamma_22_mapper()andcreate_srgb_mapper() to create instance ofPixelComponentMapperthat converts images from sRGB or gamma 2.2 into linear colorspace and back.

Multi-threading

You should enable"rayon" feature to turn on image processing inrayon thread pool.

Some benchmarks in single-threaded mode for x86_64

All benchmarks:x86_64,ARM64,WASM32.

Other libraries used to compare of resizing speed:

Resize RGB8 image (U8x3) 4928x3279 => 852x567

Pipeline:

src_image => resize => dst_image

  • Source imagenasa-4928x3279.png
  • Numbers in the table mean a duration of image resizing in milliseconds.
NearestBoxBilinearBicubicLanczos3
image34.13-88.09142.99191.80
resize8.8726.9753.0898.26145.74
libvips2.3861.575.669.7016.03
fir rust0.2810.9315.3525.7737.09
fir sse4.10.283.435.399.8215.34
fir avx20.282.623.806.8913.22

Resize RGBA8 image (U8x4) 4928x3279 => 852x567

Pipeline:

src_image => multiply by alpha => resize => divide by alpha => dst_image

  • Source imagenasa-4928x3279-rgba.png
  • Numbers in the table mean a duration of image resizing in milliseconds.
  • Theimage crate does not support multiplying and dividing by alpha channel.
NearestBoxBilinearBicubicLanczos3
resize9.9037.8574.20133.72201.29
libvips4.17169.03141.52232.30330.89
fir rust0.1920.6626.0237.2750.21
fir sse4.10.199.5911.9917.7924.83
fir avx20.197.218.6113.2222.41

Resize L8 image (U8) 4928x3279 => 852x567

Pipeline:

src_image => resize => dst_image

  • Source imagenasa-4928x3279.pnghas converted into grayscale image with one byte per pixel.
  • Numbers in the table mean a duration of image resizing in milliseconds.
NearestBoxBilinearBicubicLanczos3
image29.07-60.2589.15117.51
resize6.4211.2620.8742.8769.50
libvips2.5725.056.829.8512.68
fir rust0.154.455.579.0212.31
fir sse4.10.151.522.093.525.65
fir avx20.151.541.762.804.03

Examples

Resize RGBA8 image

Note: You must enable"image" feature to support ofimage::DynamicImage.Otherwise, you have to convert such images into supported by the crate image type.

use std::io::BufWriter;use image::codecs::png::PngEncoder;use image::{ExtendedColorType,ImageEncoder,ImageReader};use fast_image_resize::{IntoImageView,Resizer};use fast_image_resize::images::Image;fnmain(){// Read source image from filelet src_image =ImageReader::open("./data/nasa-4928x3279.png").unwrap().decode().unwrap();// Create container for data of destination imagelet dst_width =1024;let dst_height =768;letmut dst_image =Image::new(        dst_width,        dst_height,        src_image.pixel_type().unwrap(),);// Create Resizer instance and resize source image// into buffer of destination imageletmut resizer =Resizer::new();    resizer.resize(&src_image,&mut dst_image,None).unwrap();// Write destination image as PNG-fileletmut result_buf =BufWriter::new(Vec::new());PngEncoder::new(&mut result_buf).write_image(            dst_image.buffer(),            dst_width,            dst_height,            src_image.color().into(),).unwrap();}

Resize with cropping

use image::codecs::png::PngEncoder;use image::{ColorType,ImageReader,GenericImageView};use fast_image_resize::{IntoImageView,Resizer,ResizeOptions};use fast_image_resize::images::Image;fnmain(){let img =ImageReader::open("./data/nasa-4928x3279.png").unwrap().decode().unwrap();// Create container for data of destination imageletmut dst_image =Image::new(1024,768,        img.pixel_type().unwrap(),);// Create Resizer instance and resize cropped source image// into buffer of destination imageletmut resizer =Resizer::new();    resizer.resize(&img,&mut dst_image,&ResizeOptions::new().crop(10.0,// left10.0,// top2000.0,// width2000.0,// height),).unwrap();}

Change CPU extensions used by resizer

use fast_image_resizeas fr;fnmain(){letmut resizer = fr::Resizer::new();#[cfg(target_arch ="x86_64")]unsafe{        resizer.set_cpu_extensions(fr::CpuExtensions::Sse4_1);}}

About

Rust library for fast image resizing with using of SIMD instructions.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp