Skip to content

Commit

Permalink
Merge pull request #1857 from bash/remove-scoped_threadpool
Browse files Browse the repository at this point in the history
Remove multithreading in HDR decoding
  • Loading branch information
HeroicKatora authored Feb 21, 2023
2 parents 2ca903c + 7df5cb1 commit 55732d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ num-traits = "0.2.0"
gif = { version = "0.12", optional = true }
jpeg = { package = "jpeg-decoder", version = "0.3.0", default-features = false, optional = true }
png = { version = "0.17.6", optional = true }
scoped_threadpool = { version = "0.1", optional = true }
tiff = { version = "0.8.0", optional = true }
ravif = { version = "0.11.0", optional = true }
rgb = { version = "0.8.25", optional = true }
Expand Down Expand Up @@ -67,7 +66,7 @@ ico = ["bmp", "png"]
pnm = []
tga = []
bmp = []
hdr = ["scoped_threadpool"]
hdr = []
dxt = []
dds = ["dxt"]
farbfeld = []
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml.public-private-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ num-traits = { version = "0.2.0", public = true }
gif = { version = "0.11.1", optional = true }
jpeg = { package = "jpeg-decoder", version = "0.2.1", default-features = false, optional = true }
png = { version = "0.17.0", optional = true }
scoped_threadpool = { version = "0.1", optional = true }
tiff = { version = "0.7.1", optional = true }
ravif = { version = "0.8.0", optional = true }
rgb = { version = "0.8.25", optional = true }
Expand All @@ -63,7 +62,7 @@ pnm = []
tga = []
webp = []
bmp = []
hdr = ["scoped_threadpool"]
hdr = []
dxt = []
dds = ["dxt"]
farbfeld = []
Expand Down
24 changes: 9 additions & 15 deletions src/codecs/hdr/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::Primitive;
use num_traits::identities::Zero;
use scoped_threadpool::Pool;
#[cfg(test)]
use std::borrow::Cow;
use std::convert::TryFrom;
Expand Down Expand Up @@ -460,21 +459,16 @@ impl<R: BufRead> HdrDecoder<R> {
}

let chunks_iter = output_slice.chunks_mut(self.width as usize);
let mut pool = Pool::new(8); //

(pool.scoped(|scope| {
for chunk in chunks_iter {
let mut buf = vec![Default::default(); self.width as usize];
read_scanline(&mut self.r, &mut buf[..])?;
let f = &f;
scope.execute(move || {
for (dst, &pix) in chunk.iter_mut().zip(buf.iter()) {
*dst = f(pix);
}
});

let mut buf = vec![Default::default(); self.width as usize];
for chunk in chunks_iter {
// read_scanline overwrites the entire buffer or returns an Err,
// so not resetting the buffer here is ok.
read_scanline(&mut self.r, &mut buf[..])?;
for (dst, &pix) in chunk.iter_mut().zip(buf.iter()) {
*dst = f(pix);
}
Ok(())
}) as Result<(), ImageError>)?;
}
Ok(())
}

Expand Down

0 comments on commit 55732d1

Please sign in to comment.