Merge pull request #99 from jshrake/import-image-pixels-add-map-argument
Add map argument to MagickWand::import_image_pixels
This commit is contained in:
@ -938,7 +938,7 @@ impl MagickWand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accepts pixel datand stores it in the image at the location you specify.
|
/// Accepts pixel data and stores it in the image at the location you specify.
|
||||||
/// See <https://imagemagick.org/api/magick-image.php#MagickImportImagePixels> for more information.
|
/// See <https://imagemagick.org/api/magick-image.php#MagickImportImagePixels> for more information.
|
||||||
pub fn import_image_pixels(
|
pub fn import_image_pixels(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -946,9 +946,10 @@ impl MagickWand {
|
|||||||
y: isize,
|
y: isize,
|
||||||
columns: usize,
|
columns: usize,
|
||||||
rows: usize,
|
rows: usize,
|
||||||
pixels: &Vec<u8>,
|
pixels: &[u8],
|
||||||
|
map: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let pixel_map = CString::new("RGBA").unwrap();
|
let pixel_map = CString::new(map).unwrap();
|
||||||
match unsafe {
|
match unsafe {
|
||||||
bindings::MagickImportImagePixels(
|
bindings::MagickImportImagePixels(
|
||||||
self.wand,
|
self.wand,
|
||||||
|
|||||||
20
tests/lib.rs
20
tests/lib.rs
@ -396,3 +396,23 @@ fn test_resource_limits() {
|
|||||||
let wand = MagickWand::new();
|
let wand = MagickWand::new();
|
||||||
assert!(wand.read_image("tests/data/rust.png").is_ok());
|
assert!(wand.read_image("tests/data/rust.png").is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_import_export_pixels_roundtrip() {
|
||||||
|
START.call_once(|| {
|
||||||
|
magick_wand_genesis();
|
||||||
|
});
|
||||||
|
let w = 2;
|
||||||
|
let h = 2;
|
||||||
|
let map = "RGB";
|
||||||
|
let pixels = [0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255];
|
||||||
|
let mut wand = MagickWand::new();
|
||||||
|
wand.new_image(4, 4, &PixelWand::new()).unwrap();
|
||||||
|
assert!(wand.import_image_pixels(0, 0, w, h, &pixels, map).is_ok());
|
||||||
|
let exported_pixels = wand.export_image_pixels(0, 0, w, h, map).unwrap();
|
||||||
|
assert_eq!(exported_pixels.len(), pixels.len());
|
||||||
|
assert!(exported_pixels
|
||||||
|
.iter()
|
||||||
|
.zip(pixels.iter())
|
||||||
|
.all(|(a, b)| a == b));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user