private void doDesaturate(float normalizedAmount, Allocation input, Allocation output) { Matrix3f m = new Matrix3f(new float[]{ MathUtil.interpolate(1, 0.299f, normalizedAmount), MathUtil.interpolate(0, 0.299f, normalizedAmount), MathUtil.interpolate(0, 0.299f, normalizedAmount), MathUtil.interpolate(0, 0.587f, normalizedAmount), MathUtil.interpolate(1, 0.587f, normalizedAmount), MathUtil.interpolate(0, 0.587f, normalizedAmount), MathUtil.interpolate(0, 0.114f, normalizedAmount), MathUtil.interpolate(0, 0.114f, normalizedAmount), MathUtil.interpolate(1, 0.114f, normalizedAmount), }); mSIGrey.setColorMatrix(m); mSIGrey.forEach(input, output); }
/** * Load a color matrix with a hue offset. Can be used with {@link ScriptIntrinsicColorMatrix}. * from https://github.com/googlesamples/android-RenderScriptIntrinsic * * @param mat 3x3 color matrix * @param hueOffset offset for hue, any value */ private static void setColorMatrix3f(Matrix3f mat, float hueOffset) { float cos = (float) Math.cos(hueOffset); float sin = (float) Math.sin(hueOffset); mat.set(0, 0, .299f + .701f * cos + .168f * sin); mat.set(1, 0, .587f - .587f * cos + .330f * sin); mat.set(2, 0, .114f - .114f * cos - .497f * sin); mat.set(0, 1, .299f - .299f * cos - .328f * sin); mat.set(1, 1, .587f + .413f * cos + .035f * sin); mat.set(2, 1, .114f - .114f * cos + .292f * sin); mat.set(0, 2, .299f - .300f * cos + 1.25f * sin); mat.set(1, 2, .587f - .588f * cos - 1.05f * sin); mat.set(2, 2, .114f + .886f * cos - .203f * sin); }
public void setUniformMatrix (int location, Matrix3f matrix) { setUniformMatrix(location, matrix, false); }
public void setUniformMatrix (int location, Matrix3f matrix, boolean transpose) { if(location == -1) return; GLES20.glUniformMatrix3fv(location, 1, transpose, matrix.getArray(), 0); }