|
实际测试这个函数调用到的地方不少,只是不是特别频繁:
===================================================- static LCD_COLOR _DMA_MixColors(LCD_COLOR Color, LCD_COLOR BkColor, U8 Intens) {
- U32 ColorFG, ColorBG, ColorDst;
- if ((BkColor & 0xFF000000) == 0xFF000000) {
- return Color;
- }
- ColorFG = Color ^ 0xFF000000;
- ColorBG = BkColor ^ 0xFF000000;
- //
- // Set up mode
- //
- DMA2D->CR = 0x00020000UL | (1 << 9); // Control Register (Memory to memory with blending of FG and BG and TCIE)
- //
- // Set up pointers
- //
- DMA2D->FGMAR = (U32)&ColorFG; // Foreground Memory Address Register
- DMA2D->BGMAR = (U32)&ColorBG; // Background Memory Address Register
- DMA2D->OMAR = (U32)&ColorDst; // Output Memory Address Register (Destination address)
- //
- // Set up pixel format
- //
- DMA2D->FGPFCCR = LTDC_Pixelformat_ARGB8888
- | (1UL << 16)
- | ((U32)Intens << 24);
- DMA2D->BGPFCCR = LTDC_Pixelformat_ARGB8888
- | (0UL << 16)
- | ((U32)(255 - Intens) << 24);
- DMA2D->OPFCCR = LTDC_Pixelformat_ARGB8888;
- //
- // Set up size
- //
- DMA2D->NLR = (U32)(1 << 16) | 1; // Number of Line Register (Size configuration of area to be transfered)
- //
- // Execute operation
- //
- //_DMA_ExecOperation();
- DMA2D->CR |= 1; // Control Register (Start operation)
- //
- // Wait until transfer is done
- //
- while (DMA2D->CR & DMA2D_CR_START) {
- //__WFI(); // Sleep until next interrupt
- }
- return ColorDst ^ 0xFF000000;
- }
复制代码 ==============================================================
两个颜色点的融合,居然让他们搞出这么多代码来,效率极其低下,但是批量混合就有意义了。
查了了UCGUI3.98里面的颜色混合函数:
LCD_COLOR LCD_MixColors256(LCD_COLOR Color, LCD_COLOR BkColor, unsigned Intens) {
/* Calc Color seperations for FgColor first */
U32 R = (Color & 0xff) * Intens;
U32 G = (Color & 0xff00) * Intens;
U32 B = (Color & 0xff0000)* Intens;
/* Add Color seperations for BkColor */
Intens = 256 - Intens;
R += (BkColor & 0xff) * Intens;
G += (BkColor & 0xff00) * Intens;
B += (BkColor & 0xff0000) * Intens;
R = (R >> 8);
G = (G >> 8) & 0xff00;
B = (B >> 8) & 0xff0000;
return R + G + B;
}
或者下面这种类似的函数
- LCD_COLOR LCD_MixColors(GUI_COLOR Color, GUI_COLOR Color0, U8 Intens) {
- U32 r, g, b, a;
- U8 Intens0;
- #if (GUI_USE_ARGB)
- if (Color0 & 0xFF000000) {
- #else
- if ((Color0 & 0xFF000000) != 0xFF000000) {
- #endif
- //
- // Calculate Color separations for FgColor first
- //
- r = ( Color & 0x000000ff) * Intens;
- g = ( Color & 0x0000ff00) * Intens;
- b = ( Color & 0x00ff0000) * Intens;
- a = ((Color & 0xff000000) >> 24) * Intens;
- //
- // Add Color separations for Color0
- //
- Intens0 = 255 - Intens;
- r += ( Color0 & 0x000000ff) * Intens0;
- g += ( Color0 & 0x0000ff00) * Intens0;
- b += ( Color0 & 0x00ff0000) * Intens0;
- a += ((Color0 & 0xff000000) >> 24) * Intens0;
- r = (r >> 8) & 0x000000ff;
- g = (g >> 8) & 0x0000ff00;
- b = (b >> 8) & 0x00ff0000;
- a = (a << (24 - 8)) & 0xff000000;
- Color = r | g | b | a;
- }
- return Color;
- }
复制代码 ======================================================
1. 实际对比速度后发现,上面DMA2D实现的是下面这个纯计算实现的3倍时间,
2. 再次测试后,差不多是1.5倍时间左右,上面的函数90个时钟周期左右,下面的是60个左右。
3. 再再次测试后,找到第一次为什么时间更长的原因了,这个是因为使能了DMA2D的中断
关闭中断后基本就是第二次测试结果了,不过开启中断的时间也没有想象中的那么长,也就是130个时钟周期左右。 |
|