I have a custom decoder that uses Conceal to load encrypted images from local storage.
Everything works (images are displayed) but performance is terrible when loading local camera images since no downsampling or bitmap resizing is applied at all when the actual JPEG decoder does it work.
class CryptoImageDecoder(val crypto: Crypto, val poolFactory: PoolFactory) : ImageDecoder {
val defaultDecoder = DefaultImageDecoder(null,
Fresco.getImagePipelineFactory().platformDecoder,
Bitmap.Config.ARGB_8888)
override fun decode(encodedImage: EncodedImage,
length: Int,
qualityInfo: QualityInfo?,
options: ImageDecodeOptions?): CloseableImage {
encodedImage.use {
val inputStream = encodedImage.inputStream
inputStream.skip(CRYPTO_HEADER_BYTES.size.toLong()) //Skip header
val cipherInputStream = crypto.getCipherInputStream(inputStream, CRYPTO_ENTITY)
cipherInputStream.use {
val bytes = poolFactory.pooledByteBufferFactory.newByteBuffer(cipherInputStream)
val bytesClosable = CloseableReference.of(bytes)
val clearEncodedImage = EncodedImage(bytesClosable)
//This is always 1, no matter what resizeOptions I use in the request
//clearEncodedImage.sampleSize = how to calculate this?
clearEncodedImage.encodedCacheKey = encodedImage.encodedCacheKey
return defaultDecoder.decode(clearEncodedImage, bytes.size(), qualityInfo, options)
}
}
}
}
The way the request is done pretty straightforward
val request = ImageRequestBuilder.newBuilderWithSource(attachment.sourceImageUri)
.setSource(attachment.sourceImageUri)
.setResizeOptions(ResizeOptions.forSquareSize(300))
.build()
val controller = Fresco.newDraweeControllerBuilder()
.setOldController(holder.draweeView.controller)
.setImageRequest(request)
.build()
Why are resize options ignored, is there another option that I am missing for the decoder?