Adding a volume effect to the indicator lines - page 9

 

Horizontal gradient on the kanvas.

Files:
gradient.mq5  5 kb
 

Slightly improved the code, and also introduced a variable which is responsible for the rendering speed:

input uchar speed=5;             // visible effect

Changing the speed of visualization is done by updating the canvas not after each drawing of the line, but at intervals.

The size of the gap is calculated using arithmetic operation "remainder of division":

      if(i%speed==0)
         canvas_.Update()
Files:
gradient.mq5  5 kb
 

I have applied different colours here: I have applied a colour with transparency (alpha channel 255) to the background colour (alpha channel 128). I have a question - which formula is used to calculate the final pixel colour for COLOR_FORMAT_ARGB_RAW and COLOR_FORMAT_ARGB_NORMALIZE modes.

If you refer to the article Calculating resulting colour, the calculations do not match.

Альфа-канал — Википедия
Альфа-канал — Википедия
  • ru.wikipedia.org
В компьютерной графике альфа-композиция обозначает процесс комбинирования изображения с фоном с целью создания эффекта частичной прозрачности. Этот метод часто применяется для многопроходной обработки изображения по частям с последующей комбинацией этих частей в единое двумерное результирующее изображение. Таким образом, альфа канал...
 

Where is it wrong: are the colour constants storing the wrong data or is the PrintFormat function malfunctioning?

Here's a script that outputs colours in integer form via PrintFormat:

//+------------------------------------------------------------------+
//|                                                  Script_test.mq5 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- зададим прозрачность
   uchar alfa=0x80; // значение 0x80 означает 128/255=50 % прозрачности   
   //--- выведем преобразование в ARGB для цвета clrBlue
   PrintFormat("0x%.8X - clrBlue",clrBlue);
   PrintFormat("0x%.8X - clrBlue ARGB with alfa=0x80 (transparency 50%%)",ColorToARGB(clrBlue,alfa));
   //--- выведем преобразование в ARGB для цвета clrGreen
   PrintFormat("0x%.8X - clrGreen",clrGreen);
   PrintFormat("0x%.8X - clrGreen ARGB with alfa=0x80 (transparency 50%%)",ColorToARGB(clrGreen,alfa));
   //--- выведем преобразование в ARGB для цвета clrRed
   PrintFormat("0x%.8X - clrRed",clrRed);
   PrintFormat("0x%.8X - clrRed ARGB with alfa=0x0x80 (transparency 50%%)",ColorToARGB(clrRed,alfa));
  }
//+------------------------------------------------------------------+

Output result:

2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x80FF0000 - clrRed ARGB with alfa=0x0x80 (transparency 50%)
2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x000000FF - clrRed
2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x80008000 - clrGreen ARGB with alfa=0x80 (transparency 50%)
2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x00008000 - clrGreen
2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x800000FF - clrBlue ARGB with alfa=0x80 (transparency 50%)
2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x00FF0000 - clrBlue

Whyis clrRed represented as0x000000FF and not0x00FF0000? Because red is C'255,0,0'.

Why isclrBlue represented as0x00FF0000 and not0x0000FF? Because blue is C'0,0,255'.

Files:
 
This is correct. It's just that ARGB has a different storage format to Color.
 
TheXpert:
This is correct. It's just that ARGB has a different data storage format compared to Color.

The recording format should be the same: first the alpha channel (if there is one) then RGB. According to help type Color record blue through literals:

C'0x00,0x00,0xFF'// blue

i.e. in integer representation, blue colour (without alpha channel) should be written as: 0x0000FF. But the test script outputs the blue colour backwards:

2015.01.24 21:50:31.164 Script_test (GBPUSD,D1) 0x00FF0000 - clrBlue

It turns out that the colour is written backwards in the colour constants.

Документация по MQL5: Основы языка / Типы данных / Целые типы / Тип color
Документация по MQL5: Основы языка / Типы данных / Целые типы / Тип color
  • www.mql5.com
Основы языка / Типы данных / Целые типы / Тип color - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
barabashkakvn:

It turns out that colour is written backwards in colour constants.

Yes. This order in the literal does not mean the same order in Color
 

With COLOR_FORMAT_ARGB_RAW, theTransparentLevelSet methodwith parameter "0" (full transparency) produces near-transparency, but clearly not full transparency.

 
barabashkakvn:

COLOR_FORMAT_ARGB_RAW methodTransparentLevelSet with parameter "0" (full transparency) makes transparency close to full transparency but obviously not full transparency.

Clarification: residual transparency at transparency level "0" is only observed on x32. There is no residual transparency on x64:

x32


x64


Is this kanvas behaviour in COLOR_FORMAT_ARGB_RAW mode a bug or a feature of drawing in x32 and x64 systems?

 
barabashkakvn:

Clarification: residual transparency at transparency level "0" is only observed on x32. There is no residual transparency on x64:

Is this kanvas behaviour in COLOR_FORMAT_ARGB_RAW mode a bug or a feature of drawing in x32 and x64 systems?

Service Desk is needed... )))