raw_preview_rs
A Rust library that quickly creates preview JPEGs from RAW image files and extracts EXIF metadata.
This crate statically links several C/C++ dependencies; building it requires native build tools (see below).
Features
- RAW Image Processing: Supports 27+ RAW formats, including CR2, NEF, ARW, RAF, and more.
- Standard Image Formats: Handles JPEG, PNG, TIFF, BMP, and WebP.
- EXIF Metadata Extraction: Extracts and preserves EXIF metadata, including camera make, model, ISO, and more.
- Resolution Reduction: Automatically reduces image resolution for fast previews.
Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
# Run package tests
# Build the package (release)
Usage
Example: Processing a RAW File
use process_any_image;
match process_any_image
Example: Processing a JPEG File
use process_any_image;
match process_any_image
Example: In-memory API (bytes)
The crate now provides APIs that accept image data as bytes (no temporary files required). These are useful when images come from HTTP uploads, in-memory caches, or other non-filesystem sources.
Example: process a JPEG/PNG image provided as bytes:
use fs;
use process_image_bytes;
let bytes = read.expect;
let exif = process_image_bytes.expect;
println!;
Example: convert RAW bytes (DNG/CR2/etc.) to JPEG:
use fs;
use convert_raw_bytes_to_jpeg;
let raw_bytes = read.expect;
let exif = convert_raw_bytes_to_jpeg.expect;
println!;
Note: processing using the bytes-based API is performed entirely in-memory via the native FFI and does not create temporary files. The function will still write the resulting JPEG preview to the output_path you provide (i.e., you must supply a filesystem path where the preview will be saved).
If you prefer the preview JPEG bytes to be returned directly (instead of writing to disk), the crate exposes Vec-returning helpers at the crate root. Example usage:
use File;
use Write;
use fs;
use ;
// Image file (JPEG/PNG/etc.) -> get JPEG bytes in-memory
let img_bytes = read.expect;
let = process_image_bytes_to_vec.expect;
create.unwrap.write_all.unwrap;
println!;
// RAW file (DNG/CR2/etc.) -> get JPEG bytes in-memory
let raw_bytes = read.expect;
let = convert_raw_bytes_to_vec.expect;
create.unwrap.write_all.unwrap;
println!;
Supported Formats
RAW Formats (processed via LibRaw):
- Canon: CR2, CR3
- Nikon: NEF
- Sony: ARW, SR2, SRF
- Fujifilm: RAF
- Panasonic: RW2
- Olympus: ORF
- Pentax: PEF, PTX
- Samsung: SRW
- Hasselblad: 3FR, FFF
- Mamiya: MEF
- Minolta: MRW, MDC
- Sigma: X3F
- Kodak: DCR, KDC
- PhaseOne: IIQ, CAP
- Leica: RWL
- GoPro: GPR
- Epson: ERF
- Leaf: MOS
- RED: R3D
- Adobe: DNG
- Generic: RAW
Standard Image Formats:
- JPEG: JPG, JPEG
- PNG: PNG
- TIFF: TIFF, TIF
- Bitmap: BMP
- WebP: WEBP
Build Requirements
This library has several native dependencies that are automatically downloaded and built during compilation. To ensure a successful build, you need the following tools installed on your system:
Required Build Tools
All Platforms
-
CMake (version 3.10 or higher)
- Used for building TinyEXIF and TinyXML2
- Download from: https://cmake.org/download/
-
Make
- Used for building all dependencies
- Usually pre-installed on Unix-like systems
macOS
# Install Xcode Command Line Tools (includes make, clang, etc.)
# Install CMake using Homebrew
# Install autotools (recommended for LibRaw)
Ubuntu/Debian
# Install build essentials and CMake
# Install autotools (recommended for LibRaw)
CentOS/RHEL/Fedora
# Install build tools and CMake
# Install autotools (recommended for LibRaw)
Windows
- Visual Studio (2019 or later) with C++ build tools
- CMake - Download from https://cmake.org/download/
- Git (for downloading dependencies)
Alternatively, use vcpkg or Conan to manage dependencies.
Optional Tools
- autoconf, automake, libtool: Recommended for building LibRaw from source
- If these are not available, the build script will attempt to use pre-generated configure scripts
- Without these tools, some LibRaw versions may fail to build
Build Troubleshooting
If you encounter build issues:
- Missing autotools: Install autoconf, automake, and libtool
- CMake not found: Ensure CMake is in your PATH
- Compiler errors: Ensure you have a C++11 compatible compiler
- Network issues: The build downloads dependencies from the internet
For detailed error messages, run:
RUST_BACKTRACE=1
Cross-compilation
Cross-compilation is supported but requires the target platform's build tools. Ensure CMake and make are available for your target platform.
Dependencies
This library automatically manages all its native dependencies through a custom build script. The following libraries are downloaded, compiled, and statically linked during the build process:
| Dependency | Version | Purpose | Source |
|---|---|---|---|
| zlib | 1.3 | Compression library | zlib.net |
| LibRaw | 0.21.4 | RAW image processing | GitHub |
| libjpeg-turbo | 2.1.5 | JPEG compression/decompression | GitHub |
| TinyEXIF | 1.0.3 | EXIF metadata extraction | GitHub |
| TinyXML2 | 11.0.0 | XML parsing for XMP metadata | GitHub |
| stb_image | latest | Standard image format decoding | GitHub |
Dependency Management Features
- Automatic Download: All dependencies are downloaded from their official sources
- Version Pinning: Specific versions are used to ensure build reproducibility
- Static Linking: All libraries are statically linked for easy deployment
- Caching: Built dependencies are cached to speed up subsequent builds
- Cross-platform: Works on macOS, Linux, and Windows with appropriate build tools
No manual dependency installation is required - just ensure you have the build tools listed above.
Disabling SIMD for libjpeg-turbo builds
By default SIMD optimizations are enabled for native builds. You can disable SIMD specifically for the bundled libjpeg-turbo build in two ways:
- Disable via Cargo features (recommended):
# Build without the default "simd" feature
- Force-disable via environment variable:
# Example: disable SIMD for one build
RAW_PREVIEW_RS_DISABLE_SIMD=1
When SIMD is disabled the build script will pass flags to the native build to avoid auto-vectorization (portable across compilers). This helps when building for targets that don't support the host's SIMD instruction set.
License
This project is licensed under the GNU General Public License (GPL) version 3. See the LICENSE file for details.