From fcc1daa1d477599e0a7b6b897d48f7cb43f52d99 Mon Sep 17 00:00:00 2001 From: Colin White Date: Sun, 17 Nov 2024 18:04:38 -0800 Subject: [PATCH] Fix tests. --- ...ceptor.kt => EngineInterceptor.android.kt} | 1 - .../coil3/intercept/EngineInterceptor.kt | 67 ++++++++++--------- ...tor.kt => EngineInterceptor.nonAndroid.kt} | 0 3 files changed, 35 insertions(+), 33 deletions(-) rename coil-core/src/androidMain/kotlin/coil3/intercept/{EngineInterceptor.kt => EngineInterceptor.android.kt} (97%) rename coil-core/src/nonAndroidMain/kotlin/coil3/intercept/{EngineInterceptor.kt => EngineInterceptor.nonAndroid.kt} (100%) diff --git a/coil-core/src/androidMain/kotlin/coil3/intercept/EngineInterceptor.kt b/coil-core/src/androidMain/kotlin/coil3/intercept/EngineInterceptor.android.kt similarity index 97% rename from coil-core/src/androidMain/kotlin/coil3/intercept/EngineInterceptor.kt rename to coil-core/src/androidMain/kotlin/coil3/intercept/EngineInterceptor.android.kt index 74fd1d403..c04482e18 100644 --- a/coil-core/src/androidMain/kotlin/coil3/intercept/EngineInterceptor.kt +++ b/coil-core/src/androidMain/kotlin/coil3/intercept/EngineInterceptor.android.kt @@ -7,7 +7,6 @@ import coil3.asDrawable import coil3.intercept.EngineInterceptor.Companion.TAG import coil3.request.Options import coil3.request.bitmapConfig -import coil3.request.transformations import coil3.size.Precision import coil3.transform.Transformation import coil3.util.DrawableUtils diff --git a/coil-core/src/commonMain/kotlin/coil3/intercept/EngineInterceptor.kt b/coil-core/src/commonMain/kotlin/coil3/intercept/EngineInterceptor.kt index ea4a007d6..2241834e4 100644 --- a/coil-core/src/commonMain/kotlin/coil3/intercept/EngineInterceptor.kt +++ b/coil-core/src/commonMain/kotlin/coil3/intercept/EngineInterceptor.kt @@ -13,6 +13,8 @@ import coil3.decode.FileImageSource import coil3.fetch.FetchResult import coil3.fetch.ImageFetchResult import coil3.fetch.SourceFetchResult +import coil3.intercept.EngineInterceptor.Companion.TAG +import coil3.intercept.EngineInterceptor.ExecuteResult import coil3.memory.MemoryCacheService import coil3.request.ImageRequest import coil3.request.ImageResult @@ -143,7 +145,7 @@ internal class EngineInterceptor( } // Apply any transformations and prepare to draw. - val finalResult = transform(executeResult, request, options, eventListener) + val finalResult = transform(executeResult, request, options, eventListener, logger) finalResult.image.prepareToDraw() return finalResult } @@ -216,37 +218,6 @@ internal class EngineInterceptor( ) } - private suspend fun transform( - result: ExecuteResult, - request: ImageRequest, - options: Options, - eventListener: EventListener, - ): ExecuteResult { - val transformations = request.transformations - if (transformations.isEmpty()) { - return result - } - - // Skip the transformations as converting to a bitmap is disabled. - val image = result.image - if (image is BitmapImage && !request.allowConversionToBitmap) { - logger?.log(TAG, Logger.Level.Info) { - val type = result.image::class.simpleName - "allowConversionToBitmap=false, skipping transformations for type $type." - } - return result - } - - // Apply the transformations. - val input = convertImageToBitmap(image, options, transformations, logger) - eventListener.transformStart(request, input) - val output = transformations.foldIndices(input) { bitmap, transformation -> - transformation.transform(bitmap, options.size).also { coroutineContext.ensureActive() } - } - eventListener.transformEnd(request, output) - return result.copy(image = output.asImage()) - } - data class ExecuteResult( val image: Image, val isSampled: Boolean, @@ -259,6 +230,38 @@ internal class EngineInterceptor( } } +internal suspend fun transform( + result: ExecuteResult, + request: ImageRequest, + options: Options, + eventListener: EventListener, + logger: Logger?, +): ExecuteResult { + val transformations = request.transformations + if (transformations.isEmpty()) { + return result + } + + // Skip the transformations as converting to a bitmap is disabled. + val image = result.image + if (image is BitmapImage && !request.allowConversionToBitmap) { + logger?.log(TAG, Logger.Level.Info) { + val type = result.image::class.simpleName + "allowConversionToBitmap=false, skipping transformations for type $type." + } + return result + } + + // Apply the transformations. + val input = convertImageToBitmap(image, options, transformations, logger) + eventListener.transformStart(request, input) + val output = transformations.foldIndices(input) { bitmap, transformation -> + transformation.transform(bitmap, options.size).also { coroutineContext.ensureActive() } + } + eventListener.transformEnd(request, output) + return result.copy(image = output.asImage()) +} + /** Convert [image] to a [Bitmap]. */ internal expect fun convertImageToBitmap( image: Image, diff --git a/coil-core/src/nonAndroidMain/kotlin/coil3/intercept/EngineInterceptor.kt b/coil-core/src/nonAndroidMain/kotlin/coil3/intercept/EngineInterceptor.nonAndroid.kt similarity index 100% rename from coil-core/src/nonAndroidMain/kotlin/coil3/intercept/EngineInterceptor.kt rename to coil-core/src/nonAndroidMain/kotlin/coil3/intercept/EngineInterceptor.nonAndroid.kt