Skip to content

Commit 5710ccf

Browse files
committed
Fix XYZ and always set channel names to RGBA when using oiio
1 parent f4df3bb commit 5710ccf

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "image2"
3-
version = "1.5.2"
3+
version = "1.5.3"
44
authors = ["Zach Shipko <[email protected]>"]
55
license = "ISC"
66
keywords = ["image", "image-processing"]

src/color.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,15 @@ impl Color for Xyz {
158158
b /= 12.92
159159
}
160160

161-
r *= 100.;
162-
g *= 100.;
163-
b *= 100.;
164-
165161
pixel[0] = r * 0.4124 + g * 0.3576 + b * 0.1805;
166162
pixel[1] = r * 0.2126 + g * 0.7152 + b * 0.0722;
167163
pixel[2] = r * 0.0193 + g * 0.1192 + b * 0.9505;
168164
}
169165

170166
fn to_rgb(px: &Pixel<Xyz>, mut rgb: &mut Pixel<Rgb>) {
171-
let x = px[0] / 100.;
172-
let y = px[1] / 100.;
173-
let z = px[2] / 100.;
167+
let x = px[0];
168+
let y = px[1];
169+
let z = px[2];
174170

175171
rgb[0] = {
176172
let var_r = x * 3.2406 + y * -1.5372 + z * -0.4986;

src/io/oiio.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ impl ImageOutput {
8989
/// Note: `image` dimensions and type will take precendence over the ImageSpec
9090
pub fn write<T: Type, C: Color>(mut self, image: &Image<T, C>) -> Result<(), Error> {
9191
let base_type = T::BASE;
92-
let name = C::NAME.as_bytes().as_ptr() as *const _;
9392
let path: &std::path::Path = self.path.as_ref();
9493
let path_str = std::ffi::CString::new(path.to_string_lossy().as_bytes().to_vec()).unwrap();
9594
let filename = path_str.as_ptr();
@@ -98,16 +97,12 @@ impl ImageOutput {
9897
let out = self.image_output;
9998
let spec = &mut self.spec;
10099
unsafe {
101-
cpp!([out as "ImageOutput*", name as "const char *", filename as "const char *", base_type as "TypeDesc::BASETYPE", spec as "ImageSpec *", width as "size_t", height as "size_t", channels as "size_t", pixels as "const void*"] {
100+
cpp!([out as "ImageOutput*", filename as "const char *", base_type as "TypeDesc::BASETYPE", spec as "ImageSpec *", width as "size_t", height as "size_t", channels as "size_t", pixels as "const void*"] {
102101
ImageSpec outspec (*spec);
103102
outspec.width = width;
104103
outspec.height = height;
105104
outspec.nchannels = channels;
106-
auto x = std::vector<std::string>(channels);
107-
for (int i = 0; i < channels; i++){
108-
x[i] = std::string(1, name[i]);
109-
}
110-
outspec.channelnames = x;
105+
outspec.channelnames.assign({"R", "G", "B", "A"});
111106
outspec.set_format(TypeDesc(base_type));
112107
out->open (filename, outspec);
113108
out->write_image (base_type, pixels);

src/tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,13 @@ fn test_saturation() {
211211

212212
#[test]
213213
fn test_xyz() {
214+
let image: Image<f32, Rgb> = Image::open("images/A.exr").unwrap();
215+
let image: Image<f32, Xyz> = image.convert();
216+
assert!(image.save("images/test-xyz.exr").is_ok());
217+
214218
let image: Image<f32, Xyz> = Image::open("images/A.exr").unwrap();
215-
assert!(image.save("images/test-xyz.jpg").is_ok());
219+
let image: Image<f32, Rgb> = image.convert();
220+
assert!(image.save("images/test-xyz1.exr").is_ok());
216221
}
217222

218223
#[cfg(feature = "oiio")]

0 commit comments

Comments
 (0)