linebender / linebender/tiny-skia

into_png: Consume a Pixmap to write it to PNG without copying

Open
#79 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.6k
Forks
99
Avg merge
2h 52m
Merged PRs (30d)
1

Description

The TODO note in encode_png to eliminate the clone of the Pixmap can be addressed by adding a variant function that consumes `self`. Here's an example I've implemented from the outside:
```rust
pub fn into_png(mut image: MaybeFromPool) -> Result, png::EncodingError> {
for pixel in image.pixels_mut() {
unsafe {
// Treat this PremultipliedColorU8 slice as a ColorU8 slice
*pixel = mem::transmute(pixel.demultiply());
}
}

let mut data = Vec::with_capacity(1024 * 1024);
{
let mut encoder = png::Encoder::new(&mut data, image.width(), image.height());
encoder.set_color(png::ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header()?;
writer.write_image_data(image.data())?;
}

Ok(data)
}
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate encode_png and its TODO, then read the surrounding MaybeFromPool and Pixmap ownership APIs. Use the issue's example as the behavior reference and verify that the consuming PNG path produces the same output without cloning the Pixmap.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, performance
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.