Skip to content

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

Closed
@KurtE

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions