Skip to content

Commit 8fd5853

Browse files
author
Jason Sams
committed
Document ColorMatrix intrinsic and add helpers
Increase size of test image. Add helpers for greyscale and yuv<>rgb conversions Change-Id: I6cdd06ae23623b47f5034585ed5d385ff11348ac
1 parent fb3ec44 commit 8fd5853

File tree

7 files changed

+120
-8
lines changed

7 files changed

+120
-8
lines changed

graphics/java/android/renderscript/Matrix4f.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,34 @@ public void load(Matrix4f src) {
112112
System.arraycopy(src.getArray(), 0, mMat, 0, mMat.length);
113113
}
114114

115+
/**
116+
* Sets the values of the matrix to those of the parameter
117+
*
118+
* @param src matrix to load the values from
119+
* @hide
120+
*/
121+
public void load(Matrix3f src) {
122+
mMat[0] = src.mMat[0];
123+
mMat[1] = src.mMat[1];
124+
mMat[2] = src.mMat[2];
125+
mMat[3] = 0;
126+
127+
mMat[4] = src.mMat[3];
128+
mMat[5] = src.mMat[4];
129+
mMat[6] = src.mMat[5];
130+
mMat[7] = 0;
131+
132+
mMat[8] = src.mMat[6];
133+
mMat[9] = src.mMat[7];
134+
mMat[10] = src.mMat[8];
135+
mMat[11] = 0;
136+
137+
mMat[12] = 0;
138+
mMat[13] = 0;
139+
mMat[14] = 0;
140+
mMat[15] = 1;
141+
}
142+
115143
/**
116144
* Sets current values to be a rotation matrix of certain angle
117145
* about a given axis

graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
3939
}
4040

4141
/**
42-
* Supported elements types are float, float4, uchar, uchar4
43-
*
42+
* Supported elements types are uchar4
4443
*
4544
* @param rs
4645
* @param e
@@ -53,13 +52,98 @@ public static ScriptIntrinsicColorMatrix create(RenderScript rs, Element e) {
5352

5453
}
5554

56-
public void setColorMatrix(Matrix4f m) {
57-
mMatrix.load(m);
55+
private void setMatrix() {
5856
FieldPacker fp = new FieldPacker(16*4);
59-
fp.addMatrix(m);
57+
fp.addMatrix(mMatrix);
6058
setVar(0, fp);
6159
}
6260

61+
/**
62+
* Set the color matrix which will be applied to each cell of the image.
63+
*
64+
* @param m The 4x4 matrix to set.
65+
*/
66+
public void setColorMatrix(Matrix4f m) {
67+
mMatrix.load(m);
68+
setMatrix();
69+
}
70+
71+
/**
72+
* Set the color matrix which will be applied to each cell of the image.
73+
* This will set the alpha channel to be a copy.
74+
*
75+
* @param m The 3x3 matrix to set.
76+
*/
77+
public void setColorMatrix(Matrix3f m) {
78+
mMatrix.load(m);
79+
setMatrix();
80+
}
81+
82+
/**
83+
* Set a color matrix to convert from RGB to luminace. The alpha channel
84+
* will be a copy.
85+
*
86+
*/
87+
public void setGreyscale() {
88+
mMatrix.loadIdentity();
89+
mMatrix.set(0, 0, 0.299f);
90+
mMatrix.set(1, 0, 0.587f);
91+
mMatrix.set(2, 0, 0.114f);
92+
mMatrix.set(0, 1, 0.299f);
93+
mMatrix.set(1, 1, 0.587f);
94+
mMatrix.set(2, 1, 0.114f);
95+
mMatrix.set(0, 2, 0.299f);
96+
mMatrix.set(1, 2, 0.587f);
97+
mMatrix.set(2, 2, 0.114f);
98+
setMatrix();
99+
}
100+
101+
/**
102+
* Set the matrix to convert from YUV to RGB with a direct copy of the 4th
103+
* channel.
104+
*
105+
*/
106+
public void setYUVtoRGB() {
107+
mMatrix.loadIdentity();
108+
mMatrix.set(0, 0, 1.f);
109+
mMatrix.set(1, 0, 0.f);
110+
mMatrix.set(2, 0, 1.13983f);
111+
mMatrix.set(0, 1, 1.f);
112+
mMatrix.set(1, 1, -0.39465f);
113+
mMatrix.set(2, 1, -0.5806f);
114+
mMatrix.set(0, 2, 1.f);
115+
mMatrix.set(1, 2, 2.03211f);
116+
mMatrix.set(2, 2, 0.f);
117+
setMatrix();
118+
}
119+
120+
/**
121+
* Set the matrix to convert from RGB to YUV with a direct copy of the 4th
122+
* channel.
123+
*
124+
*/
125+
public void setRGBtoYUV() {
126+
mMatrix.loadIdentity();
127+
mMatrix.set(0, 0, 0.299f);
128+
mMatrix.set(1, 0, 0.587f);
129+
mMatrix.set(2, 0, 0.114f);
130+
mMatrix.set(0, 1, -0.14713f);
131+
mMatrix.set(1, 1, -0.28886f);
132+
mMatrix.set(2, 1, 0.436f);
133+
mMatrix.set(0, 2, 0.615f);
134+
mMatrix.set(1, 2, -0.51499f);
135+
mMatrix.set(2, 2, -0.10001f);
136+
setMatrix();
137+
}
138+
139+
140+
/**
141+
* Invoke the kernel and apply the matrix to each cell of ain and copy to
142+
* aout.
143+
*
144+
* @param ain Input allocation
145+
* @param aout Output allocation
146+
*/
63147
public void forEach(Allocation ain, Allocation aout) {
64148
forEach(0, ain, aout, null);
65149
}

graphics/java/android/renderscript/ScriptIntrinsicYuvToRGB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 The Android Open Source Project
2+
* Copyright (C) 2012 The Android Open Source Project
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
Binary file not shown.
1.01 MB
Loading
194 KB
Loading

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ protected void onCreate(Bundle savedInstanceState) {
243243
super.onCreate(savedInstanceState);
244244
setContentView(R.layout.main);
245245

246-
mBitmapIn = loadBitmap(R.drawable.city);
247-
mBitmapOut = loadBitmap(R.drawable.city);
246+
mBitmapIn = loadBitmap(R.drawable.img1600x1067);
247+
mBitmapOut = loadBitmap(R.drawable.img1600x1067);
248248

249249
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
250250

0 commit comments

Comments
 (0)