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

Open
EricBanker12 opened this issue Feb 3, 2025 · 0 comments · May be fixed by #24897
Open

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

EricBanker12 opened this issue Feb 3, 2025 · 0 comments · May be fixed by #24897

Comments

@EricBanker12
Copy link

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 added a commit to EricBanker12/qmk_firmware that referenced this issue Feb 3, 2025
@EricBanker12 EricBanker12 linked a pull request Feb 3, 2025 that will close this issue
14 tasks
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