With kim 0.25, memory error
I upgraded to Kim 0.25, and now I'm getting a memory error on Android phones. I've gone back to 0.24, which is working fine for now.
I think it's Android InputStream Byte Reader for Android devices below 13. It works fine with my version, but you rejected it because it was taken from Kotlin.
java.lang.OutOfMemoryError: Failed to allocate a 402636816 byte allocation with 50331648 free bytes and 182MB until OOM, target footprint 261441248, growth limit 402653184
at com.ashampoo.kim.output.ByteArrayByteWriter.ensureCapacity(ByteArrayByteWriter.kt:56)
at com.ashampoo.kim.output.ByteArrayByteWriter.write(ByteArrayByteWriter.kt:34)
at com.ashampoo.kim.input.ByteReaderExtensionsKt.readRemainingBytes(ByteReaderExtensions.kt:164)
at com.ashampoo.kim.format.jpeg.JpegUtils.traverseJFIF(JpegUtils.kt:62)
at com.ashampoo.kim.format.jpeg.JpegRewriter.readSegments(JpegRewriter.kt:78)
at com.ashampoo.kim.format.jpeg.JpegRewriter.updateExifMetadataLossless(JpegRewriter.kt:113)
at com.ravenfeld.panoramax.baba.lib.ssot.impl.extension.KimExt.addTag(KimExt.kt:36)
at com.ravenfeld.panoramax.baba.lib.ssot.impl.api.SequenceApiImpl.addPhoto-gIAlu-s(SequenceApiImpl.kt:216)
at com.ravenfeld.panoramax.baba.feature.camera.data.repository.CameraRepositoryImpl.addPhoto(CameraRepositoryImpl.kt:40)
at com.ravenfeld.panoramax.baba.feature.camera.domain.usecase.OnTakenPhotoUseCase.invoke(OnTakenPhotoUseCase.kt:16)
Thanks for reporting this. I'll need to look into it.
A reproducible example would be really helpful if you have one. That's something I should add to my unit tests.
Regarding the Android source: I had to reject that copy due to an incompatible license. It's important for me to ensure this project remains under the Apache license so it can be used in closed-source commercial projects. I appreciate your understanding.
No problem, I understand perfectly. To reproduce this, I wanted to read a tag on an Android 12.
The stack trace suggests you tried to write something: updateExifMetadataLossless()
To investigate this further, can you share a sample photo and the specific call you made?
For the example photo it's any photo, since it was taken via the phone
As a reminder, here is the project where I use your library
https://gitlab.com/ravenfeld/baba
fun addTag(
byteReader: () -> ByteReader?,
byteWriter: () -> ByteWriter?,
block: (outputSet: TiffOutputSet) -> Unit
) {
val metadata = byteReader()?.let {
Kim.readMetadata(it)
} ?: return
val outputSet: TiffOutputSet = metadata.exif?.createOutputSet() ?: TiffOutputSet()
block(outputSet)
byteReader()?.let { byteReader ->
// Currently bug with Android >29 with the direct byteWriter (Kim 0.22.1)
val byteArrayByteWriter = ByteArrayByteWriter()
JpegRewriter.updateExifMetadataLossless(
byteReader = byteReader,
byteWriter = byteArrayByteWriter,
outputSet = outputSet
)
byteWriter()?.use { byteWriter ->
byteWriter.write(byteArrayByteWriter.toByteArray())
}
}
}