implement basic methods for descrambling images
This commit is contained in:
@@ -82,7 +82,11 @@ afterEvaluate {
|
||||
}
|
||||
dependencies {
|
||||
//noinspection GradleDependency
|
||||
implementation('com.github.KotatsuApp:kotatsu-parsers:078b59b1e2') {
|
||||
// TODO: change bac
|
||||
// implementation('com.github.KotatsuApp:kotatsu-parsers:078b59b1e2') {
|
||||
// exclude group: 'org.json', module: 'json'
|
||||
// }
|
||||
implementation('com.github.AwkwardPeak7:kotatsu-parsers:d7d42465de') {
|
||||
exclude group: 'org.json', module: 'json'
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.koitharu.kotatsu.core.parser
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Bitmap as AndroidBitmap
|
||||
import android.graphics.Rect as AndroidRect
|
||||
import org.koitharu.kotatsu.parsers.bitmap.Bitmap
|
||||
import org.koitharu.kotatsu.parsers.bitmap.Rect
|
||||
|
||||
class BitmapImpl private constructor() : Bitmap {
|
||||
|
||||
lateinit var androidBitmap: AndroidBitmap
|
||||
|
||||
private lateinit var canvas: Canvas
|
||||
|
||||
override val height: Int
|
||||
get() = androidBitmap.height
|
||||
|
||||
override val width: Int
|
||||
get() = androidBitmap.width
|
||||
|
||||
override fun drawBitmap(sourceBitmap: Bitmap, src: Rect, dst: Rect) {
|
||||
val androidSourceBitmap = (sourceBitmap as BitmapImpl).androidBitmap
|
||||
|
||||
canvas.drawBitmap(androidSourceBitmap, src.toAndroidRect(), dst.toAndroidRect(), null)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(width: Int, height: Int): Bitmap {
|
||||
val instance = BitmapImpl()
|
||||
instance.androidBitmap = AndroidBitmap.createBitmap(width, height, AndroidBitmap.Config.ARGB_8888)
|
||||
instance.canvas = Canvas(instance.androidBitmap)
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
fun create(bitmap: AndroidBitmap): Bitmap {
|
||||
val instance = BitmapImpl()
|
||||
instance.androidBitmap = bitmap.copy(AndroidBitmap.Config.ARGB_8888, true)
|
||||
instance.canvas = Canvas(instance.androidBitmap)
|
||||
|
||||
return instance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Rect.toAndroidRect(): AndroidRect {
|
||||
return AndroidRect(left, top, right, bottom)
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.koitharu.kotatsu.core.parser
|
||||
|
||||
import android.graphics.Bitmap as AndroidBitmap
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.BitmapFactory
|
||||
import android.util.Base64
|
||||
import android.webkit.WebView
|
||||
import androidx.annotation.MainThread
|
||||
@@ -10,7 +12,11 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.asResponseBody
|
||||
import okio.Buffer
|
||||
import org.koitharu.kotatsu.core.network.MangaHttpClient
|
||||
import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar
|
||||
import org.koitharu.kotatsu.core.prefs.SourceSettings
|
||||
@@ -19,6 +25,7 @@ import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
||||
import org.koitharu.kotatsu.core.util.ext.sanitizeHeaderValue
|
||||
import org.koitharu.kotatsu.core.util.ext.toList
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.bitmap.Bitmap
|
||||
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.network.UserAgents
|
||||
@@ -68,6 +75,28 @@ class MangaLoaderContextImpl @Inject constructor(
|
||||
return LocaleListCompat.getAdjustedDefault().toList()
|
||||
}
|
||||
|
||||
override fun redrawImageResponse(response: Response, redraw: (image: Bitmap) -> Bitmap): Response {
|
||||
val image = requireNotNull(response.body) {
|
||||
"Response is null"
|
||||
}.byteStream()
|
||||
|
||||
val bitmap = BitmapFactory.decodeStream(image)
|
||||
val result = redraw(BitmapImpl.create(bitmap)) as BitmapImpl
|
||||
|
||||
val body = Buffer().run {
|
||||
result.androidBitmap.compress(AndroidBitmap.CompressFormat.JPEG, 90, outputStream())
|
||||
asResponseBody("image/jpeg".toMediaType())
|
||||
}
|
||||
|
||||
return response.newBuilder()
|
||||
.body(body)
|
||||
.build()
|
||||
}
|
||||
|
||||
override fun createBitmap(width: Int, height: Int): Bitmap {
|
||||
return BitmapImpl.create(width, height)
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private fun obtainWebView(): WebView {
|
||||
return webViewCached?.get() ?: WebView(androidContext).also {
|
||||
|
||||
Reference in New Issue
Block a user