Comments (4)
0.25.0 is now released!
from image.
This is actually being addressed in the 0.25 release! The ImageDecoder
trait is being changed to be object safe, at which point we can add a io::Reader::into_decoder
method:
let decoder = Reader::open("path/to/image.png")?.into_decoder()?;
let size = decoder.total_bytes();
decoder.read_image(&mut buf[..size])?
I'll tack on to the end here that we currently use a Cursor over a &[u8] to construct an io::Reader, which feels a little odd. Is there a nicer way to get with_guessed_format without having to go via an I/O trait when you have the image in a buffer already, or is this the intended way?
If you only need to know the format, you can call guess_format
which directly takes a slice of bytes. But if you're going to be decoding the image anyway, you already need to have a Cursor<&[u8]>
so might as well use it for guessing the format. And with_guessed_format
is pretty simple: it reads the first 16-bytes, looks them up in a table of magic bytes for different formats, and then seeks back to the start.
from image.
There's currently a 0.25.0-preview.0 release out. Assuming no glaring issues are found with it, a full 0.25.0 should be at most a few weeks away.
As far as taking advantage of the whole image being in memory, that's actually something that's been discussed in the context of the png
crate (which is one of the few decoders fast enough for it to possibly matter). The strategy we're investigating there is using the methods provided by the BufRead
trait. In particular, the implementation of Cursor::fill_buf
returns the the entire remainder of the slice. If you are curious there's currently a draft PR and more discussion here.
from image.
Amazing! Do you have a rough ETA for 0.25 (like, is it a few weeks away, a few months, or a few years)?
For the PS, I was more wondering whether there was a way to decode something that is in a &[u8]
without a Cursor
in the first place (I could imagine some impls could be faster when the whole image is in memory maybe?). But if that's not the case, that's fine — just wanted to check if there was a part of the API I had missed!
from image.
Related Issues (20)
- SVG image "format could not be determined" HOT 4
- JPG image first two bytes are not an SOI marker HOT 1
- Panic when checking broken tiff file HOT 1
- Freeze when trying to open and save jpg and webp files HOT 3
- Random crashes when decoding exr file HOT 2
- `image` still depends on `jpeg-decoder` through the `tiff` crate
- `rayon` is included in the dependency tree even when the `rayon` feature is disabled when `ravif` feature is enabled HOT 1
- The documentation on `crop()` is confusing HOT 1
- Add in-place versions of all rotation operations HOT 1
- `DynamicImage::crop()` is slow because `to_image()` is slow HOT 1
- Cropping API doesn't check bounds, easy to misuse HOT 7
- EnumeratePixels and EnumerateRows should implement DoubleEndedIterator HOT 3
- Implement a `rows()` iterator on `SubImage` HOT 6
- how to convert a rgbaImage to opencv's Mat?
- Regression: Hot lib reload, unable to find __rust_alloc. HOT 6
- Increased generation loss in JPEG encoder HOT 1
- Broken link in docs HOT 2
- Should the next major release be 1.0? HOT 2
- Detect alpha on jpeg HOT 2
- Alternate versions of the crates which allow regular breaking changes HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image.