Git Product home page Git Product logo

hokoblur's Introduction

HokoBlur

(中文版本请参看这里)

HokoBlur is an Android component which provides dynamic blur effect.

See the Kotlin implement HokoBlur-Kotlin

1. Introductions

  • Functions:

    • Add blur to the image;
    • Dynamic blur, real-time blurring of the background
  • Features:

    • Multiple schemes: RenderScript、OpenGL、Native and Java;
    • Multiple algorithms: Box、Stack and Gaussian algorithms. Provide different blur effect;
    • Multi-core and multi-threading, accelerate blurring,asynchronous interface;

2. Getting started

Download

   implementation 'io.github.hokofly:hoko-blur:1.5.3'

Static Blur

synchronous api

HokoBlur.with(context)
    .scheme(Blur.SCHEME_NATIVE) //different implementation, RenderScript、OpenGL、Native(default) and Java
    .mode(Blur.MODE_STACK) //blur algorithms,Gaussian、Stack(default) and Box
    .radius(10) //blur radius,max=25,default=5
    .sampleFactor(2.0f) //scale factor,if factor=2,the width and height of a bitmap will be scale to 1/2 sizes,default=5
    .forceCopy(false) //If scale factor=1.0f,the origin bitmap will be modified. You could set forceCopy=true to avoid it. default=false
    .translateX(150)//add x axis offset when blurring
    .translateY(150)//add y axis offset when blurring
    .processor() //build a blur processor
    .blur(bitmap);	//blur a bitmap, synchronous method

Daily development does not need such complicated settings. If you want a blur effect, just use as follow:

Bitmap outBitmap = Blur.with(context).blur(bitmap);

When it comes to a large size bitmap, it is recommended to use an asynchronous method. The blur job could be cancelled.

Future f = HokoBlur.with(this)
    .scheme(Blur.SCHEME_NATIVE)
    .mode(Blur.MODE_STACK)
    .radius(10)
    .sampleFactor(2.0f)
    .forceCopy(false)
    .asyncBlur(bitmap, new AsyncBlurTask.CallBack() {
        @Override
        public void onBlurSuccess(Bitmap outBitmap) {
        	// do something...
        }

        @Override
        public void onBlurFailed() {

        }
    });
f.cancel(false);    

3. Sample

Animation

动态模糊

Arbitrary Locaton Blur

动态模糊

4. Dynamic background blur

Dynamic Blur provides real-time background blurring of View and ViewGroup, not based on Bitmap implementations. The component will blur the area where the View is located. See the repository HokoBlurDrawable.

动态模糊

5. Tips

  1. When the Bitmap is not scaled (sampleFactor(1.0f)), the incoming Bitmap will be directly modified by the subsequent operations. So when the function returns a bitmap, it can be used immediately.

  2. It is strongly recommended to use the downScale operation before the blur operation to reduce the size of the blurred image, which will greatly improve the blur efficiency and effect.

  3. Please limit the blur radius to 25. Increasing the radius leads to much less blur effect increase than by increasing the scale factor, and if the radius increase, blur efficiency will also decrease;

  4. The RenderScript solution has to be verified for compatibility. If there are scenarios that require more computation and more complex blurring, the RenderScript scheme may be better.

  5. Algorithm selection

    • If you have low effect requirements for blurring and want to blur the image faster, please choose Box algorithm.;
    • If you have a higher effect requirement for blurring and can tolerate slower blurring of the image, please choose the Gaussian algorithm;
    • The Stack algorithm has a blur effect that is very close to the Gaussian algorithm, and it improves the efficiency. Generally, the Stack algorithm is recommended;
  6. BlurDrawable is implemented by OpenGL, so if the hardware acceleration is not enabled, the background blur will be invalid.

  7. Sample and usage. Please see the sample project.

hokoblur's People

Contributors

hokofly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hokoblur's Issues

OPENGL scheme is causing a memory leak

First, thanks for that great work. Second, once I set the scheme to OPENGL and turn the app with the profiler and start sending camera frames(30 fps) to the api, it works fine but I can see the memory consumption in the profiler is getting increased to 100mb by 100 mb until it is 2.5 GB then the app crashes. For one image, it is ok but since I am working with a stream it is not ok, I was able to solve that by setting mode to NATIVE, I will try to solve that in the next days if I managed to find enough time and make a PR. Thanks agains :)

x86_64模拟器下无法链接so

报错:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libhoko_blur.so" not found

