mirror of
https://github.com/gedoor/legado.git
synced 2024-07-17 00:58:29 +08:00
优化
This commit is contained in:
parent
706a7fd878
commit
d1b3ce8a7b
@ -246,6 +246,8 @@ dependencies {
|
||||
//加解密类库
|
||||
implementation('cn.hutool:hutool-crypto:5.7.22')
|
||||
|
||||
implementation('com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3')
|
||||
|
||||
//代码编辑com.github.AmrDeveloper:CodeView已集成到应用内
|
||||
//epubLib集成到应用内
|
||||
|
||||
|
@ -1,75 +0,0 @@
|
||||
package io.legado.app.help
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import android.renderscript.Allocation
|
||||
import android.renderscript.Element
|
||||
import android.renderscript.RenderScript
|
||||
import android.renderscript.ScriptIntrinsicBlur
|
||||
import androidx.annotation.IntRange
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||
import java.security.MessageDigest
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
* @radius: 0..25
|
||||
*/
|
||||
class BlurTransformation(
|
||||
context: Context,
|
||||
@IntRange(from = 0, to = 25) private val radius: Int
|
||||
) : CenterCrop() {
|
||||
|
||||
private val rs: RenderScript = RenderScript.create(context)
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
override fun transform(
|
||||
pool: BitmapPool,
|
||||
toTransform: Bitmap,
|
||||
outWidth: Int,
|
||||
outHeight: Int
|
||||
): Bitmap {
|
||||
val transform = super.transform(pool, toTransform, outWidth, outHeight)
|
||||
//图片缩小1/2
|
||||
val width = (min(outWidth, transform.width) / 2f).roundToInt()
|
||||
val height = (min(outHeight, transform.height) / 2f).roundToInt()
|
||||
val blurredBitmap = Bitmap.createScaledBitmap(transform, width, height, false)
|
||||
// Allocate memory for Renderscript to work with
|
||||
//分配用于渲染脚本的内存
|
||||
val input = Allocation.createFromBitmap(
|
||||
rs,
|
||||
blurredBitmap,
|
||||
Allocation.MipmapControl.MIPMAP_FULL,
|
||||
Allocation.USAGE_SHARED
|
||||
)
|
||||
val output = Allocation.createTyped(rs, input.type)
|
||||
|
||||
// Load up an instance of the specific script that we want to use.
|
||||
//加载我们想要使用的特定脚本的实例。
|
||||
val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
|
||||
script.setInput(input)
|
||||
|
||||
// Set the blur radius
|
||||
//设置模糊半径0..25
|
||||
script.setRadius(radius.toFloat())
|
||||
|
||||
// Start the ScriptIntrinsicBlur
|
||||
//启动 ScriptIntrinsicBlur,
|
||||
script.forEach(output)
|
||||
|
||||
// Copy the output to the blurred bitmap
|
||||
//将输出复制到模糊的位图
|
||||
output.copyTo(blurredBitmap)
|
||||
|
||||
return blurredBitmap
|
||||
}
|
||||
|
||||
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
|
||||
messageDigest.update("blur transformation".toByteArray())
|
||||
}
|
||||
}
|
@ -73,7 +73,7 @@ object ThemeConfig {
|
||||
if (bgCfg.second == 0) {
|
||||
return bgImage
|
||||
}
|
||||
return bgImage.stackBlur(bgCfg.second.toFloat())
|
||||
return bgImage.stackBlur(bgCfg.second)
|
||||
}
|
||||
|
||||
fun upConfig() {
|
||||
|
@ -0,0 +1,41 @@
|
||||
package io.legado.app.help.glide
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Build
|
||||
import androidx.annotation.IntRange
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||
import io.legado.app.utils.stackBlur
|
||||
import java.security.MessageDigest
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
/**
|
||||
* 模糊
|
||||
* @radius: 0..25
|
||||
*/
|
||||
class BlurTransformation(
|
||||
@IntRange(from = 0, to = 25) private val radius: Int
|
||||
) : CenterCrop() {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
override fun transform(
|
||||
pool: BitmapPool,
|
||||
toTransform: Bitmap,
|
||||
outWidth: Int,
|
||||
outHeight: Int
|
||||
): Bitmap {
|
||||
val transform = super.transform(pool, toTransform, outWidth, outHeight)
|
||||
//图片缩小1/2
|
||||
val width = (min(outWidth, transform.width) / 5f).roundToInt()
|
||||
val height = (min(outHeight, transform.height) / 5f).roundToInt()
|
||||
val blurredBitmap = Bitmap.createScaledBitmap(transform, width, height, false)
|
||||
return blurredBitmap.stackBlur(radius)
|
||||
}
|
||||
|
||||
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
|
||||
messageDigest.update("blur transformation".toByteArray())
|
||||
}
|
||||
}
|
@ -11,10 +11,10 @@ import io.legado.app.R
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.data.entities.BaseSource
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.help.BlurTransformation
|
||||
import io.legado.app.help.CacheManager
|
||||
import io.legado.app.help.DefaultData
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.glide.BlurTransformation
|
||||
import io.legado.app.help.glide.ImageLoader
|
||||
import io.legado.app.help.glide.OkHttpModelLoader
|
||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||
@ -86,7 +86,7 @@ object BookCover {
|
||||
loadOnlyWifi: Boolean = false
|
||||
): RequestBuilder<Drawable> {
|
||||
val loadBlur = ImageLoader.load(context, defaultDrawable)
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25)))
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(25)))
|
||||
return if (AppConfig.useDefaultCover) {
|
||||
loadBlur.centerCrop()
|
||||
} else {
|
||||
@ -95,7 +95,7 @@ object BookCover {
|
||||
.apply(options)
|
||||
.transition(DrawableTransitionOptions.withCrossFade(1500))
|
||||
.thumbnail(loadBlur)
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(context, 25)))
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(25)))
|
||||
.centerCrop()
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,8 @@ package io.legado.app.utils
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.graphics.Bitmap.Config
|
||||
import android.renderscript.Allocation
|
||||
import android.renderscript.Element
|
||||
import android.renderscript.RenderScript
|
||||
import android.renderscript.ScriptIntrinsicBlur
|
||||
import android.view.View
|
||||
import splitties.init.appCtx
|
||||
import com.google.android.renderscript.Toolkit
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import kotlin.math.*
|
||||
@ -250,33 +246,9 @@ fun Bitmap.changeSize(newWidth: Int, newHeight: Int): Bitmap {
|
||||
/**
|
||||
* 高斯模糊
|
||||
*/
|
||||
fun Bitmap.stackBlur(radius: Float = 8f): Bitmap? {
|
||||
val rs = RenderScript.create(appCtx)
|
||||
fun Bitmap.stackBlur(radius: Int = 8): Bitmap {
|
||||
val blurredBitmap = this.copy(Config.ARGB_8888, true)
|
||||
|
||||
//分配用于渲染脚本的内存
|
||||
val input = Allocation.createFromBitmap(
|
||||
rs,
|
||||
blurredBitmap,
|
||||
Allocation.MipmapControl.MIPMAP_FULL,
|
||||
Allocation.USAGE_SHARED
|
||||
)
|
||||
val output = Allocation.createTyped(rs, input.type)
|
||||
|
||||
//加载我们想要使用的特定脚本的实例。
|
||||
val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
|
||||
script.setInput(input)
|
||||
|
||||
//设置模糊半径
|
||||
script.setRadius(radius)
|
||||
|
||||
//启动 ScriptIntrinsicBlur
|
||||
script.forEach(output)
|
||||
|
||||
//将输出复制到模糊的位图
|
||||
output.copyTo(blurredBitmap)
|
||||
|
||||
return blurredBitmap
|
||||
return Toolkit.blur(blurredBitmap, radius)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user