summaryrefslogtreecommitdiff
path: root/media/mca
diff options
context:
space:
mode:
authorHampus Wessman <hampus.wessman@sonymobile.com>2013-04-15 12:26:51 +0200
committerEd Savage-Jones <edward.savage-jones@sonymobile.com>2017-07-27 13:44:00 +0000
commit8673c2adc72069a25aaa99776fec7c93495daa07 (patch)
tree3101bd35bde2cc5725554315a3053455377fcb02 /media/mca
parent9b9e823096ebee3a39e1a3e36b6c6a60f2f38d05 (diff)
Fix graphical artifact in the fisheye effect
The fisheye effect generates a graphical artifact close to the center of the picture, due to bad precision and division by zero in the shader. The problem is fixed by making a small change in the shader, so that the picture is uniformly scaled close to the center instead. This avoids the problem and looks as expected, without affecting the performance. Bug: 64107054 Test: Manual - Install dev sample HelloEffects and use the 'fisheye' from the overflow. There is a small artifact in the center of the puppy without this patch applied. Think of the puppies!! Change-Id: I063f60facd30708db29ff544fdb47ac896e3d54b
Diffstat (limited to 'media/mca')
-rw-r--r--media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java4
1 files changed, 4 insertions, 0 deletions
diff --git a/media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java b/media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java
index 2ff65889e1ac..e0dbd571d560 100644
--- a/media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java
+++ b/media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java
@@ -49,6 +49,8 @@ public class FisheyeFilter extends Filter {
private int mHeight = 0;
private int mTarget = FrameFormat.TARGET_UNSPECIFIED;
+ // The constant min_dist, below, is an arbitrary number that gives good enough precision in
+ // the center of the picture without affecting the fisheye effect noticeably.
private static final String mFisheyeShader =
"precision mediump float;\n" +
"uniform sampler2D tex_sampler_0;\n" +
@@ -59,8 +61,10 @@ public class FisheyeFilter extends Filter {
"varying vec2 v_texcoord;\n" +
"void main() {\n" +
" const float m_pi_2 = 1.570963;\n" +
+ " const float min_dist = 0.01;\n" +
" vec2 coord = v_texcoord - vec2(0.5, 0.5);\n" +
" float dist = length(coord * scale);\n" +
+ " dist = max(dist, min_dist);\n" +
" float radian = m_pi_2 - atan(alpha * sqrt(radius2 - dist * dist), dist);\n" +
" float scalar = radian * factor / dist;\n" +
" vec2 new_coord = coord * scalar + vec2(0.5, 0.5);\n" +