-
Notifications
You must be signed in to change notification settings - Fork 293
Real ESRGAN Support Suwayomi - Updated with fixes #1684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
9c5fa50
db87ee1
2aeed85
0826b38
e55d96f
f4df615
219388a
d2f1a01
6618bce
92b087d
cd5b63a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,14 @@ import suwayomi.tachidesk.manga.impl.util.storage.ImageUtil | |
| import suwayomi.tachidesk.manga.model.table.ChapterTable | ||
| import suwayomi.tachidesk.manga.model.table.MangaTable | ||
| import suwayomi.tachidesk.manga.model.table.PageTable | ||
| import suwayomi.tachidesk.server.serverConfig | ||
| import suwayomi.tachidesk.util.ConversionUtil | ||
| import java.io.ByteArrayInputStream | ||
| import java.io.ByteArrayOutputStream | ||
| import java.io.File | ||
| import java.io.InputStream | ||
| import java.io.PipedInputStream | ||
| import java.io.PipedOutputStream | ||
| import javax.imageio.ImageIO | ||
|
|
||
| object Page { | ||
|
|
@@ -142,20 +145,49 @@ object Page { | |
| image: Pair<InputStream, String>, | ||
| format: String? = null, | ||
| ): Pair<InputStream, String> { | ||
| val imageExtension = MimeUtils.guessExtensionFromMimeType(image.second) ?: image.second.removePrefix("image/") | ||
| var currentImage = image | ||
| var currentMimeType = image.second | ||
|
|
||
| // Step 1: Check if HTTP upscaling is configured | ||
| val conversions = serverConfig.downloadConversions.value | ||
| val defaultConversion = conversions["default"] | ||
| val imageType = image.second | ||
| val conversion = conversions[imageType] ?: defaultConversion | ||
|
||
|
|
||
| // Apply HTTP upscaling if configured (complementary with format conversion) | ||
| if (conversion != null && ConversionUtil.isHttpConversion(conversion)) { | ||
| try { | ||
| val upscaledStream = ConversionUtil.upscaleImageHttp(currentImage.first, currentMimeType, conversion.target) | ||
| if (upscaledStream != null) { | ||
| // Update current image to upscaled version | ||
| currentImage = Pair(upscaledStream, "image/jpeg") // HTTP upscaler returns JPEG | ||
| currentMimeType = "image/jpeg" | ||
| } | ||
| } catch (e: Exception) { | ||
| // HTTP upscaling failed, continue with original image | ||
| } | ||
| } | ||
|
|
||
| val targetExtension = | ||
| (if (format != imageExtension) format else null) | ||
| ?: return image | ||
| // Step 2: Apply format conversion if requested (works on upscaled or original image) | ||
| val imageExtension = MimeUtils.guessExtensionFromMimeType(currentMimeType) ?: currentMimeType.removePrefix("image/") | ||
| val targetExtension = (if (format != imageExtension) format else null) ?: return currentImage | ||
|
|
||
| return convertToFormat(currentImage.first, currentMimeType, targetExtension) | ||
| } | ||
|
|
||
| private fun convertToFormat( | ||
| inputStream: InputStream, | ||
| sourceMimeType: String, | ||
| targetExtension: String, | ||
| ): Pair<InputStream, String> { | ||
| val outStream = ByteArrayOutputStream() | ||
| val writers = ImageIO.getImageWritersBySuffix(targetExtension) | ||
| val writer = writers.next() | ||
| ImageIO.createImageOutputStream(outStream).use { o -> | ||
| writer.setOutput(o) | ||
|
|
||
| val inImage = | ||
| ConversionUtil.readImage(image.first, image.second) | ||
| ConversionUtil.readImage(inputStream, sourceMimeType) | ||
| ?: throw NoSuchElementException("No conversion to $targetExtension possible") | ||
| writer.write(inImage) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.