a tool for clipping regions of interest based on a bitmap mask, which is commonly referred to as an atlas.
under the hood, I'm simply utilizing an OffscreenCanvas
with ctx.globalCompositeOperation = "source-in"
to clip
there are several ways of going about extracting masked regions of interest from an image.
but in general, you need 3 sets of information/data:
- source image
- can be anything accepted by
ctx.drawImage
(akaCanvasImageSource
)
- can be anything accepted by
- bitmap of mask
- can be anything accepted by
ctx.drawImage
(akaCanvasImageSource
) - can be either a boolean
Array
orUint8Array
of y-major stream of pixel data (px_data = [x0y0, x1y0, x2y0, ..., x0y1, x1y1, ...]
) - can be
scanlinedrawing instructions (TODO)
- can be anything accepted by
- offset position of mask
- [x, y, width, height] = [185, 184, 172, 258]
although clipping regions of interest is the fundamental functionality of this library, it is just a small portion of the codebase
much of the library provides an interface for managing clips asynchronously, converting from various input atlas formats to different various output atlas formats, and previewing clips on canvas asynchronously.
the source is written in Typescript
and the documentation is generated using TypeDoc
.
description | data |
---|---|
input source image | |
input juice bitmask | |
input mask rect coordinates | let rect = { x: 185, y: 184, width: 172, height: 258 } |
output extracted image |
- improve name consistency, especially the loadImage function of JAtlasManager and JAtlasManager.source
- make more
Promise<void>
functions return their important value rather than just signallyingundefined
- make an interactive HScroller
- design uncaching/deleting of
ClipMask.data_blob
- turn
ClipMask
orJAtlas
into a recursive/nestedJAtlasManager
, with the clipped parent image always being thesource
of the child/nestedJAtlas
clip - for web supported MIME image formats, don't put the MIME-text inside of
JAtlas.kind
, but rather keep it prepended toJAtlas.data
, and introduceJAtlas.kind = "mime" | "native" | "uri" | "data_uri" | "base64" | etc...
for natively supported web browser images - use
idat_codec_ts
to encode 1bit png clipmasks intoJAtlas.data
, because browsers are too stupid to realize the compressibility of bit-data. although webp might already do that, but the native webp encoding is not lossless, nor can you set an option for it to become lossless. But I have yet to see an artifacact from the lossy compression of webp, unlike jpg, where it was immediately clear at 75% quality encoding