Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization-Deserialization for DynamicImage using PNG and TIFF #2224

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- The color space information of pixels is not clearly communicated.

## Changes
- Added Float32 RGB and RGBA image encoding/decoding support for TIFF.
- Implemented serialization/deserialization for DynamicImage using PNG for uint images, and TIFF for float32 images. The TIFF images are further compressed using Zlib::Deflate to reduce size. The PNG or TIFF-encoded images are stored internally as base64 encoded strings.

### Version 0.25.1

Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.25.1"
edition = "2021"
resolver = "2"


# note: when changed, also update test runner in `.github/workflows/rust.yml`
rust-version = "1.67.1"

Expand Down Expand Up @@ -55,13 +56,17 @@ rgb = { version = "0.8.25", optional = true }
tiff = { version = "0.9.0", optional = true }
zune-core = { version = "0.4.11", default-features = false, optional = true }
zune-jpeg = { version = "0.4.11", optional = true }
base64 = "0.22"
serde = "1.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have serde be an optional feature. That would also let us make it depend on the png and tiff features

flate2 = "1.0.30"

[dev-dependencies]
crc32fast = "1.2.0"
num-complex = "0.4"
glob = "0.3"
quickcheck = "1"
criterion = "0.5.0"
serde_json = "1.0"

[features]
default = ["rayon", "default-formats"]
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,20 @@ fn main() {
image::save_buffer("image.png", buffer, 800, 600, image::ExtendedColorType::Rgb8).unwrap()
}
```

### Serialization and Deserialization
A `DynamicImage` object can be serialized and deserialized:

```rust,no_run
fn main() {
use image::DynamicImage;
let path = "/path/to/image";
let img = image::open(&path).expect("Could not find image in path.");
let img_string = serde_json::to_string(&img).expect("Could not serialize.");
// Send the image

// Receive an image
let recv_json: String = todo!();
let recv_img = serde_json::from_str::<DynamicImage>(&recv_json).expect("Could not deserialize");
}
```
Loading