I am creating photo filters using independent RGB colour transformation. I create RGB curve using path and then convert the path to output array (0-255).
Here is the code,
for (int x = 0; x<256; x++) {
PathInterpolator pathInterpolator = new PathInterpolator(path);
allPoints[x] = 255.0f * pathInterpolator.getInterpolation((float) x / 255.0f);
}
The allPoints array has different value on different android version. I get required result in lollipop devices but not on older devices.
Any idea why this is happening ?
If I am to guess, then I think that on older devices PathInterpolatorCompat only interpolates the first contour of the path whereas on lollipop complete path is interpolated.
EDIT
As a workaround, for older versions I am using PathMeasure. But clearly it is not ideal way to solve the problem. Here is the code :
PathMeasure pm = new PathMeasure(path, false);
for (int i = 0; i < 256; i++) {
allPoints[i] = -1;
}
int x = 0;
float[] acoordinates = {0, 0};
do {
float pathLength = pm.getLength();
for (float i = 0; i <= pathLength; i += 0.1f) {
pm.getPosTan(i, acoordinates, null);
if ((int) (acoordinates[0]) > x && x < 256) {
allPoints[x] = acoordinates[1];
x++;
}
if (x > 255) {
break;
}
}
} while (pm.nextContour());
for (int i = 0; i < 256; i++) {
if (allPoints[i] == -1) {
allPoints[i] = allPoints[i - 1];
}
}
This is neither accurate nor recommended solution for this.