Function turbojpeg::transform

source ·
pub fn transform(transform: &Transform, jpeg_data: &[u8]) -> Result<OwnedBuf>
Expand description

Losslessly transform a JPEG image without recompression.

TurboJPEG applies the transformation on the DCT coefficients, without performing complete decompression. This is faster and also means that the transforms are lossless.

Returns the transformed JPEG data in a buffer owned by TurboJPEG. If this does not fit your needs, please see Transformer.

§Example

// read JPEG data from file
let jpeg_data = std::fs::read("examples/parrots.jpg")?;

// define the transformation: rotate 90 degrees clockwise
let mut transform = turbojpeg::Transform::op(turbojpeg::TransformOp::Rot90);
transform.optimize = true;

// apply the transformation
let rotated_data = turbojpeg::transform(&transform, &jpeg_data)?;

// write the rotated JPEG back to disk
std::fs::write(std::env::temp_dir().join("rotated_parrots.jpg"), &rotated_data)?;