Document ColorMatrix intrinsic and add helpers
Increase size of test image. Add helpers for greyscale and yuv<>rgb conversions Change-Id: I6cdd06ae23623b47f5034585ed5d385ff11348ac
This commit is contained in:
@@ -112,6 +112,34 @@ public class Matrix4f {
|
||||
System.arraycopy(src.getArray(), 0, mMat, 0, mMat.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the values of the matrix to those of the parameter
|
||||
*
|
||||
* @param src matrix to load the values from
|
||||
* @hide
|
||||
*/
|
||||
public void load(Matrix3f src) {
|
||||
mMat[0] = src.mMat[0];
|
||||
mMat[1] = src.mMat[1];
|
||||
mMat[2] = src.mMat[2];
|
||||
mMat[3] = 0;
|
||||
|
||||
mMat[4] = src.mMat[3];
|
||||
mMat[5] = src.mMat[4];
|
||||
mMat[6] = src.mMat[5];
|
||||
mMat[7] = 0;
|
||||
|
||||
mMat[8] = src.mMat[6];
|
||||
mMat[9] = src.mMat[7];
|
||||
mMat[10] = src.mMat[8];
|
||||
mMat[11] = 0;
|
||||
|
||||
mMat[12] = 0;
|
||||
mMat[13] = 0;
|
||||
mMat[14] = 0;
|
||||
mMat[15] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current values to be a rotation matrix of certain angle
|
||||
* about a given axis
|
||||
|
||||
@@ -39,8 +39,7 @@ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
|
||||
}
|
||||
|
||||
/**
|
||||
* Supported elements types are float, float4, uchar, uchar4
|
||||
*
|
||||
* Supported elements types are uchar4
|
||||
*
|
||||
* @param rs
|
||||
* @param e
|
||||
@@ -53,13 +52,98 @@ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
|
||||
|
||||
}
|
||||
|
||||
public void setColorMatrix(Matrix4f m) {
|
||||
mMatrix.load(m);
|
||||
private void setMatrix() {
|
||||
FieldPacker fp = new FieldPacker(16*4);
|
||||
fp.addMatrix(m);
|
||||
fp.addMatrix(mMatrix);
|
||||
setVar(0, fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color matrix which will be applied to each cell of the image.
|
||||
*
|
||||
* @param m The 4x4 matrix to set.
|
||||
*/
|
||||
public void setColorMatrix(Matrix4f m) {
|
||||
mMatrix.load(m);
|
||||
setMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color matrix which will be applied to each cell of the image.
|
||||
* This will set the alpha channel to be a copy.
|
||||
*
|
||||
* @param m The 3x3 matrix to set.
|
||||
*/
|
||||
public void setColorMatrix(Matrix3f m) {
|
||||
mMatrix.load(m);
|
||||
setMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a color matrix to convert from RGB to luminace. The alpha channel
|
||||
* will be a copy.
|
||||
*
|
||||
*/
|
||||
public void setGreyscale() {
|
||||
mMatrix.loadIdentity();
|
||||
mMatrix.set(0, 0, 0.299f);
|
||||
mMatrix.set(1, 0, 0.587f);
|
||||
mMatrix.set(2, 0, 0.114f);
|
||||
mMatrix.set(0, 1, 0.299f);
|
||||
mMatrix.set(1, 1, 0.587f);
|
||||
mMatrix.set(2, 1, 0.114f);
|
||||
mMatrix.set(0, 2, 0.299f);
|
||||
mMatrix.set(1, 2, 0.587f);
|
||||
mMatrix.set(2, 2, 0.114f);
|
||||
setMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix to convert from YUV to RGB with a direct copy of the 4th
|
||||
* channel.
|
||||
*
|
||||
*/
|
||||
public void setYUVtoRGB() {
|
||||
mMatrix.loadIdentity();
|
||||
mMatrix.set(0, 0, 1.f);
|
||||
mMatrix.set(1, 0, 0.f);
|
||||
mMatrix.set(2, 0, 1.13983f);
|
||||
mMatrix.set(0, 1, 1.f);
|
||||
mMatrix.set(1, 1, -0.39465f);
|
||||
mMatrix.set(2, 1, -0.5806f);
|
||||
mMatrix.set(0, 2, 1.f);
|
||||
mMatrix.set(1, 2, 2.03211f);
|
||||
mMatrix.set(2, 2, 0.f);
|
||||
setMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix to convert from RGB to YUV with a direct copy of the 4th
|
||||
* channel.
|
||||
*
|
||||
*/
|
||||
public void setRGBtoYUV() {
|
||||
mMatrix.loadIdentity();
|
||||
mMatrix.set(0, 0, 0.299f);
|
||||
mMatrix.set(1, 0, 0.587f);
|
||||
mMatrix.set(2, 0, 0.114f);
|
||||
mMatrix.set(0, 1, -0.14713f);
|
||||
mMatrix.set(1, 1, -0.28886f);
|
||||
mMatrix.set(2, 1, 0.436f);
|
||||
mMatrix.set(0, 2, 0.615f);
|
||||
mMatrix.set(1, 2, -0.51499f);
|
||||
mMatrix.set(2, 2, -0.10001f);
|
||||
setMatrix();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invoke the kernel and apply the matrix to each cell of ain and copy to
|
||||
* aout.
|
||||
*
|
||||
* @param ain Input allocation
|
||||
* @param aout Output allocation
|
||||
*/
|
||||
public void forEach(Allocation ain, Allocation aout) {
|
||||
forEach(0, ain, aout, null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 597 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
@@ -243,8 +243,8 @@ public class ImageProcessingActivity extends Activity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
mBitmapIn = loadBitmap(R.drawable.city);
|
||||
mBitmapOut = loadBitmap(R.drawable.city);
|
||||
mBitmapIn = loadBitmap(R.drawable.img1600x1067);
|
||||
mBitmapOut = loadBitmap(R.drawable.img1600x1067);
|
||||
|
||||
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user