Assuming you have a structure like this:
typedef struct LabColor {
uint8_t L;
uint8_t a;
uint8_t b;
} LabColor;
and an array of 4 of them:
LabColor colors[4];
getMeSomeColors (colors);
and weight:
float weights[4];
getMeSomeWeights (weights);
One possible way to mix is as follows:
float LSum = 0.0;
float aSum = 0.0;
float bSum = 0.0;
float weightSum = 0.0;
for (int i = 0; i < 4; i++)
{
LSum += ((float)colors [ i ].L * weights [ i ]);
aSum += ((float)colors [ i ].a * weights [ i ]);
bSum += ((float)colors [ i ].b * weights [ i ]);
weightSum += weights[i];
}
LabColor result;
result.L = (uint8_t)(LSum / weightSum);
result.a = (uint8_t)((aSum / weightSum) + 127);
result.b = (uint8_t)((bSum / weightSum) + 127);
, 0 1. , . 1, .
. , , , .