aar中找不到x86_64的libhoko_blur.so文件
截屏2020-08-21 下午5 29 12

Add a License

Hi,

I really like your Library and it's great at doing what it should do, we're now using it (or well our slimmed down fork of it) in the V2 versions of Lawnchair Launcher.

But exactly because we have made a fork I would be very glad if you could add some Open Source license to your library or at least clearly stated the licensing terms of it in the README. Without a license your library technically counts as proprietary and any fork or anyone modifying it/using parts of it is in danger of being sued by you if you ever decided to do so.

If you're unsure which license to choose you can use <choosealicense.com> for a little help, or ask here.

闪退问题

11-23 14:14:24.223 32679-321/com.amez.mall E/CrashReport-Native: Faile to open comm file(/system/build.prop)
11-23 14:14:24.441 32679-321/com.amez.mall E/CrashReport-Native: Failed to get java thread with thread name: RenderThread

在华为P9P的8.0.0上没有问题,在一加5的8.1.0上出现上面问题

opengl的shader的写法存在机型兼容性问题

private static String getGaussianSampleCode() {

    StringBuilder sb = new StringBuilder();

    sb.append("   int diameter = 2 * uRadius + 1;  \n")
            .append("   vec4 sampleTex;\n")
            .append("   vec3 col;  \n")
            .append("   float weightSum = 0.0; \n")
            .append("   for(int i = 0; i < diameter; i++) {\n")
            .append("       vec2 offset = vec2(float(i - uRadius) * uWidthOffset, float(i - uRadius) * uHeightOffset);  \n")
            .append("       sampleTex = vec4(texture2D(uTexture, vTexCoord.st+offset));\n")
            .append("       float index = float(i); \n")
            .append("       float gaussWeight = getGaussWeight(index - float(diameter - 1)/2.0,")
            .append("           (float(diameter - 1)/2.0 + 1.0) / 2.0); \n")
            .append("       col += sampleTex.rgb * gaussWeight; \n")
            .append("       weightSum += gaussWeight;\n")
            .append("   }   \n")
            .append("   gl_FragColor = vec4(col / weightSum, sampleTex.a);   \n");

    return sb.toString();
}

如上:vec3 col的写法最好写成vec3 col = vec3(0.0,0.0,0.0);主动进行初始化,否则在一些机型上会有问题,导致最终渲染效果不正确

Strange unblurred line when using custom sampleFactor

I am seeing this
wallpaper-gaussian

My code

        return if (!isApplyBlur) bitmap else HokoBlur.with(context)
            .scheme(HokoBlur.SCHEME_NATIVE) //different implementation, RenderScript、OpenGL、Native(default) and Java
            .mode(HokoBlur.MODE_GAUSSIAN) //blur algorithms,Gaussian、Stack(default) and Box
            .radius(2) //blur radius,max=25,default=5
            .sampleFactor(7f) //scale factor,if factor=2,the width and height of a bitmap will be scale to 1/2 sizes,default=5. An odd value will create a unblur line (bug)
//            .forceCopy(false) //If scale factor=1.0f,the origin bitmap will be modified. You could set forceCopy=true to avoid it. default=false
//            .needUpscale(true) //After blurring,the bitmap will be up-scaled to origin sizes,default=true
//            .processor() //build a blur processor
            .blur(bitmap)  

Running on Android 13, hokoblur version 1.4.0

  • Sample size of 7 will fix problem in Pixel 4a, but cause problem in S22 ultra
  • Sample size of 9 will fix problem on Pixel 4a and S22 Ultra, but cause problem in other devices
  • Sample size of 8 will fix problem on others but not on Pixel 4a

So it is screen size related, most likely, but what should the sampleFactor be related to screensize?

I also tried HokoBlur.STACK but then instead of 2 lines I will get 1 line on the right most of the bitmap
wallpaper-stacked

Hard to see
Screen-Shot-2023-06-14-at-4-33-19-PM

Not working on Android Pie

Hey, great library, love the performance of it. Any idea why the BlurDrawable.java does'nt work on Android Pie?

在Fragment里初始化的时候显示黑色

MainActivity中放了一个ViewPager,其中放了三个Fragment,第一个Fragment里面放了一个子Fragment,最后这个Fragment里面放了blur的三个布局,启动app的时候,默认加载都是显示黑色,触摸移动后正常显示毛玻璃化。

Mac 电脑中编译报错了,是要用Windows编译吗?

