New vga.getPixel function.

All about the VGA for the ESP32-S3
Post Reply
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

New vga.getPixel function.

Post by Fernando Perez »

Although logic advises me to wait for you to publish instructions for its correct use, impatience leads me to try the new instruction now.
I want to use it in programs that use the 256 colors of VGA Annex, but for testing I have limited myself to the 24 named colors.
I have programmed and executed this:

Code: [Local Link Removed for Guests]

' Annex32-S3 CAN DMT VGA 1.51.2 qio opi LFS 
vga.delete
vga.init 2
vga.fill white
vga.show

i = 1 : fill = 0

for y = 140 to 300 step 80
  for x = 8 to 565 step 78
    READ c$
    command "fill = vga.color(" + c$ + ")"
    vga.rect x, y, 76, 76, black
    vga.rect x+1, y+1, 74, 74, fill, 1
    px = vga.getPixel(x+10, y+10)
    wlog c$, fill, px, fill-px
    incr i
  next x
next y  

vga.show

END

DATA "black","navy","blue","darkgreen","darkcyan","green","cyan","maroon"
DATA "purple","olive","darkgrey","skyblue","violet","brown","greenyellow","silver"
DATA "lightgrey","red","magenta","orange","pink","gold","yellow","white"
With these results:
image.png
I don't see a clear relationship between them. And, furthermore, in the colors Silver and lightGrey it returns the same result.

How is it used?
image.png
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2056
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: New vga.getPixel function.

Post by cicciocb »

The logic is quite simple, there are only 8 bits for the colors.

The 16 bits 565RGB is converted to 8 bits 332RBG; this means that 8 bits are lost in the conversion :roll:

So, converting back from 8 bits to 16 bits, only 8 bits will be significative and the others will always be at 0.

The exact notation is

16 bits : RRRRRGGGGGGBBBBB
8 bits : RRRGGGBB
image.png
The conversion is done as shown in the image below :
image.png
As you can see, only 8 bits are transferred and the other 8 bits are "lost" in the conversion.

Converting back to 16 bits, the 8 "missing bits" are simply replaced by 0 :
image.png

From a practical point of view, the significative bits represents this number
image.png
So, the color read back, will be the = (original_color) AND &hE718

If you look at your table, you'll see that the column PX corresponds to column Fill and &hE718.


Example
violet -> 37212 -> 37212 and &hE718 = 33048

It is normal that different 16bits colors can have the same result but is simply because, at the end, they are converted to the same 8 bit color
You do not have the required permissions to view the files attached to this post.
User avatar
Fernando Perez
Posts: 378
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 195 times
Been thanked: 267 times

Re: New vga.getPixel function.

Post by Fernando Perez »

I finally understood it.
I couldn't find a clear explanation on the Internet.
Thank you, Francesco.
User avatar
Electroguard
Posts: 860
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 275 times
Been thanked: 323 times

Re: New vga.getPixel function.

Post by Electroguard »

The logic is quite simple...
Masterful - how to start an inferiority complex then stop it with a big and colourful explanation !
Post Reply