Repository navigation
feat(ImageAsset): toNativeImage and toImageSource - #195
Merged
Merged
Conversation
`toNativeImageSync()` / `toNativeImage()` return the asset's pixels as the platform's image: an ARGB_8888 Bitmap on Android, a UIImage on iOS, a WriteableBitmap on Windows and a GdkTexture on Linux. `toImageSourceSync()` / `toImageSource()` wrap it in core's ImageSource. The async forms decode off the main thread; encoded assets are decoded for the call. - canvas-core: read_pixels_into / read_pixels_8888_into write the pixels in a requested 8-bit layout in one Skia conversion. - Android: nativeWriteToBitmap writes straight into the locked bitmap. - iOS: canvas_native_image_asset_read_pixels_8888 plus NSCImageAsset.toUIImage(Async). - Node-API: readPixels8888Into writes into a JS buffer (Windows: the WriteableBitmap's PixelBuffer); toGdkTexture(Sync) builds a GdkMemoryTexture on the GTK thread. Android was checked on an emulator: bitmaps match the canvas's pixels exactly for an opaque PNG and within 1 for an alpha PNG, sync and async. iOS type-checks against the generated header; Windows and Linux are not built here.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a way to get an
ImageAsset's pixels as the platform's own image type, e.g. to show them in an<Image>:It works for assets loaded from encoded data, which are decoded for the call, and for raw-pixel assets.
Bitmap(ARGB_8888)nativeWriteToBitmapwrites premultiplied RGBA straight into the locked bitmapUIImagecanvas_native_image_asset_read_pixels_8888, wrapped in aCGImage(sRGB, premultiplied)WriteableBitmapreadPixels8888Intowrites BGRA straight into itsPixelBufferGdkTexturepointer (what core'sImageSource.linuxholds)GdkMemoryTexturemade on the GTK thread; its reference is dropped once the JS pointer is collectedUnderneath,
canvas-coregainsread_pixels_into/read_pixels_8888_into: one Skia conversion into the requested 8-bit layout.The async forms keep the asset referenced until native code is done with its pointer. The Android callback holds only an id, like the loads since #192.
Testing
getImageDataexactly for an opaque PNG and within 1 (premultiply rounding) for a PNG with alpha, sync and async. A JPEG shows in a core<Image>throughtoImageSource().swiftc -typecheck, simulator SDK). The xcframework was not rebuilt and nothing was run.canvas_native.hgets the new declaration by hand in cbindgen's format (both copies); the iOS pre-build and the Android CMake build regenerate it.Not checked: whether core's Windows
ImageSourceaccepts aWriteableBitmap. It is a valid XAML image source, but core may assumeBitmapImage.