Refactored some variable names
This commit is contained in:
parent
09a1523d57
commit
f62e850b86
3 changed files with 312 additions and 316 deletions
2
app/src/main/java/com/kabouzeid/gramophone/helper/bitmapblur/BlurProcess.java
Normal file → Executable file
2
app/src/main/java/com/kabouzeid/gramophone/helper/bitmapblur/BlurProcess.java
Normal file → Executable file
|
|
@ -1,7 +1,6 @@
|
||||||
package com.kabouzeid.gramophone.helper.bitmapblur;
|
package com.kabouzeid.gramophone.helper.bitmapblur;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
|
|
||||||
interface BlurProcess {
|
interface BlurProcess {
|
||||||
/**
|
/**
|
||||||
|
|
@ -12,6 +11,5 @@ interface BlurProcess {
|
||||||
* @param radius the radius in pixels to blur the image
|
* @param radius the radius in pixels to blur the image
|
||||||
* @return the blurred version of the image.
|
* @return the blurred version of the image.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
Bitmap blur(Bitmap original, float radius);
|
Bitmap blur(Bitmap original, float radius);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
app/src/main/java/com/kabouzeid/gramophone/helper/bitmapblur/JavaBlurProcess.java
Normal file → Executable file
15
app/src/main/java/com/kabouzeid/gramophone/helper/bitmapblur/JavaBlurProcess.java
Normal file → Executable file
|
|
@ -1,19 +1,17 @@
|
||||||
package com.kabouzeid.gramophone.helper.bitmapblur;
|
package com.kabouzeid.gramophone.helper.bitmapblur;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blur using Java code.
|
* Blur using Java code.
|
||||||
* <p/>
|
*
|
||||||
* This is a compromise between Gaussian Blur and Box blur
|
* This is a compromise between Gaussian Blur and Box blur
|
||||||
* It creates much better looking blurs than Box Blur, but is
|
* It creates much better looking blurs than Box Blur, but is
|
||||||
* 7x faster than my Gaussian Blur implementation.
|
* 7x faster than my Gaussian Blur implementation.
|
||||||
* <p/>
|
|
||||||
* I called it Stack Blur because this describes best how this
|
* I called it Stack Blur because this describes best how this
|
||||||
* filter works internally: it creates a kind of moving stack
|
* filter works internally: it creates a kind of moving stack
|
||||||
* of colors whilst scanning through the image. Thereby it
|
* of colors whilst scanning through the image. Thereby it
|
||||||
|
|
@ -25,11 +23,12 @@ import java.util.concurrent.Callable;
|
||||||
*
|
*
|
||||||
* @author Enrique López Mañas <eenriquelopez@gmail.com>
|
* @author Enrique López Mañas <eenriquelopez@gmail.com>
|
||||||
* http://www.neo-tech.es
|
* http://www.neo-tech.es
|
||||||
* <p/>
|
*
|
||||||
* Author of the original algorithm: Mario Klingemann <mario.quasimondo.com>
|
* Author of the original algorithm: Mario Klingemann <mario.quasimondo.com>
|
||||||
* <p/>
|
*
|
||||||
* Based heavily on http://vitiy.info/Code/stackblur.cpp
|
* Based heavily on http://vitiy.info/Code/stackblur.cpp
|
||||||
* See http://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/
|
* See http://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/
|
||||||
|
*
|
||||||
* @copyright: Enrique López Mañas
|
* @copyright: Enrique López Mañas
|
||||||
* @license: Apache License 2.0
|
* @license: Apache License 2.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -73,9 +72,8 @@ class JavaBlurProcess implements BlurProcess {
|
||||||
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24
|
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24
|
||||||
};
|
};
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap blur(@NonNull Bitmap original, float radius) {
|
public Bitmap blur(Bitmap original, float radius) {
|
||||||
int w = original.getWidth();
|
int w = original.getWidth();
|
||||||
int h = original.getHeight();
|
int h = original.getHeight();
|
||||||
int[] currentPixels = new int[w * h];
|
int[] currentPixels = new int[w * h];
|
||||||
|
|
@ -322,7 +320,6 @@ class JavaBlurProcess implements BlurProcess {
|
||||||
_round = round;
|
_round = round;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
blurIteration(_src, _w, _h, _radius, _totalCores, _coreIndex, _round);
|
blurIteration(_src, _w, _h, _radius, _totalCores, _coreIndex, _round);
|
||||||
|
|
|
||||||
|
|
@ -43,19 +43,19 @@ public class StackBlurManager {
|
||||||
/**
|
/**
|
||||||
* Resized original image
|
* Resized original image
|
||||||
*/
|
*/
|
||||||
private final Bitmap _image;
|
private final Bitmap image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Most recent result of blurring
|
* Most recent result of blurring
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private Bitmap _result;
|
private Bitmap result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method of blurring
|
* Method of blurring
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BlurProcess _blurProcess;
|
private final BlurProcess blurProcess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method (basic initialization and construction of the pixel array)
|
* Constructor method (basic initialization and construction of the pixel array)
|
||||||
|
|
@ -63,19 +63,20 @@ public class StackBlurManager {
|
||||||
* @param image The image that will be analysed
|
* @param image The image that will be analysed
|
||||||
*/
|
*/
|
||||||
public StackBlurManager(@NonNull Bitmap image) {
|
public StackBlurManager(@NonNull Bitmap image) {
|
||||||
_image = Util.getResizedBitmap(image, 500, 500, false);
|
// resize Bitmap to prevent OOM and OOB exceptions and increase the performance
|
||||||
_blurProcess = new JavaBlurProcess();
|
this.image = Util.getResizedBitmap(image, 500, 500, false);
|
||||||
|
blurProcess = new JavaBlurProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the image on the given radius. Radius must be at least 1
|
* Process the image on the given radius. Radius must be at least 1
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius the blur radius
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Bitmap process(int radius) {
|
public Bitmap process(int radius) {
|
||||||
_result = _blurProcess.blur(_image, radius);
|
result = blurProcess.blur(image, radius);
|
||||||
return _result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -85,6 +86,6 @@ public class StackBlurManager {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Bitmap returnBlurredImage() {
|
public Bitmap returnBlurredImage() {
|
||||||
return _result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue