Pixel Data JS - v0.28.0
    Preparing search index...

    Class PixelWriter<M>

    const targ = new PixelData(new ImageData(10, 10))
    const writer = new PixelWriter(targ, (writer) => {
    return {
    ...mutatorApplyMask(writer),
    ...mutatorBlendPixelData(writer),
    ...mutatorBlendColor(writer),
    ...mutatorBlendPixel(writer),
    ...mutatorFill(writer),
    }
    })

    // to import all mutator functions
    const writer = new PixelWriter(targ, makeFullPixelMutator)

    writer.withHistory((mutator) => {
    mutator.applyMask()
    mutator.blendPixelData()
    })

    Type Parameters

    • M
    Index

    Constructors

    Properties

    accumulator: PixelAccumulator
    historyActionFactory: (
        config: PixelEngineConfig,
        accumulator: PixelAccumulator,
        patch: PixelPatchTiles,
        after?: () => void,
        afterUndo?: () => void,
        afterRedo?: () => void,
        applyPatchTilesFn?: (
            target: PixelData32,
            tiles: PixelTile[],
            tileSize: number,
        ) => void,
    ) => HistoryAction
    historyManager: HistoryManager
    mutator: M
    pixelTilePool: TilePool<PixelTile>

    Methods

    • Parameters

      • newWidth: number
      • newHeight: number
      • offsetX: number = 0
      • offsetY: number = 0
      • Optionalafter: (target: ImageData) => void
      • OptionalafterUndo: (target: ImageData) => void
      • OptionalafterRedo: (target: ImageData) => void
      • resizeImageDataFn: (
            target: ImageDataLike,
            newWidth: number,
            newHeight: number,
            offsetX?: number,
            offsetY?: number,
        ) => ImageData = resizeImageData
          • (
                target: ImageDataLike,
                newWidth: number,
                newHeight: number,
                offsetX?: number,
                offsetY?: number,
            ): ImageData
          • Non destructively resizes the ImageData buffer to new dimensions, optionally offsetting the original content. This operation creates a new buffer. It does not scale or stretch pixels; instead, it crops or pads the image based on the new dimensions and provides an offset for repositioning.

            Parameters

            • target: ImageDataLike

              The target to resize.

            • newWidth: number

              The target width in pixels.

            • newHeight: number

              The target height in pixels.

            • offsetX: number = 0

              The horizontal offset for placing the original image within the new buffer.

            • offsetY: number = 0

              The vertical offset for placing the original image within the new buffer.

            Returns ImageData

            A new ImageData instance with the specified dimensions.

            // Centers an 80x80 image in a new 100x100 buffer
            const resized = resizeImageData(
            originalData,
            100,
            100,
            10,
            10
            );

      Returns void

    • Executes transaction and commits the resulting pixel changes as a single undoable history action.

      • If transaction throws, all accumulated changes are rolled back and the error is re-thrown. No action is committed.
      • If transaction completes without modifying any pixels, no action is committed.
      • withHistory is not re-entrant. Calling it again from inside transaction will throw immediately to prevent silent data loss from a nested extractPatch.

      Parameters

      • transaction: (mutator: M) => void

        Callback to be executed inside the transaction.

      • Optionalafter: () => void

        Called after both undo and redo — use for generic change notifications.

      • OptionalafterUndo: () => void

        Called after undo only — use for dimension or state changes specific to undo.

      • OptionalafterRedo: () => void

        Called after redo only.

      Returns void