Skipped RenderScript support mode compilation for mips : required components not found in Build-Tools 28.0.3
Please check and update your BuildTools.
Skipped RenderScript support mode compilation for mips : required components not found in Build-Tools 28.0.3
Please check and update your BuildTools.
warning: Linking two modules of different data layouts: '/Users/lixin/work/android/sdk/build-tools/28.0.3/renderscript/lib/bc/armeabi-v7a/libclcore.bc' is 'e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64' whereas '/Users/lixin/work/git/HokoBlur/hoko-blur/build/generated/res/rs/debug/raw/bc32/boxblur.bc' is 'e-p:32:32-i64:64-v128:64:128-n32-S64'

warning: Linking two modules of different target triples: /Users/lixin/work/android/sdk/build-tools/28.0.3/renderscript/lib/bc/armeabi-v7a/libclcore.bc' is 'armv7--linux-android' whereas '/Users/lixin/work/git/HokoBlur/hoko-blur/build/generated/res/rs/debug/raw/bc32/boxblur.bc' is 'armv7-none-linux-gnueabi'

warning: Linking two modules of different data layouts: '/Users/lixin/work/android/sdk/build-tools/28.0.3/renderscript/lib/bc/armeabi-v7a/libclcore.bc' is 'e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64' whereas '/Users/lixin/work/git/HokoBlur/hoko-blur/build/generated/res/rs/debug/raw/bc32/stackblur.bc' is 'e-p:32:32-i64:64-v128:64:128-n32-S64'

warning: Linking two modules of different target triples: /Users/lixin/work/android/sdk/build-tools/28.0.3/renderscript/lib/bc/armeabi-v7a/libclcore.bc' is 'armv7--linux-android' whereas '/Users/lixin/work/git/HokoBlur/hoko-blur/build/generated/res/rs/debug/raw/bc32/stackblur.bc' is 'armv7-none-linux-gnueabi'

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':hoko-blur:compileDebugRenderscript'.

A problem occurred starting process 'command '/Users/lixin/work/android/sdk/build-tools/28.0.3/arm-linux-androideabi-ld''

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 5s
10 actionable tasks: 1 executed, 9 up-to-date
ERROR: Cause: error=86, Bad CPU type in executable

开了硬件加速,但是BlurDrawable还是无效

第一次执行无效,第二次app就闪退是为什么?我运行您的demo却没有问题。但是我看你的demo都没有配置什么东西,甚至硬件加速也只有MultiBlurActivity这个开了。
log只有:
E/libEGL: call to OpenGL ES API with no current context (logged once per thread) E/OpenGLRenderer: GL error: 0x506 A/OpenGLRenderer: GL errors! frameworks/base/libs/hwui/BakedOpRenderer.cpp:98 A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 18772 (RenderThread)

接入高德地图崩溃 Too large blur size, check width < 1800 and height < 3200

 --------- beginning of crash
