MCUFRIEND_kbv.h how does the tft.pushcolors work

I'm using the "pushColors" function to draw a bitmap, which works fine! (see code below)

the only problem is that it displays a square image (includes the background) and I just want to display
the object/person.

As far as I'm aware, the Hex code (bmp converted to c.) which relates to the colours, are plotted one by one, the picture size tells the function when to start a new line as the bmp code is all on one continuous line.

what I want to do is use white colour (0xFFFF), in an if statement to say "if code != 0xFFFF draw pixel.
(but using the fast pushColor function)

so that when the hex code is drawn, it skips the white pixels and doesn't draw them on the screen, so that it only draws the image.

that way if the background is showing something like the sky and I display a picture of a plane onto the background, the sky will be shown around the plane.

can anyone help?

x = 296;
    y = 0; 
    
    tft.setAddrWindow(x, y, x + 24 - 1 , y + 480 -1);
    tft.pushColors((const uint8_t*)Wall3, 24 * 480, 1, false);

no replies so far :frowning:

so I have been doing some searching, the bmp file get put into the flash memory via the PROGMEM function

"const unsigned short pacman[0x2774] PROGMEM ={0x000, 0x000 etc…}

I have looked up PROGMEM and found that to retrieve it from the flash you use:

pgm_read_byte_near(pacman + k);

so I have put this into my code:

int newline = 0;
  for (int i = 0; i <= 10100; i++){
    if (newline > 99){
    y ++;
    newline = 0;  
    }
  uint16_t colour = pgm_read_byte_near(pacman + i);

 tft.drawPixel ( x + newline, y, colour);

 newline ++;

}

it reads from the flash memory, then saves it as “colour”
this is then used for the colour of the pixel.

note: i = the array size

newline = the width of the picture - 1

it builds the image pixel by pixel.

this works ok but I have a colour issue, the colours are not correct and when I view the code in the serial monitor, the code is only 8 bit, why is this? I’m getting closer but might go blind looking at the screen for so long, if anyone want to give me some help it would be appreciated :slight_smile:

there is this code in the example:

void showbgd(int x, int y, const uint8_t *bmp, int w, int h, uint16_t color, uint16_t bg, uint8_t pad = 7)
{
    int yy, xx;
    uint8_t first = 1, RVS = pad & 0x80;
    uint16_t pixel;
    pad &= 31;
    uint16_t wid = (w + pad) & ~pad;                    //bits per row
    tft.setAddrWindow(x, y, x + w - 1, y + h - 1); //
    for (yy = 0; yy < h; yy++) {
        uint32_t ofs = (RVS ? (h - yy - 1) : yy) * wid; //bit offset
        const uint8_t *p = bmp + (ofs >> 3);            //flash address
        uint8_t mask = 0x80 >> (ofs & 7);               //bit mask


        
        uint8_t c = pgm_read_byte(p++);
        
        
        
        for (xx = 0; xx < w; xx++) {
            if (mask == 0) {
                c = pgm_read_byte(p++);
                mask = 0x80;
            }
            pixel = (c & mask) ? color : bg;
            tft.pushColors(&pixel, 1, first);
            first = 0;
            mask >>= 1;
        }
    }
    tft.setAddrWindow(0, 0, tft.width() - 1, tft.height() - 1);
}

but I don’t understand it.

I figured it out

used "byte" instead of "Word"

uint16_t colour = pgm_read_byte_near(pacman + i);

silly me.