case(METHOD_REPR_COLOR_AVERAGE):
{
int num = index2 - index1 + 1;
for (int i = index1; i <= index2; i++)
{
RGBColor color = list.getColor(i);
temp[0] += color.getSample(0);
temp[1] += color.getSample(1);
temp[2] += color.getSample(2);
}
result[0] = (int)(temp[0] / num);
result[1] = (int)(temp[1] / num);
result[2] = (int)(temp[2] / num);
return result;
}
case(METHOD_REPR_COLOR_WEIGHTED_AVERAGE):
{
long num = 0;
for (int i = index1; i <= index2; i++)
{
RGBColor color = list.getColor(i);
int counter = color.getCounter();
temp[0] += color.getSample(0) * counter;
temp[1] += color.getSample(1) * counter;
temp[2] += color.getSample(2) * counter;
num += counter;
}
if (num == 0)
{
//System.out.println("ERROR IN FINDREPRESENTATIVECOLOR (WEIGHTED AVERAGE): ZERO COUNTER");
return null;
}
result[0] = (int)(temp[0] / num);
result[1] = (int)(temp[1] / num);
result[2] = (int)(temp[2] / num);
return result;
}
case(METHOD_REPR_COLOR_MEDIAN):
{
RGBColor color = list.getColor((index1 + index2) / 2);
result[0] = color.getSample(0);
result[1] = color.getSample(1);
result[2] = color.getSample(2);
return result;
}
default: throw new IllegalStateException("Unknown method for determining a representative color.");
}
}