Refactor: simplify code

This commit is contained in:
Ming Ming 2022-06-16 19:24:58 +08:00
parent 4d1905863b
commit 12542856a0
3 changed files with 10 additions and 13 deletions

View file

@ -2,10 +2,11 @@ package com.nkming.nc_photos.plugin.image_processor
import android.content.Context
import android.content.res.AssetManager
import android.graphics.*
import android.graphics.Bitmap
import android.net.Uri
import com.nkming.nc_photos.plugin.BitmapResizeMethod
import com.nkming.nc_photos.plugin.BitmapUtil
import com.nkming.nc_photos.plugin.use
/**
* DeepLab is a state-of-art deep learning model for semantic image
@ -23,12 +24,10 @@ class DeepLab3Portrait(
val rgb8Image = BitmapUtil.loadImage(
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
isAllowSwapSide = true, shouldUpscale = false
).let {
).use {
width = it.width
height = it.height
val rgb8 = TfLiteHelper.bitmapToRgb8Array(it)
it.recycle()
rgb8
TfLiteHelper.bitmapToRgb8Array(it)
}
val am = context.assets

View file

@ -6,6 +6,7 @@ import android.graphics.Bitmap
import android.net.Uri
import com.nkming.nc_photos.plugin.BitmapResizeMethod
import com.nkming.nc_photos.plugin.BitmapUtil
import com.nkming.nc_photos.plugin.use
class Esrgan(context: Context, maxWidth: Int, maxHeight: Int) {
fun infer(imageUri: Uri): Bitmap {
@ -15,12 +16,10 @@ class Esrgan(context: Context, maxWidth: Int, maxHeight: Int) {
context, imageUri, maxWidth / 4, maxHeight / 4,
BitmapResizeMethod.FIT, isAllowSwapSide = true,
shouldUpscale = false
).let {
).use {
width = it.width
height = it.height
val rgb8 = TfLiteHelper.bitmapToRgb8Array(it)
it.recycle()
rgb8
TfLiteHelper.bitmapToRgb8Array(it)
}
val am = context.assets

View file

@ -6,6 +6,7 @@ import android.graphics.Bitmap
import android.net.Uri
import com.nkming.nc_photos.plugin.BitmapResizeMethod
import com.nkming.nc_photos.plugin.BitmapUtil
import com.nkming.nc_photos.plugin.use
class ZeroDce(context: Context, maxWidth: Int, maxHeight: Int, iteration: Int) {
fun infer(imageUri: Uri): Bitmap {
@ -14,12 +15,10 @@ class ZeroDce(context: Context, maxWidth: Int, maxHeight: Int, iteration: Int) {
val rgb8Image = BitmapUtil.loadImage(
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
isAllowSwapSide = true, shouldUpscale = false
).let {
).use {
width = it.width
height = it.height
val rgb8 = TfLiteHelper.bitmapToRgb8Array(it)
it.recycle()
rgb8
TfLiteHelper.bitmapToRgb8Array(it)
}
val am = context.assets