-
Notifications
You must be signed in to change notification settings - Fork 63
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
Serialize BufferedImages as base64 #694
Conversation
This commit introduces toBase64() and encodeGzip() methods for ByteArray and image resizing methods for BufferedImage.
The commit introduces an ImageEncodingOptions class which controls how images are encoded when serializing a DataFrame to JSON with metadata. These options include whether to encode images as Base64, a size limit for resizing images, and an optional GZIP compression.
The default kotlin kernel renderer in the Kotlin Notebook plugin serializes images in their original dimensions, potentially causing an OOM exception. This commit overrides the default renderer to prevent such issues.
core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io/writeJson.kt
Outdated
Show resolved
Hide resolved
core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/Integration.kt
Outdated
Show resolved
Hide resolved
core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/json.kt
Outdated
Show resolved
Hide resolved
* Refactored image encoding logic for DataFrame serialization. * Removed custom renderer for buffered images as it affects rendering of single image objects
Introduced a configuration option to conditionally downsize BufferedImages in the HTML renderer. This mitigates potential memory problems by resizing images according to the provided DisplayConfiguration, specifically affecting the output of dataframes in the Kotlin Notebook plugin.
This commit introduces ImageSerializationTests for validating image base64 encoding. Additionally, a utility function has been added to Utils.kt to parse string into JsonObject for tests.
Developed a mechanism to enable or disable ImageViewer based on the current IDE version in the JupyterHtmlRenderer.
...erated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/ImageSerializationTests.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
In the ImageSerializationTests class, the method 'checkImagesEncodedAsStrings' has been renamed to 'checkImagesEncodedAsToString'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ermolenkodev wow these tests are very heavy! It takes my laptop about 2 full minutes to run just these ones.
Could you make the images like waaay smaller? Like 0.5KB or smaller instead of 2-4MB?
Fixes #675