Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
run: cargo test

wasm:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
run: cargo test --target wasm32-wasip1

aarch64:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Cargo.lock
.DS_Store
/image.png
/.vscode
/.idea
16 changes: 9 additions & 7 deletions src/pixmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ impl Pixmap {
let size = IntSize::from_wh(width, height)?;
let data_len = data_len_for_size(size)?;

// We cannot check that allocation was successful yet.
// We have to wait for https://github.com/rust-lang/rust/issues/48043
let mut data = Vec::new();
data.try_reserve_exact(data_len).ok()?;
data.resize(data_len, 0);

Some(Pixmap {
data: vec![0; data_len],
size,
})
Some(Pixmap { data, size })
}

/// Creates a new pixmap by taking ownership over an image buffer
Expand Down Expand Up @@ -81,7 +79,11 @@ impl Pixmap {
let mut decoder = png::Decoder::new(data);
decoder.set_transformations(png::Transformations::normalize_to_color8());
let mut reader = decoder.read_info()?;
let mut img_data = vec![0; reader.output_buffer_size()];
let mut img_data = Vec::new();
img_data
.try_reserve_exact(reader.output_buffer_size())
.map_err(|_| make_custom_png_error("failed to reserve output buffer"))?;
img_data.resize(reader.output_buffer_size(), 0);
let info = reader.next_frame(&mut img_data)?;

if info.bit_depth != png::BitDepth::Eight {
Expand Down
Loading