Skip to content

Commit

Permalink
Mark the public non-api classes as final classes & format cpp code
Browse files Browse the repository at this point in the history
  • Loading branch information
HokoFly committed Oct 23, 2023
1 parent d8c583c commit 67b4c9a
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 134 deletions.
14 changes: 0 additions & 14 deletions hoko-blur/src/main/java/com/hoko/blur/anno/ThreadSafe.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Created by yuxfzju on 2017/2/18.
*/

public class NativeBlurFilter {
public final class NativeBlurFilter {
public static void doBlur(@Mode int mode, Bitmap bitmap, int radius, int cores, int index, @Direction int direction) {
switch (mode) {
case HokoBlur.MODE_BOX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Created by yuxfzju on 16/8/29.
*/
public class EglBuffer {
public final class EglBuffer {
private static final String TAG = EglBuffer.class.getSimpleName();

private static final EGL10 EGL = (EGL10) EGLContext.getEGL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static com.hoko.blur.task.AndroidBlurResultDispatcher.MAIN_THREAD_DISPATCHER;

public class HokoBlurBuild implements IBlurBuild {
public final class HokoBlurBuild implements IBlurBuild {

@Mode
int mMode = HokoBlur.MODE_STACK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Created by yuxfzju on 2017/2/7.
*/

public class AndroidBlurResultDispatcher implements IBlurResultDispatcher {
public final class AndroidBlurResultDispatcher implements IBlurResultDispatcher {

public static final IBlurResultDispatcher MAIN_THREAD_DISPATCHER = new AndroidBlurResultDispatcher(SingleMainHandler.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.hoko.blur.api.IBlurProcessor;
import com.hoko.blur.api.IBlurResultDispatcher;

public class BitmapAsyncBlurTask extends AsyncBlurTask<Bitmap> {
public final class BitmapAsyncBlurTask extends AsyncBlurTask<Bitmap> {
public BitmapAsyncBlurTask(IBlurProcessor processor, Bitmap bitmap, Callback callback, IBlurResultDispatcher dispatcher) {
super(processor, bitmap, callback, dispatcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Created by yuxfzju on 2017/2/17.
*/

public class BlurSubTask implements Callable<Void> {
public final class BlurSubTask implements Callable<Void> {

@Scheme
private final int mScheme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.hoko.blur.api.IBlurProcessor;
import com.hoko.blur.api.IBlurResultDispatcher;

public class ViewAsyncBlurTask extends AsyncBlurTask<View> {
public final class ViewAsyncBlurTask extends AsyncBlurTask<View> {
public ViewAsyncBlurTask(IBlurProcessor processor, View target, Callback callback, IBlurResultDispatcher dispatcher) {
super(processor, target, callback, dispatcher);
}
Expand Down
2 changes: 1 addition & 1 deletion hoko-blur/src/main/java/com/hoko/blur/util/BitmapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Created by yuxfzju on 16/9/12.
*/
public class BitmapUtil {
public final class BitmapUtil {
private static final Paint SCALE_PAINT = new Paint();
public static Bitmap getScaledBitmap(Bitmap bitmap, float factor) {
if (bitmap == null) {
Expand Down
2 changes: 1 addition & 1 deletion hoko-blur/src/main/java/com/hoko/blur/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created by yuxfzju on 2017/2/3.
*/

public class MathUtil {
public final class MathUtil {
public static int clamp(int i, int minValue, int maxValue) {
if (i < minValue) {
return minValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import androidx.annotation.Nullable;

public class Preconditions {
public final class Preconditions {
/**
* Ensures that an object reference passed as a parameter to the calling method is not null.
*
Expand Down
2 changes: 1 addition & 1 deletion hoko-blur/src/main/java/com/hoko/blur/util/ShaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Created by yuxfzju on 16/9/4.
*/
public class ShaderUtil {
public final class ShaderUtil {

private static final String TAG = ShaderUtil.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Created by yuxfzju on 2017/2/7.
*/

public class SingleMainHandler {
public final class SingleMainHandler {

private static class MainHandlerHolder {
private static Handler sMainHandler = new Handler(Looper.getMainLooper());
Expand Down
22 changes: 0 additions & 22 deletions hoko-blur/src/main/jni/BlurUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,20 @@ JNIEXPORT void JNICALL
Java_com_hoko_blur_util_BitmapUtil_replaceBitmap(JNIEnv *env, jclass type, jobject jbitmap,
jintArray j_inArray, jint j_x, jint j_y,
jint j_deltaW, jint j_deltaH) {

if (jbitmap == nullptr) {
return;
}

AndroidBitmapInfo bmpInfo = {0};
if (AndroidBitmap_getInfo(env, jbitmap, &bmpInfo) < 0) {
return;
}

int *pixels = nullptr;
if (AndroidBitmap_lockPixels(env, jbitmap, (void **) &pixels) < 0) {
return;
}


jint *c_inArray;
c_inArray = env->GetIntArrayElements(j_inArray, nullptr);

int w = bmpInfo.width;
int h = bmpInfo.height;

for (int i = j_x; i < j_x + j_deltaW; i++) {
for (int j = j_y; j < j_y + j_deltaH; j++) {
jint argb = c_inArray[i - j_x + (j - j_y) * j_deltaW];
Expand All @@ -55,22 +47,8 @@ Java_com_hoko_blur_util_BitmapUtil_replaceBitmap(JNIEnv *env, jclass type, jobje
pixels[i + j * w] = a + r + g + b;
}
}
// for(int i = j_y * w; i < w * (j_y + j_deltaH); i ++) {
// jint argb = c_inArray[i];
// jint a = ((argb >> 24) & 0xff) << 24;
// jint r = (argb >> 16) & 0xff;
// jint g = ((argb >> 8) & 0xff) << 8;
// jint b = (argb & 0xff) << 16;
//
// pixels[i] = a + r + g + b;
//
// }
// __android_log_print(ANDROID_LOG_ERROR, "unlockPixels", "unlockPixels");

AndroidBitmap_unlockPixels(env, jbitmap);

env->ReleaseIntArrayElements(j_inArray, c_inArray, 0);

}

#ifdef __cplusplus
Expand Down
29 changes: 4 additions & 25 deletions hoko-blur/src/main/jni/BoxBlurFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ extern "C" {

void boxBlurHorizontal(jint *in, jint *out, jint width, jint height, jint radius, jint startX,
jint startY, jint deltaX, jint deltaY) {
jint widthMinus1 = width - 1;
jint tableSize = 2 * radius + 1;
jint divide[256 * tableSize];

for (jint i = 0; i < 256 * tableSize; i++)
for (jint i = 0; i < 256 * tableSize; i++) {
divide[i] = i / tableSize;

}
for (jint y = startY; y < startY + deltaY; y++) {
jint ta = 0, tr = 0, tg = 0, tb = 0;

Expand All @@ -32,7 +30,6 @@ void boxBlurHorizontal(jint *in, jint *out, jint width, jint height, jint radius
jint baseIndex = y * width;

for (jint x = startX; x < startX + deltaX; x++) {

jint i1 = x + radius + 1;
if (i1 > startX + deltaX - 1)
i1 = startX + deltaX - 1;
Expand All @@ -56,28 +53,23 @@ void boxBlurHorizontal(jint *in, jint *out, jint width, jint height, jint radius

void boxBlurVertical(jint *in, jint *out, jint width, jint height, jint radius, jint startX, jint startY,
jint deltaX, jint deltaY) {
jint heightMinus1 = height - 1;
jint tableSize = 2 * radius + 1;
jint divide[256 * tableSize];

for (jint i = 0; i < 256 * tableSize; i++)
for (jint i = 0; i < 256 * tableSize; i++) {
divide[i] = i / tableSize;

}
for (jint x = startX; x < startX + deltaX; x++) {
jint ta = 0, tr = 0, tg = 0, tb = 0;

for (jint i = -radius; i <= radius; i++) {
jint rgb = in[x + clamp(i, startY, startY + deltaY - 1) * width];
ta += (rgb >> 24) & 0xff;
tr += (rgb >> 16) & 0xff;
tg += (rgb >> 8) & 0xff;
tb += rgb & 0xff;
}

for (jint y = startY; y < startY + deltaY; y++) {
out[y * width + x] = (divide[ta] << 24) | (divide[tr] << 16) | (divide[tg] << 8) |
divide[tb];

jint i1 = y + radius + 1;
if (i1 > startY + deltaY - 1)
i1 = startY + deltaY - 1;
Expand All @@ -101,56 +93,43 @@ Java_com_hoko_blur_filter_NativeBlurFilter_nativeBoxBlur(JNIEnv *env, jclass typ
jobject jbitmap, jint j_radius,
jint j_cores, jint j_index,
jint j_direction) {

if (jbitmap == nullptr) {
return;
}

AndroidBitmapInfo bmpInfo = {0};
if (AndroidBitmap_getInfo(env, jbitmap, &bmpInfo) < 0) {
return;
}

int *pixels = nullptr;
if (AndroidBitmap_lockPixels(env, jbitmap, (void **) &pixels) < 0) {
return;
}

int w = bmpInfo.width;
int h = bmpInfo.height;

jint *copy = nullptr;
copy = (jint *) malloc(sizeof(jint) * w * h);

for (int i = 0; i < w * h; i++) {
copy[i] = pixels[i];
}

if (j_direction == HORIZONTAL) {
int deltaY = h / j_cores;
int startY = j_index * deltaY;

if (j_index == j_cores - 1) {
deltaY = h - (j_cores - 1) * deltaY;
}

boxBlurHorizontal(copy, pixels, w, h, j_radius, 0, startY, w, deltaY);

} else if (j_direction == VERTICAL) {
int deltaX = w / j_cores;
int startX = j_index * deltaX;

if (j_index == j_cores - 1) {
deltaX = w - (j_cores - 1) * (w / j_cores);
}

boxBlurVertical(copy, pixels, w, h, j_radius, startX, 0, deltaX, h);
}

AndroidBitmap_unlockPixels(env, jbitmap);

free(copy);

}

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion hoko-blur/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.6)
project(Hoko_blur)
project(HokoBlur)

set(CMAKE_CXX_STANDARD 11)

Expand Down
Loading

0 comments on commit 67b4c9a

Please sign in to comment.