4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Android blurring sample
2 |
3 | 
4 |
5 |
6 | #### Acknowledgements
7 |
8 | ##### Stack Blur v1.0 from
9 | [http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html](http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html)
10 |
11 | **Java Author:** Mario Klingemann
12 | [http://incubator.quasimondo.com](http://incubator.quasimondo.com)
13 | created Feburary 29, 2004
14 |
15 | **Android port:** Yahel Bouaziz
16 | [http://www.kayenko.com](http://www.kayenko.com)
17 | ported april 5th, 2012
18 |
19 | ```
20 | This is a compromise between Gaussian Blur and Box blur
21 | It creates much better looking blurs than Box Blur, but is
22 | 7x faster than my Gaussian Blur implementation.
23 |
24 | I called it Stack Blur because this describes best how this
25 | filter works internally: it creates a kind of moving stack
26 | of colors whilst scanning through the image. Thereby it
27 | just has to add one new block of color to the right side
28 | of the stack and remove the leftmost color. The remaining
29 | colors on the topmost layer of the stack are either added on
30 | or reduced by one, depending on if they are on the right or
31 | on the left side of the stack.
32 |
33 | If you are using this algorithm in your code please add
34 | the following line:
35 |
36 | Stack Blur Algorithm by Mario Klingemann
37 | ```
38 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 |
3 | android {
4 | compileSdkVersion 19
5 | buildToolsVersion "19.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 19
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile "com.android.support:support-v4:19.0.+"
24 | }
25 |
--------------------------------------------------------------------------------
/app/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/com/paveldudka/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.paveldudka;
2 |
3 | import android.app.ActionBar;
4 | import android.app.FragmentTransaction;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentStatePagerAdapter;
10 | import android.support.v4.view.ViewPager;
11 |
12 | import com.paveldudka.fragments.FastBlurFragment;
13 | import com.paveldudka.fragments.RSBlurFragment;
14 | import com.paveldudka.util.ZoomOutPageTransformer;
15 |
16 | import java.util.ArrayList;
17 |
18 | public class MainActivity extends FragmentActivity {
19 |
20 | private CustomPagerAdapter pagerAdapter;
21 | private ViewPager viewPager;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | pagerAdapter =
28 | new CustomPagerAdapter(
29 | getSupportFragmentManager());
30 | viewPager = (ViewPager) findViewById(R.id.pager);
31 | viewPager.setAdapter(pagerAdapter);
32 | viewPager.setPageTransformer(true, new ZoomOutPageTransformer());
33 | getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
34 |
35 | ActionBar.TabListener tabListener = new ActionBar.TabListener() {
36 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
37 | viewPager.setCurrentItem(tab.getPosition(), true);
38 | }
39 |
40 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
41 | // hide the given tab
42 | }
43 |
44 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
45 | // probably ignore this event
46 | }
47 | };
48 |
49 | for (int i = 0; i < pagerAdapter.getCount(); i++) {
50 | getActionBar().addTab(
51 | getActionBar().newTab()
52 | .setText(pagerAdapter.getPageTitle(i))
53 | .setTabListener(tabListener));
54 | }
55 |
56 | viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
57 | @Override
58 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
59 |
60 | }
61 |
62 | @Override
63 | public void onPageSelected(int position) {
64 | getActionBar().setSelectedNavigationItem(position);
65 | }
66 |
67 | @Override
68 | public void onPageScrollStateChanged(int state) {
69 |
70 | }
71 | });
72 | }
73 |
74 | public class CustomPagerAdapter extends FragmentStatePagerAdapter {
75 |
76 | private ArrayList fragments = new ArrayList();
77 |
78 | public CustomPagerAdapter(FragmentManager fm) {
79 | super(fm);
80 | fragments.add(Fragment.instantiate(MainActivity.this, RSBlurFragment.class.getName()));
81 | fragments.add(Fragment.instantiate(MainActivity.this, FastBlurFragment.class.getName()));
82 | }
83 |
84 | @Override
85 | public Fragment getItem(int i) {
86 | return fragments.get(i);
87 | }
88 |
89 | @Override
90 | public int getCount() {
91 | return fragments.size();
92 | }
93 |
94 | @Override
95 | public CharSequence getPageTitle(int position) {
96 | return fragments.get(position).toString();
97 | }
98 | }
99 | }
100 |
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/paveldudka/fragments/FastBlurFragment.java:
--------------------------------------------------------------------------------
1 | package com.paveldudka.fragments;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.drawable.BitmapDrawable;
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.ViewTreeObserver;
13 | import android.widget.CheckBox;
14 | import android.widget.CompoundButton;
15 | import android.widget.FrameLayout;
16 | import android.widget.ImageView;
17 | import android.widget.TextView;
18 |
19 | import com.paveldudka.R;
20 | import com.paveldudka.util.FastBlur;
21 |
22 | /**
23 | * Created by paveldudka on 3/4/14.
24 | */
25 | public class FastBlurFragment extends Fragment {
26 | private final String DOWNSCALE_FILTER = "downscale_filter";
27 |
28 | private ImageView image;
29 | private TextView text;
30 | private CheckBox downScale;
31 | private TextView statusText;
32 |
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
35 | View view = inflater.inflate(R.layout.fragment_layout, container, false);
36 | image = (ImageView) view.findViewById(R.id.picture);
37 | text = (TextView) view.findViewById(R.id.text);
38 | image.setImageResource(R.drawable.picture);
39 | statusText = addStatusText((ViewGroup) view.findViewById(R.id.controls));
40 | addCheckBoxes((ViewGroup) view.findViewById(R.id.controls));
41 |
42 | if (savedInstanceState != null) {
43 | downScale.setChecked(savedInstanceState.getBoolean(DOWNSCALE_FILTER));
44 | }
45 | applyBlur();
46 | return view;
47 | }
48 |
49 | private void applyBlur() {
50 | image.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
51 | @Override
52 | public boolean onPreDraw() {
53 | image.getViewTreeObserver().removeOnPreDrawListener(this);
54 | image.buildDrawingCache();
55 |
56 | Bitmap bmp = image.getDrawingCache();
57 | blur(bmp, text);
58 | return true;
59 | }
60 | });
61 | }
62 |
63 | private void blur(Bitmap bkg, View view) {
64 | long startMs = System.currentTimeMillis();
65 | float scaleFactor = 1;
66 | float radius = 20;
67 | if (downScale.isChecked()) {
68 | scaleFactor = 8;
69 | radius = 2;
70 | }
71 |
72 | Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth()/scaleFactor),
73 | (int) (view.getMeasuredHeight()/scaleFactor), Bitmap.Config.ARGB_8888);
74 | Canvas canvas = new Canvas(overlay);
75 | canvas.translate(-view.getLeft()/scaleFactor, -view.getTop()/scaleFactor);
76 | canvas.scale(1 / scaleFactor, 1 / scaleFactor);
77 | Paint paint = new Paint();
78 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
79 | canvas.drawBitmap(bkg, 0, 0, paint);
80 |
81 | overlay = FastBlur.doBlur(overlay, (int)radius, true);
82 | view.setBackground(new BitmapDrawable(getResources(), overlay));
83 | statusText.setText(System.currentTimeMillis() - startMs + "ms");
84 | }
85 |
86 | @Override
87 | public String toString() {
88 | return "Fast blur";
89 | }
90 |
91 | private void addCheckBoxes(ViewGroup container) {
92 |
93 | downScale = new CheckBox(getActivity());
94 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
95 | downScale.setLayoutParams(lp);
96 | downScale.setText("Downscale before blur");
97 | downScale.setVisibility(View.VISIBLE);
98 | downScale.setTextColor(0xFFFFFFFF);
99 | downScale.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
100 | @Override
101 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
102 | applyBlur();
103 | }
104 | });
105 | container.addView(downScale);
106 | }
107 |
108 | private TextView addStatusText(ViewGroup container) {
109 | TextView result = new TextView(getActivity());
110 | result.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
111 | result.setTextColor(0xFFFFFFFF);
112 | container.addView(result);
113 | return result;
114 | }
115 |
116 | @Override
117 | public void onSaveInstanceState(Bundle outState) {
118 | outState.putBoolean(DOWNSCALE_FILTER, downScale.isChecked());
119 | super.onSaveInstanceState(outState);
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/paveldudka/fragments/RSBlurFragment.java:
--------------------------------------------------------------------------------
1 | package com.paveldudka.fragments;
2 |
3 | import android.annotation.TargetApi;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.drawable.BitmapDrawable;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.renderscript.Allocation;
11 | import android.renderscript.RenderScript;
12 | import android.renderscript.ScriptIntrinsicBlur;
13 | import android.support.v4.app.Fragment;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.view.ViewTreeObserver;
18 | import android.widget.CheckBox;
19 | import android.widget.CompoundButton;
20 | import android.widget.FrameLayout;
21 | import android.widget.ImageView;
22 | import android.widget.TextView;
23 |
24 | import com.paveldudka.R;
25 |
26 | /**
27 | * Created by paveldudka on 3/4/14.
28 | */
29 | public class RSBlurFragment extends Fragment {
30 | private ImageView image;
31 | private TextView text;
32 | private TextView statusText;
33 | private CheckBox downScale;
34 |
35 | @Override
36 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
37 | View view = inflater.inflate(R.layout.fragment_layout, container, false);
38 | image = (ImageView) view.findViewById(R.id.picture);
39 | text = (TextView) view.findViewById(R.id.text);
40 | image.setImageResource(R.drawable.picture);
41 | statusText = addStatusText((ViewGroup) view.findViewById(R.id.controls));
42 | addCheckBoxes((ViewGroup) view.findViewById(R.id.controls));
43 | applyBlur();
44 | return view;
45 | }
46 |
47 | private void applyBlur() {
48 | image.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
49 | @Override
50 | public boolean onPreDraw() {
51 | image.getViewTreeObserver().removeOnPreDrawListener(this);
52 | image.buildDrawingCache();
53 |
54 | Bitmap bmp = image.getDrawingCache();
55 | blur(bmp, text);
56 | return true;
57 | }
58 | });
59 | }
60 |
61 | @TargetApi(Build.VERSION_CODES.KITKAT)
62 | private void blur(Bitmap bkg, View view) {
63 | long startMs = System.currentTimeMillis();
64 |
65 |
66 | float scaleFactor = 1;
67 | float radius = 20;
68 |
69 | if (downScale.isChecked()) {
70 | scaleFactor = 8;
71 | radius = 2;
72 | }
73 |
74 | Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor),
75 | (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
76 |
77 | Canvas canvas = new Canvas(overlay);
78 |
79 | canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
80 | canvas.scale(1 / scaleFactor, 1 / scaleFactor);
81 | Paint paint = new Paint();
82 | paint.setFlags(Paint.FILTER_BITMAP_FLAG);
83 | canvas.drawBitmap(bkg, 0, 0, paint);
84 |
85 | RenderScript rs = RenderScript.create(getActivity());
86 |
87 | Allocation overlayAlloc = Allocation.createFromBitmap(
88 | rs, overlay);
89 |
90 | ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(
91 | rs, overlayAlloc.getElement());
92 |
93 | blur.setInput(overlayAlloc);
94 |
95 | blur.setRadius(radius);
96 |
97 | blur.forEach(overlayAlloc);
98 |
99 | overlayAlloc.copyTo(overlay);
100 |
101 | view.setBackground(new BitmapDrawable(
102 | getResources(), overlay));
103 |
104 | rs.destroy();
105 | statusText.setText(System.currentTimeMillis() - startMs + "ms");
106 | }
107 |
108 | @Override
109 | public String toString() {
110 | return "RenderScript";
111 | }
112 |
113 | private TextView addStatusText(ViewGroup container) {
114 | TextView result = new TextView(getActivity());
115 | result.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
116 | result.setTextColor(0xFFFFFFFF);
117 | container.addView(result);
118 | return result;
119 | }
120 |
121 | private void addCheckBoxes(ViewGroup container) {
122 | downScale = new CheckBox(getActivity());
123 | ViewGroup.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
124 | downScale.setLayoutParams(lp);
125 | downScale.setText("Downscale before blur");
126 | downScale.setVisibility(View.VISIBLE);
127 | downScale.setTextColor(0xFFFFFFFF);
128 | downScale.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
129 | @Override
130 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
131 | applyBlur();
132 | }
133 | });
134 | container.addView(downScale);
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/java/com/paveldudka/util/FastBlur.java:
--------------------------------------------------------------------------------
1 | package com.paveldudka.util;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by paveld on 3/6/14.
7 | */
8 | public class FastBlur {
9 |
10 | public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
11 |
12 | // Stack Blur v1.0 from
13 | // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
14 | //
15 | // Java Author: Mario Klingemann
16 | // http://incubator.quasimondo.com
17 | // created Feburary 29, 2004
18 | // Android port : Yahel Bouaziz
19 | // http://www.kayenko.com
20 | // ported april 5th, 2012
21 |
22 | // This is a compromise between Gaussian Blur and Box blur
23 | // It creates much better looking blurs than Box Blur, but is
24 | // 7x faster than my Gaussian Blur implementation.
25 | //
26 | // I called it Stack Blur because this describes best how this
27 | // filter works internally: it creates a kind of moving stack
28 | // of colors whilst scanning through the image. Thereby it
29 | // just has to add one new block of color to the right side
30 | // of the stack and remove the leftmost color. The remaining
31 | // colors on the topmost layer of the stack are either added on
32 | // or reduced by one, depending on if they are on the right or
33 | // on the left side of the stack.
34 | //
35 | // If you are using this algorithm in your code please add
36 | // the following line:
37 | //
38 | // Stack Blur Algorithm by Mario Klingemann
39 |
40 | Bitmap bitmap;
41 | if (canReuseInBitmap) {
42 | bitmap = sentBitmap;
43 | } else {
44 | bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
45 | }
46 |
47 | if (radius < 1) {
48 | return (null);
49 | }
50 |
51 | int w = bitmap.getWidth();
52 | int h = bitmap.getHeight();
53 |
54 | int[] pix = new int[w * h];
55 | bitmap.getPixels(pix, 0, w, 0, 0, w, h);
56 |
57 | int wm = w - 1;
58 | int hm = h - 1;
59 | int wh = w * h;
60 | int div = radius + radius + 1;
61 |
62 | int r[] = new int[wh];
63 | int g[] = new int[wh];
64 | int b[] = new int[wh];
65 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
66 | int vmin[] = new int[Math.max(w, h)];
67 |
68 | int divsum = (div + 1) >> 1;
69 | divsum *= divsum;
70 | int dv[] = new int[256 * divsum];
71 | for (i = 0; i < 256 * divsum; i++) {
72 | dv[i] = (i / divsum);
73 | }
74 |
75 | yw = yi = 0;
76 |
77 | int[][] stack = new int[div][3];
78 | int stackpointer;
79 | int stackstart;
80 | int[] sir;
81 | int rbs;
82 | int r1 = radius + 1;
83 | int routsum, goutsum, boutsum;
84 | int rinsum, ginsum, binsum;
85 |
86 | for (y = 0; y < h; y++) {
87 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
88 | for (i = -radius; i <= radius; i++) {
89 | p = pix[yi + Math.min(wm, Math.max(i, 0))];
90 | sir = stack[i + radius];
91 | sir[0] = (p & 0xff0000) >> 16;
92 | sir[1] = (p & 0x00ff00) >> 8;
93 | sir[2] = (p & 0x0000ff);
94 | rbs = r1 - Math.abs(i);
95 | rsum += sir[0] * rbs;
96 | gsum += sir[1] * rbs;
97 | bsum += sir[2] * rbs;
98 | if (i > 0) {
99 | rinsum += sir[0];
100 | ginsum += sir[1];
101 | binsum += sir[2];
102 | } else {
103 | routsum += sir[0];
104 | goutsum += sir[1];
105 | boutsum += sir[2];
106 | }
107 | }
108 | stackpointer = radius;
109 |
110 | for (x = 0; x < w; x++) {
111 |
112 | r[yi] = dv[rsum];
113 | g[yi] = dv[gsum];
114 | b[yi] = dv[bsum];
115 |
116 | rsum -= routsum;
117 | gsum -= goutsum;
118 | bsum -= boutsum;
119 |
120 | stackstart = stackpointer - radius + div;
121 | sir = stack[stackstart % div];
122 |
123 | routsum -= sir[0];
124 | goutsum -= sir[1];
125 | boutsum -= sir[2];
126 |
127 | if (y == 0) {
128 | vmin[x] = Math.min(x + radius + 1, wm);
129 | }
130 | p = pix[yw + vmin[x]];
131 |
132 | sir[0] = (p & 0xff0000) >> 16;
133 | sir[1] = (p & 0x00ff00) >> 8;
134 | sir[2] = (p & 0x0000ff);
135 |
136 | rinsum += sir[0];
137 | ginsum += sir[1];
138 | binsum += sir[2];
139 |
140 | rsum += rinsum;
141 | gsum += ginsum;
142 | bsum += binsum;
143 |
144 | stackpointer = (stackpointer + 1) % div;
145 | sir = stack[(stackpointer) % div];
146 |
147 | routsum += sir[0];
148 | goutsum += sir[1];
149 | boutsum += sir[2];
150 |
151 | rinsum -= sir[0];
152 | ginsum -= sir[1];
153 | binsum -= sir[2];
154 |
155 | yi++;
156 | }
157 | yw += w;
158 | }
159 | for (x = 0; x < w; x++) {
160 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
161 | yp = -radius * w;
162 | for (i = -radius; i <= radius; i++) {
163 | yi = Math.max(0, yp) + x;
164 |
165 | sir = stack[i + radius];
166 |
167 | sir[0] = r[yi];
168 | sir[1] = g[yi];
169 | sir[2] = b[yi];
170 |
171 | rbs = r1 - Math.abs(i);
172 |
173 | rsum += r[yi] * rbs;
174 | gsum += g[yi] * rbs;
175 | bsum += b[yi] * rbs;
176 |
177 | if (i > 0) {
178 | rinsum += sir[0];
179 | ginsum += sir[1];
180 | binsum += sir[2];
181 | } else {
182 | routsum += sir[0];
183 | goutsum += sir[1];
184 | boutsum += sir[2];
185 | }
186 |
187 | if (i < hm) {
188 | yp += w;
189 | }
190 | }
191 | yi = x;
192 | stackpointer = radius;
193 | for (y = 0; y < h; y++) {
194 | // Preserve alpha channel: ( 0xff000000 & pix[yi] )
195 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];
196 |
197 | rsum -= routsum;
198 | gsum -= goutsum;
199 | bsum -= boutsum;
200 |
201 | stackstart = stackpointer - radius + div;
202 | sir = stack[stackstart % div];
203 |
204 | routsum -= sir[0];
205 | goutsum -= sir[1];
206 | boutsum -= sir[2];
207 |
208 | if (x == 0) {
209 | vmin[y] = Math.min(y + r1, hm) * w;
210 | }
211 | p = x + vmin[y];
212 |
213 | sir[0] = r[p];
214 | sir[1] = g[p];
215 | sir[2] = b[p];
216 |
217 | rinsum += sir[0];
218 | ginsum += sir[1];
219 | binsum += sir[2];
220 |
221 | rsum += rinsum;
222 | gsum += ginsum;
223 | bsum += binsum;
224 |
225 | stackpointer = (stackpointer + 1) % div;
226 | sir = stack[stackpointer];
227 |
228 | routsum += sir[0];
229 | goutsum += sir[1];
230 | boutsum += sir[2];
231 |
232 | rinsum -= sir[0];
233 | ginsum -= sir[1];
234 | binsum -= sir[2];
235 |
236 | yi += w;
237 | }
238 | }
239 |
240 | bitmap.setPixels(pix, 0, w, 0, 0, w, h);
241 |
242 | return (bitmap);
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/app/src/main/java/com/paveldudka/util/ZoomOutPageTransformer.java:
--------------------------------------------------------------------------------
1 | package com.paveldudka.util;
2 |
3 | import android.support.v4.view.ViewPager;
4 | import android.view.View;
5 |
6 | /**
7 | * Created by paveld on 3/7/14.
8 | */
9 | public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
10 | private static final float MIN_SCALE = 0.85f;
11 | private static final float MIN_ALPHA = 0.5f;
12 |
13 | public void transformPage(View view, float position) {
14 | int pageWidth = view.getWidth();
15 | int pageHeight = view.getHeight();
16 |
17 | if (position < -1) { // [-Infinity,-1)
18 | // This page is way off-screen to the left.
19 | view.setAlpha(0);
20 |
21 | } else if (position <= 1) { // [-1,1]
22 | // Modify the default slide transition to shrink the page as well
23 | float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
24 | float vertMargin = pageHeight * (1 - scaleFactor) / 2;
25 | float horzMargin = pageWidth * (1 - scaleFactor) / 2;
26 | if (position < 0) {
27 | view.setTranslationX(horzMargin - vertMargin / 2);
28 | } else {
29 | view.setTranslationX(-horzMargin + vertMargin / 2);
30 | }
31 |
32 | // Scale the page down (between MIN_SCALE and 1)
33 | view.setScaleX(scaleFactor);
34 | view.setScaleY(scaleFactor);
35 |
36 | // Fade the page relative to its size.
37 | view.setAlpha(MIN_ALPHA +
38 | (scaleFactor - MIN_SCALE) /
39 | (1 - MIN_SCALE) * (1 - MIN_ALPHA));
40 |
41 | } else { // (1,+Infinity]
42 | // This page is way off-screen to the right.
43 | view.setAlpha(0);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/picture.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/app/src/main/res/drawable-xhdpi/picture.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
13 |
23 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Blurring
5 | Tricky bluring
6 | Hello world!
7 | Settings
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/blurring.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:0.9.+'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | mavenCentral()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/paveldudka/blurring/67da9e0a4bfbcc2214151b5719efa50421c5140b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------