piderman314 / bardecoder

Detect and decode QR Codes, written in 100% Rust.
MIT License
272 stars 34 forks source link

Support for SubImages? #49

Closed KyleMaas closed 1 year ago

KyleMaas commented 1 year ago

The documentation says to keep the source image size small, but the source images I have are huge. So I tried slicing them up using DynamicImage::view(). However, this results in a type of SubImage<&DynamicImage>, which supports the GenericImage trait and thus I think it supports everything bardecoder needs. But I can't seem to find an efficient way to coerce this into something that bardecoder will work on. I've resorted to essentially this:

decoder.decode(&(DynamicImage::ImageRgba8(original_image.view(x, y, w, h).to_image())));

...which seems like a really silly thing to have to do. Is there a better way to do this?

piderman314 commented 1 year ago

I'll see if I can do something with GenericImage[View] but rust is being a bit difficult about passing traits in generic structs.

KyleMaas commented 1 year ago

That'd be awesome. I tried my hand at making my a builder but am still not familiar enough with Rust to be successful at it.

piderman314 commented 1 year ago

I have implemented a change for this that would allow you to call decoder.decode(&original_image.view(x, y, w, h).to_image()); . Could you please have a look to see if it works? :)

piderman314 commented 1 year ago

I think decoder.decode(&*original_image.view(x, y, w, h)); would also work though I personally prefer the first one.

piderman314 commented 1 year ago

Also to avoid version conflicts, it is now required to use image version 0.24 or newer.

KyleMaas commented 1 year ago

That does seem to function as expected. Thanks!