From 8015f012863bef21abf6607c280250b29083d8c4 Mon Sep 17 00:00:00 2001
From: Kornel <kornel@geekhood.net>
Date: Mon, 12 Jun 2017 13:13:13 +0100
Subject: [PATCH] Add ToOwned and Clone

---
 Cargo.toml         |  2 +-
 examples/thread.rs |  2 +-
 src/context.rs     |  2 +-
 src/pipeline.rs    |  2 ++
 src/tonecurve.rs   | 12 ++++--------
 5 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 9857c7d..6964a8e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ categories = ["multimedia::images", "api-bindings"]
 version = "4.2.0"
 
 [dependencies]
-foreign-types = "0.2.0"
+foreign-types = "0.3.0"
 lcms2-sys = "2.4.4"
 
 [features]
diff --git a/examples/thread.rs b/examples/thread.rs
index 1394035..cee12f0 100644
--- a/examples/thread.rs
+++ b/examples/thread.rs
@@ -13,7 +13,7 @@ fn main() {
         tr.transform_pixels(&[[1u8,2,3]], &mut [out]);
     }).join().unwrap();
 
-    /// Or each object can also own its context, which allows it to be sent to another thread
+    // Or each object can also own its context, which allows it to be sent to another thread
     let profile = Profile::new_srgb_context(ThreadContext::new());
     let tr = Transform::new_context(ThreadContext::new(), &profile, PixelFormat::RGB_8, &profile, PixelFormat::RGB_8, Intent::Saturation).unwrap();
 
diff --git a/src/context.rs b/src/context.rs
index 1bf0044..350879f 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -169,7 +169,7 @@ impl Drop for ThreadContext {
 impl Default for GlobalContext {
     fn default() -> Self {
         Self::new()
-    }
+        }
 }
 
 impl Default for ThreadContext {
diff --git a/src/pipeline.rs b/src/pipeline.rs
index ae2ba3f..4e90059 100644
--- a/src/pipeline.rs
+++ b/src/pipeline.rs
@@ -6,8 +6,10 @@ use eval::FloatOrU16;
 use foreign_types::ForeignTypeRef;
 
 foreign_type! {
+    #[doc(hidden)]
     type CType = ffi::Pipeline;
     fn drop = ffi::cmsPipelineFree;
+    fn clone = ffi::cmsPipelineDup;
     /// This is an owned version of `PipelineRef`.
     pub struct Pipeline;
     /// Pipelines are a convenient way to model complex operations on image data.
diff --git a/src/tonecurve.rs b/src/tonecurve.rs
index b8ab1aa..4bada58 100644
--- a/src/tonecurve.rs
+++ b/src/tonecurve.rs
@@ -7,6 +7,7 @@ use foreign_types::{ForeignType, ForeignTypeRef};
 foreign_type! {
     type CType = ffi::ToneCurve;
     fn drop = ffi::cmsFreeToneCurve;
+    fn clone = ffi::cmsDupToneCurve;
     /// Owned version of `ToneCurveRef`
     pub struct ToneCurve;
     /// Tone curves are powerful constructs that can contain curves specified in diverse ways.
@@ -85,7 +86,7 @@ impl ToneCurveRef {
     /// Creates a tone curve that is the inverse  of given tone curve. In the case it couldn’t be analytically reversed, a tablulated curve of nResultSamples is created.
     pub fn reversed_samples(&self, samples: usize) -> ToneCurve {
         unsafe { ToneCurve::from_ptr(ffi::cmsReverseToneCurveEx(samples as i32, self.as_ptr())) }
-    }
+        }
 
     /// Composites two tone curves in the form Y^-1(X(t))
     /// (self is X, the argument is Y)
@@ -148,12 +149,6 @@ impl ToneCurveRef {
     }
 }
 
-impl Clone for ToneCurve {
-    fn clone(&self) -> ToneCurve {
-        unsafe { ToneCurve::from_ptr(ffi::cmsDupToneCurve(self.as_ptr())) }
-    }
-}
-
 impl fmt::Debug for ToneCurveRef {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "ToneCurve({} entries, gamma ~{:.1})", self.estimated_entries().len(), self.estimated_gamma(1.).unwrap_or(0.))
@@ -167,7 +162,8 @@ fn tones() {
     let _ = ToneCurve::new(-10.);
 
     let g = ToneCurve::new(1./2.2);
-    let mut z = g.clone();
+    let r: &ToneCurveRef = &g;
+    let mut z: ToneCurve = r.to_owned().clone();
     assert!(g.estimated_gamma(0.1).is_some());
     assert_eq!(1., g.eval(1.));
     assert_eq!(0, g.eval(0u16));
-- 
GitLab