Transparent mode

Hello everybody,

I am working with Mega2560 and a touch screen display 320 x 240.

Is there a way to draw bitmap in transparent mode ?

If yes, how to do ? Is there a special color for the background of the picture or else to do ?

Thank you for your help.

Pierre

I have the need to do that too, but it’s low priority in my project.

One solution, only works for full or no transparency:

Modify the bitmap library so that for each pixel to be drawn, check if the color == transparency key (“they” often use purple as transparency key), if it is equal, simply do not draw the pixel. Then in the bitmap file/array, use the purple (or whatever you choose) where you want full transparency.

If you want alpha blending that is another story…Not impossible, but requires heavy modifications, including hardware modification to connect the RD pin of your display to an Arduino digital pin so you can read the color of a pixel actually displayed.

guix:
... Modify the bitmap library so that for each pixel to be drawn, check if the color == transparency key ("they" often use purple as transparency key), if it is equal, simply do not draw the pixel. ...

I have tried something, but it does'nt work

if I replace the following lines 1179 and 1180 of UTF.cpp :

col=pgm_read_word(&data[tc]);
LCD_Write_DATA(col>>8,col & 0xff);

by :

col=pgm_read_word(&data[tc]);
ii (col != transparency_color)
  LCD_Write_DATA(col>>8,col & 0xff);

the display is modified but not accordingly to what I was expected.

I think that one can't display nothing because the LCD_Write_DATA makes a register to advance each time it is called. But if we have to call LCD_Write_DATA, where to get the in place color ?

A step beyond, in the line 269 of UTFT.cpp, :

LCD_Writ_Bus(VH,VL,display_transfer_mode);

if I replace VH or VL by an other value (a static one or just the fact to swap VH an VL), I think the program crashes because nothing is displayed ???

Thank you for your help.

Pierre

I think you have to do it like that:

If color == transparent, go to the next pixel (with setXY) and increment the current position in the bitmap array (so 'col' is set to be the next pixel's color).

guix:
I think you have to do it like that:

If color == transparent, go to the next pixel (with setXY) and increment the current position in the bitmap array (so ‘col’ is set to be the next pixel’s color).

I am sorry, but I don’t see how to do since setXY only defines the size of the bitmap in the following part of the drawBitmap method :

		if (orient==PORTRAIT)
		{
			cbi(P_CS, B_CS);
			setXY(x, y, x+sx-1, y+sy-1);
			for (tc=0; tc<(sx*sy); tc++)
			{
				col=pgm_read_word(&data[tc]);
				LCD_Write_DATA(col>>8,col & 0xff);
			}
			sbi(P_CS, B_CS);
		}

Sincerely.

Pierre.

I believe you would have to make mods to the UTFT libraries further for bitmap transparency. UTFT's command setBackColor(VGA_TRANSPARENT) is valid but only for text background. The coding within the class or whatever for the transparency setting involved with the setBackColor command might be a good place to start. It's over my head at this point. But would be a really cool feature to have for something like icons over a background bitmap.

Finally, I have created a new method that manage the transparent mode :

#define BMP_TRANSPARENT  0x8010 //purple

void UTFT_M::drawTransparentBitmap(int x, int y, int sx, int sy, bitmapdatatype data) {
  unsigned int col;
  int tx, ty, tc;
  if (orient == PORTRAIT) {
    for (tc = 0; tc < (sx*sy); tc++) {
      col = pgm_read_word(&data[tc]);
      if (col != BMP_TRANSPARENT) {
        cbi(P_CS, B_CS);
        setXY(x+tc%sx, y+tc/sx, x+tc%sx, y+tc/sx);
        LCD_Write_DATA(col >> 8, col & 0xff);
        sbi(P_CS, B_CS);
      }
    }
  }
  else
  {
    for (ty = 0; ty < sy; ty++)
      for (tx = sx-1; tx >= 0; tx--) {
        col = pgm_read_word(&data[(ty*sx)+tx]);
        if (col != BMP_TRANSPARENT) {
          cbi(P_CS, B_CS);
          setXY(x+tx, y+ty, x+tx, y+ty);
          LCD_Write_DATA(col >> 8, col & 0xff);
          sbi(P_CS, B_CS);
        }
      }
  }	 
  clrXY();
}

I have integrated it in a child class of UTFT. I don’t have checked the part where orient = LANDSCAPE

Nevertheless, this metod is equivalent to draw pixel by pixel ; not drawing it if it is the BMP_TRANSPARENT color.

Sincerely.

Pierre

ChPr, is your display's controller SSD1289 ?

If yes then I have found a much better way to do it, using the Compare registers. All is required is that you change the initlcd.h file, like so:

Replace:

LCD_Write_COM_DATA(0x11,0x6070);
LCD_Write_COM_DATA(0x05,0x0000);
LCD_Write_COM_DATA(0x06,0x0000);

By:

LCD_Write_COM_DATA(0x11,0b0110000001110111); // 3 first bits = toggle RGB compare registers
LCD_Write_COM_DATA(0x05,0b1111110000000000); // Compare register 1: RRRRRR00GGGGGG00
LCD_Write_COM_DATA(0x06,0b0000000011111100); // Compare register 2: 00000000BBBBBB00

And then in your bitmap files/arrays, use the transparency key 0xF81F instead of your 0x8010 (the purple I was talking about is, in 32bits color mode, R=255, G=0, B=255, and that is 0xF81F in RGB565 format)

Then you can use the classic drawBitmap functions :wink:

You could also make functions toggleTransparency and setTransparencyKey or whatever...

PS: I completely forgot this post...UTFT Lib and transparent bitmap - #5 by xlilcasper - Programming Questions - Arduino Forum and that was only 3 months ago lol