decode JPG file
Closed this issue · 2 comments
oskarko commented
HI team!
Is there any way for decoding a JPG file with Spectrum just like mozjpeg does? I mean, just decode the file into rgb format, not compressing at all. Some example would be very appreciated. Thanks!
lambdapioneer commented
Hi @oskarko, absolutely!
Spectrum supports any combination of encoded/decoded images for the input and output. See: https://libspectrum.io/docs/supported_image_flows. For decoding you'll simply call spectrum.decode(...)
instead of spectrum.transcode(...)
.
You can e.g. check the Android sample app on how to do this:
private fun decode(): SpectrumResult {
val optionsBuilder = DecodeOptions.Builder()
applyModelToOptions(optionsBuilder)
val inputStream = context.contentResolver.openInputStream(transcodeViewModel.inputImageUri!!)
inputStream.use {
val bitmapTarget = BitmapTarget()
return spectrum.decode(
EncodedImageSource.from(inputStream),
bitmapTarget,
optionsBuilder.build(),
"caller_context_decode").also {
outputBitmap = bitmapTarget.bitmap
}
}
}
lambdapioneer commented
Closing here, as I haven't heard otherwise :)