Vendor things
BIN
third-party/vendor/image/examples/concat/200x300.png
vendored
Normal file
|
After Width: | Height: | Size: 772 B |
BIN
third-party/vendor/image/examples/concat/300x300.png
vendored
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
third-party/vendor/image/examples/concat/400x300.png
vendored
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
43
third-party/vendor/image/examples/concat/main.rs
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use image::{GenericImage, GenericImageView, ImageBuffer, Pixel, Primitive};
|
||||
|
||||
/// Example showcasing a generic implementation of image concatenation.
|
||||
///
|
||||
/// The example images are coming from https://placeholder.com/
|
||||
///
|
||||
/// Run from the root of the repository with:
|
||||
/// cargo run --release --example concat
|
||||
fn main() {
|
||||
h_concat(&[
|
||||
image::open("examples/concat/200x300.png").unwrap(),
|
||||
image::open("examples/concat/300x300.png").unwrap(),
|
||||
image::open("examples/concat/400x300.png").unwrap(),
|
||||
])
|
||||
.save("examples/concat/concatenated_900x300.png")
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Concatenate horizontally images with the same pixel type.
|
||||
fn h_concat<I, P, S>(images: &[I]) -> ImageBuffer<P, Vec<S>>
|
||||
where
|
||||
I: GenericImageView<Pixel = P>,
|
||||
P: Pixel<Subpixel = S> + 'static,
|
||||
S: Primitive + 'static,
|
||||
{
|
||||
// The final width is the sum of all images width.
|
||||
let img_width_out: u32 = images.iter().map(|im| im.width()).sum();
|
||||
|
||||
// The final height is the maximum height from the input images.
|
||||
let img_height_out: u32 = images.iter().map(|im| im.height()).max().unwrap_or(0);
|
||||
|
||||
// Initialize an image buffer with the appropriate size.
|
||||
let mut imgbuf = image::ImageBuffer::new(img_width_out, img_height_out);
|
||||
let mut accumulated_width = 0;
|
||||
|
||||
// Copy each input image at the correct location in the output image.
|
||||
for img in images {
|
||||
imgbuf.copy_from(img, accumulated_width, 0).unwrap();
|
||||
accumulated_width += img.width();
|
||||
}
|
||||
|
||||
imgbuf
|
||||
}
|
||||
23
third-party/vendor/image/examples/convert.rs
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//! An example of opening an image.
|
||||
extern crate image;
|
||||
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let (from, into) = if env::args_os().count() == 3 {
|
||||
(
|
||||
env::args_os().nth(1).unwrap(),
|
||||
env::args_os().nth(2).unwrap(),
|
||||
)
|
||||
} else {
|
||||
println!("Please enter a from and into path.");
|
||||
std::process::exit(1);
|
||||
};
|
||||
|
||||
// Use the open function to load an image from a Path.
|
||||
// ```open``` returns a dynamic image.
|
||||
let im = image::open(Path::new(&from)).unwrap();
|
||||
// Write the contents of this image using extension guessing.
|
||||
im.save(Path::new(&into)).unwrap();
|
||||
}
|
||||
17
third-party/vendor/image/examples/decode.rs
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
//! An example of opening an image.
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let from = if env::args_os().count() == 2 {
|
||||
env::args_os().nth(1).unwrap()
|
||||
} else {
|
||||
println!("Please enter a from and into path.");
|
||||
std::process::exit(1);
|
||||
};
|
||||
|
||||
// Use the open function to load an image from a Path.
|
||||
// ```open``` returns a dynamic image.
|
||||
let im = image::open(Path::new(&from)).unwrap();
|
||||
println!("{}", im.as_bytes().len());
|
||||
}
|
||||
BIN
third-party/vendor/image/examples/fractal.png
vendored
Normal file
|
After Width: | Height: | Size: 345 KiB |
BIN
third-party/vendor/image/examples/fractal.png.png
vendored
Normal file
|
After Width: | Height: | Size: 345 KiB |
45
third-party/vendor/image/examples/fractal.rs
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//! An example of generating julia fractals.
|
||||
extern crate image;
|
||||
extern crate num_complex;
|
||||
|
||||
fn main() {
|
||||
let imgx = 800;
|
||||
let imgy = 800;
|
||||
|
||||
let scalex = 3.0 / imgx as f32;
|
||||
let scaley = 3.0 / imgy as f32;
|
||||
|
||||
// Create a new ImgBuf with width: imgx and height: imgy
|
||||
let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
|
||||
|
||||
// Iterate over the coordinates and pixels of the image
|
||||
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
|
||||
let r = (0.3 * x as f32) as u8;
|
||||
let b = (0.3 * y as f32) as u8;
|
||||
*pixel = image::Rgb([r, 0, b]);
|
||||
}
|
||||
|
||||
// A redundant loop to demonstrate reading image data
|
||||
for x in 0..imgx {
|
||||
for y in 0..imgy {
|
||||
let cx = y as f32 * scalex - 1.5;
|
||||
let cy = x as f32 * scaley - 1.5;
|
||||
|
||||
let c = num_complex::Complex::new(-0.4, 0.6);
|
||||
let mut z = num_complex::Complex::new(cx, cy);
|
||||
|
||||
let mut i = 0;
|
||||
while i < 255 && z.norm() <= 2.0 {
|
||||
z = z * z + c;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
let pixel = imgbuf.get_pixel_mut(x, y);
|
||||
let data = (*pixel as image::Rgb<u8>).0;
|
||||
*pixel = image::Rgb([data[0], i as u8, data[2]]);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the image as “fractal.png”, the format is deduced from the path
|
||||
imgbuf.save("fractal.png").unwrap();
|
||||
}
|
||||
16
third-party/vendor/image/examples/gradient/main.rs
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use image::{Pixel, Rgba, RgbaImage};
|
||||
|
||||
fn main() {
|
||||
let mut img = RgbaImage::new(100, 100);
|
||||
|
||||
let start = Rgba::from_slice(&[0, 128, 0, 0]);
|
||||
let end = Rgba::from_slice(&[255, 255, 255, 255]);
|
||||
|
||||
image::imageops::vertical_gradient(&mut img, start, end);
|
||||
img.save("vertical_gradient.png").unwrap();
|
||||
image::imageops::vertical_gradient(&mut img, end, start);
|
||||
img.save("vertical_gradient_reverse.png").unwrap();
|
||||
|
||||
image::imageops::horizontal_gradient(&mut img, start, end);
|
||||
img.save("horizontal_gradient.png").unwrap();
|
||||
}
|
||||
31
third-party/vendor/image/examples/opening.rs
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//! An example of opening an image.
|
||||
extern crate image;
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
use image::{GenericImageView, ImageFormat};
|
||||
|
||||
fn main() {
|
||||
let file = if env::args().count() == 2 {
|
||||
env::args().nth(1).unwrap()
|
||||
} else {
|
||||
panic!("Please enter a file")
|
||||
};
|
||||
|
||||
// Use the open function to load an image from a Path.
|
||||
// ```open``` returns a dynamic image.
|
||||
let im = image::open(Path::new(&file)).unwrap();
|
||||
|
||||
// The dimensions method returns the images width and height
|
||||
println!("dimensions {:?}", im.dimensions());
|
||||
|
||||
// The color method returns the image's ColorType
|
||||
println!("{:?}", im.color());
|
||||
|
||||
let fout = &mut File::create(Path::new(&format!("{}.png", file))).unwrap();
|
||||
|
||||
// Write the contents of this image to the Writer in PNG format.
|
||||
im.write_to(fout, ImageFormat::Png).unwrap();
|
||||
}
|
||||
52
third-party/vendor/image/examples/scaledown/main.rs
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use image::imageops::FilterType;
|
||||
use image::ImageFormat;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
struct Elapsed(Duration);
|
||||
|
||||
impl Elapsed {
|
||||
fn from(start: &Instant) -> Self {
|
||||
Elapsed(start.elapsed())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Elapsed {
|
||||
fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match (self.0.as_secs(), self.0.subsec_nanos()) {
|
||||
(0, n) if n < 1000 => write!(out, "{} ns", n),
|
||||
(0, n) if n < 1_000_000 => write!(out, "{} µs", n / 1000),
|
||||
(0, n) => write!(out, "{} ms", n / 1_000_000),
|
||||
(s, n) if s < 10 => write!(out, "{}.{:02} s", s, n / 10_000_000),
|
||||
(s, _) => write!(out, "{} s", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let img = image::open("examples/scaledown/test.jpg").unwrap();
|
||||
for &(name, filter) in [
|
||||
("near", FilterType::Nearest),
|
||||
("tri", FilterType::Triangle),
|
||||
("cmr", FilterType::CatmullRom),
|
||||
("gauss", FilterType::Gaussian),
|
||||
("lcz2", FilterType::Lanczos3),
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
let timer = Instant::now();
|
||||
let scaled = img.resize(400, 400, filter);
|
||||
println!("Scaled by {} in {}", name, Elapsed::from(&timer));
|
||||
let mut output = File::create(&format!("test-{}.png", name)).unwrap();
|
||||
scaled.write_to(&mut output, ImageFormat::Png).unwrap();
|
||||
}
|
||||
|
||||
for size in &[20_u32, 40, 100, 200, 400] {
|
||||
let timer = Instant::now();
|
||||
let scaled = img.thumbnail(*size, *size);
|
||||
println!("Thumbnailed to {} in {}", size, Elapsed::from(&timer));
|
||||
let mut output = File::create(format!("test-thumb{}.png", size)).unwrap();
|
||||
scaled.write_to(&mut output, ImageFormat::Png).unwrap();
|
||||
}
|
||||
}
|
||||
BIN
third-party/vendor/image/examples/scaledown/scaledown-test-cmr.png
vendored
Normal file
|
After Width: | Height: | Size: 111 KiB |
BIN
third-party/vendor/image/examples/scaledown/scaledown-test-gauss.png
vendored
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
third-party/vendor/image/examples/scaledown/scaledown-test-lcz2.png
vendored
Normal file
|
After Width: | Height: | Size: 115 KiB |
BIN
third-party/vendor/image/examples/scaledown/scaledown-test-near.png
vendored
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
third-party/vendor/image/examples/scaledown/scaledown-test-tri.png
vendored
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
third-party/vendor/image/examples/scaledown/test.jpg
vendored
Normal file
|
After Width: | Height: | Size: 3.6 MiB |
50
third-party/vendor/image/examples/scaleup/main.rs
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use image::imageops::FilterType;
|
||||
use image::ImageFormat;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
struct Elapsed(Duration);
|
||||
|
||||
impl Elapsed {
|
||||
fn from(start: &Instant) -> Self {
|
||||
Elapsed(start.elapsed())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Elapsed {
|
||||
fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
match (self.0.as_secs(), self.0.subsec_nanos()) {
|
||||
(0, n) if n < 1000 => write!(out, "{} ns", n),
|
||||
(0, n) if n < 1_000_000 => write!(out, "{} µs", n / 1000),
|
||||
(0, n) => write!(out, "{} ms", n / 1_000_000),
|
||||
(s, n) if s < 10 => write!(out, "{}.{:02} s", s, n / 10_000_000),
|
||||
(s, _) => write!(out, "{} s", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let tiny = image::open("examples/scaleup/tinycross.png").unwrap();
|
||||
for &(name, filter) in [
|
||||
("near", FilterType::Nearest),
|
||||
("tri", FilterType::Triangle),
|
||||
("xcmr", FilterType::CatmullRom),
|
||||
("ygauss", FilterType::Gaussian),
|
||||
("zlcz2", FilterType::Lanczos3),
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
let timer = Instant::now();
|
||||
let scaled = tiny.resize(32, 32, filter);
|
||||
println!("Scaled by {} in {}", name, Elapsed::from(&timer));
|
||||
let mut output = File::create(&format!("up2-{}.png", name)).unwrap();
|
||||
scaled.write_to(&mut output, ImageFormat::Png).unwrap();
|
||||
|
||||
let timer = Instant::now();
|
||||
let scaled = tiny.resize(48, 48, filter);
|
||||
println!("Scaled by {} in {}", name, Elapsed::from(&timer));
|
||||
let mut output = File::create(&format!("up3-{}.png", name)).unwrap();
|
||||
scaled.write_to(&mut output, ImageFormat::Png).unwrap();
|
||||
}
|
||||
}
|
||||
BIN
third-party/vendor/image/examples/scaleup/tinycross.png
vendored
Normal file
|
After Width: | Height: | Size: 245 B |
9
third-party/vendor/image/examples/tile/main.rs
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use image::RgbaImage;
|
||||
|
||||
fn main() {
|
||||
let mut img = RgbaImage::new(1920, 1080);
|
||||
let tile = image::open("examples/scaleup/tinycross.png").unwrap();
|
||||
|
||||
image::imageops::tile(&mut img, &tile);
|
||||
img.save("tiled_wallpaper.png").unwrap();
|
||||
}
|
||||