Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite committed Nov 18, 2024
1 parent a6c49e7 commit fcc1daa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit fcc1daa

Please sign in to comment.