RawProcessor

Struct RawProcessor 

Source
pub struct RawProcessor { /* private fields */ }
Expand description

RAW 图像文件的主要处理器

这是 RawLib 库的核心结构体,提供了与 LibRaw 库交互的高级接口。 它使用 RAII 模式管理 LibRaw 实例的生命周期,确保资源被正确释放。

§安全性

  • 使用 RAII 模式自动管理 LibRaw 实例
  • 实现了 Send trait,支持跨线程使用
  • 所有 FFI 调用都被包装在安全的接口中

Implementations§

Source§

impl RawProcessor

Source

pub fn new() -> Result<Self>

创建新的 RawProcessor 实例

初始化一个 LibRaw 实例并准备处理 RAW 文件。 如果初始化失败,将返回错误。

§返回值

Ok(RawProcessor) - 成功创建的处理器实例 Err(RawError) - 初始化失败时的错误信息

§示例
let processor = RawProcessor::new()?;
Source

pub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

从文件系统打开 RAW 文件

打开指定的 RAW 文件并读取其基本信息。这个方法会:

  1. 检查文件是否存在
  2. 根据平台选择合适的 API(Windows 使用宽字符,Unix 使用 UTF-8)
  3. 调用 LibRaw 打开文件
§参数
  • path - RAW 文件的路径
§返回值

Ok(()) - 文件成功打开 Err(RawError) - 打开失败时的错误信息

§平台支持
  • Windows: 使用宽字符 API 支持完整的 Unicode 文件名
  • Unix/Linux/macOS: 使用 UTF-8 字符串
Source

pub fn unpack(&mut self) -> Result<()>

Unpack the RAW data

Source

pub fn dcraw_process(&mut self) -> Result<()>

Process the RAW data (demosaic, white balance, etc.)

Source

pub fn recycle(&mut self)

Recycle internal buffers

Source

pub fn unpack_thumb(&mut self) -> Result<()>

Unpack thumbnail data

Source

pub fn extract_thumbnail<P: AsRef<Path>>(path: P) -> Result<ThumbnailData>

Extract thumbnail as raw bytes

This method opens the RAW file, extracts the embedded thumbnail, and returns it as a byte vector. The thumbnail is typically in JPEG format.

§Arguments
  • path - Path to the RAW file
§Returns

Returns ThumbnailData containing the thumbnail image data and metadata

§Example
use rawlib::RawProcessor;
 
let thumb_data = RawProcessor::extract_thumbnail("image.cr2").unwrap();
std::fs::write("thumb.jpg", &thumb_data.data).unwrap();

这是提取缩略图的最简单方法,它处理了整个流程:

  1. 创建新的处理器实例
  2. 打开 RAW 文件
  3. 解包缩略图数据
  4. 获取处理后的缩略图数据
Source

pub fn get_thumbnail(&self) -> Result<ThumbnailData>

从已打开和解包的文件中获取缩略图数据

这个方法假设:

  • 文件已经被 open_file() 打开
  • 缩略图数据已经被 unpack_thumb() 解包
§返回值

Ok(ThumbnailData) - 包含格式、尺寸和原始数据的缩略图信息 Err(RawError) - 获取缩略图失败时的错误信息

Source

pub fn version() -> String

获取 LibRaw 版本字符串

返回当前链接的 LibRaw 库的版本信息字符串,例如 “0.21.4-Release”。 这个方法对于调试和兼容性检查很有用。

§返回值

包含版本信息的字符串

Source

pub fn version_number() -> i32

获取 LibRaw 版本号(整数格式)

返回 LibRaw 库的数值版本号,例如 5380(对应 0.21.4)。 版本号编码格式为:major * 10000 + minor * 100 + patch

§返回值

整数格式的版本号

Trait Implementations§

Source§

impl Default for RawProcessor

默认构造函数实现

提供了默认构造函数,使 RawProcessor 可以更容易地在需要默认值的 场景中使用。如果创建失败,会 panic,因为这是默认实现的一部分。

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for RawProcessor

RAII 资源清理实现

当 RawProcessor 实例离开作用域时,自动释放 LibRaw 分配的资源。 这确保了即使在发生错误时也不会出现内存泄漏。

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for RawProcessor

线程安全实现

LibRaw 本身不是线程安全的,但是 RawProcessor 实例可以安全地 在不同线程之间传递(只要不在多个线程中同时使用同一个实例)。 Send trait 允许我们将 RawProcessor 实例发送到其他线程。

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.