// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
impl SaveStage { pub(super) fn save_simple(
&self,
data: &[Image<f64>],
buffers: &mut [Option<JxlOutputBuffer>],
) -> Result<()> { for i inself.channels.iter().skip(1) {
assert_eq!(data[self.channels[0]].size(), data[*i].size());
} let Some(buf) = buffers[self.output_buffer_index].as_mut() else { return Ok(());
}; let size = data[0].size();
self.check_buffer_size(size, Some(buf))?;
let output_channels = self.output_channels();
for (c, &chan) inself.channels.iter().enumerate() { for y in0..size.1 { let src_row = data[chan].row(y);
for (x, &px) in src_row.iter().enumerate() { let (dx, dy) = self.orientation.display_pixel((x, y), size); let dx = dx * output_channels + c; let bps = self.data_format.bytes_per_sample();
// Fill opaque alpha if needed (when RGBA requested but image has no alpha) ifself.fill_opaque_alpha { let alpha_channel = self.channels.len(); // alpha is after the source channels let opaque_bytes = self.data_format.opaque_alpha_bytes(); for y in0..size.1 { for x in0..size.0 { let (dx, dy) = self.orientation.display_pixel((x, y), size); let dx = dx * output_channels + alpha_channel; let bps = self.data_format.bytes_per_sample();
buf.write_bytes(dy, dx * bps, &opaque_bytes);
}
}
}
Ok(())
}
}
#[cfg(test)] mod test { usesuper::*; usecrate::{
api::JxlColorType, headers::Orientation, image::Rect, util::test::assert_almost_eq,
}; use rand::SeedableRng; use rand_xorshift::XorShiftRng; use test_log::test;
for y in0..128 { for x in0..128 { // Conversion stages handle bit depth scaling, save stage just casts let expected = src[0].row(y)[x] as u8;
assert_eq!(expected, dst.row(y)[x]);
}
}
// Iterate over the DESTINATION image pixels. for y_dest in0..oh { for x_dest in0..ow { // For each destination pixel, find its corresponding source pixel. let (src_x, src_y) = transform(x_dest, y_dest, w, h);
assert_almost_eq(
dst.row(y_dest)[x_dest],
src[0].row(src_y)[src_x] as f32, 1e-5, 1e-5,
);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.