diff --git a/src/lib.rs b/src/lib.rs index 6ce1db08e96fff90f543d0b78f31a0c933bcbd1e..d312d1c5f5bf4b9a1f01b7e23802152908d8110f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,10 @@ //! See [Little CMS full documentation](https://pornel.github.io/rust-lcms2-sys/) for more in-depth information about LCMS functions. +//! +//! The main types you need to use in this crate are `Profile` and `Transform` #![allow(dead_code)] extern crate lcms2_sys as ffi; + #[macro_use] extern crate foreign_types; diff --git a/src/transform.rs b/src/transform.rs index ac953d0df2a7767c98567e372f1eb31e62cce012..67195fd24d46dab1d8750a161402bc23b9c106cd 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -3,11 +3,27 @@ use context::Context; use std::os::raw::c_void; use std::marker::PhantomData; -/// Conversion between two ICC profiles +/// Conversion between two ICC profiles. /// -/// Usually you don't need to specify `InputPixelFormat`/`OutputPixelFormat` parameters explicitly. -/// They will be inferred from the call to `transform_pixels` or `transform_in_place`. -/// You might get "cannot infer type for `InputPixelFormat`" error before you write calls to one of these functions. +/// The transform ensures type safety and thread safety at compile time. To do this, it has a few generic types associated with it. +/// Usually, you don't need to specify any of the generic parameters (like `InputPixelFormat`/`OutputPixelFormat`) explicitly, +/// because they are inferred from calls to constructors and `transform_pixels` or `transform_in_place`. +/// +/// If you get error such as: +/// +/// > cannot infer type for `InputPixelFormat` +/// > type annotations required: cannot resolve `_: std::marker::Copy` +/// +/// then don't worry! Write some code that calls `transform_pixels()`, +/// because this is the function that makes the type of the transform clear. +/// +/// * `InputPixelFormat` — e.g. `(u8,u8,u8)` or struct `RGB<u8>`, etc. +/// The type must have appropriate number of bytes per pixel (i.e. you can't just use `[u8]` for everything). +/// * `OutputPixelFormat` — similar to `InputPixelFormat`. If both are the same, then `transform_in_place()` function works. +/// * `Context` — it's `GlobalContext` for the default non-thread-safe version, or `ThreadContext` for thread-safe version. +/// Thread-safety: +/// +/// * Transform is `Send` if you create it with `ThreadContext` (use `new_*_context()` functions). pub struct Transform<InputPixelFormat, OutputPixelFormat, Context = GlobalContext> { pub(crate) handle: ffi::HTRANSFORM, _from: PhantomData<InputPixelFormat>, @@ -20,11 +36,15 @@ unsafe impl<'a, F, T, C: Send> Send for Transform<F, T, C> {} impl<InputPixelFormat: Copy + Clone, OutputPixelFormat: Copy + Clone> Transform<InputPixelFormat, OutputPixelFormat, GlobalContext> { /// Creates a color transform for translating bitmaps. /// + /// Basic, non-tread-safe version. + /// /// * Input: Handle to a profile object capable to work in input direction - /// * InputFormat: A bit-field format specifier as described in Formatters section. + /// * InputFormat: A bit-field format specifier /// * Output: Handle to a profile object capable to work in output direction - /// * OutputFormat: A bit-field format specifier as described in Formatters section. + /// * OutputFormat: A bit-field format specifier /// * Intent: Rendering intent + /// + /// See documentation of these types for more detail. pub fn new(input: &Profile, in_format: PixelFormat, output: &Profile,