Skip to content

Draft: Extend Pixmap to support strides and new pixel types - #187

Open
mstoeckl wants to merge 3 commits into
linebender:mainfrom
mstoeckl:stride
Open

mstoeckl wants to merge 3 commits into
linebender:mainfrom
mstoeckl:stride

Conversation

@mstoeckl

@mstoeckl mstoeckl commented Aug 30, 2026 •

Copy link
Copy Markdown

This eliminates the internal SubPixmapMut type, adds stride parameters to the Pixmap* types, and adds a PixelType parameter that can be used in the future to support new pixel types (like Rgba16F, or RgbaU16). This modifies and adds new methods for these parameters (and makes a usable form of ::subpixmap() public), but also removes methods like PixmapMut::pixels_mut() which embedded assumptions that no longer apply.

I've made Pixmap hold a dynamic PixelType instead of making the struct generic, because 1) the overhead of looking up the pixel type is negligible, and it's never done in hot code 2) this should help keep code size down 3) Skia's skPixmap does the same 4) my experience using the image crate is that encoding pixel types in the type system by default can make using the library awkward, especially when more generics get involved.)

Interpreting parts of a Mask as a "SubPixmapMut" was confusing because
SubPixmapMut (typically) has 4-byte pixels, while Mask uses 1-byte
pixels. The new GenericPixmapMut struct should also make it easier
to handle non-u8888 pixel formats in the future.
@mstoeckl mstoeckl changed the title Draft: Extend Pixmap to support strides and new pixel type Draft: Extend Pixmap to support strides and new pixel types Aug 30, 2026
This only implements a single pixel type (the current RgbaU8),
but introduces some stride alignment checks and match expressions
that should be useful when implementing this in the future.

Unfortunately the direct pixel access methods like pixels_mut() had to
be removed for the Pixmap to remain general over PixelType, and handle
strides which are not a multiple of the pixel byte size. While it
may be possible to add simple abstractions for efficient pixel and
row access, the logic for users to do this themselves with data_mut()
and bytemuck is not very complex.

The (currently inactive) constraints on pixel type alignment will
likely be needed to efficiently (in both time and code size) operate
on pixel types with higher bit depth.

This eliminates the internal SubPixmapMut type, and makes public
the power to construct lightweight views for rectangles of PixmapMut
and PixmapRef through their ::subpixmap methods.
This will be needed to allocate memory for future PixelTypes
which have alignment constraints.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant