cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to use the Shape widget to paint parts of images into a Dynamic Bitmap?

scottSD
Senior III

I would like to use the Shape widget to essentially paint a masked image into a Dynamic Bitmap instead of the frame buffer. It looks like the painters are written for the frame buffer as the target.

One reason I want to do this is to reduce the number of alpha blends by blending parts of a number of images into one Dynamic Bitmap which I can then store into one Image widget on the display as a background. This would significantly improve animation performance. I need to use a Dynamic Bitmap because the background needs to be able to be determined at run time.

I have been writing my own code to add images as well as parts of images into the Dynamic Bitmap, but am wondering if it is possible to use images masked by the Shape widget to accomplish this?

I know I can place Shapes and other widgets on the display, and copy the frame buffer to a Dynamic Bitmap. I am looking for a way to do this without needing to place them on the display first.

15 REPLIES 15
scottSD
Senior III

Can anyone answer this question?

JimFouch
Associate III

I'm pretty new to TouchGFX, but as a workaround, could you stop the DMA from sending new data to the display while you render your Dynamic Bitmap and then re-enable it? This way at least your user wouldn't see the rendering. Not sure if the display would go dark, or just remain on the last image sent before you paused DMA.

Martin KJELDSEN
Chief III

@JimFouch​ It doesn't work quite like that. DMA2D (ChromART) copies data from flash to framebuffer. If it's disabled, the CPU will just do it instead (software fallback).

@scottSD​ The Painters just take a pointer in their render function and they do blend with what's already there, so i think it should be possible. I'm a little tied up right now but i'd be happy to look into this further when i can.

From AbstractPainter.hpp:

virtual void render(uint8_t* ptr, int x, int xAdjust, int y, unsigned count, const uint8_t* covers);

/Martin

Martin,

Thanks for the reply. I would appreciate that. I will start to look at it as well.

@Martin KJELDSEN​ 

I am starting to look at this and am wondering about a few things. I know you're very busy, but if you could take the time to answer, that would be great.

I assume I need to emulate what the canvas class does with the RenderingBuffer and the Rasterizer, but instead of passing it an address to the framebuffer, I should pass it the address of my dynamic Bitmap.

Is this the correct approach or am I way off?

@Martin KJELDSEN​ 

I think I was making this more difficult than it needs to be.

I did do some testing based on your post about the painter's render function (not using RenderingBuffer and Rasterizer which I mentioned above). I was able to paint a shape into a dynamic bitmap and display it, but it is not quite right. It has a number of vertical lines through it so I probably have something wrong with the increment of the pointer or possibly the "covers" parameter.

Here is a snippet of the code I used:

uint8_t* dynDataP = (uint8_t*)dynBmp.getData();
for(int y = 0; y < bmp_h; y++)
{
	shape1Painter.render((uint8_t*)dynDataP, 0, 0, y, bmp_h, 0);
	dynDataP+= bmp_h*bbp/ 8;
}

I am not sure what the parameter "covers" does and how to set it. Is there more documentation about that parameter somewhere?

My being busy does not relieve me of my responsibility of helping - Doing the best i can with the time i have so if i'm not super responsive you know what's up 🙂

Can you show me a screenshot of this?

Also, i don't blame you for being confused about "covers". The API doc says this:

     * @param covers   The coverage in of each pixel.

That's jibberish. It realates to coverage of each pixel in a scanline in a Canvas renderer. We are in the process of doing a complete review of all the API doc to remove deprecated functions and fix things, like this, that are completely wrong or difficult to understand.

I'll have to get back to you with a more precise definition and how you can use it in a more direct way like you're doing. Usually the Canvas class handles calling render and retrieving "covers" from a scanline.

/Martin

/Martin

Martin,

Thanks for the reply. I appreciate it.

I'm looking forward to the updated documentation. I ran Doxygen on the project, which does help but is only as good as the comments in the code itself.

Below is a screenshot of it running on the Simulator. I made the shape visible for demonstration purposes. The shape uses the 240x240 image on the right. The Image widget using the Dynamic Bitmap is on the left.

0690X00000BwEHzQAN.png

 I see that the Drawable class has a function drawToDynamicBitmap(), but assume that doesn't blend, and simply copies it over in the Dynamic Bitmap's memory?

@Martin KJELDSEN​ 

Sorry about asking about this (I don't want to be a pest)...

Have you had a chance to investigate how I can use the painter's render function directly?