2

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.

Varun Verma
  • 692
  • 7
  • 13
  • shouldn't you use a `PathMeasure` in your case? – pskink Aug 10 '15 at 09:16
  • I am using PathMeasure for older versions (see my edited answer), but it is not ideal solution for me since I need values ranging from 0-255, and I need to extract those by myself via loop. (Not accurate and slow solution) – Varun Verma Aug 10 '15 at 14:05
  • cannot you just use `pm.getPosTan` inside `getInterpolation(float t)` ? – pskink Aug 10 '15 at 14:13
  • Can you elaborate your answer ? – Varun Verma Aug 10 '15 at 14:25
  • i mean: create a custom `Interpolator` and override `getIntarpolation` – pskink Aug 10 '15 at 14:31
  • This thought crossed my mind but it is not feasible, since in this case I don't know the value of **t** for which I would get integer value of **x**. In the solution I mentioned, I am looping through complete path (varying from 0-1) and obtaining closest possible integer value of **x** (and corresponding **y** value). – Varun Verma Aug 10 '15 at 14:47

0 Answers0