piense
Posts: 6
Joined: Thu Jun 09, 2016 4:11 am

OpenVG & vgWritePixels

Wed Sep 13, 2017 11:15 pm

I'm trying to use OpenVG on a Pi3 to display some images. I get the image in a buffer in RAM and am using vgWritePixels to push that data to a window that's rendered to the screen. I'm using the hello_font example in raspberrypi/firmware as a starting point which defaults to using the VG_sARGB_8888 image format. That seems to work ok, but when I changed the image format to VG_sRGBA_8888 to better fit the format I have coming in, bad things happen. It's hard to describe but best as I can figure the image is a somewhat transparent version of the Red channel but certain rectangular areas of the image look normal. All I'm changing is the image format to the vgWritePixels call, and the corresponding mapping of the input channels in the source array. It's all very strange. Need be I can supply all the details and code but maybe those symptoms ring a bell for someone and can point me in the right direction to understanding what might be going on.

User avatar
Paeryn
Posts: 1674
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: OpenVG & vgWritePixels

Thu Sep 14, 2017 2:02 am

How are you mapping the channels? Assuming the data is an array of uint8_t then the first pixel is :-

for VG_sARGB, data[0] = blue, data[1] = green, data[2] = red, data[3] = alpha
for VG_sRGBA, data[0] = alpha, data[1] = blue, data[2] = green, data[3] = red

OpenVG defines the order as highest bits on the left when read as a word but the RPi is little-endian so the lowest byte is stored at the lowest address in memory (a 32-bit value of 0x01020304 is stored as 0x04, 0x03, 0x02, 0x01).
She who travels light — forgot something.

piense
Posts: 6
Joined: Thu Jun 09, 2016 4:11 am

Re: OpenVG & vgWritePixels

Fri Sep 15, 2017 5:14 am

I figured that much out, admittedly more by trial and error than an intelligent understanding of the problem. But the problem I'm seeing isn't a simple channel mapping problem. I rendered the primary colors to the screen and there's just blocks of picture missing in certain channels.

User avatar
Paeryn
Posts: 1674
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: OpenVG & vgWritePixels

Fri Sep 15, 2017 8:56 am

There shouldn't be bits missing in just some channels, the only thing which affects whether pixels are copied or not is scissoring. Any pixels that are updated get the values you pass in (unless you use the _pre formats which clamp a pixel's colour channels to its alpha value).

Can you give a short example of what you are doing?
She who travels light — forgot something.

blackshard83
Posts: 67
Joined: Fri Jan 10, 2014 8:31 am

Re: OpenVG & vgWritePixels

Tue Sep 26, 2017 11:38 am

It looks weird to me too, you should "just" see the colors altered if you fail to match the channels from the source image to the OpenVG format. Nonetheless it could be tricky because if you map a color channel to the alpha channel you may actually miss some parts of the image because the color channel may express very low values in a region of the image and, as long as it is mismatched as alpha channel, OpenVG renders an almost fully transparent pixel there.

Have you considered to use the ABGR/BGRA formats? You should be able to render the source data without swapping the channels as it should be free of costs.

PS: maybe a couple of screenshots may be useful ;)

User avatar
Gavinmc42
Posts: 1518
Joined: Wed Aug 28, 2013 3:31 am

Re: OpenVG & vgWritePixels

Wed Sep 27, 2017 1:44 am

You might want to check how Ultibo does it.
https://ultibo.org/forum/viewtopic.php?f=15&t=659
But it might not be of any use for you as it use the VC4 libraries.

Try Peter Lemon's VG stuff?
https://github.com/PeterLemon/Raspberry ... nate_Array
Or AJ's
https://github.com/ajstarks/openvg
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Graphics programming”

Who is online

Users browsing this forum: No registered users and 1 guest