Create and update textures from BGRA, RGB, BGR and greyscale pixels with row padding - #460
Merged
Merged
Conversation
…pixels with row padding Adds PixelLayout (Rgba8, Bgra8, Rgb8, Bgr8, Gray8) and overloads CreateTexture(pixels, width, height, layout, rowStride = 0) and UpdateTexture(texture, pixels, width, height, layout, rowStride = 0), so an OpenCV Mat, a SkiaSharp bitmap or a Windows DIB can be uploaded as it sits in memory instead of being swizzled and repacked by the caller. Conversion to RGBA8 happens on the calling thread into a pooled buffer. Because Invoker.Invoke waits for its body, that buffer is handed to the window thread as is, so a converted update makes one pass over the pixels and no further copy on any thread. Tightly packed RGBA8 skips conversion. The update path is restructured around one private core that performs the in-place attempt and the recreate fallback inside a single Invoke, which both public overloads share. Refs #458 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PkBLq2ZjJSRADscJJf5A5D
|
This was referenced Sep 25, 2026
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.



Closes #458. Follow-up to #459.
CreateTexture/UpdateTextureonly accepted tightly packed RGBA8, so anything from OpenCV or SkiaSharp had to be swizzled and repacked by the caller first. This PR adds overloads that take the pixels as they sit in memory.API
PixelLayoutis named for byte order in memory.Bgra8is SkiaSharp'sBgra8888, OpenCV'sCV_8UC4and a Windows DIB.Bgr8is OpenCV's default three-channel order.Gray8coversCV_8UC1. Three-channel and grey sources get opaque alpha.rowStrideis bytes per row, for exampleMat.Step()orSKBitmap.RowBytes. 0 means tightly packed. The buffer only has to reach the end of the last row's pixels, so an OpenCV region of interest can be passed without copying it out first.PixelLayoutand notPixelFormat:ImGuiApp.csand most Silk.NET consumers also importSilk.NET.OpenGL.PixelFormat, soPixelFormatwould be ambiguous.How it works
Images/PixelConvertervalidates the source geometry and converts rows into a pooled RGBA8 buffer on the calling thread. Tightly packedRgba8skips conversion and goes through the existing zero-copy path.Invoker.Invokewaits for its body to finish, so the pooled buffer can be handed to the window thread as is. A converted update makes one pass over the pixels and no further copy, on any thread.UpdateTextureFromBuffer. It does the in-place attempt and the recreate fallback inside a singleInvoke, and both public overloads share it. Behaviour of the existing overload is unchanged, and its tests still pass as they were.Docs
ImGui.App/README.mdnow covers the layout overloads and the straight-alpha expectation. Its OpenCvSharp and SkiaSharp snippets passMat/SKBitmapmemory directly instead of converting first. The API tables in both READMEs and the key-file list inCLAUDE.mdare updated.Tests
PixelConverterTests(13): each layout, row padding, an unpadded last row, and validation of stride, length, dimensions and layout.ImGuiAppTests(7 new): converted create, in-place converted update,Rgba8pass-through, converted recreate on resize, worker-thread converted update reaching the backend on the invoker thread, and argument errors.ImGui.App.Tests471/471 andImGui.App.Testing.Tests95/95 pass. The full solution builds with 0 warnings in Release.Not in this PR
Sub-rectangle updates and a nearest/linear filter option would need new
IRendererBackendmembers, implemented across OpenGL, Metal and the software renderer. Left out until there's a concrete need.🤖 Generated with Claude Code
https://claude.ai/code/session_01PkBLq2ZjJSRADscJJf5A5D
Generated by Claude Code