kornelski / imgref

A trivial Rust struct for interchange of pixel buffers with width, height & stride
https://lib.rs/crates/imgref
Apache License 2.0
59 stars 6 forks source link

Why must width and height be non-zero? #10

Closed yoanlcq closed 5 years ago

yoanlcq commented 5 years ago

Currently, width and height are not allowed to be zero. In a way, this makes sense, but IMHO it is surprising and impractical.

This kind of decision is inherently opinionated and I don't wish to enforce my point of view. It might also be interesting to see what's the stance of similar crates on the matter. :)

kornelski commented 5 years ago

The 0px space is an interesting use case.

When width and height is 0, the formula for minimum required buffer size fails:

let buf = &mut self.buf[start .. start + self.stride * height + width - self.stride];
kornelski commented 5 years ago

OK, removing the restriction on width/height wasn't too hard. I've left requirement for stride to be non-0, because buf.chunks(0) makes no sense.

yoanlcq commented 5 years ago

Thanks, and good point ! At first sight I would have thought it would be OK for stride to be zero, but indeed it's not. Infinite loops are no fun :)