From 64a805e0194357622ef7e18efc74d97a301ccdb3 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Wed, 28 Apr 2021 14:58:50 +0800 Subject: [PATCH] fix: add configuration to unload native webp library --- .../configuration/KomgaProperties.kt | 2 ++ .../infrastructure/image/ImageConverter.kt | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaProperties.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaProperties.kt index f31a853b8..a912fe0e1 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaProperties.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/configuration/KomgaProperties.kt @@ -18,6 +18,8 @@ class KomgaProperties { var rememberMe = RememberMe() + var nativeWebp: Boolean = true + var database = Database() class RememberMe { diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/image/ImageConverter.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/image/ImageConverter.kt index 27f95a614..1d480ee57 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/image/ImageConverter.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/image/ImageConverter.kt @@ -3,6 +3,7 @@ package org.gotson.komga.infrastructure.image import com.luciad.imageio.webp.WebP import mu.KotlinLogging import net.coobird.thumbnailator.Thumbnails +import org.gotson.komga.infrastructure.configuration.KomgaProperties import org.springframework.stereotype.Service import java.awt.Color import java.awt.image.BufferedImage @@ -14,7 +15,9 @@ import javax.imageio.spi.ImageReaderSpi private val logger = KotlinLogging.logger {} @Service -class ImageConverter { +class ImageConverter( + private val komgaProperties: KomgaProperties, +) { val supportedReadFormats by lazy { ImageIO.getReaderFormatNames().toList() } val supportedReadMediaTypes by lazy { ImageIO.getReaderMIMETypes().toList() } @@ -35,12 +38,19 @@ class ImageConverter { } as ImageReaderSpi? if (nativeWebp != null) { - if (!WebP.loadNativeLibrary()) { - logger.warn { "Could not load native WebP library" } - registry.deregisterServiceProvider(nativeWebp) - } else if (javaWebp != null) { - logger.info { "Using native WebP library" } - registry.setOrdering(ImageReaderSpi::class.java, nativeWebp, javaWebp) + when { + !komgaProperties.nativeWebp -> { + logger.warn { "Unloading native WebP library" } + registry.deregisterServiceProvider(nativeWebp) + } + !WebP.loadNativeLibrary() -> { + logger.warn { "Could not load native WebP library" } + registry.deregisterServiceProvider(nativeWebp) + } + javaWebp != null -> { + logger.info { "Using native WebP library" } + registry.setOrdering(ImageReaderSpi::class.java, nativeWebp, javaWebp) + } } }