Skip to main content

Crate lepton_jpeg

Crate lepton_jpeg 

Source
Expand description

A lossless JPEG compressor with precise bit-for-bit recovery, supporting both baseline and progressive JPEGs. Achieves compression savings of around 22%, making it suitable for cold cloud storage use cases.

This crate is a Rust port of Dropbox’s original lepton JPEG compression tool. It retains the performance characteristics of the C++ version while benefiting from Rust’s memory safety guarantees. All JPEG content—including metadata and even malformed segments—is preserved accurately.

The original C++ codebase has been deprecated by Dropbox. This Rust implementation incorporates an exhaustive security review of the original, making it a safer and more maintainable alternative.

Structs§

CpuTimeMeasure
platform independent threadtime measurement
EnabledFeatures
Features that are enabled in the encoder. Turn off for potential backward compat issues.
LeptonError
Standard error returned by Lepton library
LeptonFileReader
This is the state machine for the decoder for reading lepton files. The data is pushed into the state machine and processed in chuncks. Once the calculations are done the data is retrieved from the output buffers.
Metrics
Metrics for the Lepton JPEG compression and decompression process.
SimpleThreadPool
A simple thread pool that spawns threads on demand and reuses them for executing closures. There is no limit on the number of threads, but the number of idle threads is limited to the number of CPUs available.
SingleThreadPool
single thread pool that creates that doesn’t create any threads

Enums§

ExitCode
Well-defined errors for bad things that are expected to happen as part of compression/decompression
LeptonThreadPriority
Priority levels for threads in the thread pool.
ThreadPoolHolder
Holds either a reference to a LeptonThreadPool or an owned Box.

Statics§

DEFAULT_THREAD_POOL
A default instance of the SimpleThreadPool that can be used for encoding and decoding operations.

Traits§

LeptonThreadPool
A trait that defines the interface for a Lepton thread pool. It has a simple fire-and-forget interface, which is sufficient for the current use cases, but also requires the thread pool to be static, since we don’t require the thread to return within a specific lifetime.
StreamPosition
Trait for types that can provide the current position in a stream. This is intentionally a subset of the Seek trait, as it only requires remembering the current position without allowing seeking to arbitrary positions.

Functions§

catch_unwind_result
Helper function to catch panics and convert them into the appropriate LeptonError
decode_lepton
Reads an entire lepton file and writes it out as a JPEG
dump_jpeg
used by utility to dump out the contents of a jpeg file or lepton file for debugging purposes
encode_lepton
Reads a jpeg and writes it out as a lepton file
encode_lepton_verify
Encodes JPEG as compressed Lepton format, verifies roundtrip in buffer. Requires everything to be buffered since we need to pass through the data multiple times
get_git_version
Returns the git version used to build this libary as a static string.
get_version_string
Returns the version string of the library, which includes the package version and the git version. This is useful for debugging and logging purposes to know the exact version of the library is being used