Crate a_sixel

Source
Expand description

A-Sixel library for encoding sixel images.

§Basic Usage

use a_sixel::BitMergeSixelEncoderBest;
use image::RgbaImage;

let img = RgbaImage::new(100, 100);
println!("{}", <BitMergeSixelEncoderBest>::encode(img));

§Choosing an Encoder

For a more detailed breakdown, here’s the encoders by average speed and quality against the test images (speed figures will vary) at 256 colors with Sierra dithering:

AlgorithmMSEDSSIMPHash DistanceMean ΔEMax ΔEΔE >2.3ΔE >5.0Execution Time (ms)
adu15.070.00538.661.7912.8831.6%4.4%1416
bit35.820.013231.143.1611.0364.5%15.1%426
bit-no-dither31.780.021439.103.0910.2364.0%13.4%274
bit-merge-low10.670.003813.971.959.9832.4%2.2%785
bit-merge10.360.003713.551.8910.0131.0%2.2%932
bit-merge-better10.310.003713.451.8510.2130.6%2.2%1275
bit-merge-best10.290.003713.521.8310.2630.6%2.2%1496
focal14.620.005619.972.309.1645.3%3.3%2428
k-means10.070.003613.071.8010.1729.1%2.2%2996
k-medians17.670.006821.072.6110.1753.6%5.1%7305
median-cut19.630.005916.452.2410.3642.2%5.9%692
octree54.480.014826.033.8912.4978.6%25.4%682
wu17.890.006821.032.3410.2446.3%5.1%1853

Note: Execution time includes the time taken to compute error statistics - this is non-trivial. For example, exclusive of error statistics computation, bit-no-dither takes <100ms on average. Performance figures will vary based on machine, etc. They are only useful for comparing algorithms against each other within this dataset.

Here’s the encoders at 16 colors with Sierra dithering:

AlgorithmMSEDSSIMPHash DistanceMean ΔEMax ΔEΔE >2.3ΔE >5.0Execution Time (ms)
adu116.850.03639.834.0218.3966%33%332
bit178.470.04959.795.5316.6189%51%307
bit-merge95.170.03041.523.9516.1667%31%712
focal118.570.03548.594.3616.8872%34%2150
k-means99.360.03143.103.9916.4167%31%637
k-medians166.880.05060.595.4816.7788%52%5447
median-cut164.520.03745.284.6816.7274%42%374
octree459.370.08575.077.6918.8998%74%446
wu125.840.03950.524.4816.7075%39%906

Re-exports§

pub use crate::adu::ADUPaletteBuilder;adu
pub use crate::bit::BitPaletteBuilder;
pub use crate::bitmerge::BitMergePaletteBuilder;bit-merge
pub use crate::focal::FocalPaletteBuilder;focal
pub use crate::kmeans::KMeansPaletteBuilder;k-means
pub use crate::kmedians::KMediansPaletteBuilder;k-medians
pub use crate::median_cut::MedianCutPaletteBuilder;median-cut
pub use crate::octree::OctreePaletteBuilder;octree
pub use crate::wu::WuPaletteBuilder;wu

Modules§

aduadu
Use Adaptive Distributive Units to “learn” the image’s color properties and select palette entries.
bit
Encodes a palette by bucketing bit ranges into a power of two number of buckets. This is very fast and produces ok results for most images at larger palette sizes (e.g. 256).
bitmergebit-merge
Uses BitSixelEncoder with k-means and agglomerative merging to build a palette.
dither
A collection of various dithering algorithms that can be used with the SixelEncoder to dither the result.
focalfocal
Use weighted pixels based on the image’s spectral properties to provided weighted input to k-means.
kmeansk-means
Use k-means clustering to determine a palette for the image.
kmediansk-medians
Uses k-medians to build a palette of colors.
median_cutmedian-cut
https://en.wikipedia.org/wiki/Median_cut
octreeoctree
Uses an octree to build a palette from an image.
wuwu
Uses Wu’s quantization algorithm to build a palette from an image.

Structs§

SixelEncoder
The main type for performing sixel encoding.

Traits§

PaletteBuilder
A trait for types that perform quantization of an image to a target palette size.

Type Aliases§

ADUSixelEncoderadu
BitMergeSixelEncoderbit-merge
BitMergeSixelEncoderBestbit-merge
BitMergeSixelEncoderBetterbit-merge
BitMergeSixelEncoderLowbit-merge
BitSixelEncoder
FocalSixelEncoderfocal
KMeansSixelEncoderk-means
KMediansSixelEncoderk-medians
MedianCutSixelEncodermedian-cut
OctreeSixelEncoderoctree
WuSixelEncoderwu