Skip to content

Issues with void ArduinoGraphics::image(const Image& img, int x, int y, int width, int height) #46

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

Closed
KurtE opened this issue Aug 13, 2024 · 2 comments · Fixed by #45
Closed
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@KurtE
Copy link
Contributor

KurtE commented Aug 13, 2024

void ArduinoGraphics::image(const Image& img, int x, int y, int width, int height)
{
  if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > height)) {
    // offscreen
    return;
  }
...

The first issue I ran into is there is an error/typo in the check for proper ranges...
The line should be:

  if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > _height)) {

That is, you should be testing against the height of the display, not the height of the image passed in.

Another issue I have run into, is in the RGB format the order of the bytes:
That is in my own code potentially calling it:

void writeClippedRect24(int16_t x, int16_t y, int16_t cx, int16_t cy, uint32_t *pixels) {
    y += g_image_offset_y;
    x += g_image_offset_x;
#if 1
    Image img(ENCODING_RGB, (uint8_t *)pixels, cx, cy);
    Display.image(img, x, y, cx, cy);
#else
    //Display.image(img, x, y);
    for (int16_t iy = y; iy < (y + cy); iy++) {
        for (int16_t ix = x; ix < (x + cx); ix++) {
            uint32_t color = *pixels++;
            Display.set(ix, iy, color >> 16, color >> 8, color);
        }
    }
#endif    
}

Where the RGB bytes are within the uint32_t is different. Mine is setup to handle the order of bytes
returned by JPEGDEC RGB8888 format where Alpha is the high byte and the code in

void ArduinoGraphics::imageRGB(const Image& img, int x, int y, int width, int height)
{
  const uint8_t* data = img.data();

  for (int j = 0; j < height; j++) {
    for (int i = 0; i < width; i++) {
      uint8_t r = *data++;
      uint8_t g = *data++;
      uint8_t b = *data++;

      set(x + i, y + j, r, g, b);

      data++;
    }

    data += (4 * (img.width() - width));
  }
}

Assumes that it is the 4th byte that is skipped. Not sure of best fix for this. For me just changing back to my own code
works. Alternative is to either change the library by changing the skipped byte or by adding different image type

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Aug 13, 2024
@leonardocavagnis
Copy link
Contributor

The line should be:

  if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > _height)) {

That is, you should be testing against the height of the display, not the height of the image passed in.

Good catch! Open a PR on it.

@leonardocavagnis
Copy link
Contributor

Fixed by #45

@leonardocavagnis leonardocavagnis linked a pull request Nov 4, 2024 that will close this issue
@per1234 per1234 added the conclusion: resolved Issue was resolved label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants