mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 21:11:52 +01:00
Minor cleanup
This commit is contained in:
parent
88b56121a3
commit
31b62b2779
@ -292,7 +292,7 @@ class SettingsReaderController : SettingsController() {
|
|||||||
switchPreference {
|
switchPreference {
|
||||||
bindTo(preferences.longStripSplitWebtoon())
|
bindTo(preferences.longStripSplitWebtoon())
|
||||||
titleRes = R.string.pref_long_strip_split
|
titleRes = R.string.pref_long_strip_split
|
||||||
summaryRes = R.string.pref_long_strip_split_summary
|
summaryRes = R.string.split_tall_images_summary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ object ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun findImageType(stream: InputStream): ImageType? {
|
fun findImageType(stream: InputStream): ImageType? {
|
||||||
try {
|
return try {
|
||||||
return when (getImageType(stream)?.format) {
|
when (getImageType(stream)?.format) {
|
||||||
Format.Avif -> ImageType.AVIF
|
Format.Avif -> ImageType.AVIF
|
||||||
Format.Gif -> ImageType.GIF
|
Format.Gif -> ImageType.GIF
|
||||||
Format.Heif -> ImageType.HEIF
|
Format.Heif -> ImageType.HEIF
|
||||||
@ -62,8 +62,8 @@ object ImageUtil {
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExtensionFromMimeType(mime: String?): String {
|
fun getExtensionFromMimeType(mime: String?): String {
|
||||||
@ -185,7 +185,8 @@ object ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class Side {
|
enum class Side {
|
||||||
RIGHT, LEFT
|
RIGHT,
|
||||||
|
LEFT,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,24 +207,20 @@ object ImageUtil {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val bitmapRegionDecoder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
val bitmapRegionDecoder = getBitmapRegionDecoder(imageFile.openInputStream())
|
||||||
BitmapRegionDecoder.newInstance(imageFile.openInputStream())
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
BitmapRegionDecoder.newInstance(imageFile.openInputStream(), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bitmapRegionDecoder == null) {
|
if (bitmapRegionDecoder == null) {
|
||||||
logcat { "Failed to create new instance of BitmapRegionDecoder" }
|
logcat { "Failed to create new instance of BitmapRegionDecoder" }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val options = extractImageOptions(imageFile.openInputStream(), resetAfterExtraction = false).apply { inJustDecodeBounds = false }
|
val options = extractImageOptions(imageFile.openInputStream(), resetAfterExtraction = false).apply {
|
||||||
|
inJustDecodeBounds = false
|
||||||
|
}
|
||||||
|
|
||||||
// Values are stored as they get modified during split loop
|
// Values are stored as they get modified during split loop
|
||||||
val imageWidth = options.outWidth
|
val imageWidth = options.outWidth
|
||||||
|
|
||||||
val splitDataList = getSplitDataForOptions(options)
|
val splitDataList = options.splitData
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
splitDataList.forEach { splitData ->
|
splitDataList.forEach { splitData ->
|
||||||
@ -264,8 +261,8 @@ object ImageUtil {
|
|||||||
*/
|
*/
|
||||||
fun isStripSplitNeeded(imageStream: BufferedInputStream): Boolean {
|
fun isStripSplitNeeded(imageStream: BufferedInputStream): Boolean {
|
||||||
if (isAnimatedAndSupported(imageStream)) return false
|
if (isAnimatedAndSupported(imageStream)) return false
|
||||||
val options = extractImageOptions(imageStream)
|
|
||||||
|
|
||||||
|
val options = extractImageOptions(imageStream)
|
||||||
val imageHeightIsBiggerThanWidth = options.outHeight > options.outWidth
|
val imageHeightIsBiggerThanWidth = options.outHeight > options.outWidth
|
||||||
val imageHeightBiggerThanScreenHeight = options.outHeight > getDisplayMaxHeightInPx
|
val imageHeightBiggerThanScreenHeight = options.outHeight > getDisplayMaxHeightInPx
|
||||||
return imageHeightIsBiggerThanWidth && imageHeightBiggerThanScreenHeight
|
return imageHeightIsBiggerThanWidth && imageHeightBiggerThanScreenHeight
|
||||||
@ -275,16 +272,8 @@ object ImageUtil {
|
|||||||
* Split the imageStream according to the provided splitData
|
* Split the imageStream according to the provided splitData
|
||||||
*/
|
*/
|
||||||
fun splitStrip(imageStream: InputStream, splitData: SplitData): InputStream {
|
fun splitStrip(imageStream: InputStream, splitData: SplitData): InputStream {
|
||||||
val bitmapRegionDecoder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
val bitmapRegionDecoder = getBitmapRegionDecoder(imageStream)
|
||||||
BitmapRegionDecoder.newInstance(imageStream)
|
?: throw Exception("Failed to create new instance of BitmapRegionDecoder")
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
BitmapRegionDecoder.newInstance(imageStream, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bitmapRegionDecoder == null) {
|
|
||||||
throw Exception("Failed to create new instance of BitmapRegionDecoder")
|
|
||||||
}
|
|
||||||
|
|
||||||
logcat {
|
logcat {
|
||||||
"WebtoonSplit #${splitData.index} with topOffset=${splitData.topOffset} " +
|
"WebtoonSplit #${splitData.index} with topOffset=${splitData.topOffset} " +
|
||||||
@ -308,22 +297,21 @@ object ImageUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getSplitDataForStream(imageStream: InputStream): List<SplitData> {
|
fun getSplitDataForStream(imageStream: InputStream): List<SplitData> {
|
||||||
val options = extractImageOptions(imageStream)
|
return extractImageOptions(imageStream).splitData
|
||||||
return getSplitDataForOptions(options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSplitDataForOptions(options: BitmapFactory.Options): List<SplitData> {
|
private val BitmapFactory.Options.splitData
|
||||||
val imageHeight = options.outHeight
|
get(): List<SplitData> {
|
||||||
|
val imageHeight = outHeight
|
||||||
|
|
||||||
val splitHeight = (getDisplayMaxHeightInPx * 1.5).toInt()
|
val splitHeight = (getDisplayMaxHeightInPx * 1.5).toInt()
|
||||||
// -1 so it doesn't try to split when imageHeight = splitHeight
|
// -1 so it doesn't try to split when imageHeight = splitHeight
|
||||||
val partCount = (imageHeight - 1) / splitHeight + 1
|
val partCount = (imageHeight - 1) / splitHeight + 1
|
||||||
|
|
||||||
val optimalSplitHeight = imageHeight / partCount
|
val optimalSplitHeight = imageHeight / partCount
|
||||||
|
|
||||||
logcat {
|
logcat {
|
||||||
"Generating SplitData for image with height of $imageHeight. " +
|
"Generating SplitData for image (height: $imageHeight): " +
|
||||||
"Estimated $partCount part and ${optimalSplitHeight}px height per part"
|
"$partCount parts @ ${optimalSplitHeight}px height per part"
|
||||||
}
|
}
|
||||||
|
|
||||||
return mutableListOf<SplitData>().apply {
|
return mutableListOf<SplitData>().apply {
|
||||||
@ -584,6 +572,15 @@ object ImageUtil {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getBitmapRegionDecoder(imageStream: InputStream): BitmapRegionDecoder? {
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
BitmapRegionDecoder.newInstance(imageStream)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
BitmapRegionDecoder.newInstance(imageStream, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Android doesn't include some mappings
|
// Android doesn't include some mappings
|
||||||
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
private val SUPPLEMENTARY_MIMETYPE_MAPPING = mapOf(
|
||||||
// https://issuetracker.google.com/issues/182703810
|
// https://issuetracker.google.com/issues/182703810
|
||||||
|
@ -297,8 +297,7 @@
|
|||||||
<string name="pref_dual_page_split">Dual page split</string>
|
<string name="pref_dual_page_split">Dual page split</string>
|
||||||
<string name="pref_dual_page_invert">Invert dual page split placement</string>
|
<string name="pref_dual_page_invert">Invert dual page split placement</string>
|
||||||
<string name="pref_dual_page_invert_summary">If the placement of the dual page split doesn\'t match reading direction</string>
|
<string name="pref_dual_page_invert_summary">If the placement of the dual page split doesn\'t match reading direction</string>
|
||||||
<string name="pref_long_strip_split">Split tall images (Alpha)</string>
|
<string name="pref_long_strip_split">Split tall images (BETA)</string>
|
||||||
<string name="pref_long_strip_split_summary">Improves reader performance</string>
|
|
||||||
<string name="pref_cutout_short">Show content in cutout area</string>
|
<string name="pref_cutout_short">Show content in cutout area</string>
|
||||||
<string name="pref_page_transitions">Animate page transitions</string>
|
<string name="pref_page_transitions">Animate page transitions</string>
|
||||||
<string name="pref_double_tap_anim_speed">Double tap animation speed</string>
|
<string name="pref_double_tap_anim_speed">Double tap animation speed</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user