Here you can find the source of combineComponent(float[] partsComponent, float[] partsAlpha, int partsN)
Parameter | Description |
---|---|
partsComponent | values of the component. |
partsAlpha | alpha values. |
partsN | number of values. |
public static float combineComponent(float[] partsComponent, float[] partsAlpha, int partsN)
//package com.java2s; //License from project: Apache License public class Main { /**// www .ja va 2 s. c om * Combine multiple values of an color component (red, green or blue). * * @param partsComponent * values of the component. * @param partsAlpha * alpha values. * @param partsN * number of values. * @return combined value */ public static float combineComponent(float[] partsComponent, float[] partsAlpha, int partsN) { float sumComponent = 0.f; float sumAlpha = 0.f; int count = 0; for (int i = 0; i < partsN; i++) { if ((!Float.isNaN(partsComponent[i])) && (!Float.isNaN(partsAlpha[i]))) { sumComponent += partsComponent[i] * partsAlpha[i]; sumAlpha += partsAlpha[i]; count++; } } // fall back to the simple method without partsAlpha if ((count <= 0) || (sumAlpha <= 0.f)) { count = 0; for (int i = 0; i < partsN; i++) { if (!Float.isNaN(partsComponent[i])) { sumComponent += partsComponent[i]; count++; } } sumAlpha = count; } if (count > 0) { return sumComponent / sumAlpha; } else { return 0.f; } } }