ucvt 0.1.0

Universal Converter
docs.rs failed to build ucvt-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

ucvt

Universal Converter — image and structured-text format conversion for Rust and C.

Features

Domain Formats
Image PNG, JPEG, GIF, BMP, ICO, TIFF, WebP
Text JSON, TOML, YAML, XML / XAML

Every conversion is available in four call shapes:

Function Description
b2b bytes → bytes
b2f bytes → file (format inferred from extension)
f2b file → bytes
f2f file → file
d2d directory / glob / %d pattern → directory

Batch operations (d2d) run in parallel via rayon.

The crate also exposes a C ABI (cdylib) so the same conversions can be called from C, C++, Python, C#, and any other language that supports the C calling convention.

Usage

[dependencies]
ucvt = "0.1.0"

Image conversion

use ucvt::img;
use image::ImageFormat;

// file → file (formats inferred from extensions)
img::f2f("photo.png", "photo.jpeg")?;

// bytes → bytes
let png_bytes = std::fs::read("photo.png")?;
let jpeg_bytes = img::b2b(&png_bytes, ImageFormat::Png, ImageFormat::Jpeg)?;

// batch: convert every file in a directory
img::d2d("frames/", "frames_out/")?;

// batch: glob pattern
img::d2d("frames/*.png", "frames_out/*.jpeg")?;

// batch: ffmpeg-style sequential numbering
img::d2d("frames/frame_%d.png", "frames_out/frame_%d.jpeg")?;

Structured-text conversion

use ucvt::txt::{self, TextFormat};

// file → file
txt::f2f("config.json", "config.toml")?;

// bytes → bytes
let json = br#"{"name": "Alice", "age": 30}"#;
let toml_bytes = txt::b2b(json, TextFormat::Json, TextFormat::Toml)?;

// batch
txt::d2d("data/", "data_out/")?;
txt::d2d("data/*.json", "data_out/*.yaml")?;

C ABI

The cdylib target exports extern "C" functions prefixed with i_ (image) and t_ (text):

// image
bool i_b2b(const uint8_t *src, size_t src_len, int src_fmt,
            uint8_t **dst, uint64_t *dst_len, int dst_fmt);
bool i_f2f(const uint8_t *src_path, size_t src_path_len,
            const uint8_t *dst_path, size_t dst_path_len);
bool i_d2d(const uint8_t *src, size_t src_len,
            const uint8_t *dst, size_t dst_len);
void i_free(uint8_t *dst, uint64_t dst_len);

// text
bool t_b2b(const uint8_t *src, size_t src_len, int src_fmt,
            uint8_t **dst, uint64_t *dst_len, int dst_fmt);
bool t_b2f(const uint8_t *src, size_t src_len, int src_fmt,
            const uint8_t *dst_path, size_t dst_path_len);
bool t_f2b(const uint8_t *src_path, size_t src_path_len, int dst_fmt,
            uint8_t **dst, uint64_t *dst_len);
bool t_f2f(const uint8_t *src_path, size_t src_path_len,
            const uint8_t *dst_path, size_t dst_path_len);
bool t_d2d(const uint8_t *src, size_t src_len,
            const uint8_t *dst, size_t dst_len);
void t_free(uint8_t *dst, uint64_t dst_len);

Format codes

Image (i_* functions):

Code Format
0 PNG
1 JPEG
2 GIF
3 BMP
4 ICO
5 TIFF
6 WebP

Text (t_* functions):

Code Format
0 JSON
1 TOML
2 YAML
3 XML / XAML

License

MIT