Add function to write entire image
This commit is contained in:
1 parent
fb233771b5
commit
503c4d29ed
2 files changed
+14
-9
No files matched your search
@@ -165,6 +165,19 @@ impl<W: Write + Seek> TiffEncoder<W> {
|
||||
let encoder = DirectoryEncoder::new(&mut self.writer)?;
|
||||
ImageEncoder::new(encoder, width, height)
|
||||
}
|
||||
|
||||
pub fn write_image<C: ColorType>(&mut self, width: u32, height: u32, data: &[C::Inner]) -> TiffResult<()> {
|
||||
let encoder = DirectoryEncoder::new(&mut self.writer)?;
|
||||
let mut image: ImageEncoder<W, C> = ImageEncoder::new(encoder, width, height).unwrap();
|
||||
|
||||
let mut idx = 0;
|
||||
while image.next_strip_sample_count() > 0 {
|
||||
let sample_count = image.next_strip_sample_count() as usize;
|
||||
image.write_strip(&data[idx..idx+sample_count]).unwrap();
|
||||
idx += sample_count;
|
||||
}
|
||||
image.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DirectoryEncoder<'a, W> {
|
||||
|
||||
@@ -22,15 +22,7 @@ fn encode_decode() {
|
||||
{
|
||||
let mut tiff = TiffEncoder::new(&mut file).unwrap();
|
||||
|
||||
let mut image = tiff.new_image::<RGB8>(100, 100).unwrap();
|
||||
|
||||
let mut idx = 0;
|
||||
while image.next_strip_sample_count() > 0 {
|
||||
let sample_count = image.next_strip_sample_count() as usize;
|
||||
image.write_strip(&image_data[idx..idx+sample_count]).unwrap();
|
||||
idx += sample_count;
|
||||
}
|
||||
image.finish().unwrap();
|
||||
tiff.write_image::<RGB8>(100, 100, &image_data).unwrap();
|
||||
}
|
||||
{
|
||||
file.seek(SeekFrom::Start(0)).unwrap();
|
||||
|
||||
Reference in new issue
Block a user