Skip to content

feat(rust)!: add watermark removal - #51

Merged
jcollomosse merged 4 commits into
adobe:mainfrom
cdmurph32:rust-removal
Nov 10, 2026
Merged

jcollomosse merged 4 commits into
adobe:mainfrom
cdmurph32:rust-removal

Conversation

@cdmurph32

Copy link
Copy Markdown
Collaborator

Summary

  • Add an explicitly loaded Rust WatermarkRemover and CLI remove command, preserving image dimensions and alpha.
  • Download published P/Q models with cargo xtask fetch-removers, with size checks to reject truncated downloads.
  • Keep model export and reference-parity tooling under python/; add removal tests, a benchmark, and CI coverage.
  • Bump the Rust crate to 0.5.0 because the new public Error variants require exhaustive matches to be updated.

Validation

  • Rust workspace tests and real-model removal/re-watermarking tests.
  • Strict clippy and formatting checks.
  • Package verification.
  • Python/Rust parity suite covering 80 cases across all four variants.
  • Complete CDN downloads verified against the tested model hashes.

(Sent by AI, with oversight)

Add an explicitly loaded remover, published model downloads, and reference parity tests.

BREAKING CHANGE: the new Error variants require exhaustive matches to be updated. Bump the Rust crate to 0.5.0.
Write removed images atomically, document output conversion, and retain download errors when cleanup fails. Cover JPEG quality and HTTP failures, and run validation when Python tooling changes.
Keep CI focused on Rust behavior using the published P/Q models. Leave model export and Python-reference parity checks as optional manual tooling.
Use the published remover ONNX models and remove obsolete export instructions. Keep reference-parity checks available as optional manual tooling.
@tmathern
tmathern requested a review from jcollomosse November 10, 2026 02:54
.unwrap_or_else(|| std::path::Path::new("."));
// Encode beside the destination, then atomically replace it. A failure
// leaves the old output intact and removes the temporary file on drop.
let mut file = tempfile::NamedTempFile::new_in(parent)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NamedTempFile can be touchy on permissions. Is there a need to keep/restore/change them, or are NamedTempFile's default correct here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll fix this in a follow up PR.

quality.unwrap_or(90),
))?;
} else {
image::DynamicImage::ImageRgba8(recovered.to_rgba8())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a need to check if the image has an alpha for the conversion? to_rgb for no alpha, to_rgba8 if there is one?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll fix this in a follow up PR.

fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
if let Command::Remove {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When removing, it just removes the watermark, all metadata is kept (EXIF etc.)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, metadata is not retained. This is true of the apply command as well.

) -> DynamicImage {
let (w, h, left, top) = center_crop_size_and_offset(variant, &input);
let has_alpha = input.color().has_alpha();
let mut output = input.to_rgba32f();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can reduce the amount of copies kept? Is the original as-is needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll fix that in a follow up PR

Comment thread rust/README.md
The CLI writes PNG or JPEG (`--quality 90` by default for JPEG); the library
accepts decoded `DynamicImage` values. Missing or incompatible remover models
return errors. A shared remover serializes inference independently of encoders
and decoders. Existing callers incur no removal-model startup or memory cost.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't there a memory cost if a session starts, and removes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. That comment needs to be updated.

Comment thread rust/src/remover.rs Resolved
@jcollomosse
jcollomosse merged commit 831ecd6 into adobe:main Nov 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants