summaryrefslogtreecommitdiff
path: root/src/lossless
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <[email protected]>2024-10-11 19:01:52 -0400
committerLibravatar Silas Bartha <[email protected]>2024-10-11 19:01:52 -0400
commit6c94102afc70ce28eee3d17aad997a056aaf9195 (patch)
tree11232fc59c356ce4f3b52cb140d779a3f1dc2006 /src/lossless
parent5b5f1bed5e8da9d799e5910793477ba0360d5135 (diff)
gltf, wav, and binary codecsv0.3.0
Diffstat (limited to 'src/lossless')
-rw-r--r--src/lossless/lsb.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lossless/lsb.rs b/src/lossless/lsb.rs
index 2ce1456..1c9a213 100644
--- a/src/lossless/lsb.rs
+++ b/src/lossless/lsb.rs
@@ -2,7 +2,7 @@ use std::{cmp::Ordering, io::{BufWriter, Cursor}};
use image::{DynamicImage, GenericImageView, Pixel};
-use crate::{codec::Codec, CodecError};
+use crate::{codec::Codec, Error};
/// Least-significant bit (LSB) steganography encodes data in the least-significant bits of colors
/// in an image. This implementation reduces the colors in the carrier (irreversibly) in order to
@@ -12,14 +12,14 @@ use crate::{codec::Codec, CodecError};
pub struct LsbCodec;
impl Codec for LsbCodec {
- fn encode(&self, carrier: &[u8], payload: &[u8]) -> Result<Vec<u8>, CodecError>
+ fn encode(&self, carrier: &[u8], payload: &[u8]) -> Result<Vec<u8>, Error>
{
let image_format = image::guess_format(carrier).unwrap();
let mut image: DynamicImage = image::load_from_memory(carrier).unwrap();
let payload: &[u8] = payload;
if image.pixels().count() < payload.len() {
- return Err(CodecError::DataInvalid("Payload Too Big for Carrier".into()));
+ return Err(Error::DataInvalid("Payload Too Big for Carrier".into()));
}
let mut payload_iter = payload.iter();
@@ -43,17 +43,17 @@ impl Codec for LsbCodec {
}
}
},
- _ => return Err(CodecError::DataInvalid("Unsupported Image Color Format".into()))
+ _ => return Err(Error::DataInvalid("Unsupported Image Color Format".into()))
}
let mut buf = BufWriter::new(Cursor::new(Vec::<u8>::new()));
if let Err(e) = image.write_to(&mut buf, image_format) {
- return Err(CodecError::DependencyError(e.to_string()))
+ return Err(Error::DependencyError(e.to_string()))
}
Ok(buf.into_inner().unwrap().into_inner())
}
- fn decode(&self, carrier: &[u8]) -> Result<(Vec<u8>, Vec<u8>), CodecError>
+ fn decode(&self, carrier: &[u8]) -> Result<(Vec<u8>, Vec<u8>), Error>
{
let image_format = image::guess_format(carrier).unwrap();
let mut image: DynamicImage = image::load_from_memory(carrier).unwrap();
@@ -78,12 +78,12 @@ impl Codec for LsbCodec {
}
}
},
- _ => return Err(CodecError::DataInvalid("Unsupported Image Color Format".into()))
+ _ => return Err(Error::DataInvalid("Unsupported Image Color Format".into()))
}
let mut buf = BufWriter::new(Cursor::new(Vec::<u8>::new()));
if let Err(e) = image.write_to(&mut buf, image_format) {
- return Err(CodecError::DependencyError(e.to_string()))
+ return Err(Error::DependencyError(e.to_string()))
}
Ok((buf.into_inner().unwrap().into_inner(), payload))
}