https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

Stefan Oltmann

11/03/2023, 1:46 PM
I need some help with skiko:
Image.makeFromEncoded(myImageBytes)
uses the EXIF orientation to correctly rotate the image, which is all fine and well. In the case of my application I want an option to load it without orientation or to provide a custom one. The file might be accompanied with a sidecar XMP where the user specified another orientation than what was written into the file. I would be helpful if SKIA at least would have a flag what orientation the loaded image has. Now I would need to parse the file myself to find out.
1
k

Kirill Grouchnikov

11/03/2023, 1:53 PM
If it’s not available in Skia, it’s unlikely that it will be added in Skiko. https://github.com/Ashampoo/kim#read-metadata seems to give the info you’re looking for.
👍 1
s

Stefan Oltmann

11/03/2023, 1:54 PM
Yes, but it's an extra call and I may need to translate one tiff orientation to another. Seems easier to just load the image ignoring that flag. All I found is some discussion to load it as Bitmap, which ignores the flag, and convert it to an Image. But this API seems not to be available in skiko.
k

Kirill Grouchnikov

11/03/2023, 1:58 PM
If there’s a Skia API that is not in Skiko, the project owners are pretty receptive in getting PRs to add the missing bindings. I did that some time ago for shaders, and as long as it’s covered with tests, it should be easy to get in.
s

Stefan Oltmann

11/03/2023, 1:59 PM
Ok, thank you. I will look into that.
Okay, it's friday... 😅 This is way easier than I was thinking at the first place. I can use https://github.com/Ashampoo/kim/blob/main/src/commonMain/kotlin/com/ashampoo/kim/format/jpeg/JpegOrientationOffsetFinder.kt to locate the orientation byte in the byteArray and change that before I feed that into
Image.makeFromEncoded(myImageBytes)
😅
Copy code
val xmpOrientation: TiffOrientation = TiffOrientation.MIRROR_VERTICAL // TODO: load from XMP

            if (xmpOrientation != null) {

                val orientationOffset =
                    JpegOrientationOffsetFinder.findOrientationOffset(ByteArrayByteReader(bytesToUse))

                if (orientationOffset != null) {

                    bytesToUse[orientationOffset.toInt()] = xmpOrientation.value.toByte()

                } else {

                    val updatedBytes =
                        Kim.update(bytesToUse, setOf(MetadataUpdate.Orientation(xmpOrientation)))

                    bytesToUse = updatedBytes
                }
            }
I somehow doubt the team will do this, but I asked anyway. https://issues.skia.org/issues/309372890