MCPcopy Index your code
hub / github.com/Cykooz/fast_image_resize

github.com/Cykooz/fast_image_resize @v6.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v6.0.0 ↗ · + Follow
1,117 symbols 3,539 edges 178 files 78 documented · 7% updated 13d agov6.0.0 · 2026-01-13★ 4522 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fast_image_resize

github crates.io docs.rs

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

CHANGELOG

Supported pixel formats and available optimizations:

Format Description SSE4.1 AVX2 Neon Wasm32 SIMD128
U8 One u8 component per pixel (e.g. L) + + + +
U8x2 Two u8 components per pixel (e.g. LA) + + + +
U8x3 Three u8 components per pixel (e.g. RGB) + + + +
U8x4 Four u8 components per pixel (e.g. RGBA, RGBx, CMYK) + + + +
U16 One u16 components per pixel (e.g. L16) + + + +
U16x2 Two u16 components per pixel (e.g. LA16) + + + +
U16x3 Three u16 components per pixel (e.g. RGB16) + + + +
U16x4 Four u16 components per pixel (e.g. RGBA16, RGBx16, CMYK16) + + + +
I32 One i32 component per pixel (e.g. L32) - - - -
F32 One f32 component per pixel (e.g. L32F) + + - -
F32x2 Two f32 components per pixel (e.g. LA32F) + + - -
F32x3 Three f32 components per pixel (e.g. RGB32F) + + - -
F32x4 Four f32 components per pixel (e.g. RGBA32F) + + - -

Colorspace

Resizer from this crate does not convert image into linear colorspace during a resize process. If it is important for you to resize images with a non-linear color space (e.g. sRGB) correctly, then you have to convert it to a linear color space before resizing and convert back to the color space of result image. Read more about resizing with respect to color space.

This crate provides the PixelComponentMapper structure that allows you to create colorspace converters for images whose pixels based on u8 and u16 components.

In addition, the crate contains functions create_gamma_22_mapper() and create_srgb_mapper() to create instance of PixelComponentMapper that 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 in rayon thread pool.

Use in a no_std environment

To use the crate in a no_std environment you must disable default features and enabled the no_std feature:

[dependencies]
fast_image_resize = { version = "6.0", default-features = false, features = ["no_std"] }

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 image nasa-4928x3279.png
  • Numbers in the table mean a duration of image resizing in milliseconds.
Nearest Box Bilinear Bicubic Lanczos3
image 29.28 - 83.28 136.97 189.93
resize 7.42 26.82 49.29 93.22 140.26
libvips 2.42 61.73 5.66 9.81 15.78
fir rust 0.28 10.87 16.12 26.63 38.08
fir sse4.1 0.28 3.37 5.34 9.89 15.30
fir avx2 0.28 2.52 3.67 6.80 13.21

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

Pipeline:

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

  • Source image nasa-4928x3279-rgba.png
  • Numbers in the table mean a duration of image resizing in milliseconds.
  • The image crate does not support multiplying and dividing by alpha channel.
Nearest Box Bilinear Bicubic Lanczos3
resize 9.59 34.02 64.61 126.43 187.18
libvips 4.19 169.02 142.22 228.64 330.24
fir rust 0.19 20.30 25.25 36.57 49.69
fir sse4.1 0.19 9.51 11.90 17.78 24.49
fir avx2 0.19 7.11 8.39 13.68 21.72

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

Pipeline:

src_image => resize => dst_image

  • Source image nasa-4928x3279.png has converted into grayscale image with one byte per pixel.
  • Numbers in the table mean a duration of image resizing in milliseconds.
Nearest Box Bilinear Bicubic Lanczos3
image 26.90 - 56.49 85.11 112.72
resize 6.57 11.06 18.83 38.44 63.98
libvips 2.62 24.92 6.81 9.84 12.73
fir rust 0.16 4.42 5.45 8.69 12.04
fir sse4.1 0.16 1.45 2.02 3.37 5.44
fir avx2 0.16 1.51 1.73 2.74 4.11

Examples

Resize RGBA8 image

Note: You must enable "image" feature to support of image::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;

fn main() {
    // Read source image from file
    let src_image = ImageReader::open("./data/nasa-4928x3279.png")
        .unwrap()
        .decode()
        .unwrap();

    // Create container for data of destination image
    let dst_width = 1024;
    let dst_height = 768;
    let mut dst_image = Image::new(
        dst_width,
        dst_height,
        src_image.pixel_type().unwrap(),
    );

    // Create Resizer instance and resize source image
    // into buffer of destination image
    let mut resizer = Resizer::new();
    resizer.resize(&src_image, &mut dst_image, None).unwrap();

    // Write destination image as PNG-file
    let mut 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;

fn main() {
    let img = ImageReader::open("./data/nasa-4928x3279.png")
        .unwrap()
        .decode()
        .unwrap();

    // Create container for data of destination image
    let mut dst_image = Image::new(
        1024,
        768,
        img.pixel_type().unwrap(),
    );

    // Create Resizer instance and resize cropped source image
    // into buffer of destination image
    let mut resizer = Resizer::new();
    resizer.resize(
        &img,
        &mut dst_image,
        &ResizeOptions::new().crop(
            10.0,   // left 
            10.0,   // top
            2000.0, // width
            2000.0, // height
        ),
    ).unwrap();
}

Change CPU extensions used by resizer

```rust, no_run use fast_image_resize as fr;

fn main() { let mut resizer = fr::Resizer::new(); #[cfg(target_arch = "x86_64")] unsafe { resizer.set_cpu_extensions(fr::CpuExtensions::Sse4_1); } } ```

Extension points exported contracts — how you extend this code

IntoImageView (Interface)
Conversion into an [ImageView]. [5 implementers]
src/image_view.rs
PixelTestingExt (Interface)
(no doc) [13 implementers]
benches/utils/testing.rs
PixelComponent (Interface)
Information about one component of a pixel. [4 implementers]
src/pixels.rs
Convolution (Interface)
(no doc) [13 implementers]
src/convolution/mod.rs
AlphaMulDiv (Interface)
(no doc) [13 implementers]
src/alpha/mod.rs
PixelTestingExt (Interface)
(no doc) [13 implementers]
tests/testing.rs
FromF32 (Interface)
(no doc) [2 implementers]
src/color/mod.rs
PixelTrait (Interface)
(no doc) [1 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

iter_rows_mut
called by 178
src/images/typed_image.rs
iter_rows
called by 139
src/images/typed_image.rs
height
called by 127
src/images/image.rs
into_remainder
called by 123
src/array_chunks.rs
clip
called by 123
src/convolution/optimisations.rs
width
called by 86
src/images/image.rs
values
called by 81
src/convolution/optimisations.rs
chunks
called by 75
src/convolution/optimisations.rs

Shape

Function 791
Method 249
Class 40
Enum 20
Interface 17

Languages

Rust100%

Modules by API surface

src/neon_utils.rs53 symbols
tests/resize_tests.rs45 symbols
src/resizer.rs24 symbols
src/pixels.rs24 symbols
src/images/unsafe_image.rs18 symbols
src/convolution/filters.rs18 symbols
src/color/mod.rs18 symbols
tests/testing.rs17 symbols
tests/alpha_tests.rs17 symbols
src/simd_utils.rs17 symbols
src/mul_div.rs17 symbols
src/images/typed_image.rs17 symbols

For agents

$ claude mcp add fast_image_resize \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page