Simplify color adjustment using homogeneous coordinates

Change-Id: Ie31abacb134c29d82a6041fa7d521f68a1a273af
This commit is contained in:
Alan Viverette 2013-10-03 16:40:52 -07:00
parent 59d6992f4d
commit 794c5ba973
2 changed files with 6 additions and 12 deletions

View File

@ -169,7 +169,8 @@ String8 ProgramCache::generateFragmentShader(const Key& needs) {
fs << "gl_FragColor.rgb = gl_FragColor.rgb/gl_FragColor.a;";
}
fs << "gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));";
fs << "gl_FragColor.rgb = mat3(colorMatrix) * gl_FragColor.rgb + vec3(colorMatrix[3]);";
fs << "vec4 transformed = colorMatrix * vec4(gl_FragColor.rgb, 1);";
fs << "gl_FragColor.rgb = transformed.rgb/transformed.a;";
fs << "gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1.0 / 2.2));";
if (!needs.isOpaque() && needs.isPremultiplied()) {
// and re-premultiply if needed after gamma correction

View File

@ -1507,9 +1507,7 @@ void SurfaceFlinger::doDisplayComposition(const sp<const DisplayDevice>& hw,
RenderEngine& engine(getRenderEngine());
mat4 colorMatrix = mColorMatrix;
if (mDaltonize) {
// preserve last row of color matrix
colorMatrix = colorMatrix * mDaltonizer();
colorMatrix[3] = mColorMatrix[3];
}
engine.beginGroup(colorMatrix);
doComposeSurfaces(hw, dirtyRegion);
@ -2570,16 +2568,11 @@ status_t SurfaceFlinger::onTransact(
// color matrix is sent as mat3 matrix followed by vec3
// offset, then packed into a mat4 where the last row is
// the offset and extra values are 0
for (size_t i = 0 ; i < 3 ; i++) {
for (size_t j = 0; j < 3; j++) {
mColorMatrix[i][j] = data.readFloat();
}
mColorMatrix[i][3] = 0;
for (size_t i = 0 ; i < 4; i++) {
for (size_t j = 0; j < 4; j++) {
mColorMatrix[i][j] = data.readFloat();
}
}
for (size_t i = 0; i < 3; i++) {
mColorMatrix[3][i] = data.readFloat();
}
mColorMatrix[3][3] = 0;
} else {
mColorMatrix = mat4();
}