Skip to content
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

Images not cached when using custom Decoder #2539

Closed
suhaibroomy opened this issue Sep 21, 2020 · 2 comments
Closed

Images not cached when using custom Decoder #2539

suhaibroomy opened this issue Sep 21, 2020 · 2 comments
Labels

Comments

@suhaibroomy
Copy link

#2501 # Description

I am using a custom decoder for encrypted images. My Decoder decrypts the encrypted input stream and then decodes Images just like it is done in DefaultImageDecoder. I noticed that images fetched using this decoder are not saved in cache and is fetched from network every time. I would like to cache these images just like others

Reproduction

class MyImageDecoder(private val elementToDecrypt: ElementToDecrypt?) : ImageDecoder {

private val poolFactory: PoolFactory by inject(PoolFactory::class.java)

val defaultDecoder: DefaultImageDecoder by inject(DefaultImageDecoder::class.java)

override fun decode(
    encodedImage: EncodedImage,
    length: Int,
    qualityInfo: QualityInfo,
    options: ImageDecodeOptions
): CloseableImage {

    var decryptedInputStream: InputStream? = null
    var clearEncodedImage: EncodedImage? = null

    try {
        val inputStream = encodedImage.inputStream

        decryptedInputStream = elementToDecrypt?.let {
            DecryptStore.decryptStream(inputStream, elementToDecrypt)
        } ?: inputStream

        val bytes = poolFactory.pooledByteBufferFactory.newByteBuffer(decryptedInputStream)
        val bytesClosable = CloseableReference.of(bytes)
        clearEncodedImage = EncodedImage(bytesClosable)

        var imageFormat = encodedImage.imageFormat
        if (imageFormat == null || imageFormat === ImageFormat.UNKNOWN) {
            imageFormat =
                ImageFormatChecker.getImageFormat_WrapIOException(clearEncodedImage.inputStream)
            encodedImage.imageFormat = imageFormat
        }

        when {
            imageFormat === DefaultImageFormats.JPEG -> {
                return defaultDecoder.decodeJpeg(clearEncodedImage, length, qualityInfo, options)
            }
            imageFormat === DefaultImageFormats.GIF -> {
                return defaultDecoder.decodeGif(clearEncodedImage, length, qualityInfo, options)
            }
            imageFormat === DefaultImageFormats.WEBP_ANIMATED -> {
                return defaultDecoder.decodeAnimatedWebp(clearEncodedImage, length, qualityInfo, options)
            }
            imageFormat === ImageFormat.UNKNOWN -> {
                throw DecodeException("unknown image format", clearEncodedImage)
            }
            else -> {
                throw DecodeException("unknown image format", clearEncodedImage)
            }
        }
    } catch (ex: Exception) {
        Timber.e("Something went wrong decoding the image")
        throw ex
    } finally {
        decryptedInputStream?.close()
        clearEncodedImage?.close()
    }
}
}

Additional Information

  • Fresco version: 2.3.0
@stale
Copy link

stale bot commented Oct 4, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "bug" or "enhancement" and I will leave it open. Thank you for your contributions.

@stale stale bot added the stale label Oct 4, 2020
@stale
Copy link

stale bot commented Oct 11, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to reopen with up-to-date information.

@stale stale bot closed this as completed Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant