硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4377|回复: 4
收起左侧

[emWin] 官方F429的emWin驱动中,仅仅只有前景色和背景色两个颜色点的混合居然也用DAM2D,连

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
发表于 2016-1-8 01:59:50 | 显示全部楼层 |阅读模式
实际测试这个函数调用到的地方不少,只是不是特别频繁:
===================================================
  1. static LCD_COLOR _DMA_MixColors(LCD_COLOR Color, LCD_COLOR BkColor, U8 Intens) {
  2.   U32 ColorFG, ColorBG, ColorDst;
  3.   if ((BkColor & 0xFF000000) == 0xFF000000) {
  4.     return Color;
  5.   }
  6.   ColorFG = Color   ^ 0xFF000000;
  7.   ColorBG = BkColor ^ 0xFF000000;
  8.   //
  9.   // Set up mode
  10.   //
  11.   DMA2D->CR      = 0x00020000UL | (1 << 9);         // Control Register (Memory to memory with blending of FG and BG and TCIE)
  12.   //
  13.   // Set up pointers
  14.   //
  15.   DMA2D->FGMAR   = (U32)&ColorFG;                   // Foreground Memory Address Register
  16.   DMA2D->BGMAR   = (U32)&ColorBG;                   // Background Memory Address Register
  17.   DMA2D->OMAR    = (U32)&ColorDst;                  // Output Memory Address Register (Destination address)
  18.   //
  19.   // Set up pixel format
  20.   //
  21.   DMA2D->FGPFCCR = LTDC_Pixelformat_ARGB8888
  22.                  | (1UL << 16)
  23.                  | ((U32)Intens << 24);
  24.   DMA2D->BGPFCCR = LTDC_Pixelformat_ARGB8888
  25.                  | (0UL << 16)
  26.                  | ((U32)(255 - Intens) << 24);
  27.   DMA2D->OPFCCR  = LTDC_Pixelformat_ARGB8888;
  28.   //
  29.   // Set up size
  30.   //
  31.   DMA2D->NLR     = (U32)(1 << 16) | 1;              // Number of Line Register (Size configuration of area to be transfered)
  32.   //
  33.   // Execute operation
  34.   //
  35.   //_DMA_ExecOperation();
  36.   DMA2D->CR     |= 1;                               // Control Register (Start operation)
  37.   //
  38.   // Wait until transfer is done
  39.   //
  40.   while (DMA2D->CR & DMA2D_CR_START) {
  41.     //__WFI();                                      // Sleep until next interrupt
  42.   }
  43.   return ColorDst ^ 0xFF000000;
  44. }
复制代码
==============================================================
两个颜色点的融合,居然让他们搞出这么多代码来,效率极其低下,但是批量混合就有意义了。
查了了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;
}
或者下面这种类似的函数
  1. LCD_COLOR LCD_MixColors(GUI_COLOR Color, GUI_COLOR Color0, U8 Intens) {
  2.   U32 r, g, b, a;
  3.   U8  Intens0;
  4. #if (GUI_USE_ARGB)
  5.   if (Color0 & 0xFF000000) {
  6. #else
  7.   if ((Color0 & 0xFF000000) != 0xFF000000) {
  8. #endif
  9.     //
  10.     // Calculate Color separations for FgColor first
  11.     //
  12.     r = ( Color & 0x000000ff)        * Intens;
  13.     g = ( Color & 0x0000ff00)        * Intens;
  14.     b = ( Color & 0x00ff0000)        * Intens;
  15.     a = ((Color & 0xff000000) >> 24) * Intens;
  16.     //
  17.     // Add Color separations for Color0
  18.     //
  19.     Intens0 = 255 - Intens;
  20.     r += ( Color0 & 0x000000ff)        * Intens0;
  21.     g += ( Color0 & 0x0000ff00)        * Intens0;
  22.     b += ( Color0 & 0x00ff0000)        * Intens0;
  23.     a += ((Color0 & 0xff000000) >> 24) * Intens0;
  24.     r =  (r >> 8) & 0x000000ff;
  25.     g =  (g >> 8) & 0x0000ff00;
  26.     b =  (b >> 8) & 0x00ff0000;
  27.     a =  (a << (24 - 8)) & 0xff000000;
  28.     Color = r | g | b | a;
  29.   }
  30.   return Color;
  31. }
复制代码
======================================================
1. 实际对比速度后发现,上面DMA2D实现的是下面这个纯计算实现的3倍时间,
2. 再次测试后,差不多是1.5倍时间左右,上面的函数90个时钟周期左右,下面的是60个左右。
3. 再再次测试后,找到第一次为什么时间更长的原因了,这个是因为使能了DMA2D的中断
    关闭中断后基本就是第二次测试结果了,不过开启中断的时间也没有想象中的那么长,也就是130个时钟周期左右。
回复

使用道具 举报

32

主题

97

回帖

193

积分

初级会员

积分
193
发表于 2016-1-8 02:01:38 | 显示全部楼层

Re:F429的emWin驱动中,仅仅只有前景色和背景色两个颜色点的混合居然也用DAM2D,连

你这是还没睡呢,还是刚起来呀?我是睡醒了[s:149][s:149][s:149][s:149]
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
 楼主| 发表于 2016-1-8 02:07:11 | 显示全部楼层

回 beyondabcd 的帖子

beyondabcd:你这是还没睡呢,还是刚起来呀?我是睡醒了[s:149][s:149][s:149][s:149] (2016-01-08 02:01) 
就要休息了。[s:145]
回复

使用道具 举报

1

主题

2

回帖

1

积分

新手上路

积分
1
发表于 2016-1-8 09:36:50 | 显示全部楼层
[s:151] 精力真好
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
 楼主| 发表于 2016-1-9 10:51:26 | 显示全部楼层
更新了三次次,这个问题算是真正的搞清楚了。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-16 12:22 , Processed in 0.044355 second(s), 30 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表