Comments (13)
Tested it both on simulator and embedded target (STM32) and fix works on both. Thanks for the quick fix!
from tinybmp.
@Dominaezzz This should hopefully be fixed in the just-released 0.3.3. Can you do a cargo update
and check your image again please?
from tinybmp.
Thanks for the detailed issue report! I can make my own image, but for completeness sake would you be able to post the image file you're having issues with so it's easier to reproduce the error?
from tinybmp.
Sure! For instance, you can try with these two images attached.
images.zip
from tinybmp.
For more details, here is how the above images appear on the simulator:
And this is the modified example that produces that image:
//! # Example: BMP images
//!
//! Draw a 16BPP BMP image of the Rust logo to a display
//!
//! This example uses the [tinybmp](https://crates.io/crates/tinybmp) crate to load the BMP from a
//! byte slice read in at compile time.
//!
//! The `graphics` feature of `tinybmp` needs to be enabled in `Cargo.toml` to use the `Bmp` object
//! with embedded-graphics.
use embedded_graphics::{image::Image, pixelcolor::BinaryColor, prelude::*};
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
use tinybmp::Bmp;
fn main() -> Result<(), core::convert::Infallible> {
let mut display: SimulatorDisplay<BinaryColor> = SimulatorDisplay::new(Size::new(400, 200));
// Load the BMP image.
// The color type must be specified explicitly to match the color format used by the image,
// otherwise the compiler may infer an incorrect type.
let bmp: Bmp<BinaryColor> = Bmp::from_slice(include_bytes!("./assets/light.bmp")).unwrap();
// To draw the `bmp` object to the display it needs to be wrapped in an `Image` object to set
// the position at which it should drawn. Here, the top left corner of the image is set to
// `(32, 32)`.
let image = Image::new(&bmp, Point::new(0, 0));
// Display the image
image.draw(&mut display)?;
let bmp: Bmp<BinaryColor> = Bmp::from_slice(include_bytes!("./assets/nolight.bmp")).unwrap();
// To draw the `bmp` object to the display it needs to be wrapped in an `Image` object to set
// the position at which it should drawn. Here, the top left corner of the image is set to
// `(32, 32)`.
let image = Image::new(&bmp, Point::new(200, 0));
// Display the image
image.draw(&mut display)?;
let output_settings = OutputSettingsBuilder::new().scale(2).build();
Window::new("BMP image", &output_settings).show_static(&display);
Ok(())
}
from tinybmp.
Thanks again for taking the time to provide files, details and test cases. This made reproducing and fixing this issue so much easier.
I have a fix available in #19. If you're interested in testing that PR out in your own code and reporting back, that would be a great confirmation.
from tinybmp.
Great, thanks for confirming!
from tinybmp.
This is released in version 0.3.2.
from tinybmp.
With the new version, this 1bpp image now comes out as completely black. Was scratching my head for a while.
I'm using this.
let image = Bmp::<BinaryColor>::from_slice(&frame[0..]).expect("Should load fine");
for Pixel(coord, color) in image.pixels() {
let pixel = if color.is_on() { 1 } else { 0 };
// Upload pixel to E-Ink display.
// pixel is now always 1.
}
from tinybmp.
Thanks for posting a sample image to check with. I did some debugging and the colour table in your image only has one entry:
[src/raw_bmp.rs:108] color_table = ColorTable {
data: [
0,
0,
0,
0,
],
}
This means that when color
is 1
, there is no entry for the pixel colour in the table, so tinybmp
defaults to 0
(off). @rfuest is this an issue with the BMP or tinybmp
?
from tinybmp.
The issue is caused by this line:
tinybmp/src/header/dib_header.rs
Line 91 in 2e9de3e
BPP^2
instead of the correct 2^BPP
.from tinybmp.
Just ran my project with 0.3.3
and it works now!
Thanks for fixing this so promptly!
from tinybmp.
Great news! Thanks for bearing with us :)
from tinybmp.
Related Issues (17)
- Unable to get the compression info HOT 5
- tinybmp does not support negative height HOT 3
- Support RLE (Run Length Encoding) HOT 3
- Improve crate error handling
- Upgrade to nom 7.x
- Add MSRV HOT 1
- Update master changelog from 0.3 branch HOT 1
- RFC: Loading images from SPI flash HOT 5
- Crash / Out of Bounds read in RawBmp HOT 11
- Accessing individual pixels without copying the buffer HOT 2
- Implement the ImagePixelGetter trait HOT 4
- Add a lib.rs/readme example showing individual pixel retrieval
- `uefi-rs` integration? HOT 1
- CI is broken HOT 1
- New release? HOT 2
- Branch rename HOT 1
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 tinybmp.