2019-01-15 17:53:47.627 9869-9890/com.ocom.showdataproject A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 9890 (RenderThread)
2019-01-15 17:53:47.709 9939-9939/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2019-01-15 17:53:47.709 9939-9939/? A/DEBUG: Build fingerprint: 'Xiaomi/capricorn/capricorn:7.0/NRD90M/8.9.6:user/release-keys'
2019-01-15 17:53:47.709 9939-9939/? A/DEBUG: Revision: '0'
2019-01-15 17:53:47.709 9939-9939/? A/DEBUG: ABI: 'arm'
2019-01-15 17:53:47.710 9939-9939/? A/DEBUG: pid: 9869, tid: 9890, name: RenderThread  >>> com.ocom.showdataproject <<<
2019-01-15 17:53:47.710 9939-9939/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
2019-01-15 17:53:47.715 9939-9939/? A/DEBUG: Abort message: 'art/runtime/java_vm_ext.cc:475] JNI DETECTED ERROR IN APPLICATION: JNI GetStaticMethodID called with pending exception java.lang.IllegalArgumentException: Too large blur size, check width < 1800 and height < 3200'
2019-01-15 17:53:47.716 9939-9939/? A/DEBUG:     r0 00000000  r1 000026a2  r2 00000006  r3 00000008
2019-01-15 17:53:47.716 9939-9939/? A/DEBUG:     r4 d0cdf978  r5 00000006  r6 d0cdf920  r7 0000010c
2019-01-15 17:53:47.716 9939-9939/? A/DEBUG:     r8 00000000  r9 ecd69a54  sl 00000dd7  fp ecd2ef4f
2019-01-15 17:53:47.716 9939-9939/? A/DEBUG:     ip 0000000b  sp d0cdee78  lr ef2d52c7  pc ef2d7b48  cpsr 200f0010
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG: backtrace:
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #00 pc 00049b48  /system/lib/libc.so (tgkill+12)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #01 pc 000472c3  /system/lib/libc.so (pthread_kill+34)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #02 pc 0001d565  /system/lib/libc.so (raise+10)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #03 pc 000190b1  /system/lib/libc.so (__libc_android_abort+34)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #04 pc 00017114  /system/lib/libc.so (abort+4)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #05 pc 003196a5  /system/lib/libart.so (_ZN3art7Runtime5AbortEv+252)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #06 pc 000b5391  /system/lib/libart.so (_ZN3art10LogMessageD2Ev+864)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #07 pc 0023894d  /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1664)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #08 pc 00238b3f  /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+58)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #09 pc 000cad8b  /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+46)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #10 pc 000ca977  /system/lib/libart.so (_ZN3art11ScopedCheck11CheckThreadEP7_JNIEnv+362)
2019-01-15 17:53:47.735 9939-9939/? A/DEBUG:     #11 pc 000c998f  /system/lib/libart.so (_ZN3art11ScopedCheck22CheckPossibleHeapValueERNS_18ScopedObjectAccessEcNS_12JniValueTypeE+26)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #12 pc 000c8e6b  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE+802)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #13 pc 000cc329  /system/lib/libart.so (_ZN3art8CheckJNI19GetMethodIDInternalEPKcP7_JNIEnvP7_jclassS2_S2_b+464)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #14 pc 000c3725  /system/lib/libart.so (_ZN3art8CheckJNI17GetStaticMethodIDEP7_JNIEnvP7_jclassPKcS6_+24)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #15 pc 00008517  /data/app/com.ocom.showdataproject-1/lib/arm/libhoko_blur.so (postEventFromNativeC+98)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #16 pc 000089fd  /data/app/com.ocom.showdataproject-1/lib/arm/libhoko_blur.so (_ZN7android11DrawFunctorclEiPv+4)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #17 pc 00021fef  /system/lib/libhwui.so
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #18 pc 00060915  /system/lib/libhwui.so
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #19 pc 00064657  /system/lib/libhwui.so
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #20 pc 00023c09  /system/lib/libhwui.so
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #21 pc 00023801  /system/lib/libhwui.so
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #22 pc 000252c7  /system/lib/libhwui.so
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #23 pc 000286f9  /system/lib/libhwui.so (_ZN7android10uirenderer12renderthread12RenderThread10threadLoopEv+80)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #24 pc 0000e575  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #25 pc 000647ed  /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+80)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #26 pc 00046d93  /system/lib/libc.so (_ZL15__pthread_startPv+22)
2019-01-15 17:53:47.736 9939-9939/? A/DEBUG:     #27 pc 00019afd  /system/lib/libc.so (__start_thread+6)
2019-01-15 17:53:48.036 9940-9940/? E/GpuMonitor: fital error, can not mkdir:/sdcard/MIUI/debug_log/common, errno:13
2019-01-15 17:53:49.003 577-577/? E/lowmemorykiller: Error writing /proc/9869/oom_score_adj; errno=22
2019-01-15 17:53:49.293 1879-1879/? E/PropertyValuesHolder: java.lang.reflect.InvocationTargetException
2019-01-15 17:53:49.293 1879-1879/? E/PropertyValuesHolder: java.lang.reflect.InvocationTargetException
2019-01-15 17:53:49.346 472-2618/? E/ANDR-PERF-OPTSHANDLER: perf_lock_rel: updated /sys/class/scsi_host/host0/../../../clkscale_enable with 1
     return value 2

触发方式:横屏应用页面接入高德地图 同时使用BlurRelativeLayout 高度200dp 宽度设置match_parent
打开此页面会崩溃

安装环境 :小米5s
Android7.0
分辨率1080*1920

OverlayColor特性的支持

在布局背景模糊或者动态模糊完成后,如果布局内的控件例如一个textview背景使用了android:background="?android:selectableItemBackground",并赋予点击事件监听,当点击这个textview的时候,背景模糊效果会出现在textview区域内失效,我在你的demo里试验了这个问题,存在。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.