- switch black and white at ends of quantitative colormaps
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tiffwrite"
|
name = "tiffwrite"
|
||||||
version = "2024.10.2"
|
version = "2024.10.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|||||||
@@ -138,15 +138,15 @@ def get_colormap(colormap: str) -> np.ndarray:
|
|||||||
if colormap.endswith('_r'):
|
if colormap.endswith('_r'):
|
||||||
cm = cm[::-1]
|
cm = cm[::-1]
|
||||||
if colormap.startswith('glasbey') or colormap.endswith('glasbey'):
|
if colormap.startswith('glasbey') or colormap.endswith('glasbey'):
|
||||||
cm[0] = 0, 0, 0
|
cm[0] = 255, 255, 255
|
||||||
cm[-1] = 255, 255, 255
|
cm[-1] = 0, 0, 0
|
||||||
else:
|
else:
|
||||||
cmap = matplotlib.colormaps.get_cmap(colormap)
|
cmap = matplotlib.colormaps.get_cmap(colormap)
|
||||||
if cmap.N < 256:
|
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),
|
matplotlib.cm.ScalarMappable(matplotlib.colors.Normalize(1, 254),
|
||||||
cmap).to_rgba(np.arange(1, 254))[:, :3],
|
cmap).to_rgba(np.arange(1, 254))[:, :3],
|
||||||
(1, 1, 1)))).astype('uint8')
|
(0, 0, 0)))).astype('uint8')
|
||||||
else:
|
else:
|
||||||
cm = (255 * matplotlib.cm.ScalarMappable(matplotlib.colors.Normalize(0, 255), cmap)
|
cm = (255 * matplotlib.cm.ScalarMappable(matplotlib.colors.Normalize(0, 255), cmap)
|
||||||
.to_rgba(np.arange(256))[:, :3]).astype('uint8')
|
.to_rgba(np.arange(256))[:, :3]).astype('uint8')
|
||||||
|
|||||||
64
src/lib.rs
64
src/lib.rs
@@ -123,20 +123,20 @@ impl Tag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn byte(code: u16, byte: &Vec<u8>) -> Self {
|
pub fn byte(code: u16, value: &Vec<u8>) -> Self {
|
||||||
Tag::new(code, byte.to_owned(), 1)
|
Tag::new(code, value.to_owned(), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ascii(code: u16, ascii: &str) -> Self {
|
pub fn ascii(code: u16, value: &str) -> Self {
|
||||||
let mut bytes = ascii.as_bytes().to_vec();
|
let mut bytes = value.as_bytes().to_vec();
|
||||||
bytes.push(0);
|
bytes.push(0);
|
||||||
Tag::new(code, bytes, 2)
|
Tag::new(code, bytes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn short(code: u16, short: &Vec<u16>) -> Self {
|
pub fn short(code: u16, value: &Vec<u16>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
short
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -145,10 +145,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn long(code: u16, long: &Vec<u32>) -> Self {
|
pub fn long(code: u16, value: &Vec<u32>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
long.into_iter()
|
value.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -156,10 +156,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rational(code: u16, rational: &Vec<Rational32>) -> Self {
|
pub fn rational(code: u16, value: &Vec<Rational32>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
rational
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
u32::try_from(*x.denom())
|
u32::try_from(*x.denom())
|
||||||
@@ -175,18 +175,18 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sbyte(code: u16, sbyte: &Vec<i8>) -> Self {
|
pub fn sbyte(code: u16, value: &Vec<i8>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
sbyte.iter().map(|x| x.to_le_bytes()).flatten().collect(),
|
value.iter().map(|x| x.to_le_bytes()).flatten().collect(),
|
||||||
6,
|
6,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sshort(code: u16, sshort: &Vec<i16>) -> Self {
|
pub fn sshort(code: u16, value: &Vec<i16>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
sshort
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -195,10 +195,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slong(code: u16, slong: &Vec<i32>) -> Self {
|
pub fn slong(code: u16, value: &Vec<i32>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
slong
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -207,10 +207,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn srational(code: u16, srational: &Vec<Rational32>) -> Self {
|
pub fn srational(code: u16, value: &Vec<Rational32>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
srational
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
i32::try_from(*x.denom())
|
i32::try_from(*x.denom())
|
||||||
@@ -226,10 +226,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float(code: u16, float: &Vec<f32>) -> Self {
|
pub fn float(code: u16, value: &Vec<f32>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
float
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -238,10 +238,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn double(code: u16, double: &Vec<f64>) -> Self {
|
pub fn double(code: u16, value: &Vec<f64>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
double
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -250,16 +250,16 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ifd(code: u16, ifd: &Vec<u32>) -> Self {
|
pub fn ifd(code: u16, value: &Vec<u32>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
ifd.into_iter().map(|x| x.to_le_bytes()).flatten().collect(),
|
value.into_iter().map(|x| x.to_le_bytes()).flatten().collect(),
|
||||||
13,
|
13,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unicode(code: u16, unicode: &str) -> Self {
|
pub fn unicode(code: u16, value: &str) -> Self {
|
||||||
let mut bytes: Vec<u8> = unicode
|
let mut bytes: Vec<u8> = value
|
||||||
.encode_utf16()
|
.encode_utf16()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -268,10 +268,10 @@ impl Tag {
|
|||||||
Tag::new(code, bytes, 14)
|
Tag::new(code, bytes, 14)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn complex(code: u16, complex: &Vec<Complex<f32>>) -> Self {
|
pub fn complex(code: u16, value: &Vec<Complex<f32>>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
complex
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
x.re.to_le_bytes()
|
x.re.to_le_bytes()
|
||||||
@@ -285,10 +285,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn long8(code: u16, long8: &Vec<u64>) -> Self {
|
pub fn long8(code: u16, value: &Vec<u64>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
long8
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -297,10 +297,10 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slong8(code: u16, slong8: &Vec<i64>) -> Self {
|
pub fn slong8(code: u16, value: &Vec<i64>) -> Self {
|
||||||
Tag::new(
|
Tag::new(
|
||||||
code,
|
code,
|
||||||
slong8
|
value
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_le_bytes())
|
.map(|x| x.to_le_bytes())
|
||||||
.flatten()
|
.flatten()
|
||||||
|
|||||||
Reference in New Issue
Block a user