Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Quantum Painter Draw Image Example Code Is Wrong And Causes uint16_t Overflow #24896

Closed
EricBanker12 opened this issue Feb 3, 2025 · 1 comment · Fixed by #24897
Closed

Comments

@EricBanker12
Copy link
Contributor

EricBanker12 commented Feb 3, 2025

Issue Description

Quantum Painter Drawing API > Image Functions > Draw Image has the following example code:

// Draw an image on the bottom-right of the 240x320 display on initialisation
static painter_image_handle_t my_image;
void keyboard_post_init_kb(void) {
    my_image = qp_load_image_mem(gfx_my_image);
    if (my_image != NULL) {
        qp_drawimage(display, (239 - my_image->width), (319 - my_image->height), my_image);
    }
}

This example code will actually display an image 1 pixel up-left of the bottom-right corner of the 240x320 display. Additionally, it will cause uint16_t overflow for images the same size as the display. To correct this, it should be changed to the following:

// Draw an image on the bottom-right of the 240x320 display on initialisation
static painter_image_handle_t my_image;
void keyboard_post_init_kb(void) {
    my_image = qp_load_image_mem(gfx_my_image);
    if (my_image != NULL) {
        qp_drawimage(display, (240 - my_image->width), (320 - my_image->height), my_image);
    }
}

I have confirmed this uint16_t overflow behavior using a 96x24 test image with a SteelSeries Prime+ which has a 96x24 display.

qp_drawimage(display, 96 - my_image->width, 24 - my_image->height, my_image);

Test image displays correctly when following the corrected example code

qp_drawimage(display, 95 - my_image->width, 23 - my_image->height, my_image);

Test image displays incorrectly as garbled static when following original example code.

In addition to this issue on Quantum Painter Drawing API > Image Functions > Draw Image, similar issues exist for example code under:

  • Quantum Painter Drawing API > Image Functions > Animate Image
  • Quantum Painter Drawing API > Font Functions > Draw Text

Link to docs page: https://docs.qmk.fm/quantum_painter#quantum-painter-api

@EricBanker12
Copy link
Contributor Author

Changed uint16_t overflow example image host from Discord to Imgur due to Discord's external link expiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant