- switch black and white at ends of quantitative colormaps

This commit is contained in:
Wim Pomp
2024-10-14 19:03:24 +02:00
parent 140e7eaf38
commit 654755ab83
3 changed files with 37 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "tiffwrite"
version = "2024.10.2"
version = "2024.10.3"
edition = "2021"
[lib]

View File

@@ -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')

View File

@@ -123,20 +123,20 @@ impl Tag {
}
}
pub fn byte(code: u16, byte: &Vec<u8>) -> Self {
Tag::new(code, byte.to_owned(), 1)
pub fn byte(code: u16, value: &Vec<u8>) -> 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<u16>) -> Self {
pub fn short(code: u16, value: &Vec<u16>) -> 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<u32>) -> Self {
pub fn long(code: u16, value: &Vec<u32>) -> 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<Rational32>) -> Self {
pub fn rational(code: u16, value: &Vec<Rational32>) -> 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<i8>) -> Self {
pub fn sbyte(code: u16, value: &Vec<i8>) -> 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<i16>) -> Self {
pub fn sshort(code: u16, value: &Vec<i16>) -> 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<i32>) -> Self {
pub fn slong(code: u16, value: &Vec<i32>) -> 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<Rational32>) -> Self {
pub fn srational(code: u16, value: &Vec<Rational32>) -> 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<f32>) -> Self {
pub fn float(code: u16, value: &Vec<f32>) -> 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<f64>) -> Self {
pub fn double(code: u16, value: &Vec<f64>) -> 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<u32>) -> Self {
pub fn ifd(code: u16, value: &Vec<u32>) -> 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<u8> = unicode
pub fn unicode(code: u16, value: &str) -> Self {
let mut bytes: Vec<u8> = 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<Complex<f32>>) -> Self {
pub fn complex(code: u16, value: &Vec<Complex<f32>>) -> 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<u64>) -> Self {
pub fn long8(code: u16, value: &Vec<u64>) -> 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<i64>) -> Self {
pub fn slong8(code: u16, value: &Vec<i64>) -> Self {
Tag::new(
code,
slong8
value
.into_iter()
.map(|x| x.to_le_bytes())
.flatten()