From 654755ab83c5f1aa376f8ee8bf5464f87a03177c Mon Sep 17 00:00:00 2001 From: Wim Pomp Date: Mon, 14 Oct 2024 19:03:24 +0200 Subject: [PATCH] - switch black and white at ends of quantitative colormaps --- Cargo.toml | 2 +- py/tiffwrite/__init__.py | 8 ++--- src/lib.rs | 64 ++++++++++++++++++++-------------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c58af4c..d4a7d5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiffwrite" -version = "2024.10.2" +version = "2024.10.3" edition = "2021" [lib] diff --git a/py/tiffwrite/__init__.py b/py/tiffwrite/__init__.py index edcd6a2..c3b9328 100644 --- a/py/tiffwrite/__init__.py +++ b/py/tiffwrite/__init__.py @@ -138,15 +138,15 @@ def get_colormap(colormap: str) -> np.ndarray: if colormap.endswith('_r'): cm = cm[::-1] if colormap.startswith('glasbey') or colormap.endswith('glasbey'): - cm[0] = 0, 0, 0 - cm[-1] = 255, 255, 255 + cm[0] = 255, 255, 255 + cm[-1] = 0, 0, 0 else: cmap = matplotlib.colormaps.get_cmap(colormap) if cmap.N < 256: - cm = (255 * np.vstack(((0, 0, 0), + cm = (255 * np.vstack(((1, 1, 1), matplotlib.cm.ScalarMappable(matplotlib.colors.Normalize(1, 254), cmap).to_rgba(np.arange(1, 254))[:, :3], - (1, 1, 1)))).astype('uint8') + (0, 0, 0)))).astype('uint8') else: cm = (255 * matplotlib.cm.ScalarMappable(matplotlib.colors.Normalize(0, 255), cmap) .to_rgba(np.arange(256))[:, :3]).astype('uint8') diff --git a/src/lib.rs b/src/lib.rs index 37e33c0..eef6968 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,20 +123,20 @@ impl Tag { } } - pub fn byte(code: u16, byte: &Vec) -> Self { - Tag::new(code, byte.to_owned(), 1) + pub fn byte(code: u16, value: &Vec) -> Self { + Tag::new(code, value.to_owned(), 1) } - pub fn ascii(code: u16, ascii: &str) -> Self { - let mut bytes = ascii.as_bytes().to_vec(); + pub fn ascii(code: u16, value: &str) -> Self { + let mut bytes = value.as_bytes().to_vec(); bytes.push(0); Tag::new(code, bytes, 2) } - pub fn short(code: u16, short: &Vec) -> Self { + pub fn short(code: u16, value: &Vec) -> Self { Tag::new( code, - short + value .into_iter() .map(|x| x.to_le_bytes()) .flatten() @@ -145,10 +145,10 @@ impl Tag { ) } - pub fn long(code: u16, long: &Vec) -> Self { + pub fn long(code: u16, value: &Vec) -> Self { Tag::new( code, - long.into_iter() + value.into_iter() .map(|x| x.to_le_bytes()) .flatten() .collect(), @@ -156,10 +156,10 @@ impl Tag { ) } - pub fn rational(code: u16, rational: &Vec) -> Self { + pub fn rational(code: u16, value: &Vec) -> Self { Tag::new( code, - rational + value .into_iter() .map(|x| { u32::try_from(*x.denom()) @@ -175,18 +175,18 @@ impl Tag { ) } - pub fn sbyte(code: u16, sbyte: &Vec) -> Self { + pub fn sbyte(code: u16, value: &Vec) -> Self { Tag::new( code, - sbyte.iter().map(|x| x.to_le_bytes()).flatten().collect(), + value.iter().map(|x| x.to_le_bytes()).flatten().collect(), 6, ) } - pub fn sshort(code: u16, sshort: &Vec) -> Self { + pub fn sshort(code: u16, value: &Vec) -> Self { Tag::new( code, - sshort + value .into_iter() .map(|x| x.to_le_bytes()) .flatten() @@ -195,10 +195,10 @@ impl Tag { ) } - pub fn slong(code: u16, slong: &Vec) -> Self { + pub fn slong(code: u16, value: &Vec) -> Self { Tag::new( code, - slong + value .into_iter() .map(|x| x.to_le_bytes()) .flatten() @@ -207,10 +207,10 @@ impl Tag { ) } - pub fn srational(code: u16, srational: &Vec) -> Self { + pub fn srational(code: u16, value: &Vec) -> Self { Tag::new( code, - srational + value .into_iter() .map(|x| { i32::try_from(*x.denom()) @@ -226,10 +226,10 @@ impl Tag { ) } - pub fn float(code: u16, float: &Vec) -> Self { + pub fn float(code: u16, value: &Vec) -> Self { Tag::new( code, - float + value .into_iter() .map(|x| x.to_le_bytes()) .flatten() @@ -238,10 +238,10 @@ impl Tag { ) } - pub fn double(code: u16, double: &Vec) -> Self { + pub fn double(code: u16, value: &Vec) -> Self { Tag::new( code, - double + value .into_iter() .map(|x| x.to_le_bytes()) .flatten() @@ -250,16 +250,16 @@ impl Tag { ) } - pub fn ifd(code: u16, ifd: &Vec) -> Self { + pub fn ifd(code: u16, value: &Vec) -> Self { Tag::new( code, - ifd.into_iter().map(|x| x.to_le_bytes()).flatten().collect(), + value.into_iter().map(|x| x.to_le_bytes()).flatten().collect(), 13, ) } - pub fn unicode(code: u16, unicode: &str) -> Self { - let mut bytes: Vec = unicode + pub fn unicode(code: u16, value: &str) -> Self { + let mut bytes: Vec = value .encode_utf16() .map(|x| x.to_le_bytes()) .flatten() @@ -268,10 +268,10 @@ impl Tag { Tag::new(code, bytes, 14) } - pub fn complex(code: u16, complex: &Vec>) -> Self { + pub fn complex(code: u16, value: &Vec>) -> Self { Tag::new( code, - complex + value .into_iter() .map(|x| { x.re.to_le_bytes() @@ -285,10 +285,10 @@ impl Tag { ) } - pub fn long8(code: u16, long8: &Vec) -> Self { + pub fn long8(code: u16, value: &Vec) -> Self { Tag::new( code, - long8 + value .into_iter() .map(|x| x.to_le_bytes()) .flatten() @@ -297,10 +297,10 @@ impl Tag { ) } - pub fn slong8(code: u16, slong8: &Vec) -> Self { + pub fn slong8(code: u16, value: &Vec) -> Self { Tag::new( code, - slong8 + value .into_iter() .map(|x| x.to_le_bytes()) .flatten()