I need some help with skiko: `Image.makeFromEncode...
# getting-started
s
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
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
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
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
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