Skip to content

Commit ed939c3

Browse files
committed
Add rustdoc to the new functions, and fix a bug they revealed
1 parent dd58647 commit ed939c3

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.8.1
2+
3+
* Fix a bug in AVX2 path of `labs_to_rgb_bytes`
4+
15
# 0.8.0
26

37
* Speed up AVX2 code path, primarily by bringing in an AVX2 impl of `powf`,

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lab"
3-
version = "0.8.0" # bump html_root_url attribute in lib.rs
3+
version = "0.8.1" # bump html_root_url attribute in lib.rs
44
authors = ["Jesse Bees <jesse@toomanybees.com>"]
55
description = """
66
Tools for converting RGB colors to the CIE-L*a*b* color space, and

src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![doc(html_root_url = "https://docs.rs/lab/0.8.0")]
1+
#![doc(html_root_url = "https://docs.rs/lab/0.8.1")]
22

33
/*!
44
@@ -253,6 +253,20 @@ pub fn rgbs_to_labs(rgbs: &[[u8; 3]]) -> Vec<Lab> {
253253
labs
254254
}
255255

256+
/// RGB to Lab conversion that operates on a flat `&[u8]` of consecutive RGB triples.
257+
///
258+
/// # Example
259+
/// ```
260+
/// # extern crate lab;
261+
/// # use lab::{Lab, rgb_bytes_to_labs};
262+
/// let rgbs = &[255u8, 0, 0, 255, 0, 255, 0, 255, 255];
263+
/// let labs = lab::rgb_bytes_to_labs(rgbs);
264+
/// assert_eq!(labs, vec![
265+
/// Lab { l: 53.240784, a: 80.09252, b: 67.203186 },
266+
/// Lab { l: 60.32421, a: 98.23433, b: -60.824894 },
267+
/// Lab { l: 91.11321, a: -48.08751, b: -14.131201 }
268+
/// ]);
269+
/// ```
256270
pub fn rgb_bytes_to_labs(bytes: &[u8]) -> Vec<Lab> {
257271
#[cfg(all(target_arch = "x86_64", target_feature = "avx2"))]
258272
let labs = simd::rgb_bytes_to_labs(bytes);
@@ -288,6 +302,20 @@ pub fn labs_to_rgbs(labs: &[Lab]) -> Vec<[u8; 3]> {
288302
rgbs
289303
}
290304

305+
/// Lab to RGB conversion that returns RGB triples flattened into a `Vec<u8>`
306+
///
307+
/// # Example
308+
/// ```
309+
/// # extern crate lab;
310+
/// # use lab::{Lab, labs_to_rgb_bytes};
311+
/// let labs = &[
312+
/// Lab { l: 91.11321, a: -48.08751, b: -14.131201 },
313+
/// Lab { l: 60.32421, a: 98.23433, b: -60.824894 },
314+
/// Lab { l: 97.13926, a: -21.553724, b: 94.47797 },
315+
/// ];
316+
/// let rgb_bytes = lab::labs_to_rgb_bytes(labs);
317+
/// assert_eq!(rgb_bytes, vec![0, 255, 255, 255, 0, 255, 255, 255, 0]);
318+
/// ```
291319
#[inline]
292320
pub fn labs_to_rgb_bytes(labs: &[Lab]) -> Vec<u8> {
293321
#[cfg(all(target_arch = "x86_64", target_feature = "avx2"))]

src/simd/labs_to_rgbs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub fn labs_to_rgb_bytes(labs: &[Lab]) -> Vec<u8> {
4242
let chunks = labs.chunks_exact(8);
4343
let remainder = chunks.remainder();
4444
let mut vs = chunks.fold(Vec::with_capacity(labs.len()), |mut v, labs| {
45-
let rgbs = unsafe { slice_labs_to_rgb_bytes(labs) };
46-
v.extend_from_slice(&rgbs);
45+
let bytes = unsafe { slice_labs_to_rgb_bytes(labs) };
46+
v.extend_from_slice(&bytes);
4747
v
4848
});
4949

@@ -55,8 +55,8 @@ pub fn labs_to_rgb_bytes(labs: &[Lab]) -> Vec<u8> {
5555
.take(8)
5656
.collect();
5757

58-
let rgbs = unsafe { slice_labs_to_rgb_bytes(&labs) };
59-
vs.extend_from_slice(&rgbs[..remainder.len()]);
58+
let bytes = unsafe { slice_labs_to_rgb_bytes(&labs) };
59+
vs.extend_from_slice(&bytes[..remainder.len() * 3]);
6060
}
6161

6262
vs

0 commit comments

Comments
 (0)