MCPcopy Index your code
hub / github.com/PistonDevelopers/resize

github.com/PistonDevelopers/resize @v0.8.9

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.8.9 ↗ · + Follow
96 symbols 240 edges 6 files 8 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

resize Build Status crates.io

Image resampling library in pure Rust.

Features

  • Fast, with support for many pixel formats
  • No encoders/decoders, meant to be used with some external library
  • Tuned for resizing to the same dimensions multiple times: uses preallocated buffers and matrixes

Usage

use resize::Pixel::RGB8;
use resize::Type::Lanczos3;

// Downscale by 2x.
let (w1, h1) = (640, 480);
let (w2, h2) = (320, 240);
// Don't forget to fill `src` with image data (RGB8).
// This requires Vec<RGB<u8>>. If you have Vec<u8>, then use .as_rgb()/.as_rgb_mut() to reinterpret it as a slice of pixels.
let src = vec![RGB::new(0,0,0); w1*h1];
// Destination buffer. Must be mutable.
let mut dst = vec![RGB::new(0,0,0); w2*h2];
// Create reusable instance.
let mut resizer = resize::new(w1, h1, w2, h2, RGB8, Lanczos3);
// Do resize without heap allocations.
// Might be executed multiple times for different `src` or `dst`.
resizer.resize(&src, &mut dst);

See API documentation for overview of all available methods. See also this example.

Recommendations

Read this and this great articles on image resizing technics and resampling filters. Tldr; (with built-in filters of this library) use Lanczos3 for downscaling, use Mitchell for upscaling. You may also want to downscale in linear colorspace (but not upscale). Gamma correction routines currently not included to the library, but actually quite simple to accomplish manually, see here for some basic theory.

License

  • Library is licensed under MIT
  • Image used in examples is licensed under CC BY-SA 3.0

Extension points exported contracts — how you extend this code

PixelFormat (Interface)
Use [`Pixel`](crate::Pixel) presets to specify pixel format. The trait represents a temporary object that adds pixels t [4 …
src/px.rs
FloatExt (Interface)
Alternative basic float operations for no_std [2 implementers]
src/no_std_float.rs
ToFloat (Interface)
Internal, please don't use [4 implementers]
src/px.rs

Core symbols most depended-on inside this repo

new
called by 92
src/lib.rs
resize
called by 31
src/lib.rs
to_float
called by 12
src/px.rs
get_image
called by 9
benches/bench.rs
powi
called by 6
src/no_std_float.rs
cubic_bc
called by 5
src/lib.rs
abs
called by 5
src/no_std_float.rs
get_rolled
called by 3
benches/bench.rs

Shape

Function 51
Method 32
Class 8
Interface 3
Enum 2

Languages

Rust100%

Modules by API surface

src/lib.rs43 symbols
benches/bench.rs20 symbols
tests/qa.rs13 symbols
src/no_std_float.rs11 symbols
src/px.rs8 symbols
examples/resize.rs1 symbols

For agents

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

⬇ download graph artifact