Giter VIP home page Giter VIP logo

Comments (13)

jcard0na avatar jcard0na commented on June 14, 2024 1

Tested it both on simulator and embedded target (STM32) and fix works on both. Thanks for the quick fix!
image

from tinybmp.

jamwaffles avatar jamwaffles commented on June 14, 2024 1

@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.

jamwaffles avatar jamwaffles commented on June 14, 2024

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.

jcard0na avatar jcard0na commented on June 14, 2024

Sure! For instance, you can try with these two images attached.
image
images.zip

from tinybmp.

jcard0na avatar jcard0na commented on June 14, 2024

For more details, here is how the above images appear on the simulator:
image

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.

jamwaffles avatar jamwaffles commented on June 14, 2024

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.

jamwaffles avatar jamwaffles commented on June 14, 2024

Great, thanks for confirming!

from tinybmp.

jamwaffles avatar jamwaffles commented on June 14, 2024

This is released in version 0.3.2.

from tinybmp.

Dominaezzz avatar Dominaezzz commented on June 14, 2024

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.

jamwaffles avatar jamwaffles commented on June 14, 2024

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.

rfuest avatar rfuest commented on June 14, 2024

The issue is caused by this line:

bpp.bits().pow(2).into()
It calculates BPP^2 instead of the correct 2^BPP.

from tinybmp.

Dominaezzz avatar Dominaezzz commented on June 14, 2024

Just ran my project with 0.3.3 and it works now!

Thanks for fixing this so promptly!

from tinybmp.

jamwaffles avatar jamwaffles commented on June 14, 2024

Great news! Thanks for bearing with us :)

from tinybmp.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.