Errors, bugs, questions - page 2063

 
There are two bmp objects with transparency channels. When they overlap each other, some uint-colours are generated. How can I calculate these values myself if I know the uint-colours of the superimposed pixels of each object?
 
fxsaber:
There are two bmp objects with transparency channels. When they overlap each other, some uint-colours are generated. How can I calculate these values myself if I know the uint-colours of the superimposed pixels of each object?

static uchar      GetA(const uint fromcolor){return(uchar((fromcolor)>>24));}
   static uchar      GetR(const uint fromcolor){return(uchar((fromcolor)>>16));}
   static uchar      GetG(const uint fromcolor){return(uchar((fromcolor)>>8));}
   static uchar      GetB(const uint fromcolor){return(uchar(fromcolor));}
static uint       ARGBToColor(const uchar a,const uchar r,const uchar g,const uchar b){return((a<<24)|(r<<16)|(g<<8)|(b));}

static uint cColor::Mix(const uint bottom,const uint top)
  {
//===============
// if top color is not transparent => no mixing required
//===============
   if(cColor::GetA(top)==UCHAR_MAX)return(top);
//===============

//===============
   static uint bottomprev=0;
   static uint topprev=0;
   static uint resultprev=0;
//===============

//===============
   if(bottomprev==bottom && topprev==top)return(resultprev);
//===============

//===============
   bottomprev=bottom;
   topprev=top;
//===============

//===============
// Get Params of Colors
//===============
   double topA=(double)cColor::GetA(top);   double bottomA=(double)cColor::GetA(bottom);
   double topR=(double)cColor::GetR(top);   double bottomR=(double)cColor::GetR(bottom);
   double topG=(double)cColor::GetG(top);   double bottomG=(double)cColor::GetG(bottom);
   double topB=(double)cColor::GetB(top);   double bottomB=(double)cColor::GetB(bottom);
//===============

//===============
// Blend components
//===============
   uchar newA=uchar(topA+(bottomA*(255.0-topA)/255.0));
   uchar newR=uchar((topR*topA/255.0)+(bottomR*bottomA *(255.0-topA)/(255.0*255.0)));
   uchar newG=uchar((topG*topA/255.0)+(bottomG*bottomA *(255.0-topA)/(255.0*255.0)));
   uchar newB=uchar((topB*topA/255.0)+(bottomB*bottomA *(255.0-topA)/(255.0*255.0)));
//===============

//===============
   resultprev=cColor::ARGBToColor(newA,newR,newG,newB);
//===============

//===============
// New Color
//===============
   return(resultprev);
//===============
  }
 
Andrey Barinov:

Thank you! Another question. If, for example, five objects overlap at the same time, should the pairs (top/bottom) be made bottom-up or top-down?

 
fxsaber:

Thank you!


Better to draw all (bmp) objects on the same canvas at once, it's a simpler approach in the long run.

 
Andrey Barinov:

It's better to draw all (bmp) objects on one canvas at once, it's a simpler approach in the long run.

That's why I'm asking. Above is another question.

 
fxsaber:

Thank you! Another question. If, for example, five objects overlap each other, should the pairs (top/bottom) be drawn from bottom to top or from top to bottom?


I have to draw in layers, in order (zorder), from bottom to top, because I have to assume that I don't know which pixels of the five objects will intersect. As if on a real canvas.

After the mix, it looks like this


 
Andrey Barinov:

I draw in layers, according to order (like zorder), from the bottom to the top, because it's not immediately clear which pixels of the five objects will overlap. As if on a real canvas.

After mixing it up, you get something like this.

That's great! Are you using CCanvas or is it all your own solution? Which approach is better in the long run?

 
fxsaber:

Great! Are you using a refined CCanvas or a completely your own solution? Which approach is better in the long run?


Had to write my own, but with significant code snippets borrowed from the standard library (primitive drawing algorithms, anti-aliasing, etc.). Cramming pieces of code into my concept of working with graphics turned out to be easier than wrapping my concept around the standard library.

I wouldn't mind using the standard library if it were "live", but so far it's not adapted to GUI in any way.

 
Andrey Barinov:

I had to write my own, but with significant borrowing of pieces of code from the standard library (primitive drawing algorithms, anti-aliasing, etc.). Cramming pieces of code into my concept of working with graphics turned out to be easier than wrapping my concept around the standard library.

I wouldn't mind using standard library, if it were "live", but so far it's not adapted to GUI in any way.

I see now, thank you.

 
Language bug
#include <Expert\ExpertSignal.mqh>

void OnStart()
{
  CIndicator* a = NULL;   
  CExpertSignal b;
       
  b.InitIndicators(a); // 'InitIndicators' - no one of the overloads can be applied to the function call
}
Reason: